graph TB
    subgraph "Client Tier"
        SPA["React SPA<br/>(Vite + TypeScript)"]
    end

    subgraph "Application Tier"
        API["FastAPI Backend<br/>(Python 3.11+)"]
        WS["WebSocket Server<br/>(/ws/analyze)"]
        REST["REST API<br/>(/api/*)"]
    end

    subgraph "AI Services"
        GEMINI["Google Gemini<br/>2.5 Flash"]
        LLAMA["LlamaParse<br/>(Document Parsing)"]
    end

    subgraph "Authentication"
        AZURE["Azure AD<br/>(MSAL)"]
    end

    subgraph "Data Tier"
        PG["PostgreSQL<br/>(asyncpg)"]
        FS["File Storage<br/>(Local Disk)"]
    end

    SPA -->|"HTTPS"| REST
    SPA -->|"WSS"| WS
    SPA -->|"MSAL Auth"| AZURE
    API --- WS
    API --- REST
    REST -->|"SQLAlchemy Async"| PG
    WS -->|"SQLAlchemy Async"| PG
    REST -->|"Read/Write"| FS
    WS -->|"Store Files"| FS
    API -->|"Gemini API"| GEMINI
    API -->|"Parse PDFs"| LLAMA
    AZURE -.->|"JWT Verify"| API

    classDef client fill:#006DE3,stroke:#1A2142,color:#fff
    classDef app fill:#1A2142,stroke:#006DE3,color:#fff
    classDef ai fill:#01A1A2,stroke:#1A2142,color:#fff
    classDef auth fill:#7A0FF9,stroke:#1A2142,color:#fff
    classDef data fill:#C3FB5A,stroke:#1A2142,color:#1A2142

    class SPA client
    class API,WS,REST app
    class GEMINI,LLAMA ai
    class AZURE auth
    class PG,FS data
