# ninobaw/aero-doc-flow-enfidha architecture

> Architecture diagram of the GitHub repository ninobaw/aero-doc-flow-enfidha, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ninobaw/aero-doc-flow-enfidha
- Repository: https://github.com/ninobaw/aero-doc-flow-enfidha

## Overview

##### Project Type & Purpose
- This is a full-stack web application (monorepo) for document and process management (actions, correspondances, reports, QR code lifecycles, etc.).
- Frontend: a React + TypeScript SPA built with Vite, Tailwind CSS, and shadcn-ui.
- Backend: a Node.js/Express REST API; data is stored in a Supabase (PostgreSQL) database.

##### High-Level Components
A. Frontend Service
- Vite Dev Server / Static Host
- React App (src/main.tsx → App.tsx)
- Feature modules (src/pages, src/components, src/contexts, src/hooks, src/shared)
- UI library: shadcn-ui + Tailwind CSS (tailwind.config.ts)
B. Backend Service
- Node.js + Express (backend/src/server.js)
- Routes layer (backend/src/routes/*.js/.ts)
- Data models (backend/src/models/*.js)
- Database connection (backend/src/db.js)
- Seed script (backend/src/seed.js)
C. Database
- Supabase-hosted PostgreSQL (configured via supabase/config.toml)
- Tables mirror models: User, Document, Correspondance, Action, Report, etc.
D. External & Infra Tools
- Supabase CLI (migrations & config)
- Environment (.env)
- Deployment (Lovable platform, custom domain)

##### Component Relationships & Data Flow
1. Browser requests index.html → Vite serves the SPA
2. React components (pages/hooks) invoke HTTP calls (fetch/Axios) →
3. Node/Express API endpoints (auth, user, document, actionRoutes, etc.) →
4. db.js issues SQL queries to Supabase PostgreSQL →
5. Responses travel back up to React, updating UI via contexts/hooks.

##### Architectural Patterns & Design Principles
- Monorepo structure: /src (frontend) + /backend (API) in one repo.
- MVC-ish backend: Models (in /models), Controllers (in /routes), and a single server.js.
- Component-driven UI: atomic and feature components in /components + custom hooks in /hooks.
- Context for global state (AuthContext).
- Clear separation: UI vs. business logic vs. persistence.
- Use of TypeScript typings (src/types, tsconfig files).

##### Final Advice
- Every top-level directory as a sub-component (e.g., src/pages vs. src/components).
- Files end-to-end: App.tsx → authRoutes.js → User model → users table.
- Don’t over-optimize: more components and clear data flows trump minimalism here.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Service"
        direction TB
        Vite["Vite Dev Server / Static Host"]:::frontend
        ReactApp["React App Entry Point\n(src/main.tsx → src/App.tsx)"]:::frontend
        Pages["Pages Module\n(src/pages)"]:::frontend
        Components["Components Module\n(src/components)"]:::frontend
        Contexts["Contexts Module\n(src/contexts/AuthContext.tsx)"]:::frontend
        Hooks["Hooks Module\n(src/hooks)"]:::frontend
        Shared["Shared Utilities & Types\n(src/shared)"]:::frontend
        UILib["UI Library (shadcn-ui + Tailwind CSS)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Service"
        direction TB
        Server["Server Initialization\n(backend/src/server.js)"]:::backend
        Routes["Routes Layer\n(backend/src/routes)"]:::backend
        Models["Data Models\n(backend/src/models)"]:::backend
        DBConn["Database Connection\n(backend/src/db.js)"]:::backend
        Seed["Seed Script\n(backend/src/seed.js)"]:::backend
    end

    %% Database
    subgraph "Database (Supabase PostgreSQL)"
        direction TB
        DB[(Tables: User, Document, Correspondance, Action, Report)]:::db
    end

    %% External & Infra
    subgraph "External & Infra Tools"
        direction TB
        SupabaseCLI["Supabase CLI\n(migrations & config)"]:::infra
        Env["Environment Config\n(backend/.env)"]:::infra
        Deployment["Deployment\n(Lovable platform, custom domain)"]:::infra
    end

    %% Data Flows
    Browser["Browser"]:::external
    Browser -->|"HTTP GET / SPA"| Vite
    Vite -->|"serves index.html"| ReactApp
    ReactApp -->|"REST calls: /api/auth, /api/documents, ..."| Server
    Server -->|"routes requests"| Routes
    Routes -->|"uses models"| Models
    Routes -->|"calls DB client"| DBConn
    DBConn -->|"SQL queries via Supabase client"| DB
    DB -->|"query results"| DBConn
    DBConn -->|"responses"| Routes
    Routes -->|"JSON responses"| ReactApp

    %% External Tools Relations
    Server -->|"reads env vars"| Env
    DBConn -->|"reads supabase config"| SupabaseCLI
    Deployment -.-> Vite
    Deployment -.-> Server

    %% Click events
    click Vite "https://github.com/ninobaw/aero-doc-flow-enfidha/blob/main/vite.config.ts"
    click ReactApp "https://github.com/ninobaw/aero-doc-flow-enfidha/blob/main/src/main.tsx"
    click Pages "https://github.com/ninobaw/aero-doc-flow-enfidha/tree/main/src/pages"
    click Components "https://github.com/ninobaw/aero-doc-flow-enfidha/tree/main/src/components"
    click Contexts "https://github.com/ninobaw/aero-doc-flow-enfidha/blob/main/src/contexts/AuthContext.tsx"
    click Hooks "https://github.com/ninobaw/aero-doc-flow-enfidha/tree/main/src/hooks"
    click Shared "https://github.com/ninobaw/aero-doc-flow-enfidha/tree/main/src/shared"
    click UILib "https://github.com/ninobaw/aero-doc-flow-enfidha/tree/main/src/components/ui"
    click Server "https://github.com/ninobaw/aero-doc-flow-enfidha/blob/main/backend/src/server.js"
    click Routes "https://github.com/ninobaw/aero-doc-flow-enfidha/tree/main/backend/src/routes"
    click Models "https://github.com/ninobaw/aero-doc-flow-enfidha/tree/main/backend/src/models"
    click DBConn "https://github.com/ninobaw/aero-doc-flow-enfidha/blob/main/backend/src/db.js"
    click Seed "https://github.com/ninobaw/aero-doc-flow-enfidha/blob/main/backend/src/seed.js"
    click SupabaseCLI "https://github.com/ninobaw/aero-doc-flow-enfidha/blob/main/supabase/config.toml"
    click Env "https://github.com/ninobaw/aero-doc-flow-enfidha/blob/main/backend/.env"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#038CFC,color:#000;
    classDef backend fill:#DFFFE0,stroke:#28A745,color:#000;
    classDef db fill:#FFE4B5,stroke:#FF8C00,color:#000;
    classDef infra fill:#E0E0E0,stroke:#888888,color:#000;
    classDef external fill:#FFFFFF,stroke:#000000,color:#000;
```
