# adilmunawar/aditrondev architecture

> Architecture diagram of the GitHub repository adilmunawar/aditrondev, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adilmunawar/aditrondev
- Repository: https://github.com/adilmunawar/aditrondev

## Overview

##### Project type and purpose
- From the README and file tree, this is a full‑stack, TypeScript‑based web chat application.
- The front end is a React + Vite SPA (pages, components, hooks, utils).
- The back end is “Backend‑as‑a‑Service” via Supabase: Auth, Postgres DB, Realtime subscriptions, plus Edge Functions for OTP login.

##### File structure
- Top‐level artifacts:
- index.html, vite.config.ts, tailwind.config.ts → static build & styling setup
- src/ → React application code (pages, components, ui library, hooks, integrations, utils)
- supabase/ → Supabase project config and serverless functions (send‑otp, verify‑otp)
- Patterns:
- Component hierarchy under src/components for UI (auth, chat, ui primitives)
- Integration folder (supabase client & types) abstracts BaaS interactions
- Utility modules for chat business logic
- Edge functions under supabase/functions act as custom “backend” endpoints

##### Key architecture insights from README
- No dedicated Node/Express server; uses Supabase as back end
- Standard install & build via npm/Yarn, deployed as static assets + Supabase functions

a. Main components
- Browser / React SPA
– UI Layer: pages + components (Splash, AuthForm, Chat UI, Profile, etc.)
– Domain Logic: custom hooks (useMobile, useToast), utils (chat helpers)
– Integration Layer: Supabase client (src/integrations/supabase/client.ts)
- Supabase Cloud
– Auth Service (phone login, 2FA)
– Database (Postgres; user, chat, message, OTP tables)
– Realtime Engine (WebSocket/pub‑sub on messages table)
– Edge Functions (send‑otp, verify‑otp)
- External SMS Provider (Twilio or similar) – invoked by Edge Functions
- Hosting/CDN – serves the static SPA assets

b. Relationships & interactions
1. Browser → Hosting/CDN: GET index.html & JS bundle
2. Browser → Supabase Auth: request session or JWT
3. Browser → Edge Function (send‑otp): POST phone → Function writes OTP to DB & calls SMS API
4. Browser → Edge Function (verify‑otp): POST code → Function validates & returns JWT
5. Browser → Supabase DB: authenticated REST/GraphQL calls to read/write chats, contacts, groups
6. Browser ↔ Supabase Realtime: WebSocket subscription to new messages/events
7. Edge Functions → External SMS Provider: send OTP SMS

c. Architectural patterns & design principles
- Layered separation: UI, business logic (hooks/utils), data/integration
- BaaS + Serverless (Edge functions) avoids traditional backend servers
- Event‑driven realtime updates (pub/sub on message table)
- Composition over inheritance in UI (atomic ui components)

d. Relevant technologies & frameworks
- React (TSX), Vite, Tailwind CSS for front end
- Supabase (Auth, Postgres, Realtime, Edge Functions)
- TypeScript throughout
- Utility libraries under src/lib and src/utils

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef client fill:#e0ffe0,stroke:#00aa00
    classDef service fill:#e0f0ff,stroke:#0066cc
    classDef db fill:#e0f0f0,stroke:#0066cc
    classDef external fill:#f0f0f0,stroke:#888888

    Browser["Browser / React SPA"]:::client

    subgraph "React SPA (src/)"
        direction TB
        Pages["Pages (src/pages)"]:::client
        Components["Components (src/components)"]:::client
        Hooks["Hooks (src/hooks)"]:::client
        ChatUtils["Chat Utilities (src/utils/chat)"]:::client
        subgraph "Integration Layer"
            direction TB
            SupClient["Supabase Client"]:::service
            SupTypes["Supabase Types"]:::service
        end
    end

    Hosting["Hosting/CDN\n(index.html, vite.config.ts, tailwind.config.ts)"]:::external

    subgraph "Supabase Cloud"
        direction TB
        Auth["Auth Service"]:::service
        DB["Postgres DB"]:::db
        Realtime["Realtime Engine"]:::service
        subgraph "Edge Functions"
            direction TB
            SendOTP["send-otp"]:::service
            VerifyOTP["verify-otp"]:::service
            SQLUtil["Create Phone Verification Table\n(sql)"]:::service
        end
    end

    ExternalSMS["External SMS Provider"]:::external

    Browser -->|"GET static assets"| Hosting
    Browser -->|"Auth request /session"| Auth
    Browser -->|"REST calls (chat CRUD)"| DB
    Browser -->|"WebSocket subscribe"| Realtime
    Browser -->|"POST /send-otp"| SendOTP
    Browser -->|"POST /verify-otp"| VerifyOTP
    SendOTP -->|"write OTP"| DB
    SendOTP -->|"call SMS API"| ExternalSMS
    VerifyOTP -->|"validate OTP"| DB
    SQLUtil -->|"defines table"| DB

    click Pages "https://github.com/adilmunawar/aditrondev/tree/main/src/pages"
    click Components "https://github.com/adilmunawar/aditrondev/tree/main/src/components"
    click Hooks "https://github.com/adilmunawar/aditrondev/tree/main/src/hooks"
    click ChatUtils "https://github.com/adilmunawar/aditrondev/tree/main/src/utils/chat"
    click SupClient "https://github.com/adilmunawar/aditrondev/blob/main/src/integrations/supabase/client.ts"
    click SupTypes "https://github.com/adilmunawar/aditrondev/blob/main/src/integrations/supabase/types.ts"
    click SendOTP "https://github.com/adilmunawar/aditrondev/blob/main/supabase/functions/send-otp/index.ts"
    click VerifyOTP "https://github.com/adilmunawar/aditrondev/blob/main/supabase/functions/verify-otp/index.ts"
    click SQLUtil "https://github.com/adilmunawar/aditrondev/blob/main/supabase/functions/_utils/sql/create_phone_verification_table.sql"
    click Hosting "https://github.com/adilmunawar/aditrondev/blob/main/index.html"
    click Hosting "https://github.com/adilmunawar/aditrondev/blob/main/vite.config.ts"
    click Hosting "https://github.com/adilmunawar/aditrondev/blob/main/tailwind.config.ts"
```
