# rohitkattimani/rokaviz architecture

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

- Interactive diagram: https://gitdiagram.com/rohitkattimani/rokaviz
- Repository: https://github.com/rohitkattimani/rokaviz

## Overview

#### Purpose and entry points
ROKAViz is a local image-quality inspection system: users upload an image, receive model-backed quality scoring and issue explanations, and can revisit persisted analyses. The frontend starts at `src/main.tsx` and `src/App.tsx`; FastAPI starts at `backend/app/main.py`. The API is versioned under `/api/v1`.

#### Frontend application shell and workflow
The React/Vite UI presents dashboard, upload, history, and analysis-detail views through the shared application layout. Upload state and request orchestration are centralized in `src/hooks/useAnalyze.ts`; API integration is isolated behind `src/services/api.ts` and `src/services/httpClient.ts`. Results are rendered from API-shaped analysis types in `src/types/analysis.ts`, notably through `src/components/results/ResultsView.tsx`.

#### HTTP API boundary
FastAPI owns validation, routing, response serialization, CORS, and error normalization. `backend/app/main.py` exposes creation, listing, detail, image retrieval, and status endpoints; `backend/app/schemas.py` defines request/response contracts; `backend/app/validation.py` rejects invalid, unsupported, corrupt, or oversized uploads. This boundary returns structured analysis results rather than exposing model internals.

#### Analysis orchestration
`backend/app/service.py` is the core application workflow: accept validated bytes, extract image features, run local inference, derive score/label/issues/explanation, persist the result and source image, then return a frontend-consumable record. `backend/app/models.py` represents persisted analysis data, while `backend/app/database.py` manages SQLite access and filesystem-backed image storage.

#### Computer vision and local ML inference
Raw, policy-free image measurement is separated in `backend/app/features.py`, using Pillow/NumPy for dimensions, brightness, contrast, sharpness, noise, saturation, edges, entropy, clipping, and blockiness. `backend/app/ml.py` loads and applies the versioned local logistic-model ensemble from `backend/models/quality_model.npz`; it does not call hosted AI services or retrain at request time. Model probabilities are translated into issue confidence, severity, penalties, and explanations by the backend workflow.

#### Model production and artifact lifecycle
The reproducible offline training pipeline in `backend/scripts/train_model.py` generates controlled degradations, splits procedural source images before augmentation, trains issue-specific binary logistic models, and emits model weights, normalization data, feature schema, and version. Its held-out evaluation is stored at `backend/models/evaluation.json`. Runtime startup consumes the artifact; Docker builds train it before serving.

#### Deployment and persistence
For development, React communicates with the backend directly using its configured API base URL. In containers, `docker-compose.yml` runs the frontend behind Nginx (`nginx.conf`), which reverse-proxies `/api` to FastAPI; a named volume retains SQLite data and uploaded images. The backend container is defined in `backend/Dockerfile`, and `/api/v1/status` serves as its health endpoint.

Main entry points: [`backend/app/main.py`](https://github.com/rohitkattimani/rokaviz/blob/main/backend/app/main.py) (Versioned API), [`backend/app/service.py`](https://github.com/rohitkattimani/rokaviz/blob/main/backend/app/service.py) (Analysis orchestration), [`docker-compose.yml`](https://github.com/rohitkattimani/rokaviz/blob/main/docker-compose.yml) (Compose deployment), [`src/App.tsx`](https://github.com/rohitkattimani/rokaviz/blob/main/src/App.tsx) (App shell and views)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React frontend"]
  node_ui_shell["App shell and views<br/>React/Vite UI<br/>[App.tsx]"]
  node_ui_entry["Frontend entry<br/>React bootstrap<br/>[main.tsx]"]
  node_analyze_hook["Analysis workflow<br/>React hook<br/>[useAnalyze.ts]"]
  node_api_client["API client<br/>HTTP integration<br/>[api.ts]"]
  node_http_client["HTTP client<br/>transport<br/>[httpClient.ts]"]
  node_results_view["Results view<br/>React component<br/>[ResultsView.tsx]"]
  node_analysis_types["Analysis types<br/>shared UI contracts<br/>[analysis.ts]"]
end

subgraph group_api["FastAPI backend"]
  node_fastapi["Versioned API<br/>FastAPI<br/>[main.py]"]
  node_contracts_validation["Contracts and upload validation<br/>API boundary<br/>[schemas.py]"]
  node_analysis_service{{"Analysis orchestration<br/>application service<br/>[service.py]"}}
  node_feature_extraction["Image feature extraction<br/>computer vision<br/>[features.py]"]
  node_persistence[("Analysis persistence<br/>SQLite and image storage<br/>[database.py]")]
end

subgraph group_ml["Local ML lifecycle"]
  node_local_inference["Local model inference<br/>logistic ensemble runtime<br/>[ml.py]"]
  node_model_artifact["Quality model artifact<br/>versioned model<br/>[quality_model.npz]"]
  node_training_pipeline["Offline model training<br/>training pipeline<br/>[train_model.py]"]
  node_evaluation["Held-out evaluation<br/>model evaluation<br/>[evaluation.json]"]
end

subgraph group_deploy["Container deployment"]
  node_compose["Compose deployment<br/>Docker Compose<br/>[docker-compose.yml]"]
  node_nginx["Nginx reverse proxy<br/>container proxy<br/>[nginx.conf]"]
  node_backend_image["Backend container build<br/>Docker build"]
end

node_ui_entry -->|"mounts"| node_ui_shell
node_ui_shell -->|"uses"| node_analyze_hook
node_analyze_hook -->|"submits analysis requests"| node_api_client
node_api_client -->|"uses"| node_http_client
node_ui_shell -->|"renders"| node_results_view
node_results_view -->|"renders"| node_analysis_types
node_http_client -->|"/api/v1"| node_fastapi
node_fastapi -->|"validates and serializes"| node_contracts_validation
node_fastapi -->|"dispatches requests"| node_analysis_service
node_analysis_service -->|"extracts measurements"| node_feature_extraction
node_analysis_service -->|"scores features"| node_local_inference
node_analysis_service -->|"stores records and images"| node_persistence
node_local_inference -->|"loads"| node_model_artifact
node_training_pipeline -->|"produces"| node_model_artifact
node_training_pipeline -->|"writes"| node_evaluation
node_compose -->|"runs frontend proxy"| node_nginx
node_nginx -->|"proxies /api"| node_fastapi
node_compose -->|"builds backend"| node_backend_image
node_backend_image -->|"runs during build"| node_training_pipeline
node_backend_image -->|"serves"| node_fastapi
node_compose -->|"retains via named volume"| node_persistence

click node_ui_shell "https://github.com/rohitkattimani/rokaviz/blob/main/src/App.tsx"
click node_ui_entry "https://github.com/rohitkattimani/rokaviz/blob/main/src/main.tsx"
click node_analyze_hook "https://github.com/rohitkattimani/rokaviz/blob/main/src/hooks/useAnalyze.ts"
click node_api_client "https://github.com/rohitkattimani/rokaviz/blob/main/src/services/api.ts"
click node_http_client "https://github.com/rohitkattimani/rokaviz/blob/main/src/services/httpClient.ts"
click node_results_view "https://github.com/rohitkattimani/rokaviz/blob/main/src/components/results/ResultsView.tsx"
click node_analysis_types "https://github.com/rohitkattimani/rokaviz/blob/main/src/types/analysis.ts"
click node_fastapi "https://github.com/rohitkattimani/rokaviz/blob/main/backend/app/main.py"
click node_contracts_validation "https://github.com/rohitkattimani/rokaviz/blob/main/backend/app/schemas.py"
click node_analysis_service "https://github.com/rohitkattimani/rokaviz/blob/main/backend/app/service.py"
click node_feature_extraction "https://github.com/rohitkattimani/rokaviz/blob/main/backend/app/features.py"
click node_persistence "https://github.com/rohitkattimani/rokaviz/blob/main/backend/app/database.py"
click node_local_inference "https://github.com/rohitkattimani/rokaviz/blob/main/backend/app/ml.py"
click node_model_artifact "https://github.com/rohitkattimani/rokaviz/blob/main/backend/models/quality_model.npz"
click node_training_pipeline "https://github.com/rohitkattimani/rokaviz/blob/main/backend/scripts/train_model.py"
click node_evaluation "https://github.com/rohitkattimani/rokaviz/blob/main/backend/models/evaluation.json"
click node_compose "https://github.com/rohitkattimani/rokaviz/blob/main/docker-compose.yml"
click node_nginx "https://github.com/rohitkattimani/rokaviz/blob/main/nginx.conf"
click node_backend_image "https://github.com/rohitkattimani/rokaviz/blob/main/backend/Dockerfile"

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_ui_shell,node_ui_entry,node_analyze_hook,node_api_client,node_http_client,node_results_view,node_analysis_types toneBlue
class node_fastapi,node_contracts_validation,node_analysis_service,node_feature_extraction,node_persistence toneAmber
class node_local_inference,node_model_artifact,node_training_pipeline,node_evaluation toneMint
class node_compose,node_nginx,node_backend_image toneRose
```

## Components

### React frontend

- [App shell and views](https://github.com/rohitkattimani/rokaviz/blob/main/src/App.tsx): React/Vite UI · Dashboard, upload, history, and analysis detail views. · `src/App.tsx`
- [Frontend entry](https://github.com/rohitkattimani/rokaviz/blob/main/src/main.tsx): React bootstrap · `src/main.tsx`
- [Analysis workflow](https://github.com/rohitkattimani/rokaviz/blob/main/src/hooks/useAnalyze.ts): React hook · Owns upload state and request orchestration. · `src/hooks/useAnalyze.ts`
- [API client](https://github.com/rohitkattimani/rokaviz/blob/main/src/services/api.ts): HTTP integration · `src/services/api.ts`
- [HTTP client](https://github.com/rohitkattimani/rokaviz/blob/main/src/services/httpClient.ts): transport · `src/services/httpClient.ts`
- [Results view](https://github.com/rohitkattimani/rokaviz/blob/main/src/components/results/ResultsView.tsx): React component · `src/components/results/ResultsView.tsx`
- [Analysis types](https://github.com/rohitkattimani/rokaviz/blob/main/src/types/analysis.ts): shared UI contracts · API-shaped result types used for rendering. · `src/types/analysis.ts`

### FastAPI backend

- [Versioned API](https://github.com/rohitkattimani/rokaviz/blob/main/backend/app/main.py): FastAPI · Exposes analysis, history, image retrieval, and status endpoints under /api/v1. · `backend/app/main.py`
- [Contracts and upload validation](https://github.com/rohitkattimani/rokaviz/blob/main/backend/app/schemas.py): API boundary · Serializes responses and rejects invalid, corrupt, unsupported, or oversized uploads. · `backend/app/schemas.py`
- [Analysis orchestration](https://github.com/rohitkattimani/rokaviz/blob/main/backend/app/service.py): application service · Extracts features, infers quality, derives issues, and persists records. · `backend/app/service.py`
- [Image feature extraction](https://github.com/rohitkattimani/rokaviz/blob/main/backend/app/features.py): computer vision · Measures image quality signals with Pillow and NumPy. · `backend/app/features.py`
- [Analysis persistence](https://github.com/rohitkattimani/rokaviz/blob/main/backend/app/database.py): SQLite and image storage · Stores analysis records and source images. · `backend/app/database.py`

### Local ML lifecycle

- [Local model inference](https://github.com/rohitkattimani/rokaviz/blob/main/backend/app/ml.py): logistic ensemble runtime · Loads versioned local weights; no hosted AI or request-time training. · `backend/app/ml.py`
- [Quality model artifact](https://github.com/rohitkattimani/rokaviz/blob/main/backend/models/quality_model.npz): versioned model · `backend/models/quality_model.npz`
- [Offline model training](https://github.com/rohitkattimani/rokaviz/blob/main/backend/scripts/train_model.py): training pipeline · Generates degradations, trains issue models, and emits the runtime artifact. · `backend/scripts/train_model.py`
- [Held-out evaluation](https://github.com/rohitkattimani/rokaviz/blob/main/backend/models/evaluation.json): model evaluation · `backend/models/evaluation.json`

### Container deployment

- [Compose deployment](https://github.com/rohitkattimani/rokaviz/blob/main/docker-compose.yml): Docker Compose · Runs frontend and backend with persistent storage. · `docker-compose.yml`
- [Nginx reverse proxy](https://github.com/rohitkattimani/rokaviz/blob/main/nginx.conf): container proxy · Serves the frontend and proxies /api to FastAPI. · `nginx.conf`
- [Backend container build](https://github.com/rohitkattimani/rokaviz/blob/main/backend/Dockerfile): Docker build · Trains the model before serving. · `backend/Dockerfile`

## Connections

- Frontend entry → App shell and views: mounts
- App shell and views → Analysis workflow: uses
- Analysis workflow → API client: submits analysis requests
- API client → HTTP client: uses
- App shell and views → Results view: renders
- Results view → Analysis types: renders
- HTTP client → Versioned API: /api/v1
- Versioned API → Contracts and upload validation: validates and serializes
- Versioned API → Analysis orchestration: dispatches requests
- Analysis orchestration → Image feature extraction: extracts measurements
- Analysis orchestration → Local model inference: scores features
- Analysis orchestration → Analysis persistence: stores records and images
- Local model inference → Quality model artifact: loads
- Offline model training → Quality model artifact: produces
- Offline model training → Held-out evaluation: writes
- Compose deployment → Nginx reverse proxy: runs frontend proxy
- Nginx reverse proxy → Versioned API: proxies /api
- Compose deployment → Backend container build: builds backend
- Backend container build → Offline model training: runs during build
- Backend container build → Versioned API: serves
- Compose deployment → Analysis persistence: retains via named volume
