# egeiran/nhl-ml-prediction-model architecture

> Architecture diagram of the GitHub repository egeiran/nhl-ml-prediction-model, 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/egeiran/nhl-ml-prediction-model
- Repository: https://github.com/egeiran/nhl-ml-prediction-model

## Overview

This repository serves NHL betting analysis: historical game data and Elo ratings support model predictions, which are compared with Norsk Tipping odds to produce value reports and track portfolio outcomes. Users explore those results in a seven-route frontend or request predictions and reports through FastAPI. A daily export also supports static frontend data. README documents the main product capabilities; the sampled source confirms feature construction, live game retrieval, and parts of report and portfolio logic, but API routing and several frontend screens were not sampled, so those links rely on the README.

Main entry points: [`nhl-frontend/app/page.tsx`](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/app/page.tsx) (Blålinja app), [`nhl-frontend/lib/data.ts`](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/lib/data.ts) (Data access), [`NHL/report_service.py`](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/report_service.py) (Prediction reports), [`NHL/live/live_feature_builder.py`](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/live/live_feature_builder.py) (Live feature builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model["Model and ratings"]
  node_model["Random Forest model<br/>[model_utils.py]"]
  node_features["Feature engineering"]
  node_elo["Elo ratings<br/>[elo.py]"]
  node_training_data[("Historical game data<br/>[data_loader.py]")]
end

subgraph group_live["Live prediction data"]
  node_live_features["Live feature builder"]
  node_form["Team form<br/>[form_engine.py]"]
  node_nhl["NHL game API<br/>[nhl_api.py]"]
  node_odds["Norsk Tipping odds<br/>[nt_odds.py]"]
  node_team_alias["Team aliases<br/>[team_alias.py]"]
end

subgraph group_reports["Reports and tracking"]
  node_api["FastAPI service<br/>[api.py]"]
  node_report["Prediction reports<br/>[report_service.py]"]
  node_tracker["Portfolio tracker<br/>[bet_tracker.py]"]
  node_export["Static data export"]
  node_portfolio_store[("Bet history CSV<br/>[bet_tracker.py]")]
end

subgraph group_web["Frontend experience"]
  node_frontend["Blålinja app<br/>[page.tsx]"]
  node_overview["Daily overview<br/>[Oversikt.tsx]"]
  node_value_ui["Value board<br/>[VerdiSkjerm.tsx]"]
  node_match_ui["Matchup analysis<br/>[KampSkjerm.tsx]"]
  node_history_ui["Bet history"]
  node_elo_ui["Elo rankings<br/>[EloSkjerm.tsx]"]
  node_model_ui["Model diagnostics<br/>[ModellSkjerm.tsx]"]
  node_shadow_ui["Shadow bets<br/>[SkyggeSkjerm.tsx]"]
  node_data_client["Data access<br/>[data.ts]"]
end

node_user(("Hockey analyst"))
node_nhl_service(("NHL API"))
node_nt_service(("Norsk Tipping"))

node_user -->|"opens"| node_frontend
node_frontend -->|"shows"| node_overview
node_frontend -->|"shows"| node_value_ui
node_frontend -->|"shows"| node_match_ui
node_frontend -->|"shows"| node_history_ui
node_frontend -->|"shows"| node_elo_ui
node_frontend -->|"shows"| node_model_ui
node_frontend -->|"shows"| node_shadow_ui
node_frontend -->|"loads data"| node_data_client
node_data_client -.->|"requests reports"| node_api
node_data_client -.->|"reads exported data"| node_export
node_api -->|"uses reports"| node_report
node_export -->|"shares logic"| node_report
node_report -->|"builds features"| node_live_features
node_report -->|"predicts outcomes"| node_model
node_report -->|"gets odds"| node_odds
node_report -->|"gets games"| node_nhl
node_report -->|"builds portfolio"| node_tracker
node_tracker -->|"reads and writes"| node_portfolio_store
node_export -->|"publishes JSON"| node_frontend
node_live_features -->|"calculates form"| node_form
node_live_features -->|"adds ratings"| node_elo
node_live_features -->|"normalizes teams"| node_team_alias
node_form -->|"fetches recent games"| node_nhl
node_nhl -->|"requests games"| node_nhl_service
node_odds -.->|"fetches odds"| node_nt_service
node_features -->|"uses Elo features"| node_elo
node_features -.->|"transforms games"| node_training_data
node_model -.->|"consumes features"| node_features
node_elo -.->|"seeds ratings"| node_training_data
node_value_ui -.->|"loads report"| node_data_client
node_match_ui -.->|"loads matchups"| node_data_client
node_history_ui -.->|"loads portfolio"| node_data_client
node_elo_ui -.->|"loads ratings"| node_data_client
node_model_ui -.->|"loads diagnostics"| node_data_client
node_shadow_ui -.->|"loads shadow log"| node_data_client
node_overview -.->|"loads summary"| node_data_client

click node_frontend "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/app/page.tsx"
click node_overview "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/components/oversikt/Oversikt.tsx"
click node_value_ui "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/components/verdi/VerdiSkjerm.tsx"
click node_match_ui "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/components/kamp/KampSkjerm.tsx"
click node_history_ui "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/components/historikk/HistorikkSkjerm.tsx"
click node_elo_ui "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/components/elo/EloSkjerm.tsx"
click node_model_ui "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/components/modell/ModellSkjerm.tsx"
click node_shadow_ui "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/components/skygge/SkyggeSkjerm.tsx"
click node_data_client "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/lib/data.ts"
click node_api "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/api.py"
click node_report "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/report_service.py"
click node_tracker "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/bet_tracker.py"
click node_export "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/export_site_data.py"
click node_portfolio_store "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/bet_tracker.py"
click node_model "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/utils/model_utils.py"
click node_features "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/utils/feature_engineering.py"
click node_elo "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/utils/elo.py"
click node_training_data "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/utils/data_loader.py"
click node_live_features "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/live/live_feature_builder.py"
click node_form "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/live/form_engine.py"
click node_nhl "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/live/nhl_api.py"
click node_odds "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/live/nt_odds.py"
click node_team_alias "https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/utils/team_alias.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_model,node_features,node_elo,node_training_data toneBlue
class node_live_features,node_form,node_nhl,node_odds,node_team_alias toneAmber
class node_api,node_report,node_tracker,node_export,node_portfolio_store,node_nhl_service toneMint
class node_frontend,node_overview,node_value_ui,node_match_ui,node_history_ui,node_elo_ui,node_model_ui,node_shadow_ui,node_data_client toneRose
class node_user,node_nt_service toneIndigo
```

## Components

### Model and ratings

- [Random Forest model](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/utils/model_utils.py): `NHL/utils/model_utils.py`
- [Feature engineering](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/utils/feature_engineering.py): `NHL/utils/feature_engineering.py`
- [Elo ratings](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/utils/elo.py): `NHL/utils/elo.py`
- [Historical game data](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/utils/data_loader.py): `NHL/utils/data_loader.py`

### Live prediction data

- [Live feature builder](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/live/live_feature_builder.py): `NHL/live/live_feature_builder.py`
- [Team form](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/live/form_engine.py): `NHL/live/form_engine.py`
- [NHL game API](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/live/nhl_api.py): `NHL/live/nhl_api.py`
- [Norsk Tipping odds](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/live/nt_odds.py): `NHL/live/nt_odds.py`
- [Team aliases](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/utils/team_alias.py): `NHL/utils/team_alias.py`

### Reports and tracking

- [FastAPI service](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/api.py): `NHL/api.py`
- [Prediction reports](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/report_service.py): `NHL/report_service.py`
- [Portfolio tracker](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/bet_tracker.py): `NHL/bet_tracker.py`
- [Static data export](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/export_site_data.py): `NHL/export_site_data.py`
- [Bet history CSV](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/NHL/bet_tracker.py): `NHL/bet_tracker.py`

### Frontend experience

- [Blålinja app](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/app/page.tsx): `nhl-frontend/app/page.tsx`
- [Daily overview](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/components/oversikt/Oversikt.tsx): `nhl-frontend/components/oversikt/Oversikt.tsx`
- [Value board](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/components/verdi/VerdiSkjerm.tsx): `nhl-frontend/components/verdi/VerdiSkjerm.tsx`
- [Matchup analysis](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/components/kamp/KampSkjerm.tsx): `nhl-frontend/components/kamp/KampSkjerm.tsx`
- [Bet history](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/components/historikk/HistorikkSkjerm.tsx): `nhl-frontend/components/historikk/HistorikkSkjerm.tsx`
- [Elo rankings](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/components/elo/EloSkjerm.tsx): `nhl-frontend/components/elo/EloSkjerm.tsx`
- [Model diagnostics](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/components/modell/ModellSkjerm.tsx): `nhl-frontend/components/modell/ModellSkjerm.tsx`
- [Shadow bets](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/components/skygge/SkyggeSkjerm.tsx): `nhl-frontend/components/skygge/SkyggeSkjerm.tsx`
- [Data access](https://github.com/egeiran/nhl-ml-prediction-model/blob/main/nhl-frontend/lib/data.ts): `nhl-frontend/lib/data.ts`

### Other components

- **Hockey analyst**
- **NHL API**
- **Norsk Tipping**

## Connections

- Hockey analyst → Blålinja app: opens (evidence: `README.md`)
- Blålinja app → Daily overview: shows (evidence: `README.md`)
- Blålinja app → Value board: shows (evidence: `README.md`)
- Blålinja app → Matchup analysis: shows (evidence: `README.md`)
- Blålinja app → Bet history: shows (evidence: `README.md`)
- Blålinja app → Elo rankings: shows (evidence: `README.md`)
- Blålinja app → Model diagnostics: shows (evidence: `README.md`)
- Blålinja app → Shadow bets: shows (evidence: `README.md`)
- Blålinja app → Data access: loads data (evidence: `README.md`)
- Data access → FastAPI service: requests reports (evidence: `README.md`)
- Data access → Static data export: reads exported data (evidence: `README.md`)
- FastAPI service → Prediction reports: uses reports (evidence: `README.md`)
- Static data export → Prediction reports: shares logic (evidence: `NHL/report_service.py`)
- Prediction reports → Live feature builder: builds features (evidence: `NHL/report_service.py`)
- Prediction reports → Random Forest model: predicts outcomes (evidence: `NHL/report_service.py`)
- Prediction reports → Norsk Tipping odds: gets odds (evidence: `NHL/report_service.py`)
- Prediction reports → NHL game API: gets games (evidence: `NHL/report_service.py`)
- Prediction reports → Portfolio tracker: builds portfolio (evidence: `README.md`)
- Portfolio tracker → Bet history CSV: reads and writes (evidence: `README.md`)
- Static data export → Blålinja app: publishes JSON (evidence: `README.md`)
- Live feature builder → Team form: calculates form (evidence: `NHL/live/live_feature_builder.py`)
- Live feature builder → Elo ratings: adds ratings (evidence: `NHL/live/live_feature_builder.py`)
- Live feature builder → Team aliases: normalizes teams (evidence: `NHL/live/live_feature_builder.py`)
- Team form → NHL game API: fetches recent games (evidence: `NHL/live/form_engine.py`)
- NHL game API → NHL API: requests games (evidence: `NHL/live/nhl_api.py`)
- Norsk Tipping odds → Norsk Tipping: fetches odds
- Feature engineering → Elo ratings: uses Elo features (evidence: `NHL/utils/feature_engineering.py`)
- Feature engineering → Historical game data: transforms games
- Random Forest model → Feature engineering: consumes features (evidence: `README.md`)
- Elo ratings → Historical game data: seeds ratings (evidence: `README.md`)
- Value board → Data access: loads report (evidence: `README.md`)
- Matchup analysis → Data access: loads matchups (evidence: `README.md`)
- Bet history → Data access: loads portfolio (evidence: `README.md`)
- Elo rankings → Data access: loads ratings (evidence: `README.md`)
- Model diagnostics → Data access: loads diagnostics (evidence: `README.md`)
- Shadow bets → Data access: loads shadow log (evidence: `README.md`)
- Daily overview → Data access: loads summary (evidence: `README.md`)
