# gehariharan/zahav architecture

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

- Interactive diagram: https://gitdiagram.com/gehariharan/zahav
- Repository: https://github.com/gehariharan/zahav

## Overview

##### Project type and purpose
- This is a full‑stack web application called “Zahav” for precious metals trading and booking.
- The backend is a FastAPI service exposing RESTful endpoints for authentication, pricing, bookings, alerts, user management, and shipment tracking.
- The frontend is a React single‑page application offering dashboards, forms, charts, and user workflows.
- There are Docker and Docker Compose recipes for containerized development, plus CI/E2E test workflows.

##### File structure
- Top‑level “app/” holds two main modules:
- backend/ — Python FastAPI service
– app/main.py: entry point
– app/routes: REST endpoints (auth, users, bookings, prices, alerts)
– app/models + app/db: SQLAlchemy models & DB session
– app/utils: JWT auth helpers
– migrations/: Alembic scripts
– init_db.py: bootstrap sample data
- frontend/ — React app
– public/: static HTML/CSS/manifest assets
– src/: React UI (components, pages, contexts, styles, utils)
– tests/: Playwright E2E specs and unit tests
– package.json, Dockerfile
- docker-compose.yml at app/ root orchestrates services (backend, frontend, database)
- CI workflows under .github/workflows run end-to-end tests.

##### README for additional insights
- Technology stack: FastAPI, SQLAlchemy, React, Axios, Chart.js, JWT.
- Deployment options: local via batch scripts or Docker Compose.
- External integrations: SMTP/SMS/push for rate alerts, currency feeds, market news.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Legend
    subgraph "Legend"
        direction TB
        A[Frontend/UI]:::frontend
        B[Backend/API]:::backend
        C[(Database)]:::data
        D[External Service]:::external
        E[CI/CD Pipeline]:::ci
    end

    %% User Browser
    Browser["User Browser"]:::frontend

    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        ReactApp["React App (3000)"]:::frontend
        indexJs["src/index.js"]:::frontend
        Components["src/components/"]:::frontend
        Pages["src/pages/"]:::frontend
        AuthContext["AuthContext.js"]:::frontend
        BookingContext["BookingContext.js"]:::frontend
        UtilsApi["apiHealth.js"]:::frontend
        UtilsDebounce["debounce.js"]:::frontend
        FrontTests["tests/"]:::frontend
        FrontDockerfile["Dockerfile"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        FastAPI["FastAPI API (8000)"]:::backend
        MainPy["app/main.py"]:::backend
        subgraph "Routes"
            direction TB
            AuthRoute["auth.py"]:::backend
            UsersRoute["users.py"]:::backend
            BookingsRoute["bookings.py"]:::backend
            PricesRoute["prices.py"]:::backend
            AlertsRoute["alerts.py"]:::backend
        end
        subgraph "Models & DB"
            direction TB
            UserModel["user.py"]:::backend
            BookingModel["booking.py"]:::backend
            PriceModel["price.py"]:::backend
            AlertModel["alert.py"]:::backend
            DatabaseSession["database.py"]:::backend
        end
        AuthUtils["auth.py (JWT Utils)"]:::backend
        Migrations["migrations/"]:::backend
        InitDB["init_db.py"]:::backend
        BackTests["tests/"]:::backend
        BackDockerfile["Dockerfile"]:::backend
    end

    %% Data Layer
    Database[(PostgreSQL)]:::data

    %% External Services
    subgraph "External Services"
        direction TB
        SMTP["SMTP/Email Provider"]:::external
        SMS["SMS API"]:::external
        Push["Push Notification API"]:::external
        MarketData["Market Data Feed"]:::external
    end

    %% CI/CD
    CICD["GitHub Actions (E2E Tests)"]:::ci

    %% Connections
    Browser -->|"HTTP/HTTPS"| ReactApp
    ReactApp -->|"REST (Axios)"| FastAPI
    FastAPI -->|"CRUD (SQLAlchemy)"| Database
    FastAPI -->|"Migrations"| Migrations
    FastAPI -->|"Bootstrap"| InitDB
    FastAPI -->|"SMTP/Webhook"| SMTP
    FastAPI -->|"SMS API"| SMS
    FastAPI -->|"Push API"| Push
    FastAPI -->|"Market Data API"| MarketData
    CICD -->|"Docker Compose Up"| ReactApp
    CICD -->|"Docker Compose Up"| FastAPI
    CICD -->|"Run Playwright"| FrontTests
    CICD -->|"Run pytest"| BackTests

    %% Click Events Frontend
    click ReactApp "https://github.com/gehariharan/zahav/tree/main/app/frontend/"
    click indexJs "https://github.com/gehariharan/zahav/blob/main/app/frontend/src/index.js"
    click Components "https://github.com/gehariharan/zahav/tree/main/app/frontend/src/components/"
    click Pages "https://github.com/gehariharan/zahav/tree/main/app/frontend/src/pages/"
    click AuthContext "https://github.com/gehariharan/zahav/blob/main/app/frontend/src/context/AuthContext.js"
    click BookingContext "https://github.com/gehariharan/zahav/blob/main/app/frontend/src/context/BookingContext.js"
    click UtilsApi "https://github.com/gehariharan/zahav/blob/main/app/frontend/src/utils/apiHealth.js"
    click UtilsDebounce "https://github.com/gehariharan/zahav/blob/main/app/frontend/src/utils/debounce.js"
    click FrontTests "https://github.com/gehariharan/zahav/tree/main/app/frontend/tests/"
    click FrontDockerfile "https://github.com/gehariharan/zahav/tree/main/app/frontend/Dockerfile"

    %% Click Events Backend
    click FastAPI "https://github.com/gehariharan/zahav/blob/main/app/backend/app/main.py"
    click AuthRoute "https://github.com/gehariharan/zahav/blob/main/app/backend/app/routes/auth.py"
    click UsersRoute "https://github.com/gehariharan/zahav/blob/main/app/backend/app/routes/users.py"
    click BookingsRoute "https://github.com/gehariharan/zahav/blob/main/app/backend/app/routes/bookings.py"
    click PricesRoute "https://github.com/gehariharan/zahav/blob/main/app/backend/app/routes/prices.py"
    click AlertsRoute "https://github.com/gehariharan/zahav/blob/main/app/backend/app/routes/alerts.py"
    click UserModel "https://github.com/gehariharan/zahav/blob/main/app/backend/app/models/user.py"
    click BookingModel "https://github.com/gehariharan/zahav/blob/main/app/backend/app/models/booking.py"
    click PriceModel "https://github.com/gehariharan/zahav/blob/main/app/backend/app/models/price.py"
    click AlertModel "https://github.com/gehariharan/zahav/blob/main/app/backend/app/models/alert.py"
    click DatabaseSession "https://github.com/gehariharan/zahav/blob/main/app/backend/app/db/database.py"
    click AuthUtils "https://github.com/gehariharan/zahav/blob/main/app/backend/app/utils/auth.py"
    click Migrations "https://github.com/gehariharan/zahav/tree/main/app/backend/migrations/"
    click InitDB "https://github.com/gehariharan/zahav/blob/main/app/backend/init_db.py"
    click BackDockerfile "https://github.com/gehariharan/zahav/tree/main/app/backend/Dockerfile"

    %% Click Events Orchestration & CI
    click DockerCompose "https://github.com/gehariharan/zahav/blob/main/app/docker-compose.yml"
    click CICD "https://github.com/gehariharan/zahav/blob/main/.github/workflows/e2e-tests.yml"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#1E90FF,color:#000
    classDef backend fill:#DFFFE0,stroke:#2E8B57,color:#000
    classDef data fill:#FFE5B4,stroke:#FF8C00,color:#000
    classDef external fill:#F0F0F0,stroke:#A9A9A9,color:#000
    classDef ci fill:#E8D0FF,stroke:#9370DB,color:#000
```
