# High-Level Architecture Design (HLD) — Universal Enterprise Platform | Field | Value | |---|---| | **Document** | `hld.md` | | **System** | Universal Enterprise Platform (UEP) | | **Pattern** | Modular Monolith with Multi-Tenant Row-Level Security | | **Version** | 1.0.0 | | **Status** | Baselined (Elaboration Phase) | --- ## 1. System Architecture Topology ```mermaid graph TD ClientWeb["Web Portals (React + Vite + Tailwind)"] --> NGINX["API Gateway / Reverse Proxy (NGINX)"] ClientMobile["Mobile Apps / External Consumers"] --> NGINX NGINX --> AuthFilter["Auth & Tenant Context Middleware"] AuthFilter --> Keycloak["Identity Provider (Keycloak OIDC)"] subgraph Modular Monolith Core AuthFilter --> ModAuth["IAM / Auth Module (LLD-001)"] AuthFilter --> ModDomain["Core Business Modules"] AuthFilter --> ModIntegration["Integration & Sandboxes"] end ModAuth --> PG[("PostgreSQL DB (with RLS)")] ModDomain --> PG ModAuth --> Valkey[("Valkey / Redis (Token Blacklist & Cache)")] ``` --- ## 2. Core Architectural Pillars 1. **Multi-Tenancy via Row-Level Security:** Every domain table carries a `tenant_id` UUID column. When requests arrive, the Auth Middleware extracts `tenant_id` from the verified JWT and sets `SET LOCAL app.current_tenant = ''` on the database session connection pool. 2. **Deterministic Wave 0 Sandboxing:** All external third-party integrations (payment gateways, identity verification, SMS/email) implement an abstract adapter with a local deterministic mock under `app/integrations/sandbox/`. 3. **Pluggable Event Stream:** Inter-module communication executes via in-process domain event dispatchers that can scale out to message queues (RabbitMQ / Kafka) as needed.