# jasilmyg/loyalty-main-dashboard architecture

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

- Interactive diagram: https://gitdiagram.com/jasilmyg/loyalty-main-dashboard
- Repository: https://github.com/jasilmyg/loyalty-main-dashboard

## Overview

This is a retail loyalty and business-intelligence platform for myG, with a separate She Start applicant-scoring capability. The main workflow is a manager or analyst opening a dashboard, whose Django views and APIs obtain live or pre-aggregated analytics from PostgreSQL and materialized views, then return charts and KPIs. A FastAPI analytics service provides a parallel API with Redis caching. Additional branches cover forecasting, customer intelligence, market-basket recommendations, and applicant evaluation. The README documents product-level connections; sampled source confirms selected service and routing links, but not every feature implementation.

Main entry points: [`myg_loyalty_dashboard/dashboard/views.py`](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/dashboard/views.py) (Dashboard screens), [`myg_loyalty_dashboard/myg_loyalty_dashboard/urls.py`](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/myg_loyalty_dashboard/urls.py) (Django application), [`myg_loyalty_dashboard/analytics/views.py`](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/views.py) (Analytics APIs), [`myg_loyalty_dashboard/api/routes/analytics.py`](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/api/routes/analytics.py) (Async analytics routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_django["Django application<br/>[urls.py]"]
  node_dashboard["Dashboard screens<br/>[views.py]"]
  node_dashboard_logic["Dashboard logic"]
  node_django_api["Analytics APIs<br/>[views.py]"]
  node_fastapi["Analytics microservice<br/>[main.py]"]
  node_fast_routes["Async analytics routes<br/>[analytics.py]"]
end

subgraph group_analytics["Retail intelligence"]
  node_core_analytics["Analytics queries<br/>[services.py]"]
  node_rfm["RFM segmentation<br/>[rfm_engine.py]"]
  node_campaign["Campaign intelligence"]
  node_forecast["AI forecasting<br/>[forecast_agent.py]"]
  node_ai_router["AI question router<br/>[router.py]"]
  node_sql_templates["SQL templates"]
  node_next_visit["Next-visit predictor"]
end

subgraph group_data["Data services"]
  node_pg[("PostgreSQL")]
  node_mvs[("Materialized views")]
  node_clickhouse[("ClickHouse analytics")]
  node_redis[("Redis cache<br/>[redis_cache.py]")]
end

subgraph group_special["Specialized products"]
  node_she_start["Applicant scoring"]
  node_she_detail["Detailed applicant report"]
  node_basket_views["Basket analysis views<br/>[views.py]"]
  node_basket_engine["Basket recommendations<br/>[engine.py]"]
  node_basket_tables["Basket table definitions<br/>[ch_tables.py]"]
end

node_user(("Manager / analyst"))
node_google_sheets[("Google Sheets")]
node_excel["Excel upload"]

node_user -->|"opens dashboards"| node_django
node_django -->|"routes screens"| node_dashboard
node_django -->|"routes analytics"| node_django_api
node_dashboard -.->|"uses logic"| node_dashboard_logic
node_dashboard -->|"requests analytics"| node_fastapi
node_django_api -->|"queries data"| node_pg
node_django_api -->|"queries aggregates"| node_mvs
node_fastapi -->|"registers routes"| node_fast_routes
node_fast_routes -->|"queries data"| node_pg
node_fast_routes -->|"caches responses"| node_redis
node_dashboard -.->|"requests metrics"| node_core_analytics
node_dashboard -->|"shows segments"| node_rfm
node_dashboard -->|"shows campaigns"| node_campaign
node_dashboard -->|"shows forecasts"| node_forecast
node_ai_router -->|"checks patterns"| node_sql_templates
node_forecast -.->|"forecasts from sales"| node_pg
node_dashboard -->|"shows predictions"| node_next_visit
node_dashboard -->|"shows applicants"| node_she_start
node_dashboard -->|"shows detail reports"| node_she_detail
node_she_start -->|"reads evaluations"| node_google_sheets
node_she_detail -->|"reuses score helpers"| node_she_start
node_dashboard -.->|"offers basket analysis"| node_basket_views
node_basket_views -.->|"requests analysis"| node_basket_engine
node_basket_engine -->|"reads sales data"| node_clickhouse
node_basket_engine -->|"uses table definitions"| node_basket_tables
node_excel -->|"uploads sales"| node_pg
node_pg -->|"refreshes aggregates"| node_mvs
node_clickhouse -->|"fallback reads"| node_pg

click node_django "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/myg_loyalty_dashboard/urls.py"
click node_dashboard "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/dashboard/views.py"
click node_dashboard_logic "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/dashboard/dashboard_api_logic.py"
click node_django_api "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/views.py"
click node_fastapi "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/api/main.py"
click node_fast_routes "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/api/routes/analytics.py"
click node_core_analytics "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/services.py"
click node_rfm "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/rfm_engine.py"
click node_campaign "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/campaign_intelligence.py"
click node_forecast "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/ai_agent/agents/forecast_agent.py"
click node_ai_router "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/ai_agent/agents/router.py"
click node_sql_templates "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/ai_agent/agents/sql_template_engine.py"
click node_next_visit "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/dashboard/next_visit_service.py"
click node_she_start "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/she_start_engine.py"
click node_she_detail "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/she_start_detailed_engine.py"
click node_basket_views "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/market_basket/views.py"
click node_basket_engine "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/market_basket/engine.py"
click node_clickhouse "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/clickhouse_service.py"
click node_redis "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/api/redis_cache.py"
click node_basket_tables "https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/market_basket/ch_tables.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_django,node_dashboard,node_dashboard_logic,node_django_api,node_fastapi,node_fast_routes toneBlue
class node_core_analytics,node_rfm,node_campaign,node_forecast,node_ai_router,node_sql_templates,node_next_visit,node_google_sheets toneAmber
class node_pg,node_mvs,node_clickhouse,node_redis toneMint
class node_she_start,node_she_detail,node_basket_views,node_basket_engine,node_basket_tables toneRose
class node_user,node_excel toneIndigo
```

## Components

### Web application

- [Django application](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/myg_loyalty_dashboard/urls.py): `myg_loyalty_dashboard/myg_loyalty_dashboard/urls.py`
- [Dashboard screens](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/dashboard/views.py): `myg_loyalty_dashboard/dashboard/views.py`
- [Dashboard logic](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/dashboard/dashboard_api_logic.py): `myg_loyalty_dashboard/dashboard/dashboard_api_logic.py`
- [Analytics APIs](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/views.py): `myg_loyalty_dashboard/analytics/views.py`
- [Analytics microservice](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/api/main.py): `myg_loyalty_dashboard/api/main.py`
- [Async analytics routes](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/api/routes/analytics.py): `myg_loyalty_dashboard/api/routes/analytics.py`

### Retail intelligence

- [Analytics queries](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/services.py): `myg_loyalty_dashboard/analytics/services.py`
- [RFM segmentation](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/rfm_engine.py): `myg_loyalty_dashboard/analytics/rfm_engine.py`
- [Campaign intelligence](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/campaign_intelligence.py): `myg_loyalty_dashboard/analytics/campaign_intelligence.py`
- [AI forecasting](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/ai_agent/agents/forecast_agent.py): `myg_loyalty_dashboard/ai_agent/agents/forecast_agent.py`
- [AI question router](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/ai_agent/agents/router.py): `myg_loyalty_dashboard/ai_agent/agents/router.py`
- [SQL templates](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/ai_agent/agents/sql_template_engine.py): `myg_loyalty_dashboard/ai_agent/agents/sql_template_engine.py`
- [Next-visit predictor](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/dashboard/next_visit_service.py): `myg_loyalty_dashboard/dashboard/next_visit_service.py`

### Data services

- **PostgreSQL**
- **Materialized views**
- [ClickHouse analytics](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/clickhouse_service.py): `myg_loyalty_dashboard/analytics/clickhouse_service.py`
- [Redis cache](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/api/redis_cache.py): `myg_loyalty_dashboard/api/redis_cache.py`

### Specialized products

- [Applicant scoring](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/she_start_engine.py): `myg_loyalty_dashboard/analytics/she_start_engine.py`
- [Detailed applicant report](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/analytics/she_start_detailed_engine.py): `myg_loyalty_dashboard/analytics/she_start_detailed_engine.py`
- [Basket analysis views](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/market_basket/views.py): `myg_loyalty_dashboard/market_basket/views.py`
- [Basket recommendations](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/market_basket/engine.py): `myg_loyalty_dashboard/market_basket/engine.py`
- [Basket table definitions](https://github.com/jasilmyg/loyalty-main-dashboard/blob/main/myg_loyalty_dashboard/market_basket/ch_tables.py): `myg_loyalty_dashboard/market_basket/ch_tables.py`

### Other components

- **Manager / analyst**
- **Google Sheets**
- **Excel upload**

## Connections

- Manager / analyst → Django application: opens dashboards
- Django application → Dashboard screens: routes screens
- Django application → Analytics APIs: routes analytics
- Dashboard screens → Dashboard logic: uses logic
- Dashboard screens → Analytics microservice: requests analytics
- Analytics APIs → PostgreSQL: queries data
- Analytics APIs → Materialized views: queries aggregates
- Analytics microservice → Async analytics routes: registers routes (evidence: `myg_loyalty_dashboard/api/main.py`)
- Async analytics routes → PostgreSQL: queries data (evidence: `myg_loyalty_dashboard/api/routes/analytics.py`)
- Async analytics routes → Redis cache: caches responses (evidence: `myg_loyalty_dashboard/api/routes/analytics.py`)
- Dashboard screens → Analytics queries: requests metrics
- Dashboard screens → RFM segmentation: shows segments
- Dashboard screens → Campaign intelligence: shows campaigns
- Dashboard screens → AI forecasting: shows forecasts
- AI question router → SQL templates: checks patterns (evidence: `myg_loyalty_dashboard/ai_agent/agents/router.py`)
- AI forecasting → PostgreSQL: forecasts from sales
- Dashboard screens → Next-visit predictor: shows predictions
- Dashboard screens → Applicant scoring: shows applicants
- Dashboard screens → Detailed applicant report: shows detail reports
- Applicant scoring → Google Sheets: reads evaluations (evidence: `myg_loyalty_dashboard/analytics/she_start_engine.py`)
- Detailed applicant report → Applicant scoring: reuses score helpers (evidence: `myg_loyalty_dashboard/analytics/she_start_detailed_engine.py`)
- Dashboard screens → Basket analysis views: offers basket analysis
- Basket analysis views → Basket recommendations: requests analysis
- Basket recommendations → ClickHouse analytics: reads sales data (evidence: `myg_loyalty_dashboard/market_basket/engine.py`)
- Basket recommendations → Basket table definitions: uses table definitions (evidence: `myg_loyalty_dashboard/market_basket/engine.py`)
- Excel upload → PostgreSQL: uploads sales
- PostgreSQL → Materialized views: refreshes aggregates
- ClickHouse analytics → PostgreSQL: fallback reads (evidence: `myg_loyalty_dashboard/analytics/clickhouse_service.py`)
