# salf423/expresat architecture

> Architecture diagram of the GitHub repository salf423/expresat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/salf423/expresat
- Repository: https://github.com/salf423/expresat

## Overview

1. **Overall shape**
   - ExpresaT is split into a **browser client**, a **Python inference backend**, and a **model artifact/training layer**.
   - The main runtime path is optimized for **real-time sign-language translation on CPU**, with the browser handling capture/UI and the backend handling model inference.

2. **Modern frontend (`expresat/frontend`)**
   - This is the active client app, built with **Vite + React**.
   - It is organized into:
     - `pages/` for route-level screens such as Home, Translator, Learn, Auth, and About
     - `components/` for shared UI like Navbar, Footer, ThemeToggle, and EnvironmentSelector
     - `services/` for API/auth/media-pipeline integration
     - `context/` for cross-app state such as theme
   - Architecturally, this is the user-facing shell that drives camera capture, auth flows, and translation interaction.

3. **Real-time capture and preprocessing boundary**
   - The frontend contains a `mediapipeEngine` service, which indicates **client-side pose/hand landmark extraction using MediaPipe**.
   - That means the browser is not just rendering UI; it also performs the first stage of signal processing before data is sent onward.
   - This keeps the system edge-friendly by offloading vision preprocessing to the client instead of requiring a GPU server.

4. **Backend (`expresat/backend`)**
   - The backend is a **FastAPI** service launched with `uvicorn`.
   - Its key role is to manage **API endpoints and WebSocket connections** for low-latency, bidirectional communication.
   - `websockets_handler.py` suggests a dedicated real-time channel, likely used for streaming landmarks/features and returning translated text.

5. **Inference layer (`expresat/models`)**
   - The ML subsystem is separated from the web app and contains:
     - `train_and_export.py` for training and exporting
     - `inference.py` and `inference_engine.py` for production inference logic
     - exported model artifacts under `exported_model/`
   - The architecture clearly distinguishes **training-time PyTorch code** from **production inference code**.

6. **Model artifacts and deployment format**
   - The checked-in artifacts include:
     - a **PyTorch model** (`.pt`)
     - an **ONNX model** (`.onnx` + `.onnx.data`)
     - `model_metadata.json`
   - This indicates the production path uses **ONNX Runtime** for fast CPU inference, while PyTorch is retained for training/export workflows.
   - The metadata file likely stores label mappings, preprocessing parameters, or model configuration needed at runtime.

7. **End-to-end data flow**
   - The expected pipeline is:
     - user opens the React frontend
     - browser captures camera input
     - MediaPipe extracts hand/pose signals
     - features are sent over API/WebSocket to the backend
     - backend runs ONNX-based inference
     - translated text is streamed back to the UI
   - This is a classic **streaming, low-latency inference loop**, not a batch or request/response-only architecture.

8. **Legacy frontend (`expresat/frontend-legacy`)**
   - There is also a complete older static frontend built with **HTML/CSS/vanilla JS**.
   - It contains its own `api_service.js`, `auth_service.js`, `mediapipe_engine.js`, and UI logic, which suggests it once served the same product goals before the React rewrite.
   - For architecture diagrams, treat this as a **legacy presentation layer** rather than the current primary client.

9. **Authentication and persistence boundary**
   - The presence of `supabase/schema.sql` indicates a backend data layer designed around **Supabase-managed database/auth**.
   - The frontend’s `authService` modules in both generations suggest user/session handling is part of the product, even if the primary value is real-time translation.
   - This is the main persistence boundary in an otherwise mostly stateless streaming system.

10. **Deployment and hosting**
   - `netlify.toml` and the static frontend structure point to the frontend being deployable as a **static site**.
   - The backend is separately deployable as a Python service.
   - This implies a split deployment model: **static frontend hosting plus an API/WebSocket backend**.

11. **Documentation and operational guidance**
   - `docs/BACKEND_TECHNICAL_SPEC.md` and `docs/deploy.md` indicate the repository is intended to be understood and deployed as a system, not just a codebase.
   - The docs likely describe the inference contract, websocket protocol, and deployment assumptions that are central to the architecture diagram.

12. **Recommended diagram boundaries**
   - A good architecture diagram should show four boxes:
     - **Browser client**: React/Vite frontend + MediaPipe + UI
     - **Realtime backend**: FastAPI + WebSockets
     - **ML inference**: ONNX Runtime model assets and inference engine
     - **Data/auth layer**: Supabase schema/auth, if used in the current flow
   - Add a separate side box for **legacy static frontend** if you want to reflect repository history, but keep it visually distinct from the active path.

Main entry points: [`expresat/frontend/src/services`](https://github.com/salf423/expresat/tree/main/expresat/frontend/src/services) (Client services), [`expresat/frontend/src/App.jsx`](https://github.com/salf423/expresat/blob/main/expresat/frontend/src/App.jsx) (Frontend app), [`expresat/backend/main.py`](https://github.com/salf423/expresat/blob/main/expresat/backend/main.py) (Backend app), [`expresat/models/inference_engine.py`](https://github.com/salf423/expresat/blob/main/expresat/models/inference_engine.py) (Inference engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_frontend["Browser client"]
  node_n_frontend_app["Frontend app<br/>Vite React shell<br/>[App.jsx]"]
  node_n_frontend_pages["Pages<br/>Route screens"]
  node_n_frontend_components["UI components<br/>Shared UI"]
  node_n_frontend_services["Client services<br/>API/media layer"]
  node_n_frontend_context(("Theme state<br/>App context<br/>[ThemeContext.jsx]"))
  node_n_frontend_media{{"MediaPipe<br/>Client vision<br/>[mediapipeEngine.js]"}}
end

subgraph group_g_backend["Realtime backend"]
  node_n_backend_main["Backend app<br/>FastAPI entrypoint<br/>[main.py]"]
  node_n_backend_ws["WebSocket handler<br/>Realtime channel"]
end

subgraph group_g_models["ML inference"]
  node_n_models_infer_engine["Inference engine<br/>Runtime wrapper"]
  node_n_models_infer["Inference<br/>Model runtime<br/>[inference.py]"]
  node_n_models_train["Train/export<br/>Training pipeline"]
  node_n_models_artifacts[("Model artifacts<br/>ONNX/PyTorch")]
end

subgraph group_g_legacy["Legacy client"]
  node_n_legacy_app["Legacy app<br/>Static site<br/>[index.html]"]
  node_n_legacy_media{{"Legacy MediaPipe<br/>Client vision"}}
  node_n_legacy_api["Legacy services<br/>API/auth layer<br/>[api_service.js]"]
end

subgraph group_g_data["Data/auth"]
  node_n_data_schema["Supabase schema<br/>Auth/data schema<br/>[schema.sql]"]
end

node_n_docs["Docs"]

node_n_frontend_app -->|"renders"| node_n_frontend_pages
node_n_frontend_app -->|"uses"| node_n_frontend_components
node_n_frontend_app -->|"reads state"| node_n_frontend_context
node_n_frontend_pages -->|"calls"| node_n_frontend_services
node_n_frontend_services -->|"preprocesses"| node_n_frontend_media
node_n_frontend_services -->|"api calls"| node_n_backend_main
node_n_frontend_services -->|"streams"| node_n_backend_ws
node_n_backend_main -->|"mounts"| node_n_backend_ws
node_n_backend_main -->|"loads"| node_n_models_infer_engine
node_n_backend_ws -->|"invokes"| node_n_models_infer_engine
node_n_models_infer_engine -->|"executes"| node_n_models_infer
node_n_models_infer_engine -->|"reads"| node_n_models_artifacts
node_n_models_train -->|"produces"| node_n_models_artifacts
node_n_frontend_services -->|"auth/persist"| node_n_data_schema
node_n_legacy_app -->|"uses"| node_n_legacy_api
node_n_legacy_app -->|"uses"| node_n_legacy_media
node_n_legacy_api -->|"auth/persist"| node_n_data_schema
node_n_docs -.->|"documents"| node_n_backend_main
node_n_docs -.->|"documents"| node_n_frontend_app

click node_n_frontend_app "https://github.com/salf423/expresat/blob/main/expresat/frontend/src/App.jsx"
click node_n_frontend_pages "https://github.com/salf423/expresat/tree/main/expresat/frontend/src/pages"
click node_n_frontend_components "https://github.com/salf423/expresat/tree/main/expresat/frontend/src/components"
click node_n_frontend_services "https://github.com/salf423/expresat/tree/main/expresat/frontend/src/services"
click node_n_frontend_context "https://github.com/salf423/expresat/blob/main/expresat/frontend/src/context/ThemeContext.jsx"
click node_n_frontend_media "https://github.com/salf423/expresat/blob/main/expresat/frontend/src/services/mediapipeEngine.js"
click node_n_backend_main "https://github.com/salf423/expresat/blob/main/expresat/backend/main.py"
click node_n_backend_ws "https://github.com/salf423/expresat/blob/main/expresat/backend/websockets_handler.py"
click node_n_models_infer_engine "https://github.com/salf423/expresat/blob/main/expresat/models/inference_engine.py"
click node_n_models_infer "https://github.com/salf423/expresat/blob/main/expresat/models/inference.py"
click node_n_models_train "https://github.com/salf423/expresat/blob/main/expresat/models/train_and_export.py"
click node_n_models_artifacts "https://github.com/salf423/expresat/tree/main/expresat/models/exported_model"
click node_n_data_schema "https://github.com/salf423/expresat/blob/main/expresat/supabase/schema.sql"
click node_n_legacy_app "https://github.com/salf423/expresat/blob/main/expresat/frontend-legacy/index.html"
click node_n_legacy_media "https://github.com/salf423/expresat/blob/main/expresat/frontend-legacy/js/mediapipe_engine.js"
click node_n_legacy_api "https://github.com/salf423/expresat/blob/main/expresat/frontend-legacy/js/api_service.js"
click node_n_docs "https://github.com/salf423/expresat/tree/main/expresat/docs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_frontend_app,node_n_frontend_pages,node_n_frontend_components,node_n_frontend_services,node_n_frontend_context,node_n_frontend_media toneBlue
class node_n_backend_main,node_n_backend_ws toneAmber
class node_n_models_infer_engine,node_n_models_infer,node_n_models_train,node_n_models_artifacts toneMint
class node_n_legacy_app,node_n_legacy_media,node_n_legacy_api toneRose
class node_n_data_schema toneIndigo
class node_n_docs toneNeutral
```

## Components

### Browser client

Active React/Vite UI and client-side capture pipeline

- [Frontend app](https://github.com/salf423/expresat/blob/main/expresat/frontend/src/App.jsx): Vite React shell · Active browser application entry and route composition · `expresat/frontend/src/App.jsx`
- [Pages](https://github.com/salf423/expresat/tree/main/expresat/frontend/src/pages): Route screens · Home, Translator, Learn, Auth, and About screens · `expresat/frontend/src/pages`
- [UI components](https://github.com/salf423/expresat/tree/main/expresat/frontend/src/components): Shared UI · Navbar, footer, theme toggle, and environment selector · `expresat/frontend/src/components`
- [Client services](https://github.com/salf423/expresat/tree/main/expresat/frontend/src/services): API/media layer · API, auth, and MediaPipe integration services · `expresat/frontend/src/services`
- [Theme state](https://github.com/salf423/expresat/blob/main/expresat/frontend/src/context/ThemeContext.jsx): App context · Cross-app UI state such as theme · `expresat/frontend/src/context/ThemeContext.jsx`
- [MediaPipe](https://github.com/salf423/expresat/blob/main/expresat/frontend/src/services/mediapipeEngine.js): Client vision · Browser-side landmark extraction before network transfer · `expresat/frontend/src/services/mediapipeEngine.js`

### Realtime backend

FastAPI service and WebSocket transport

- [Backend app](https://github.com/salf423/expresat/blob/main/expresat/backend/main.py): FastAPI entrypoint · Python API service launched with uvicorn · `expresat/backend/main.py`
- [WebSocket handler](https://github.com/salf423/expresat/blob/main/expresat/backend/websockets_handler.py): Realtime channel · Low-latency bidirectional streaming interface · `expresat/backend/websockets_handler.py`

### ML inference

Training, export, and production inference assets

- [Inference engine](https://github.com/salf423/expresat/blob/main/expresat/models/inference_engine.py): Runtime wrapper · Production inference orchestration and model loading · `expresat/models/inference_engine.py`
- [Inference](https://github.com/salf423/expresat/blob/main/expresat/models/inference.py): Model runtime · Core prediction logic for translated output · `expresat/models/inference.py`
- [Train/export](https://github.com/salf423/expresat/blob/main/expresat/models/train_and_export.py): Training pipeline · Training and export workflow for model artifacts · `expresat/models/train_and_export.py`
- [Model artifacts](https://github.com/salf423/expresat/tree/main/expresat/models/exported_model): ONNX/PyTorch · Checked-in exported model files and metadata · `expresat/models/exported_model`

### Legacy client

Older static frontend kept for reference

- [Legacy app](https://github.com/salf423/expresat/blob/main/expresat/frontend-legacy/index.html): Static site · Older HTML/CSS/JS presentation layer · `expresat/frontend-legacy/index.html`
- [Legacy MediaPipe](https://github.com/salf423/expresat/blob/main/expresat/frontend-legacy/js/mediapipe_engine.js): Client vision · Older browser-side MediaPipe integration · `expresat/frontend-legacy/js/mediapipe_engine.js`
- [Legacy services](https://github.com/salf423/expresat/blob/main/expresat/frontend-legacy/js/api_service.js): API/auth layer · Older client API and auth modules · `expresat/frontend-legacy/js/api_service.js`

### Data/auth

Supabase-backed persistence and identity boundary

- [Supabase schema](https://github.com/salf423/expresat/blob/main/expresat/supabase/schema.sql): Auth/data schema · Database and auth boundary managed through Supabase · `expresat/supabase/schema.sql`

### Other components

- [Docs](https://github.com/salf423/expresat/tree/main/expresat/docs): System docs · Technical spec and deployment guidance · `expresat/docs`

## Connections

- Frontend app → Pages: renders · Route-level screens compose the active UI
- Frontend app → UI components: uses · Shared shell elements used across pages
- Frontend app → Theme state: reads state · Theme and cross-app UI state
- Pages → Client services: calls · Screens invoke client services for API and auth
- Client services → MediaPipe: preprocesses · Client-side landmark extraction before upload
- Client services → Backend app: api calls · HTTP requests to backend endpoints
- Client services → WebSocket handler: streams · Bidirectional realtime translation channel
- Backend app → WebSocket handler: mounts · Backend app exposes the realtime handler
- Backend app → Inference engine: loads · Backend delegates prediction to model runtime
- WebSocket handler → Inference engine: invokes · Streaming requests trigger inference
- Inference engine → Inference: executes · Wrapper calls core inference logic
- Inference engine → Model artifacts: reads · Runtime loads exported ONNX/PyTorch assets
- Train/export → Model artifacts: produces · Training/export workflow writes checked-in artifacts
- Client services → Supabase schema: auth/persist · Client authentication and persistence boundary
- Legacy app → Legacy services: uses · Legacy UI depends on local services
- Legacy app → Legacy MediaPipe: uses · Legacy client-side preprocessing
- Legacy services → Supabase schema: auth/persist · Older auth and storage boundary
- Docs → Backend app: documents · Operational and backend technical guidance
- Docs → Frontend app: documents · Deployment and system usage guidance
