# 00-team/heydari architecture

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

- Interactive diagram: https://gitdiagram.com/00-team/heydari
- Repository: https://github.com/00-team/heydari

## Overview

##### Project type and purpose
- This is a full-stack web application named “Heydari”
- Two UIs:
– Admin portal (React/TSX SPA built with Vite)
– Public website (TypeScript + SCSS site built with Webpack)
- Backend in Rust (single binary) exposing RESTful APIs, rendering templates, handling business logic, and talking to an SQLite database

##### File structure
- Top-level directories:
– admin/ (React components, layout, shared utilities, SCSS styles, Vite config via vite.config.ts)
– web/ (public site scripts and styles, Webpack configuration via webpack.config.js)
– src/ (Rust code: main.rs, web.rs, api modules, admin modules, models, migrations, templates)
– templates/ (server-side HTML templates for public pages)
– config/ (deployment scripts, systemd service file, nginx.conf)
– migrations/ (SQL schema)
– CI/CD: .github/workflows/deploy.yml

##### Extract architecture hints from README
- Some admin-privilege tooling via direct SQL

##### Main components
a. Client browsers:
– Admin SPA (served from static assets after Vite build)
– Public website SPA and server-rendered pages (Webpack build + server templates)
b. Reverse proxy / web server (NGINX) – serves static assets, proxies API calls to the Rust backend
c. Rust backend service – single process hosting:
– HTTP API endpoints (src/api/*.rs)
– Admin module logic (src/admin/*.rs)
– Template rendering (templates/) and static file serving (static/)
– Utility modules (utils.rs, config.rs)
d. SQLite database (main.db managed via migrations/)
e. CI/CD pipeline (GitHub Actions) – builds front-ends, compiles Rust, deploys via deploy.sh

##### Relationships & data flows
- Client → NGINX:
– “GET /admin” & assets → serves built SPA files
– “GET /” & other routes → serves templated pages or web SPA bundles
– “GET /static/*” → static resources (fonts, images, rapidoc.js)
– “POST/GET /api/*” → proxy to Rust backend
- NGINX → Rust backend: handles all dynamic API request routing
- Rust backend ↔ SQLite: read/write user, product, order, tag, material, blog data
- Rust backend → template engine → HTML views (for pages not entirely SPA-driven)
- GitHub Actions → on push to main:
– Build & test Rust code
– Build admin (Vite) & public (Webpack) bundles
– Run deploy.sh on target server
– Reload NGINX & systemd service (heydari.service)

##### Architectural patterns & design principles
- Clear separation of concerns:
– UI layer (admin SPA vs. public site)
– API layer (Rust modules in src/api)
– Business logic & models (src/models, src/admin, src/general)
– Data access via SQLite + migrations
- SPAs for rich interactions in admin, static + light templating for public site
- Reverse proxy for SSL termination, static-file caching, and API forwarding
- Infrastructure-as-code: nginx.conf, systemd service, deploy scripts

##### Technologies & frameworks
- Rust (backend): tokio/async runtime, web framework (e.g., Rocket or Actix)
- SQLite (database)
- TypeScript + React (admin SPA) with Vite
- TypeScript + Vanilla JS (public site) with Webpack
- SCSS for styling
- NGINX for HTTP server & reverse proxy
- GitHub Actions for CI/CD

##### Putting it all together
– Static asset bucket (static/)
– SPA bundles (admin/, web/)
– API endpoints (Rust service)
- Off to the side, illustrate CI/CD flow: GitHub Actions → build artifacts → deploy.sh → target server → NGINX & Rust service reload
– Blue for front-end
– Green for backend logic
– Orange for data stores
– Gray for infra/dev-ops

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        AdminUI["Admin SPA\n(React/TSX + Vite)"]:::frontend
        PublicUI["Public Website\n(TypeScript + SCSS + Webpack)"]:::frontend
    end

    %% Reverse Proxy
    NGINX["NGINX Reverse Proxy"]:::backend

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        RustService["Rust Backend Service\n(REST API, Templates, Business Logic)"]:::backend
        Templates["Server-side Templates\n(Handlebars/HTML)"]:::backend
        StaticAssets["Static Assets\n(fonts, images, rapidoc.js)"]:::backend
    end

    %% Data Store
    SQLiteDB["SQLite Database\n(main.db)"]:::datastore
    Migrations["SQL Migrations\n(migrations/)"]:::datastore

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        CI["GitHub Actions\n(.github/workflows/deploy.yml)"]:::infra
        DeployScripts["Deploy Scripts & Config\n(config/deploy.sh,\nnginx.conf, heydari.service)"]:::infra
    end

    %% Connections - Clients to Proxy
    AdminUI -->|"GET /admin & assets"| NGINX
    PublicUI -->|"GET / & assets"| NGINX
    PublicUI -->|"GET /static/*"| NGINX
    AdminUI -->|"GET /static/*"| NGINX

    %% Proxy to Backend
    NGINX -->|"Proxy /api/*"| RustService
    NGINX -->|"Serve Static"| StaticAssets
    NGINX -->|"Render Pages"| Templates

    %% Backend to DB and Templates
    RustService -->|"Read/Write Data"| SQLiteDB
    RustService -->|"Run Migrations"| Migrations
    RustService -->|"Render Templates"| Templates

    %% Infra CI/CD Flow
    CI -->|"Build & Test Rust"| RustService
    CI -->|"Build Admin SPA"| AdminUI
    CI -->|"Build Public Site"| PublicUI
    CI -->|"Trigger Deploy"| DeployScripts
    DeployScripts -->|"Deploy & Reload"| NGINX
    DeployScripts -->|"Deploy & Reload"| RustService

    %% Click Events
    click AdminUI "https://github.com/00-team/heydari/tree/main/admin/"
    click PublicUI "https://github.com/00-team/heydari/tree/main/web/"
    click RustService "https://github.com/00-team/heydari/tree/main/src/"
    click Templates "https://github.com/00-team/heydari/tree/main/templates/"
    click StaticAssets "https://github.com/00-team/heydari/tree/main/static/"
    click Migrations "https://github.com/00-team/heydari/tree/main/migrations/"
    click CI "https://github.com/00-team/heydari/blob/main/.github/workflows/deploy.yml"
    click DeployScripts "https://github.com/00-team/heydari/blob/main/config/deploy.sh"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366D6,color:#000
    classDef backend fill:#D0FFD6,stroke:#28A745,color:#000
    classDef datastore fill:#FFE0B3,stroke:#FF8C00,color:#000
    classDef infra fill:#E3E3E3,stroke:#AAAAAA,color:#000
```
