# adityamadhab/manash-minor architecture

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

- Interactive diagram: https://gitdiagram.com/adityamadhab/manash-minor
- Repository: https://github.com/adityamadhab/manash-minor

## Overview

MailGuard AI classifies submitted email, returns calibrated spam/ham probabilities and an explanation, and persists each prediction for later history and analytics. Its separate training workflow prepares the SpamAssassin corpus, preprocesses it, benchmarks classifiers, and saves model artifacts used for inference. The React application also exposes model-performance views, PDF/CSV exports, health status, and theme controls. Edges follow shown imports/calls or README-described API capabilities; some backend startup and endpoint wiring is supported by the SOURCE INDEX rather than full excerpts.

Main entry points: [`frontend/src/App.tsx`](https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/App.tsx) (Route shell), [`backend/app/services/predictor.py`](https://github.com/adityamadhab/manash-minor/blob/main/backend/app/services/predictor.py) (Inference service), [`frontend/src/services/api.ts`](https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/services/api.ts) (API client), [`backend/app/api/routes.py`](https://github.com/adityamadhab/manash-minor/blob/main/backend/app/api/routes.py) (REST endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web application"]
  node_app["Route shell<br/>[App.tsx]"]
  node_detect["Email detection<br/>[DetectPage.tsx]"]
  node_highlight["Text highlighting"]
  node_dashboard["Security dashboard<br/>[DashboardPage.tsx]"]
  node_history["Detection history<br/>[HistoryPage.tsx]"]
  node_performance["Model performance"]
  node_landing["Landing and about<br/>[LandingPage.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
  node_pdf["PDF reports<br/>[exportPdf.ts]"]
  node_theme["Theme control<br/>[useTheme.ts]"]
end

subgraph group_api["API and persistence"]
  node_backend["FastAPI application<br/>[main.py]"]
  node_routes["REST endpoints<br/>[routes.py]"]
  node_schemas["Request validation<br/>[prediction.py]"]
  node_security["Request safeguards<br/>[security.py]"]
  node_database[("Prediction database<br/>[session.py]")]
  node_records["Prediction records<br/>[prediction.py]"]
end

subgraph group_inference["Detection and explanation"]
  node_predictor["Inference service<br/>[predictor.py]"]
  node_preprocessor["Email preprocessing<br/>[preprocessor.py]"]
  node_explainer["Prediction explanation<br/>[explainer.py]"]
end

subgraph group_training["Model training"]
  node_trainer["Training and evaluation<br/>[train.py]"]
  node_loader["Corpus preparation<br/>[dataset_loader.py]"]
  node_dataset["SpamAssassin corpus"]
  node_artifacts["Model artifacts"]
  node_metrics["Benchmark metrics"]
end

node_user(("Email analyst"))

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_detect
node_app -->|"routes to"| node_dashboard
node_app -->|"routes to"| node_history
node_app -->|"routes to"| node_performance
node_app -->|"routes to"| node_landing
node_app -->|"uses"| node_theme
node_detect -->|"requests prediction"| node_api_client
node_detect -->|"renders terms"| node_highlight
node_detect -->|"exports report"| node_pdf
node_history -->|"requests history"| node_api_client
node_history -->|"renders terms"| node_highlight
node_history -->|"exports report"| node_pdf
node_dashboard -->|"loads statistics"| node_api_client
node_performance -->|"loads metrics"| node_api_client
node_landing -->|"checks health"| node_api_client
node_api_client -->|"calls REST API"| node_routes
node_backend -->|"registers routes"| node_routes
node_backend -->|"configures middleware"| node_security
node_backend -->|"initializes database"| node_database
node_backend -->|"loads service"| node_predictor
node_routes -->|"validates payloads"| node_schemas
node_routes -->|"requests inference"| node_predictor
node_routes -->|"reads and writes"| node_records
node_records -->|"uses session base"| node_database
node_predictor -->|"cleans email"| node_preprocessor
node_predictor -->|"explains result"| node_explainer
node_preprocessor -->|"strips HTML"| node_security
node_trainer -->|"prepares corpus"| node_loader
node_trainer -->|"preprocesses data"| node_preprocessor
node_loader -->|"loads corpus"| node_dataset
node_trainer -->|"saves models"| node_artifacts
node_trainer -->|"writes benchmarks"| node_metrics
node_predictor -->|"loads models"| node_artifacts
node_predictor -->|"loads metrics"| node_metrics

click node_app "https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/App.tsx"
click node_detect "https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/pages/DetectPage.tsx"
click node_highlight "https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/components/HighlightedText.tsx"
click node_dashboard "https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/pages/DashboardPage.tsx"
click node_history "https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/pages/HistoryPage.tsx"
click node_performance "https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/pages/PerformancePage.tsx"
click node_landing "https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/pages/LandingPage.tsx"
click node_api_client "https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/services/api.ts"
click node_pdf "https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/utils/exportPdf.ts"
click node_theme "https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/hooks/useTheme.ts"
click node_backend "https://github.com/adityamadhab/manash-minor/blob/main/backend/app/main.py"
click node_routes "https://github.com/adityamadhab/manash-minor/blob/main/backend/app/api/routes.py"
click node_schemas "https://github.com/adityamadhab/manash-minor/blob/main/backend/app/schemas/prediction.py"
click node_security "https://github.com/adityamadhab/manash-minor/blob/main/backend/app/core/security.py"
click node_database "https://github.com/adityamadhab/manash-minor/blob/main/backend/app/database/session.py"
click node_records "https://github.com/adityamadhab/manash-minor/blob/main/backend/app/models/prediction.py"
click node_predictor "https://github.com/adityamadhab/manash-minor/blob/main/backend/app/services/predictor.py"
click node_preprocessor "https://github.com/adityamadhab/manash-minor/blob/main/backend/app/ml/preprocessor.py"
click node_explainer "https://github.com/adityamadhab/manash-minor/blob/main/backend/app/ml/explainer.py"
click node_trainer "https://github.com/adityamadhab/manash-minor/blob/main/backend/train.py"
click node_loader "https://github.com/adityamadhab/manash-minor/blob/main/backend/app/ml/dataset_loader.py"
click node_dataset "https://github.com/adityamadhab/manash-minor/tree/main/backend/datasets"
click node_artifacts "https://github.com/adityamadhab/manash-minor/tree/main/backend/saved_models"
click node_metrics "https://github.com/adityamadhab/manash-minor/tree/main/backend/reports"

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_app,node_detect,node_highlight,node_dashboard,node_history,node_performance,node_landing,node_api_client,node_pdf,node_theme toneBlue
class node_backend,node_routes,node_schemas,node_security,node_database,node_records toneAmber
class node_predictor,node_preprocessor,node_explainer toneMint
class node_trainer,node_loader,node_dataset,node_artifacts,node_metrics toneRose
class node_user toneIndigo
```

## Components

### Web application

- [Route shell](https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Email detection](https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/pages/DetectPage.tsx): `frontend/src/pages/DetectPage.tsx`
- [Text highlighting](https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/components/HighlightedText.tsx): `frontend/src/components/HighlightedText.tsx`
- [Security dashboard](https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/pages/DashboardPage.tsx): `frontend/src/pages/DashboardPage.tsx`
- [Detection history](https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/pages/HistoryPage.tsx): `frontend/src/pages/HistoryPage.tsx`
- [Model performance](https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/pages/PerformancePage.tsx): `frontend/src/pages/PerformancePage.tsx`
- [Landing and about](https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/pages/LandingPage.tsx): `frontend/src/pages/LandingPage.tsx`
- [API client](https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`
- [PDF reports](https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/utils/exportPdf.ts): `frontend/src/utils/exportPdf.ts`
- [Theme control](https://github.com/adityamadhab/manash-minor/blob/main/frontend/src/hooks/useTheme.ts): `frontend/src/hooks/useTheme.ts`

### API and persistence

- [FastAPI application](https://github.com/adityamadhab/manash-minor/blob/main/backend/app/main.py): `backend/app/main.py`
- [REST endpoints](https://github.com/adityamadhab/manash-minor/blob/main/backend/app/api/routes.py): `backend/app/api/routes.py`
- [Request validation](https://github.com/adityamadhab/manash-minor/blob/main/backend/app/schemas/prediction.py): `backend/app/schemas/prediction.py`
- [Request safeguards](https://github.com/adityamadhab/manash-minor/blob/main/backend/app/core/security.py): `backend/app/core/security.py`
- [Prediction database](https://github.com/adityamadhab/manash-minor/blob/main/backend/app/database/session.py): `backend/app/database/session.py`
- [Prediction records](https://github.com/adityamadhab/manash-minor/blob/main/backend/app/models/prediction.py): `backend/app/models/prediction.py`

### Detection and explanation

- [Inference service](https://github.com/adityamadhab/manash-minor/blob/main/backend/app/services/predictor.py): `backend/app/services/predictor.py`
- [Email preprocessing](https://github.com/adityamadhab/manash-minor/blob/main/backend/app/ml/preprocessor.py): `backend/app/ml/preprocessor.py`
- [Prediction explanation](https://github.com/adityamadhab/manash-minor/blob/main/backend/app/ml/explainer.py): `backend/app/ml/explainer.py`

### Model training

- [Training and evaluation](https://github.com/adityamadhab/manash-minor/blob/main/backend/train.py): `backend/train.py`
- [Corpus preparation](https://github.com/adityamadhab/manash-minor/blob/main/backend/app/ml/dataset_loader.py): `backend/app/ml/dataset_loader.py`
- [SpamAssassin corpus](https://github.com/adityamadhab/manash-minor/tree/main/backend/datasets): `backend/datasets`
- [Model artifacts](https://github.com/adityamadhab/manash-minor/tree/main/backend/saved_models): `backend/saved_models`
- [Benchmark metrics](https://github.com/adityamadhab/manash-minor/tree/main/backend/reports): `backend/reports`

### Other components

- **Email analyst**

## Connections

- Email analyst → Route shell: uses (evidence: `README.md`)
- Route shell → Email detection: routes to (evidence: `frontend/src/App.tsx`)
- Route shell → Security dashboard: routes to (evidence: `frontend/src/App.tsx`)
- Route shell → Detection history: routes to (evidence: `frontend/src/App.tsx`)
- Route shell → Model performance: routes to (evidence: `frontend/src/App.tsx`)
- Route shell → Landing and about: routes to (evidence: `frontend/src/App.tsx`)
- Route shell → Theme control: uses (evidence: `frontend/src/App.tsx`)
- Email detection → API client: requests prediction (evidence: `frontend/src/pages/DetectPage.tsx`)
- Email detection → Text highlighting: renders terms (evidence: `frontend/src/pages/DetectPage.tsx`)
- Email detection → PDF reports: exports report (evidence: `frontend/src/pages/DetectPage.tsx`)
- Detection history → API client: requests history (evidence: `frontend/src/pages/HistoryPage.tsx`)
- Detection history → Text highlighting: renders terms (evidence: `frontend/src/pages/HistoryPage.tsx`)
- Detection history → PDF reports: exports report (evidence: `frontend/src/pages/HistoryPage.tsx`)
- Security dashboard → API client: loads statistics (evidence: `frontend/src/pages/DashboardPage.tsx`)
- Model performance → API client: loads metrics (evidence: `frontend/src/pages/PerformancePage.tsx`)
- Landing and about → API client: checks health (evidence: `frontend/src/pages/LandingPage.tsx`)
- API client → REST endpoints: calls REST API (evidence: `README.md`)
- FastAPI application → REST endpoints: registers routes (evidence: `backend/app/main.py`)
- FastAPI application → Request safeguards: configures middleware (evidence: `backend/app/main.py`)
- FastAPI application → Prediction database: initializes database (evidence: `backend/app/main.py`)
- FastAPI application → Inference service: loads service (evidence: `backend/app/main.py`)
- REST endpoints → Request validation: validates payloads (evidence: `backend/app/api/routes.py`)
- REST endpoints → Inference service: requests inference (evidence: `backend/app/api/routes.py`)
- REST endpoints → Prediction records: reads and writes (evidence: `backend/app/api/routes.py`)
- Prediction records → Prediction database: uses session base (evidence: `backend/app/models/prediction.py`)
- Inference service → Email preprocessing: cleans email (evidence: `backend/app/services/predictor.py`)
- Inference service → Prediction explanation: explains result (evidence: `backend/app/services/predictor.py`)
- Email preprocessing → Request safeguards: strips HTML (evidence: `backend/app/ml/preprocessor.py`)
- Training and evaluation → Corpus preparation: prepares corpus (evidence: `backend/train.py`)
- Training and evaluation → Email preprocessing: preprocesses data (evidence: `backend/train.py`)
- Corpus preparation → SpamAssassin corpus: loads corpus (evidence: `README.md`)
- Training and evaluation → Model artifacts: saves models (evidence: `README.md`)
- Training and evaluation → Benchmark metrics: writes benchmarks (evidence: `README.md`)
- Inference service → Model artifacts: loads models (evidence: `backend/app/services/predictor.py`)
- Inference service → Benchmark metrics: loads metrics (evidence: `backend/app/services/predictor.py`)
