# ennela/nckh-cryptographicanalysis architecture

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

- Interactive diagram: https://gitdiagram.com/ennela/nckh-cryptographicanalysis
- Repository: https://github.com/ennela/nckh-cryptographicanalysis

## Overview

This is a multi-service market-data and forecasting product: scheduled collectors acquire Vietnamese equities and Binance crypto candles, ingestion cleans and stores them, training builds and evaluates forecasting models, and the inference API serves predictions and market data to the Next.js dashboard. The README also documents model explainability, multiple model families, MLflow, and cached inference; those capabilities are included where paths are supported. Legacy collector APIs remain separate. Several links between frontend pages and API endpoints, and training-to-inference model registration, are documented or implied but not visible in the sampled calls; such links are dashed where appropriate.

Main entry points: [`services/training/train.py`](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/train.py) (Model training), [`shared/db/repositories/market_repo.py`](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/shared/db/repositories/market_repo.py) (TimescaleDB market data), [`services/inference/main.py`](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/inference/main.py) (Inference API), [`services/ingestion/tasks.py`](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/ingestion/tasks.py) (Collection tasks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_dashboard["Dashboard<br/>[page.tsx]"]
  node_forecastui["Forecast view<br/>[page.tsx]"]
  node_symbolsui["Symbol browser<br/>[page.tsx]"]
  node_explainui["Explainability view<br/>[page.tsx]"]
  node_chart["Market charts<br/>[chart.tsx]"]
  node_nav["Navigation<br/>[navbar.tsx]"]
end

subgraph group_collect["Market ingestion"]
  node_scheduler["Ingestion schedule<br/>[scheduler.py]"]
  node_tasks["Collection tasks<br/>[tasks.py]"]
  node_binance["Binance adapter<br/>[binance_adapter.py]"]
  node_vnstock["VNStock adapter<br/>[vnstock_adapter.py]"]
  node_pipeline["Clean and store<br/>[pipeline.py]"]
  node_cleaning["Data cleaning<br/>[cleaning.py]"]
  node_legacybinance["Legacy Binance collector<br/>[binance_client.py]"]
  node_legacyvnstock["Legacy VNStock collector<br/>[vnstock_client.py]"]
end

subgraph group_platform["Shared data platform"]
  node_db[("TimescaleDB market data<br/>[market_repo.py]")]
  node_sessions["DB sessions<br/>[session.py]"]
  node_ohlcv["OHLCV schema<br/>[ohlcv.py]"]
  node_dataset["Locked dataset loader<br/>[loader.py]"]
end

subgraph group_ml["Model lifecycle"]
  node_trainer["Model training<br/>[train.py]"]
  node_arima["ARIMA<br/>[arima_model.py]"]
  node_gru["GRU<br/>[gru_model.py]"]
  node_rf["Random Forest"]
  node_xgb["XGBoost and SHAP<br/>[xgboost_model.py]"]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
  node_mlflow["MLflow tracking<br/>[mlflow_utils.py]"]
end

subgraph group_serve["Forecast serving"]
  node_inference["Inference API<br/>[main.py]"]
  node_loader["Model loader<br/>[model_loader.py]"]
  node_cache[("Prediction cache<br/>[redis_cache.py]")]
end

node_user(("Investor"))
node_redis[("Redis")]
node_mlflowservice[("MLflow registry")]

node_user -->|"views"| node_dashboard
node_user -->|"requests forecasts"| node_forecastui
node_user -->|"browses assets"| node_symbolsui
node_user -->|"inspects explanations"| node_explainui
node_dashboard -.->|"renders"| node_chart
node_forecastui -.->|"renders"| node_chart
node_dashboard -.->|"uses"| node_nav
node_forecastui -.->|"requests predictions"| node_inference
node_symbolsui -.->|"requests symbols"| node_inference
node_explainui -.->|"requests explanations"| node_inference
node_scheduler -.->|"schedules"| node_tasks
node_tasks -->|"fetches crypto"| node_binance
node_tasks -->|"fetches equities"| node_vnstock
node_tasks -->|"runs cleaning"| node_pipeline
node_pipeline -->|"cleans rows"| node_cleaning
node_pipeline -->|"upserts candles"| node_db
node_tasks -->|"writes candles"| node_db
node_binance -->|"produces candles"| node_ohlcv
node_vnstock -->|"produces candles"| node_ohlcv
node_legacybinance -.->|"stores candles"| node_db
node_legacyvnstock -.->|"stores candles"| node_db
node_sessions -->|"connects"| node_db
node_trainer -.->|"loads training data"| node_dataset
node_dataset -.->|"reads snapshot"| node_db
node_trainer -.->|"trains"| node_arima
node_trainer -->|"trains"| node_gru
node_trainer -.->|"trains"| node_rf
node_trainer -.->|"trains"| node_xgb
node_trainer -.->|"evaluates"| node_evaluation
node_trainer -->|"logs runs"| node_mlflow
node_inference -->|"loads models"| node_loader
node_inference -->|"checks predictions"| node_cache
node_cache -.->|"stores entries"| node_redis
node_inference -->|"reads market data"| node_db
node_loader -.->|"loads registry models"| node_mlflowservice
node_mlflow -.->|"tracks models"| node_mlflowservice

click node_dashboard "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/frontend/app/page.tsx"
click node_forecastui "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/frontend/app/forecast/page.tsx"
click node_symbolsui "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/frontend/app/symbols/page.tsx"
click node_explainui "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/frontend/app/explainability/page.tsx"
click node_chart "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/frontend/components/chart.tsx"
click node_nav "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/frontend/components/navbar.tsx"
click node_scheduler "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/ingestion/app/scheduler.py"
click node_tasks "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/ingestion/tasks.py"
click node_binance "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/ingestion/adapters/binance_adapter.py"
click node_vnstock "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/ingestion/adapters/vnstock_adapter.py"
click node_pipeline "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/ingestion/app/pipeline.py"
click node_cleaning "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/ingestion/app/cleaning.py"
click node_legacybinance "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/api/binance_fastapi/app/binance_client.py"
click node_legacyvnstock "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/api/vnstock_fastapi/app/vnstock_client.py"
click node_db "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/shared/db/repositories/market_repo.py"
click node_sessions "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/shared/db/session.py"
click node_ohlcv "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/shared/schemas/ohlcv.py"
click node_dataset "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/shared/dataset/loader.py"
click node_trainer "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/train.py"
click node_arima "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/models/arima_model.py"
click node_gru "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/models/gru_model.py"
click node_rf "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/models/random_forest_model.py"
click node_xgb "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/models/xgboost_model.py"
click node_evaluation "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/evaluate.py"
click node_mlflow "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/mlflow_utils.py"
click node_inference "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/inference/main.py"
click node_loader "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/inference/model_loader.py"
click node_cache "https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/inference/redis_cache.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_dashboard,node_forecastui,node_symbolsui,node_explainui,node_chart,node_nav toneBlue
class node_scheduler,node_tasks,node_binance,node_vnstock,node_pipeline,node_cleaning,node_legacybinance,node_legacyvnstock,node_redis,node_mlflowservice toneAmber
class node_db,node_sessions,node_ohlcv,node_dataset toneMint
class node_trainer,node_arima,node_gru,node_rf,node_xgb,node_evaluation,node_mlflow toneRose
class node_inference,node_loader,node_cache,node_user toneIndigo
```

## Components

### Web experience

- [Dashboard](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Forecast view](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/frontend/app/forecast/page.tsx): `frontend/app/forecast/page.tsx`
- [Symbol browser](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/frontend/app/symbols/page.tsx): `frontend/app/symbols/page.tsx`
- [Explainability view](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/frontend/app/explainability/page.tsx): `frontend/app/explainability/page.tsx`
- [Market charts](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/frontend/components/chart.tsx): `frontend/components/chart.tsx`
- [Navigation](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/frontend/components/navbar.tsx): `frontend/components/navbar.tsx`

### Market ingestion

- [Ingestion schedule](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/ingestion/app/scheduler.py): `services/ingestion/app/scheduler.py`
- [Collection tasks](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/ingestion/tasks.py): `services/ingestion/tasks.py`
- [Binance adapter](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/ingestion/adapters/binance_adapter.py): `services/ingestion/adapters/binance_adapter.py`
- [VNStock adapter](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/ingestion/adapters/vnstock_adapter.py): `services/ingestion/adapters/vnstock_adapter.py`
- [Clean and store](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/ingestion/app/pipeline.py): `services/ingestion/app/pipeline.py`
- [Data cleaning](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/ingestion/app/cleaning.py): `services/ingestion/app/cleaning.py`
- [Legacy Binance collector](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/api/binance_fastapi/app/binance_client.py): `api/binance_fastapi/app/binance_client.py`
- [Legacy VNStock collector](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/api/vnstock_fastapi/app/vnstock_client.py): `api/vnstock_fastapi/app/vnstock_client.py`

### Shared data platform

- [TimescaleDB market data](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/shared/db/repositories/market_repo.py): `shared/db/repositories/market_repo.py`
- [DB sessions](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/shared/db/session.py): `shared/db/session.py`
- [OHLCV schema](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/shared/schemas/ohlcv.py): `shared/schemas/ohlcv.py`
- [Locked dataset loader](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/shared/dataset/loader.py): `shared/dataset/loader.py`

### Model lifecycle

- [Model training](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/train.py): `services/training/train.py`
- [ARIMA](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/models/arima_model.py): `services/training/models/arima_model.py`
- [GRU](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/models/gru_model.py): `services/training/models/gru_model.py`
- [Random Forest](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/models/random_forest_model.py): `services/training/models/random_forest_model.py`
- [XGBoost and SHAP](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/models/xgboost_model.py): `services/training/models/xgboost_model.py`
- [Model evaluation](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/evaluate.py): `services/training/evaluate.py`
- [MLflow tracking](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/training/mlflow_utils.py): `services/training/mlflow_utils.py`

### Forecast serving

- [Inference API](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/inference/main.py): `services/inference/main.py`
- [Model loader](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/inference/model_loader.py): `services/inference/model_loader.py`
- [Prediction cache](https://github.com/ennela/nckh-cryptographicanalysis/blob/main/services/inference/redis_cache.py): `services/inference/redis_cache.py`

### Other components

- **Investor**
- **Redis**
- **MLflow registry**

## Connections

- Investor → Dashboard: views (evidence: `README.md`)
- Investor → Forecast view: requests forecasts (evidence: `README.md`)
- Investor → Symbol browser: browses assets (evidence: `README.md`)
- Investor → Explainability view: inspects explanations (evidence: `README.md`)
- Dashboard → Market charts: renders
- Forecast view → Market charts: renders
- Dashboard → Navigation: uses
- Forecast view → Inference API: requests predictions
- Symbol browser → Inference API: requests symbols
- Explainability view → Inference API: requests explanations
- Ingestion schedule → Collection tasks: schedules
- Collection tasks → Binance adapter: fetches crypto (evidence: `services/ingestion/tasks.py`)
- Collection tasks → VNStock adapter: fetches equities (evidence: `services/ingestion/tasks.py`)
- Collection tasks → Clean and store: runs cleaning (evidence: `services/ingestion/tasks.py`)
- Clean and store → Data cleaning: cleans rows (evidence: `services/ingestion/app/pipeline.py`)
- Clean and store → TimescaleDB market data: upserts candles (evidence: `services/ingestion/app/pipeline.py`)
- Collection tasks → TimescaleDB market data: writes candles (evidence: `services/ingestion/tasks.py`)
- Binance adapter → OHLCV schema: produces candles (evidence: `services/ingestion/adapters/binance_adapter.py`)
- VNStock adapter → OHLCV schema: produces candles (evidence: `services/ingestion/adapters/vnstock_adapter.py`)
- Legacy Binance collector → TimescaleDB market data: stores candles
- Legacy VNStock collector → TimescaleDB market data: stores candles
- DB sessions → TimescaleDB market data: connects (evidence: `shared/db/session.py`)
- Model training → Locked dataset loader: loads training data
- Locked dataset loader → TimescaleDB market data: reads snapshot
- Model training → ARIMA: trains
- Model training → GRU: trains
- Model training → Random Forest: trains
- Model training → XGBoost and SHAP: trains
- Model training → Model evaluation: evaluates
- Model training → MLflow tracking: logs runs
- Inference API → Model loader: loads models (evidence: `services/inference/main.py`)
- Inference API → Prediction cache: checks predictions (evidence: `services/inference/main.py`)
- Prediction cache → Redis: stores entries
- Inference API → TimescaleDB market data: reads market data (evidence: `services/inference/main.py`)
- Model loader → MLflow registry: loads registry models
- MLflow tracking → MLflow registry: tracks models
