# ibrahem-io/dga-v4 architecture

> Architecture diagram of the GitHub repository ibrahem-io/dga-v4, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ibrahem-io/dga-v4
- Repository: https://github.com/ibrahem-io/dga-v4

## Overview

##### Project type and purpose
- This is a full-stack, single-page application built with React/TypeScript and Vite.
- It uses Netlify for hosting static assets and serverless functions, Supabase as the backend database/auth provider, and an external LLM service for AI analysis.
- The app appears to support file uploads, role-based dashboards (auditor, ministry, supervisor), and an AI-powered audit wizard.

##### File structure
- Top level:
- netlify.toml + netlify/functions – serverless backend (api-auth.ts, api-llm.ts)
- supabase/migrations – database schema migrations
- src – React front-end code under Vite (App.tsx, components/, services/, contexts/)
- Configuration: package.json, tsconfig*, vite.config.ts, tailwind.config.js, postcss.config.js, eslint.config.js
- src/services
- supabase.ts wraps Supabase client
- api.ts and enhancedApiService.ts abstract calls to netlify functions
- aiAnalysisService.ts calls the OpenAI or LLM endpoint
- submissionService.ts handles saving/uploading audit submissions
- src/components – UI broken out by feature (login, dashboards per role, wizard steps, file upload, chat, debug panels)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CI/CD & Configuration
    subgraph "CI/CD & Configuration"
        NetlifyBuild["Netlify Build & Deploy"]:::ci
        Migrations["Supabase Migrations"]:::ci
        NetlifyConfig["netlify.toml"]:::config
        ViteConfig["vite.config.ts"]:::config
        TailwindConfig["tailwind.config.js"]:::config
    end
    NetlifyBuild --> Migrations
    NetlifyBuild -->|uses| NetlifyConfig
    NetlifyBuild -->|builds with| ViteConfig
    NetlifyBuild -->|styles with| TailwindConfig

    %% CDN & Hosting
    NetlifyBuild --> CDN["CDN & Static Hosting"]:::backend
    CDN -->|serves assets| SPA

    %% Client Side
    subgraph "Browser (Client)" 
        direction TB
        SPA["React SPA"]:::frontend
        AuthContext["AuthContext Provider"]:::frontend
        subgraph "UI Components"
            direction TB
            LoginForm["LoginForm"]:::frontend
            RoleSelector["RoleSelector"]:::frontend
            FileUpload["FileUpload"]:::frontend
            WizardSteps["WizardSteps"]:::frontend
            Chat["Chat Interface"]:::frontend
            DebugPanel["Debug Panel"]:::frontend
            AuditorDashboard["AuditorDashboard"]:::frontend
            EnhancedAuditorDashboard["EnhancedAuditorDashboard"]:::frontend
            MinistryDashboard["MinistryDashboard"]:::frontend
            SupervisorDashboard["SupervisorDashboard"]:::frontend
        end
        subgraph "Client Services"
            direction TB
            SupabaseWrapper["Supabase Client"]:::service
            ApiGateway["API Service"]:::service
            EnhancedApi["Enhanced API Service"]:::service
            SubmissionService["Submission Service"]:::service
            AiService["AI Analysis Service"]:::service
        end
    end

    %% Serverless Backend
    subgraph "Netlify Serverless Functions"
        direction TB
        ApiAuth["API-Auth Function"]:::backend
        ApiLLM["API-LLM Function"]:::backend
    end

    %% Data & External
    SupabaseDB["Supabase (Postgres + Auth)"]:::db
    OpenAI["OpenAI / LLM API"]:::external

    %% Client to Services
    SPA -->|provides context to| AuthContext
    SPA -->|renders| LoginForm
    SPA -->|renders| RoleSelector
    SPA -->|renders| FileUpload
    SPA -->|renders| WizardSteps
    SPA -->|renders| Chat
    SPA -->|renders| DebugPanel
    SPA -->|renders| AuditorDashboard
    SPA -->|renders| EnhancedAuditorDashboard
    SPA -->|renders| MinistryDashboard
    SPA -->|renders| SupervisorDashboard

    %% Services interactions
    AuthContext -->|uses| SupabaseWrapper
    SupabaseWrapper -->|connects to| SupabaseDB
    SubmissionService -->|calls| ApiGateway
    AiService -->|calls| ApiGateway
    EnhancedApi -->|wraps| ApiGateway
    ApiGateway -->|invokes| ApiAuth
    ApiGateway -->|invokes| ApiLLM

    %% Functions to Data & External
    ApiAuth -->|queries| SupabaseDB
    ApiLLM -->|queries| SupabaseDB
    ApiLLM -->|forwards to| OpenAI

    %% CI/CD to Database
    Migrations -->|runs on deploy| SupabaseDB

    %% Click Events
    click SPA "https://github.com/ibrahem-io/dga-v4/blob/main/src/main.tsx"
    click SPA "https://github.com/ibrahem-io/dga-v4/blob/main/src/App.tsx"
    click LoginForm "https://github.com/ibrahem-io/dga-v4/blob/main/src/components/LoginForm.tsx"
    click RoleSelector "https://github.com/ibrahem-io/dga-v4/blob/main/src/components/RoleSelector.tsx"
    click FileUpload "https://github.com/ibrahem-io/dga-v4/blob/main/src/components/FileUpload.tsx"
    click WizardSteps "https://github.com/ibrahem-io/dga-v4/blob/main/src/components/WizardSteps.tsx"
    click Chat "https://github.com/ibrahem-io/dga-v4/blob/main/src/components/Chat.tsx"
    click DebugPanel "https://github.com/ibrahem-io/dga-v4/blob/main/src/components/DebugPanel.tsx"
    click AuditorDashboard "https://github.com/ibrahem-io/dga-v4/blob/main/src/components/auditor/AuditorDashboard.tsx"
    click EnhancedAuditorDashboard "https://github.com/ibrahem-io/dga-v4/blob/main/src/components/auditor/EnhancedAuditorDashboard.tsx"
    click MinistryDashboard "https://github.com/ibrahem-io/dga-v4/blob/main/src/components/ministry/MinistryDashboard.tsx"
    click SupervisorDashboard "https://github.com/ibrahem-io/dga-v4/blob/main/src/components/supervisor/SupervisorDashboard.tsx"
    click AuthContext "https://github.com/ibrahem-io/dga-v4/blob/main/src/contexts/AuthContext.tsx"
    click SupabaseWrapper "https://github.com/ibrahem-io/dga-v4/blob/main/src/services/supabase.ts"
    click ApiGateway "https://github.com/ibrahem-io/dga-v4/blob/main/src/services/api.ts"
    click EnhancedApi "https://github.com/ibrahem-io/dga-v4/blob/main/src/services/enhancedApiService.ts"
    click SubmissionService "https://github.com/ibrahem-io/dga-v4/blob/main/src/services/submissionService.ts"
    click AiService "https://github.com/ibrahem-io/dga-v4/blob/main/src/services/aiAnalysisService.ts"
    click ApiAuth "https://github.com/ibrahem-io/dga-v4/blob/main/netlify/functions/api-auth.ts"
    click ApiLLM "https://github.com/ibrahem-io/dga-v4/blob/main/netlify/functions/api-llm.ts"
    click Migrations "https://github.com/ibrahem-io/dga-v4/blob/main/supabase/migrations/20250715054610_ancient_castle.sql"
    click NetlifyConfig "https://github.com/ibrahem-io/dga-v4/blob/main/netlify.toml"
    click ViteConfig "https://github.com/ibrahem-io/dga-v4/blob/main/vite.config.ts"
    click TailwindConfig "https://github.com/ibrahem-io/dga-v4/blob/main/tailwind.config.js"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:1px
    classDef backend fill:#9ff,stroke:#333,stroke-width:1px
    classDef service fill:#ff9,stroke:#333,stroke-width:1px
    classDef db fill:#ffd,stroke:#333,stroke-width:1px
    classDef external fill:#9f9,stroke:#333,stroke-width:1px
    classDef ci fill:#ddf,stroke:#333,stroke-width:1px
    classDef config fill:#dfd,stroke:#333,stroke-width:1px
```
