# nodero-group-project/ade-chat-assistant-backend architecture

> Architecture diagram of the GitHub repository nodero-group-project/ade-chat-assistant-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nodero-group-project/ade-chat-assistant-backend
- Repository: https://github.com/nodero-group-project/ade-chat-assistant-backend

## Overview

This is a FastAPI backend for answering questions with Stats NZ data and managing the dataset catalogue. In the report workflow, the API classifies a question, rejects low-confidence matches, loads the chosen dataset, asks a routed Groq model to form a Stats NZ URL, retrieves data, and returns results with token usage. Dataset CRUD is a separate API capability backed by PostgreSQL. The excerpts show the main calls and integrations; unsampled modules and undocumented wiring are omitted.

Main entry points: [`app/main.py`](https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/main.py) (FastAPI endpoints), [`app/intent_classification.py`](https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/intent_classification.py) (Dataset selection), [`app/llm_query.py`](https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/llm_query.py) (StatsNZ URL generation), [`app/db.py`](https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/db.py) (Dataset repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API"]
  node_api["FastAPI endpoints<br/>[main.py]"]
end

subgraph group_catalogue["Dataset catalogue"]
  node_dataset_model["Dataset schema<br/>[Dataset.py]"]
  node_catalogue_access["Catalogue access<br/>[datasets.py]"]
  node_dataset_db["Dataset repository<br/>[db.py]"]
end

subgraph group_query["Question processing"]
  node_classification["Dataset selection"]
  node_routing["Model tier routing"]
  node_url_generation["StatsNZ URL generation<br/>[llm_query.py]"]
  node_usage["Token accounting<br/>[llm_usage.py]"]
end

subgraph group_services["External services"]
  node_postgres[("PostgreSQL")]
  node_groq["Groq"]
  node_statsnz["Stats NZ API"]
  node_stats_client["Stats NZ client<br/>[stat_nz.py]"]
end

node_user(("Client"))

node_user -->|"submits requests"| node_api
node_api -->|"classifies question"| node_classification
node_classification -->|"loads candidates"| node_catalogue_access
node_catalogue_access -->|"reads datasets"| node_dataset_db
node_dataset_db -->|"reads and writes"| node_postgres
node_api -->|"manages datasets"| node_dataset_db
node_api -->|"validates dataset input"| node_dataset_model
node_api -->|"requests URL"| node_url_generation
node_url_generation -->|"selects tier"| node_routing
node_classification -->|"requests classification"| node_groq
node_url_generation -->|"requests URL"| node_groq
node_url_generation -->|"logs tokens"| node_usage
node_classification -->|"logs tokens"| node_usage
node_api -->|"combines usage"| node_usage
node_api -->|"fetches results"| node_stats_client
node_stats_client -->|"sends GET request"| node_statsnz

click node_api "https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/main.py"
click node_dataset_model "https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/models/Dataset.py"
click node_catalogue_access "https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/datasets.py"
click node_dataset_db "https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/db.py"
click node_classification "https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/intent_classification.py"
click node_routing "https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/heuristic_router.py"
click node_url_generation "https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/llm_query.py"
click node_usage "https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/llm_usage.py"
click node_stats_client "https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/services/stat_nz.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_api,node_user toneBlue
class node_dataset_model,node_catalogue_access,node_dataset_db toneAmber
class node_classification,node_routing,node_url_generation,node_usage toneMint
class node_postgres,node_groq,node_statsnz,node_stats_client toneRose
```

## Components

### API

- [FastAPI endpoints](https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/main.py): `app/main.py`

### Dataset catalogue

- [Dataset schema](https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/models/Dataset.py): `app/models/Dataset.py`
- [Catalogue access](https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/datasets.py): `app/datasets.py`
- [Dataset repository](https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/db.py): `app/db.py`

### Question processing

- [Dataset selection](https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/intent_classification.py): `app/intent_classification.py`
- [Model tier routing](https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/heuristic_router.py): `app/heuristic_router.py`
- [StatsNZ URL generation](https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/llm_query.py): `app/llm_query.py`
- [Token accounting](https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/llm_usage.py): `app/llm_usage.py`

### External services

- **PostgreSQL**
- **Groq**
- **Stats NZ API**
- [Stats NZ client](https://github.com/nodero-group-project/ade-chat-assistant-backend/blob/main/app/services/stat_nz.py): `app/services/stat_nz.py`

### Other components

- **Client**

## Connections

- Client → FastAPI endpoints: submits requests (evidence: `app/main.py`)
- FastAPI endpoints → Dataset selection: classifies question (evidence: `app/main.py`)
- Dataset selection → Catalogue access: loads candidates (evidence: `app/intent_classification.py`)
- Catalogue access → Dataset repository: reads datasets (evidence: `app/datasets.py`)
- Dataset repository → PostgreSQL: reads and writes (evidence: `app/db.py`)
- FastAPI endpoints → Dataset repository: manages datasets (evidence: `app/main.py`)
- FastAPI endpoints → Dataset schema: validates dataset input (evidence: `app/main.py`)
- FastAPI endpoints → StatsNZ URL generation: requests URL (evidence: `app/main.py`)
- StatsNZ URL generation → Model tier routing: selects tier (evidence: `app/llm_query.py`)
- Dataset selection → Groq: requests classification (evidence: `app/intent_classification.py`)
- StatsNZ URL generation → Groq: requests URL (evidence: `app/llm_query.py`)
- StatsNZ URL generation → Token accounting: logs tokens (evidence: `app/llm_query.py`)
- Dataset selection → Token accounting: logs tokens (evidence: `app/intent_classification.py`)
- FastAPI endpoints → Token accounting: combines usage (evidence: `app/main.py`)
- FastAPI endpoints → Stats NZ client: fetches results (evidence: `app/main.py`)
- Stats NZ client → Stats NZ API: sends GET request (evidence: `app/services/stat_nz.py`)
