# Role & Context
You are a World-Class Software Architect and Principal AI Engineer. [cite_start]Your mission is to build a sovereign, enterprise-grade, and hyper-intelligent Real Estate Valuation, Analytics, and Anti-Monopoly Ecosystem for "Ninth Cloud Real Estate" (شركة السحابة التاسعة للعقارات).

The system targets the Saudi Arabian real estate market, enforcing strict data compliance with Saudi Real Estate Authority (REGA) and Ministry of Justice (MOJ) frameworks, utilizing cutting-edge spatial computing, automated mitigation of speculative manipulation, and high-frequency data streaming.

# Advanced Tech Stack
* **Frontend & Spatial Mobile:** Flutter (Dart) - Ultra-responsive web dashboard & mobile applications optimized with custom shaders and hardware-accelerated mapping.
* **Backend & Spatial Database:** Supabase (PostgreSQL with PostGIS, pgvector for AI semantic search, Edge Functions in Deno, Realtime WebSockets, Row-Level Security).
* **Hosting, Edge & Edge Compute:** Netlify (for distributed Flutter Web hosting, configuring proxy routing, edge redirects, and global cache optimization).

---

# Architecture & Engineering Guidelines

## 1. Zero-Hardcoding & Immutable Multi-Language (Arabic/English)
* **Enforcement Pattern:** The application must refuse compilation if any unlocalized string is detected in the presentation layer. Use strict custom lint rules (`flutter_lints` coupled with strict `invalid_annotation_target`).
* **Localization Structure:** Implement dual-language configuration using `.arb` templates natively natively in Flutter (`lib/l10n/app_ar.arb` as primary, `lib/l10n/app_en.arb` as secondary). Every API payload, notification, layout orientation (RTL/LTR handling via custom context extensions), and log field must dynamically match the runtime locale context.

## 2. Advanced Algorithmic Valuation & PostGIS Spatial Mesh Engine
You must implement a multi-factored spatial valuation engine mapping the dynamic real estate reality:
* **Dynamic Land Value Formula:**
    $$Land\_Value = Total\_Area \times Base\_District\_Price \times Size\_Elasticity\_Factor$$ [cite: 6]
* **Non-Linear Dimension Sizing:** If $Total\_Area > 600\text{ sqm}$ within high-density residential zones, dynamically apply a diminishing factor reducing the `Size_Elasticity_Factor` by **5% to 12%** [cite: 7] to reflect actual liquidation velocity and diminishing marginal utility[cite: 4, 7]. Separately compute structural value factoring linear depreciation ($Depreciation\_Rate = \frac{Age}{Useful\_Life}$)[cite: 4, 21].
* **Micro-Market Grid Clustering (500m × 500m):** Use PostGIS spatial indexing (`ST_MakeGrid`) to segment neighborhoods into strict macro-micro blocks[cite: 9]. Value is generated from a rolling window of the last 5 verified transactions [cite: 9] adjusted instantly by:
    * **Street Width & Facade Vectoring:** Properties on commercial streets or having North/East exposures receive an exact **+8% value multiplier** [cite: 10] compared to matching South/West exposures[cite: 10].
    * **Geographical/Structural Coherence:** Cross-reference properties with localized topological contours to automatically penalize prices near rocky terrains, cliff drop-offs, or sabkha (salt flats)[cite: 11].

## 3. Real-Time High-Frequency Ingestion & Reliability Matrix
[cite_start]The Supabase architecture must maintain a real-time transactional registry connecting 3 primary channels[cite: 13, 14]:
1.  [cite_start]**Sovereign Real Estate Exchange API (MOJ):** Real-time webhooks, immutable transaction hashes, 100% data weight (Confidence Core)[cite: 14].
2.  [cite_start]**Ejar National Integration:** Monthly batch and streaming pipelines extracting localized residential/commercial rental yield baselines (95% Confidence Score)[cite: 14].
3.  [cite_start]**Cross-Platform Automated Scrapers:** Continuous daily extraction filtering duplicated postings, verifying broker license IDs against REGA standards, evaluating raw asking prices (60% Confidence Score, isolated to speculative tracking tables)[cite: 14].

## 4. "Speculation Premium & Market Disruption" Interactive Dashboard
Create a highly visual UI engine in Flutter featuring a premium, high-contrast Dark Mode theme designed for investment analysis.
* [cite_start]**Visual Data Contrast:** Compute and render the **True Value** [cite: 19] (Real MOJ transactions + construction cost matrices + PostGIS spatial coefficients) [cite_start][cite: 21] [cite_start]vs. **Broker Target Ask** [cite: 20] (Inflated broker pricing matrices) [cite_start][cite: 22].
* [cite_start]**The Speculation Gap Index:** Visually highlight the "Speculation Premium" (e.g., "+14.5% Speculative Premium borne by the buyer without engineering justification") [cite: 23] through real-time charts (Bezier curve graphs, financial delta meters).

## 5. Algorithmic Data Cleansing & Anti-Whale Sanitization
Inject automatic data sanitization triggers inside Supabase/PostgreSQL before data points hit the AI valuation pipeline:
* [cite_start]**Intra-Family / Gift Exclusion Rule:** Automatically isolate, flag, or discard any property transaction executing at **< 40%** of its micro-market grid's 30-day moving average[cite: 26]. [cite_start]Label these as "Non-Arm's Length / Gift Transactions"[cite: 26].
* [cite_start]**Monopolistic Block Trading Exclusion:** Identify and quarantine bulk synchronized purchases (e.g., massive speculative block/plot land buyouts) to protect the consumer indexing engine from synthetic price spikes[cite: 27].

---

# Implementation & Code Generation Steps

### Step 1: Database Architecture (Supabase & PostGIS SQL Migration)
Write the complete production SQL file:
* Enable `postgis`, `postgis_topology`, and `pgvector`.
* Create tables: `districts`, `micro_grids`, `properties`, `transactions`, `ingestion_logs` with columns accounting for localized translations (using JSONB or explicit `_ar` / `_en` suffix).
* Implement Row-Level Security (RLS) keeping client data secure while public analytics remain readable.
* [cite_start]Write the PostgreSQL trigger function executing the Family/Gift Filter [cite: 26] [cite_start]and Monopoly Filter [cite: 27] automatically.

### Step 2: Internationalization Architecture & Core State Management
* Provide a production-ready folder layout matching clean code architectures.
* Generate samples of `app_ar.arb` and `app_en.arb` featuring terms like `truePrice`, `speculationGap`, and `valuationEngine`.
* Write the Flutter state manager (using Riverpod or BLoC) that intercepts locale switching, updates the global layout system, and enforces RTL/LTR responsiveness seamlessly.

### Step 3: Core Flutter Screens & Visual Speculation Widgets
* Write code for a dashboard view utilizing custom multi-layered layouts.
* [cite_start]Implement a complex "True Price vs Broker Ask" interactive card component featuring custom painters or precise progress widgets showing the speculation premium[cite: 15, 16].
* Generate an advanced property form utilizing reactive inputs, ensuring geolocation parameters map smoothly to PostGIS coordinates via native calls.

Ensure the code is robust, strictly typed, explicitly documented, and ready for deployment on Netlify and Supabase infrastructures under Ninth Cloud Real Estate branding. Let's begin by generating **Step 1** and **Step 2**.