# abdulnafih-official/ml-microservices architecture

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

- Interactive diagram: https://gitdiagram.com/abdulnafih-official/ml-microservices
- Repository: https://github.com/abdulnafih-official/ml-microservices

## Overview

ML Platform provides authenticated dataset-to-model training, model management, and prediction through a Streamlit UI and separate services. The primary flow runs from user submission through the training API and worker, then stores model artifacts and metadata for inference. Authentication and quota enforcement are distinct stages; inference validates inputs and loads cached private artifacts. The graph preserves the documented planning, profiling, training, and monitoring capabilities. Some worker internals and model-management routes are unsampled, so their documented or indexed links are limited to supported relationships.

Main entry points: [`services/training/worker/job_runner.py`](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/job_runner.py) (Job orchestration), [`services/user/api_client.py`](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/user/api_client.py) (Service API client), [`services/auth/app/routes/auth.py`](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/auth/app/routes/auth.py) (Registration and login), [`services/inference/app/routes/predict.py`](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/routes/predict.py) (Prediction API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["User interface"]
  node_streamlit["Streamlit pages<br/>[1_Train.py]"]
  node_ui_app["UI entry and session<br/>[app.py]"]
  node_api_client["Service API client<br/>[api_client.py]"]
  node_session["Login session<br/>[session.py]"]
end

subgraph group_identity["Identity and quotas"]
  node_auth_routes["Registration and login<br/>[auth.py]"]
  node_internal_auth["Internal quota API<br/>[internal.py]"]
  node_auth_models["User and quota data<br/>[models.py]"]
  node_auth_db["Auth database access<br/>[db.py]"]
  node_auth_limits["Rate limiting<br/>[rate_limit.py]"]
end

subgraph group_training["Training platform"]
  node_training_api["Training job API<br/>[jobs.py]"]
  node_training_db["Training database access<br/>[db.py]"]
  node_uploads["Dataset uploads<br/>[upload.py]"]
  node_auth_client["Quota client<br/>[auth_client.py]"]
  node_worker["Job orchestration<br/>[job_runner.py]"]
  node_profiling["Data profiling<br/>[profiler.py]"]
  node_planning["Cleaning planners"]
  node_plan_validation["Plan validation<br/>[validator.py]"]
  node_compiler["Pipeline compilation<br/>[compiler.py]"]
  node_trainers["Model training<br/>[trainers.py]"]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
  node_metadata["Model metadata<br/>[metadata.py]"]
  node_artifact_store["Private artifact storage<br/>[hf_store.py]"]
end

subgraph group_inference["Model serving"]
  node_model_routes["Model management API<br/>[models.py]"]
  node_predict_route["Prediction API<br/>[predict.py]"]
  node_input_validation["Payload validation"]
  node_model_registry["Model registry<br/>[registry.py]"]
  node_model_cache["Artifact cache<br/>[cache.py]"]
  node_hf_loader["Artifact downloader<br/>[hf_loader.py]"]
  node_inference_db["Inference database access<br/>[db.py]"]
end

subgraph group_shared["Shared platform"]
  node_common_jwt["JWT utilities<br/>[jwt_utils.py]"]
  node_common_metrics["Prometheus metrics<br/>[metrics.py]"]
end

node_user(("Platform user"))
node_postgres[("PostgreSQL")]
node_huggingface["Hugging Face"]

node_user -->|"uses"| node_streamlit
node_streamlit -->|"requests services"| node_api_client
node_ui_app -->|"uses"| node_api_client
node_ui_app -->|"uses"| node_session
node_api_client -->|"registers and logs in"| node_auth_routes
node_api_client -->|"submits jobs"| node_training_api
node_api_client -->|"manages models"| node_model_routes
node_api_client -->|"requests predictions"| node_predict_route
node_auth_routes -->|"reads and writes"| node_auth_db
node_auth_routes -->|"uses user records"| node_auth_models
node_auth_routes -->|"verifies tokens"| node_common_jwt
node_auth_routes -->|"applies limits"| node_auth_limits
node_internal_auth -->|"uses database"| node_auth_db
node_internal_auth -->|"uses quota records"| node_auth_models
node_training_api -->|"reads and writes"| node_training_db
node_training_api -->|"stores upload"| node_uploads
node_training_api -->|"reserves quota"| node_auth_client
node_auth_client -->|"calls quota endpoints"| node_internal_auth
node_worker -->|"profiles data"| node_profiling
node_worker -->|"creates cleaning plan"| node_planning
node_worker -->|"validates plan"| node_plan_validation
node_worker -->|"compiles pipeline"| node_compiler
node_worker -->|"trains model"| node_trainers
node_worker -->|"evaluates model"| node_evaluation
node_worker -->|"records metadata"| node_metadata
node_worker -->|"uploads artifact"| node_artifact_store
node_model_routes -->|"reads and writes"| node_inference_db
node_model_routes -->|"removes cached model"| node_model_cache
node_model_routes -->|"loads artifacts"| node_hf_loader
node_predict_route -->|"gets model"| node_model_registry
node_predict_route -->|"gets database session"| node_inference_db
node_predict_route -->|"validates payload"| node_input_validation
node_predict_route -->|"gets pipeline"| node_model_cache
node_model_cache -->|"downloads artifact"| node_hf_loader
node_postgres -.->|"stores auth data"| node_auth_db
node_postgres -.->|"stores job data"| node_training_db
node_postgres -.->|"stores model metadata"| node_inference_db
node_artifact_store -.->|"uploads private models"| node_huggingface
node_hf_loader -.->|"downloads private models"| node_huggingface
node_worker -.->|"records metrics"| node_common_metrics

click node_streamlit "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/user/pages/1_Train.py"
click node_ui_app "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/user/app.py"
click node_api_client "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/user/api_client.py"
click node_session "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/user/session.py"
click node_auth_routes "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/auth/app/routes/auth.py"
click node_internal_auth "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/auth/app/routes/internal.py"
click node_auth_models "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/auth/app/models.py"
click node_auth_db "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/auth/app/db.py"
click node_auth_limits "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/auth/app/rate_limit.py"
click node_training_api "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/app/routes/jobs.py"
click node_training_db "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/app/db.py"
click node_uploads "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/app/upload.py"
click node_auth_client "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/app/auth_client.py"
click node_worker "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/job_runner.py"
click node_profiling "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/profiler.py"
click node_planning "https://github.com/abdulnafih-official/ml-microservices/tree/main/services/training/worker/planner"
click node_plan_validation "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/validator.py"
click node_compiler "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/compiler.py"
click node_trainers "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/trainers.py"
click node_evaluation "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/evaluate.py"
click node_metadata "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/metadata.py"
click node_artifact_store "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/hf_store.py"
click node_model_routes "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/routes/models.py"
click node_predict_route "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/routes/predict.py"
click node_input_validation "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/input_validation.py"
click node_model_registry "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/registry.py"
click node_model_cache "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/cache.py"
click node_hf_loader "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/hf_loader.py"
click node_inference_db "https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/db.py"
click node_common_jwt "https://github.com/abdulnafih-official/ml-microservices/blob/main/shared/mlp_common/mlp_common/jwt_utils.py"
click node_common_metrics "https://github.com/abdulnafih-official/ml-microservices/blob/main/shared/mlp_common/mlp_common/metrics.py"

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_streamlit,node_ui_app,node_api_client,node_session,node_user toneBlue
class node_auth_routes,node_internal_auth,node_auth_models,node_auth_db,node_auth_limits,node_postgres toneAmber
class node_training_api,node_training_db,node_uploads,node_auth_client,node_worker,node_profiling,node_planning,node_plan_validation,node_compiler,node_trainers,node_evaluation,node_metadata,node_artifact_store toneMint
class node_model_routes,node_predict_route,node_input_validation,node_model_registry,node_model_cache,node_hf_loader,node_inference_db toneRose
class node_common_jwt,node_common_metrics,node_huggingface toneIndigo
```

## Components

### User interface

- [Streamlit pages](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/user/pages/1_Train.py): `services/user/pages/1_Train.py`
- [UI entry and session](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/user/app.py): `services/user/app.py`
- [Service API client](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/user/api_client.py): `services/user/api_client.py`
- [Login session](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/user/session.py): `services/user/session.py`

### Identity and quotas

- [Registration and login](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/auth/app/routes/auth.py): `services/auth/app/routes/auth.py`
- [Internal quota API](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/auth/app/routes/internal.py): `services/auth/app/routes/internal.py`
- [User and quota data](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/auth/app/models.py): `services/auth/app/models.py`
- [Auth database access](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/auth/app/db.py): `services/auth/app/db.py`
- [Rate limiting](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/auth/app/rate_limit.py): `services/auth/app/rate_limit.py`

### Training platform

- [Training job API](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/app/routes/jobs.py): `services/training/app/routes/jobs.py`
- [Training database access](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/app/db.py): `services/training/app/db.py`
- [Dataset uploads](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/app/upload.py): `services/training/app/upload.py`
- [Quota client](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/app/auth_client.py): `services/training/app/auth_client.py`
- [Job orchestration](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/job_runner.py): `services/training/worker/job_runner.py`
- [Data profiling](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/profiler.py): `services/training/worker/profiler.py`
- [Cleaning planners](https://github.com/abdulnafih-official/ml-microservices/tree/main/services/training/worker/planner): `services/training/worker/planner`
- [Plan validation](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/validator.py): `services/training/worker/validator.py`
- [Pipeline compilation](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/compiler.py): `services/training/worker/compiler.py`
- [Model training](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/trainers.py): `services/training/worker/trainers.py`
- [Model evaluation](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/evaluate.py): `services/training/worker/evaluate.py`
- [Model metadata](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/metadata.py): `services/training/worker/metadata.py`
- [Private artifact storage](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/training/worker/hf_store.py): `services/training/worker/hf_store.py`

### Model serving

- [Model management API](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/routes/models.py): `services/inference/app/routes/models.py`
- [Prediction API](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/routes/predict.py): `services/inference/app/routes/predict.py`
- [Payload validation](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/input_validation.py): `services/inference/app/input_validation.py`
- [Model registry](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/registry.py): `services/inference/app/registry.py`
- [Artifact cache](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/cache.py): `services/inference/app/cache.py`
- [Artifact downloader](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/hf_loader.py): `services/inference/app/hf_loader.py`
- [Inference database access](https://github.com/abdulnafih-official/ml-microservices/blob/main/services/inference/app/db.py): `services/inference/app/db.py`

### Shared platform

- [JWT utilities](https://github.com/abdulnafih-official/ml-microservices/blob/main/shared/mlp_common/mlp_common/jwt_utils.py): `shared/mlp_common/mlp_common/jwt_utils.py`
- [Prometheus metrics](https://github.com/abdulnafih-official/ml-microservices/blob/main/shared/mlp_common/mlp_common/metrics.py): `shared/mlp_common/mlp_common/metrics.py`

### Other components

- **Platform user**
- **PostgreSQL**
- **Hugging Face**

## Connections

- Platform user → Streamlit pages: uses
- Streamlit pages → Service API client: requests services (evidence: `services/user/pages/1_Train.py`)
- UI entry and session → Service API client: uses (evidence: `services/user/app.py`)
- UI entry and session → Login session: uses (evidence: `services/user/app.py`)
- Service API client → Registration and login: registers and logs in (evidence: `services/user/api_client.py`)
- Service API client → Training job API: submits jobs (evidence: `services/user/api_client.py`)
- Service API client → Model management API: manages models (evidence: `services/user/api_client.py`)
- Service API client → Prediction API: requests predictions (evidence: `services/user/api_client.py`)
- Registration and login → Auth database access: reads and writes (evidence: `services/auth/app/routes/auth.py`)
- Registration and login → User and quota data: uses user records (evidence: `services/auth/app/routes/auth.py`)
- Registration and login → JWT utilities: verifies tokens (evidence: `services/auth/app/routes/auth.py`)
- Registration and login → Rate limiting: applies limits (evidence: `services/auth/app/routes/auth.py`)
- Internal quota API → Auth database access: uses database (evidence: `services/auth/app/routes/internal.py`)
- Internal quota API → User and quota data: uses quota records (evidence: `services/auth/app/routes/internal.py`)
- Training job API → Training database access: reads and writes (evidence: `services/training/app/routes/jobs.py`)
- Training job API → Dataset uploads: stores upload (evidence: `services/training/app/routes/jobs.py`)
- Training job API → Quota client: reserves quota (evidence: `services/training/app/routes/jobs.py`)
- Quota client → Internal quota API: calls quota endpoints (evidence: `services/training/app/auth_client.py`)
- Job orchestration → Data profiling: profiles data (evidence: `services/training/worker/job_runner.py`)
- Job orchestration → Cleaning planners: creates cleaning plan (evidence: `services/training/worker/job_runner.py`)
- Job orchestration → Plan validation: validates plan (evidence: `services/training/worker/job_runner.py`)
- Job orchestration → Pipeline compilation: compiles pipeline (evidence: `services/training/worker/job_runner.py`)
- Job orchestration → Model training: trains model (evidence: `services/training/worker/job_runner.py`)
- Job orchestration → Model evaluation: evaluates model (evidence: `services/training/worker/job_runner.py`)
- Job orchestration → Model metadata: records metadata (evidence: `services/training/worker/job_runner.py`)
- Job orchestration → Private artifact storage: uploads artifact (evidence: `services/training/worker/job_runner.py`)
- Model management API → Inference database access: reads and writes (evidence: `services/inference/app/routes/models.py`)
- Model management API → Artifact cache: removes cached model (evidence: `services/inference/app/routes/models.py`)
- Model management API → Artifact downloader: loads artifacts (evidence: `services/inference/app/routes/models.py`)
- Prediction API → Model registry: gets model (evidence: `services/inference/app/routes/predict.py`)
- Prediction API → Inference database access: gets database session (evidence: `services/inference/app/routes/predict.py`)
- Prediction API → Payload validation: validates payload (evidence: `services/inference/app/routes/predict.py`)
- Prediction API → Artifact cache: gets pipeline (evidence: `services/inference/app/routes/predict.py`)
- Artifact cache → Artifact downloader: downloads artifact (evidence: `services/inference/app/cache.py`)
- PostgreSQL → Auth database access: stores auth data
- PostgreSQL → Training database access: stores job data
- PostgreSQL → Inference database access: stores model metadata
- Private artifact storage → Hugging Face: uploads private models
- Artifact downloader → Hugging Face: downloads private models
- Job orchestration → Prometheus metrics: records metrics (evidence: `services/training/worker/job_runner.py`)
