# johnnyhyytiainen/project3-kms architecture

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

- Interactive diagram: https://gitdiagram.com/johnnyhyytiainen/project3-kms
- Repository: https://github.com/johnnyhyytiainen/project3-kms

## Overview

This is a course-material knowledge system: files are registered with course and provenance, extracted into traceable chunks, embedded into a vector index, then searched to return ranked source chunks. The API also exposes an answer endpoint that passes retrieved hits to a generation agent. PostgreSQL is documented as the source of truth and ChromaDB as its vector derivative; an evaluation harness measures retrieval quality. The graph preserves the documented reconciliation capability. Some modules and their call paths were not excerpted, so uncertain links are omitted or marked unverified.

Main entry points: [`src/kms/embedding/embed.py`](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/embedding/embed.py) (Embedding pipeline), [`src/kms/extraction/extract.py`](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/extraction/extract.py) (Extraction workflow), [`src/kms/retrieval/search.py`](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/retrieval/search.py) (Vector retrieval), [`src/kms/ingestion/ingest.py`](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/ingestion/ingest.py) (Register files)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Corpus ingestion"]
  node_ingest["Register files<br/>[ingest.py]"]
  node_course_mapping["Course mapping<br/>[course_mapping.py]"]
  node_hashing["Content hashing<br/>[hashing.py]"]
end

subgraph group_processing["Extraction processing"]
  node_extract["Extraction workflow<br/>[extract.py]"]
  node_pdf_extraction["PDF extraction<br/>[pdf_extractor.py]"]
  node_cleaning["Text cleaning<br/>[cleaning.py]"]
  node_chunker["Chunking<br/>[chunker.py]"]
end

subgraph group_indexing["Embedding and storage"]
  node_postgres[("PostgreSQL")]
  node_models["Data models<br/>[models.py]"]
  node_embedding["Embedding pipeline<br/>[embed.py]"]
  node_embedding_constants["Embedding settings<br/>[constants.py]"]
  node_chroma[("ChromaDB index")]
  node_reconcile["Index reconciliation<br/>[reconcile.py]"]
end

subgraph group_serving["Search and answers"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_search["Vector retrieval<br/>[search.py]"]
  node_agent["Answer generation<br/>[agent.py]"]
  node_instructions["Answer instructions"]
end

subgraph group_evaluation["Evaluation"]
  node_eval_harness["Retrieval evaluation<br/>[harness.py]"]
end

node_course_files["Course materials"]
node_grunden{{"Grunden embeddings"}}
node_api_user(("API client"))
node_answer_model{{"Answer model"}}
node_config["Runtime configuration<br/>[config.py]"]

node_course_files -->|"registers"| node_ingest
node_ingest -->|"maps courses"| node_course_mapping
node_ingest -->|"hashes content"| node_hashing
node_ingest -->|"writes records"| node_postgres
node_ingest -->|"uses models"| node_models
node_postgres -->|"provides pending documents"| node_extract
node_extract -->|"extracts pages"| node_pdf_extraction
node_extract -->|"cleans text"| node_cleaning
node_extract -->|"creates chunks"| node_chunker
node_extract -->|"checks content"| node_hashing
node_extract -->|"stores chunks"| node_postgres
node_extract -->|"uses models"| node_models
node_postgres -->|"provides extracted chunks"| node_embedding
node_embedding -->|"requests vectors"| node_grunden
node_embedding -->|"upserts vectors"| node_chroma
node_embedding -->|"marks embedded"| node_postgres
node_embedding -->|"uses models"| node_models
node_embedding -->|"uses settings"| node_embedding_constants
node_chroma -.->|"checked against"| node_reconcile
node_postgres -.->|"checked against"| node_reconcile
node_api_user -->|"requests search"| node_api
node_api_user -->|"requests answers"| node_api
node_api -->|"calls search"| node_search
node_api -->|"requests answer"| node_agent
node_search -->|"embeds query"| node_embedding
node_search -->|"queries nearest vectors"| node_chroma
node_search -->|"loads chunk records"| node_postgres
node_search -->|"queries chunks"| node_models
node_agent -->|"builds prompt"| node_instructions
node_agent -->|"generates answer"| node_answer_model
node_eval_harness -->|"measures retrieval"| node_search
node_eval_harness -->|"resolves expected sources"| node_postgres
node_api -->|"loads settings"| node_config
node_embedding -->|"loads settings"| node_config
node_agent -->|"loads model settings"| node_config

click node_ingest "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/ingestion/ingest.py"
click node_course_mapping "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/ingestion/course_mapping.py"
click node_hashing "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/hashing.py"
click node_extract "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/extraction/extract.py"
click node_pdf_extraction "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/extraction/pdf_extractor.py"
click node_cleaning "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/extraction/cleaning.py"
click node_chunker "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/extraction/chunker.py"
click node_models "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/db/models.py"
click node_embedding "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/embedding/embed.py"
click node_embedding_constants "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/embedding/constants.py"
click node_reconcile "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/embedding/reconcile.py"
click node_api "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/api/main.py"
click node_search "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/retrieval/search.py"
click node_agent "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/generation/agent.py"
click node_instructions "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/generation/agent_instructions.py"
click node_eval_harness "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/evaluation/harness.py"
click node_config "https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/config.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_ingest,node_course_mapping,node_hashing,node_api_user toneBlue
class node_extract,node_pdf_extraction,node_cleaning,node_chunker toneAmber
class node_postgres,node_models,node_embedding,node_embedding_constants,node_chroma,node_reconcile toneMint
class node_api,node_search,node_agent,node_instructions toneRose
class node_eval_harness,node_course_files,node_grunden,node_answer_model toneIndigo
class node_config toneTeal
```

## Components

### Corpus ingestion

- [Register files](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/ingestion/ingest.py): `src/kms/ingestion/ingest.py`
- [Course mapping](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/ingestion/course_mapping.py): `src/kms/ingestion/course_mapping.py`
- [Content hashing](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/hashing.py): `src/kms/hashing.py`

### Extraction processing

- [Extraction workflow](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/extraction/extract.py): `src/kms/extraction/extract.py`
- [PDF extraction](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/extraction/pdf_extractor.py): `src/kms/extraction/pdf_extractor.py`
- [Text cleaning](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/extraction/cleaning.py): `src/kms/extraction/cleaning.py`
- [Chunking](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/extraction/chunker.py): `src/kms/extraction/chunker.py`

### Embedding and storage

- **PostgreSQL**
- [Data models](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/db/models.py): `src/kms/db/models.py`
- [Embedding pipeline](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/embedding/embed.py): `src/kms/embedding/embed.py`
- [Embedding settings](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/embedding/constants.py): `src/kms/embedding/constants.py`
- **ChromaDB index**
- [Index reconciliation](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/embedding/reconcile.py): `src/kms/embedding/reconcile.py`

### Search and answers

- [FastAPI endpoints](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/api/main.py): `src/kms/api/main.py`
- [Vector retrieval](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/retrieval/search.py): `src/kms/retrieval/search.py`
- [Answer generation](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/generation/agent.py): `src/kms/generation/agent.py`
- [Answer instructions](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/generation/agent_instructions.py): `src/kms/generation/agent_instructions.py`

### Evaluation

- [Retrieval evaluation](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/evaluation/harness.py): `src/kms/evaluation/harness.py`

### Other components

- **Course materials**
- **Grunden embeddings**
- **API client**
- **Answer model**
- [Runtime configuration](https://github.com/johnnyhyytiainen/project3-kms/blob/main/src/kms/config.py): `src/kms/config.py`

## Connections

- Course materials → Register files: registers (evidence: `README.md`)
- Register files → Course mapping: maps courses (evidence: `src/kms/ingestion/ingest.py`)
- Register files → Content hashing: hashes content (evidence: `src/kms/ingestion/ingest.py`)
- Register files → PostgreSQL: writes records (evidence: `src/kms/ingestion/ingest.py`)
- Register files → Data models: uses models (evidence: `src/kms/ingestion/ingest.py`)
- PostgreSQL → Extraction workflow: provides pending documents (evidence: `README.md`)
- Extraction workflow → PDF extraction: extracts pages (evidence: `src/kms/extraction/extract.py`)
- Extraction workflow → Text cleaning: cleans text (evidence: `src/kms/extraction/extract.py`)
- Extraction workflow → Chunking: creates chunks (evidence: `src/kms/extraction/extract.py`)
- Extraction workflow → Content hashing: checks content (evidence: `src/kms/extraction/extract.py`)
- Extraction workflow → PostgreSQL: stores chunks (evidence: `src/kms/extraction/extract.py`)
- Extraction workflow → Data models: uses models (evidence: `src/kms/extraction/extract.py`)
- PostgreSQL → Embedding pipeline: provides extracted chunks (evidence: `README.md`)
- Embedding pipeline → Grunden embeddings: requests vectors (evidence: `src/kms/embedding/embed.py`)
- Embedding pipeline → ChromaDB index: upserts vectors (evidence: `src/kms/embedding/embed.py`)
- Embedding pipeline → PostgreSQL: marks embedded (evidence: `src/kms/embedding/embed.py`)
- Embedding pipeline → Data models: uses models (evidence: `src/kms/embedding/embed.py`)
- Embedding pipeline → Embedding settings: uses settings (evidence: `src/kms/embedding/embed.py`)
- ChromaDB index → Index reconciliation: checked against
- PostgreSQL → Index reconciliation: checked against
- API client → FastAPI endpoints: requests search (evidence: `README.md`)
- API client → FastAPI endpoints: requests answers (evidence: `README.md`)
- FastAPI endpoints → Vector retrieval: calls search (evidence: `src/kms/api/main.py`)
- FastAPI endpoints → Answer generation: requests answer (evidence: `src/kms/api/main.py`)
- Vector retrieval → Embedding pipeline: embeds query (evidence: `src/kms/retrieval/search.py`)
- Vector retrieval → ChromaDB index: queries nearest vectors (evidence: `src/kms/retrieval/search.py`)
- Vector retrieval → PostgreSQL: loads chunk records (evidence: `src/kms/retrieval/search.py`)
- Vector retrieval → Data models: queries chunks (evidence: `src/kms/retrieval/search.py`)
- Answer generation → Answer instructions: builds prompt (evidence: `src/kms/generation/agent.py`)
- Answer generation → Answer model: generates answer (evidence: `README.md`)
- Retrieval evaluation → Vector retrieval: measures retrieval (evidence: `src/kms/evaluation/harness.py`)
- Retrieval evaluation → PostgreSQL: resolves expected sources (evidence: `src/kms/evaluation/harness.py`)
- FastAPI endpoints → Runtime configuration: loads settings (evidence: `src/kms/api/main.py`)
- Embedding pipeline → Runtime configuration: loads settings (evidence: `src/kms/embedding/embed.py`)
- Answer generation → Runtime configuration: loads model settings (evidence: `src/kms/generation/agent.py`)
