# rameshkunwar/aidanskvocabularybuilder architecture

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

- Interactive diagram: https://gitdiagram.com/rameshkunwar/aidanskvocabularybuilder
- Repository: https://github.com/rameshkunwar/aidanskvocabularybuilder

## Overview

#### Purpose and Entry Points
AIDanskVocabularyBuilder is a child-focused Danish vocabulary-learning system. It accepts book-page images, uses AI to extract vocabulary and kid-friendly definitions, stores learning progress, and supports spelling practice, gamification, and Danish audio pronunciation.

Backend startup is FastAPI at `backend/app/main.py`; its HTTP surface is organized in `backend/app/api/endpoints.py`. The browser client starts from `frontend/src/main.tsx` and composes the application in `frontend/src/App.tsx`.

#### Frontend Learning Experience
The React/TypeScript frontend provides distinct upload, practice, progress, and dashboard views:
- `frontend/src/pages/UploadPage.tsx`
- `frontend/src/pages/PracticePage.tsx`
- `frontend/src/pages/DashboardPage.tsx`
- `frontend/src/pages/ProgressPage.tsx`

Reusable learning UI includes word cards, point display, badges, and celebration feedback in `frontend/src/components/WordCard.tsx`, `frontend/src/components/PointsDisplay.tsx`, and `frontend/src/components/Celebration.tsx`.

#### Client/API Boundary
`frontend/src/lib/api.ts` is the primary browser-to-backend boundary. UI pages call this client to submit page images, retrieve vocabulary/progress, and record practice outcomes. Shared API/domain shapes are represented by `frontend/src/types/index.ts`.

The frontend is independently containerized (`frontend/Dockerfile`) and should remain decoupled from backend implementation details beyond the API contract.

#### API and Application Orchestration
`backend/app/api/endpoints.py` owns request handling and coordinates the main workflow: image upload, vocabulary extraction, persistence, practice/progress updates, and text-to-speech access. `backend/app/main.py` initializes the FastAPI application and mounts this API layer.

This is the principal control boundary: HTTP handlers translate client requests into extraction, LLM, database, and audio-service operations.

#### AI Extraction Pipeline
Book-page processing is implemented in `backend/app/extractor.py`. It receives uploaded imagery/content and drives structured vocabulary extraction. `backend/app/llm_adapter.py` abstracts the model provider layer, allowing Pydantic AI orchestration to use Google Gemini by default or an Ollama-backed model.

The extraction boundary should produce validated vocabulary data rather than expose raw model output to API consumers or persistence.

#### Persistence and Learning State
SQLModel/PostgreSQL integration is centralized in `backend/app/db.py`; persistent entity definitions live in `backend/app/models.py`. These models represent the durable boundary for extracted words and learner progression/gamification state.

Database initialization or maintenance is supported by `backend/update_db.py`. PostgreSQL is infrastructure rather than a frontend concern.

#### Speech and Deployment Infrastructure
`backend/app/tts.py` integrates Danish pronunciation through the external DR.dk API. It is a separate service boundary from word extraction and should tolerate external API failures independently.

The full stack is deployable with `docker-compose.yml`, using service-specific images from `backend/Dockerfile` and `frontend/Dockerfile`. `Caddyfile` indicates Caddy is the intended edge proxy/static-serving layer in a composed deployment.

Main entry points: [`backend/app/api/endpoints.py`](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/api/endpoints.py) (HTTP API), [`docker-compose.yml`](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/docker-compose.yml) (Compose deployment), [`frontend/src/pages/UploadPage.tsx`](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/src/pages/UploadPage.tsx) (Learning views), [`frontend/src/lib/api.ts`](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/src/lib/api.ts) (API client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser client"]
  node_react_entry["React entry<br/>TypeScript bootstrap<br/>[main.tsx]"]
  node_app_shell["App composition<br/>React application<br/>[App.tsx]"]
  node_learning_pages["Learning views<br/>React pages<br/>[UploadPage.tsx]"]
  node_learning_ui["Learning UI<br/>React components<br/>[WordCard.tsx]"]
  node_api_client["API client<br/>browser API boundary<br/>[api.ts]"]
  node_shared_types["API domain shapes<br/>TypeScript types<br/>[index.ts]"]
end

subgraph group_backend["FastAPI application"]
  node_fastapi_main["FastAPI startup<br/>application entry<br/>[main.py]"]
  node_api_endpoints["HTTP API<br/>request orchestration<br/>[endpoints.py]"]
  node_db_layer["Database integration<br/>SQLModel/PostgreSQL access<br/>[db.py]"]
  node_learning_models["Learning state models<br/>persistent entities<br/>[models.py]"]
  node_tts_service["Danish pronunciation<br/>external speech integration<br/>[tts.py]"]
end

subgraph group_ai["AI extraction"]
  node_extractor["Vocabulary extractor<br/>extraction pipeline<br/>[extractor.py]"]
  node_llm_adapter["Model adapter<br/>LLM provider boundary<br/>[llm_adapter.py]"]
end

subgraph group_deployment["Infrastructure"]
  node_postgres[("PostgreSQL<br/>database")]
  node_caddy["Caddy edge proxy<br/>proxy and static serving"]
  node_compose["Compose deployment<br/>stack orchestration<br/>[docker-compose.yml]"]
  node_backend_image["Backend image<br/>container image"]
  node_frontend_image["Frontend image<br/>container image"]
end

node_dr_api(("DR.dk API<br/>external API"))

node_react_entry -->|"boots"| node_app_shell
node_app_shell -->|"composes"| node_learning_pages
node_learning_pages -->|"renders"| node_learning_ui
node_learning_pages -->|"uses"| node_api_client
node_api_client -->|"uses"| node_shared_types
node_api_client -->|"HTTP requests"| node_api_endpoints
node_fastapi_main -->|"mounts"| node_api_endpoints
node_api_endpoints -->|"processes uploads"| node_extractor
node_extractor -->|"requests extraction"| node_llm_adapter
node_api_endpoints -->|"reads and updates state"| node_db_layer
node_db_layer -->|"persists"| node_learning_models
node_db_layer -->|"connects"| node_postgres
node_api_endpoints -->|"requests pronunciation"| node_tts_service
node_tts_service -->|"calls"| node_dr_api
node_compose -->|"deploys"| node_caddy
node_compose -->|"builds"| node_backend_image
node_compose -->|"builds"| node_frontend_image
node_caddy -->|"serves"| node_frontend_image
node_caddy -->|"proxies API"| node_fastapi_main
node_frontend_image -.->|"packages"| node_app_shell
node_backend_image -.->|"packages"| node_fastapi_main

click node_react_entry "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/src/main.tsx"
click node_app_shell "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/src/App.tsx"
click node_learning_pages "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/src/pages/UploadPage.tsx"
click node_learning_ui "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/src/components/WordCard.tsx"
click node_api_client "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/src/lib/api.ts"
click node_shared_types "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/src/types/index.ts"
click node_fastapi_main "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/main.py"
click node_api_endpoints "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/api/endpoints.py"
click node_extractor "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/extractor.py"
click node_llm_adapter "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/llm_adapter.py"
click node_db_layer "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/db.py"
click node_learning_models "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/models.py"
click node_tts_service "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/tts.py"
click node_caddy "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/Caddyfile"
click node_compose "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/docker-compose.yml"
click node_backend_image "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/Dockerfile"
click node_frontend_image "https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/Dockerfile"

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_react_entry,node_app_shell,node_learning_pages,node_learning_ui,node_api_client,node_shared_types toneBlue
class node_fastapi_main,node_api_endpoints,node_db_layer,node_learning_models,node_tts_service toneAmber
class node_extractor,node_llm_adapter toneMint
class node_postgres,node_caddy,node_compose,node_backend_image,node_frontend_image toneRose
class node_dr_api toneNeutral
```

## Components

### Browser client

- [React entry](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/src/main.tsx): TypeScript bootstrap · `frontend/src/main.tsx`
- [App composition](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/src/App.tsx): React application · `frontend/src/App.tsx`
- [Learning views](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/src/pages/UploadPage.tsx): React pages · Upload, practice, dashboard, and progress views. · `frontend/src/pages/UploadPage.tsx`
- [Learning UI](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/src/components/WordCard.tsx): React components · Word cards, points, and celebration feedback. · `frontend/src/components/WordCard.tsx`
- [API client](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/src/lib/api.ts): browser API boundary · `frontend/src/lib/api.ts`
- [API domain shapes](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/src/types/index.ts): TypeScript types · `frontend/src/types/index.ts`

### FastAPI application

- [FastAPI startup](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/main.py): application entry · `backend/app/main.py`
- [HTTP API](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/api/endpoints.py): request orchestration · Coordinates uploads, learning state, and pronunciation access. · `backend/app/api/endpoints.py`
- [Database integration](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/db.py): SQLModel/PostgreSQL access · `backend/app/db.py`
- [Learning state models](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/models.py): persistent entities · Words, progress, and gamification state. · `backend/app/models.py`
- [Danish pronunciation](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/tts.py): external speech integration · Independent DR.dk API boundary. · `backend/app/tts.py`

### AI extraction

- [Vocabulary extractor](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/extractor.py): extraction pipeline · Produces validated vocabulary from book-page content. · `backend/app/extractor.py`
- [Model adapter](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/app/llm_adapter.py): LLM provider boundary · Uses Gemini by default or an Ollama-backed model. · `backend/app/llm_adapter.py`

### Infrastructure

- **PostgreSQL**: database
- [Caddy edge proxy](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/Caddyfile): proxy and static serving · `Caddyfile`
- [Compose deployment](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/docker-compose.yml): stack orchestration · `docker-compose.yml`
- [Backend image](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/backend/Dockerfile): container image · `backend/Dockerfile`
- [Frontend image](https://github.com/rameshkunwar/aidanskvocabularybuilder/blob/main/frontend/Dockerfile): container image · `frontend/Dockerfile`

### Other components

- **DR.dk API**: external API

## Connections

- React entry → App composition: boots
- App composition → Learning views: composes
- Learning views → Learning UI: renders
- Learning views → API client: uses
- API client → API domain shapes: uses
- API client → HTTP API: HTTP requests
- FastAPI startup → HTTP API: mounts
- HTTP API → Vocabulary extractor: processes uploads
- Vocabulary extractor → Model adapter: requests extraction
- HTTP API → Database integration: reads and updates state
- Database integration → Learning state models: persists
- Database integration → PostgreSQL: connects
- HTTP API → Danish pronunciation: requests pronunciation
- Danish pronunciation → DR.dk API: calls
- Compose deployment → Caddy edge proxy: deploys
- Compose deployment → Backend image: builds
- Compose deployment → Frontend image: builds
- Caddy edge proxy → Frontend image: serves
- Caddy edge proxy → FastAPI startup: proxies API
- Frontend image → App composition: packages
- Backend image → FastAPI startup: packages
