# zadnap/cinematch-ml-service architecture

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

- Interactive diagram: https://gitdiagram.com/zadnap/cinematch-ml-service
- Repository: https://github.com/zadnap/cinematch-ml-service

## Overview

CineMatch is a Flask movie-recommendation service with a separate model-training workflow. A client submits a user ID, preference features, and result count; the route delegates to the recommendation service, which selects a cold-start genre strategy or a normal hybrid strategy, maps movie IDs to TMDB IDs, and returns a formatted response. Training fetches supplementary data from the web API, preprocesses and combines it with local data, then trains a two-tower retrieval model. The runtime engine loads processed data and model weights. Some training and startup relationships are supported by the SOURCE INDEX rather than excerpts; unsampled details are not expanded.

Main entry points: [`ml/training/data_preprocessor.py`](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/training/data_preprocessor.py) (Data Preprocessor), [`ml/inference/recommender.py`](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/inference/recommender.py) (Recommendation Strategies), [`ml/inference/recommender_engine.py`](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/inference/recommender_engine.py) (Inference Engine), [`ml/constants.py`](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/constants.py) (Processed Data and Weights)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Recommendation API"]
  node_route["Recommendation Route"]
  node_service["Recommendation Service"]
  node_response["Response Formatter<br/>[response.py]"]
end

subgraph group_inference["Recommendation Runtime"]
  node_recommender["Recommendation Strategies<br/>[recommender.py]"]
  node_engine["Inference Engine"]
  node_id_mapper["TMDB ID Mapper<br/>[map_to_tmdb_id.py]"]
end

subgraph group_data["Data Preparation"]
  node_web_service["Training Data API Client<br/>[web_api_service.py]"]
  node_preprocessor["Data Preprocessor"]
  node_csv_export["CSV Export Helper<br/>[export_to_csv.py]"]
  node_year_parser["Title Year Parser"]
  node_local_data[("Processed Data and Weights<br/>[constants.py]")]
end

subgraph group_training["Model Training"]
  node_two_tower["Two-Tower Model"]
  node_dataset_loader["Dataset Loader<br/>[dataset_loader.py]"]
  node_trainer["Training Workflow<br/>[train.py]"]
end

node_client(("Recommendation Client"))
node_web_api["CineMatch API"]

node_client -->|"submits request"| node_route
node_route -->|"delegates to"| node_service
node_service -->|"requests recommendations"| node_recommender
node_service -->|"formats result"| node_response
node_recommender -->|"uses runtime"| node_engine
node_recommender -->|"maps movie IDs"| node_id_mapper
node_recommender -->|"checks user offset"| node_web_service
node_engine -->|"initializes model"| node_two_tower
node_engine -->|"loads mappings"| node_preprocessor
node_engine -->|"loads features and weights"| node_local_data
node_id_mapper -->|"reads movie links"| node_local_data
node_web_service -->|"fetches training data"| node_web_api
node_preprocessor -->|"fetches source data"| node_web_service
node_preprocessor -->|"exports fetched data"| node_csv_export
node_preprocessor -->|"parses movie titles"| node_year_parser
node_preprocessor -->|"writes processed data"| node_local_data
node_dataset_loader -->|"loads training data"| node_local_data
node_two_tower -->|"uses feature matrices"| node_dataset_loader
node_trainer -->|"uses preprocessing"| node_preprocessor
node_trainer -->|"uses datasets"| node_dataset_loader
node_trainer -->|"trains model"| node_two_tower

click node_route "https://github.com/zadnap/cinematch-ml-service/blob/main/app/routes/recommend_routes.py"
click node_service "https://github.com/zadnap/cinematch-ml-service/blob/main/app/services/recommend_service.py"
click node_response "https://github.com/zadnap/cinematch-ml-service/blob/main/app/utils/response.py"
click node_recommender "https://github.com/zadnap/cinematch-ml-service/blob/main/ml/inference/recommender.py"
click node_engine "https://github.com/zadnap/cinematch-ml-service/blob/main/ml/inference/recommender_engine.py"
click node_two_tower "https://github.com/zadnap/cinematch-ml-service/blob/main/ml/models/two_towers_model.py"
click node_id_mapper "https://github.com/zadnap/cinematch-ml-service/blob/main/ml/utils/map_to_tmdb_id.py"
click node_web_service "https://github.com/zadnap/cinematch-ml-service/blob/main/ml/services/web_api_service.py"
click node_preprocessor "https://github.com/zadnap/cinematch-ml-service/blob/main/ml/training/data_preprocessor.py"
click node_csv_export "https://github.com/zadnap/cinematch-ml-service/blob/main/ml/utils/export_to_csv.py"
click node_year_parser "https://github.com/zadnap/cinematch-ml-service/blob/main/ml/utils/extract_year_from_title.py"
click node_local_data "https://github.com/zadnap/cinematch-ml-service/blob/main/ml/constants.py"
click node_dataset_loader "https://github.com/zadnap/cinematch-ml-service/blob/main/ml/training/dataset_loader.py"
click node_trainer "https://github.com/zadnap/cinematch-ml-service/blob/main/ml/training/train.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_route,node_service,node_response,node_client toneBlue
class node_recommender,node_engine,node_id_mapper toneAmber
class node_web_service,node_preprocessor,node_csv_export,node_year_parser,node_local_data,node_web_api toneMint
class node_two_tower,node_dataset_loader,node_trainer toneRose
```

## Components

### Recommendation API

- [Recommendation Route](https://github.com/zadnap/cinematch-ml-service/blob/main/app/routes/recommend_routes.py): `app/routes/recommend_routes.py`
- [Recommendation Service](https://github.com/zadnap/cinematch-ml-service/blob/main/app/services/recommend_service.py): `app/services/recommend_service.py`
- [Response Formatter](https://github.com/zadnap/cinematch-ml-service/blob/main/app/utils/response.py): `app/utils/response.py`

### Recommendation Runtime

- [Recommendation Strategies](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/inference/recommender.py): `ml/inference/recommender.py`
- [Inference Engine](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/inference/recommender_engine.py): `ml/inference/recommender_engine.py`
- [TMDB ID Mapper](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/utils/map_to_tmdb_id.py): `ml/utils/map_to_tmdb_id.py`

### Data Preparation

- [Training Data API Client](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/services/web_api_service.py): `ml/services/web_api_service.py`
- [Data Preprocessor](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/training/data_preprocessor.py): `ml/training/data_preprocessor.py`
- [CSV Export Helper](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/utils/export_to_csv.py): `ml/utils/export_to_csv.py`
- [Title Year Parser](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/utils/extract_year_from_title.py): `ml/utils/extract_year_from_title.py`
- [Processed Data and Weights](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/constants.py): `ml/constants.py`

### Model Training

- [Two-Tower Model](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/models/two_towers_model.py): `ml/models/two_towers_model.py`
- [Dataset Loader](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/training/dataset_loader.py): `ml/training/dataset_loader.py`
- [Training Workflow](https://github.com/zadnap/cinematch-ml-service/blob/main/ml/training/train.py): `ml/training/train.py`

### Other components

- **Recommendation Client**
- **CineMatch API**

## Connections

- Recommendation Client → Recommendation Route: submits request (evidence: `README.md`)
- Recommendation Route → Recommendation Service: delegates to (evidence: `app/routes/recommend_routes.py`)
- Recommendation Service → Recommendation Strategies: requests recommendations (evidence: `app/services/recommend_service.py`)
- Recommendation Service → Response Formatter: formats result (evidence: `app/services/recommend_service.py`)
- Recommendation Strategies → Inference Engine: uses runtime (evidence: `ml/inference/recommender.py`)
- Recommendation Strategies → TMDB ID Mapper: maps movie IDs (evidence: `ml/inference/recommender.py`)
- Recommendation Strategies → Training Data API Client: checks user offset (evidence: `ml/inference/recommender.py`)
- Inference Engine → Two-Tower Model: initializes model (evidence: `ml/inference/recommender_engine.py`)
- Inference Engine → Data Preprocessor: loads mappings (evidence: `ml/inference/recommender_engine.py`)
- Inference Engine → Processed Data and Weights: loads features and weights (evidence: `ml/inference/recommender_engine.py`)
- TMDB ID Mapper → Processed Data and Weights: reads movie links (evidence: `ml/utils/map_to_tmdb_id.py`)
- Training Data API Client → CineMatch API: fetches training data (evidence: `ml/services/web_api_service.py`)
- Data Preprocessor → Training Data API Client: fetches source data (evidence: `ml/training/data_preprocessor.py`)
- Data Preprocessor → CSV Export Helper: exports fetched data (evidence: `ml/training/data_preprocessor.py`)
- Data Preprocessor → Title Year Parser: parses movie titles (evidence: `ml/training/data_preprocessor.py`)
- Data Preprocessor → Processed Data and Weights: writes processed data (evidence: `ml/training/data_preprocessor.py`)
- Dataset Loader → Processed Data and Weights: loads training data (evidence: `ml/training/dataset_loader.py`)
- Two-Tower Model → Dataset Loader: uses feature matrices (evidence: `ml/models/two_towers_model.py`)
- Training Workflow → Data Preprocessor: uses preprocessing (evidence: `ml/training/train.py`)
- Training Workflow → Dataset Loader: uses datasets (evidence: `ml/training/train.py`)
- Training Workflow → Two-Tower Model: trains model (evidence: `ml/training/train.py`)
