# markkentos/tk-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/markkentos/tk-assistant
- Repository: https://github.com/markkentos/tk-assistant

## Overview

tk-assistant is a Russian labor-law question-answering product built around a QLoRA-tuned 7B model, with a deployed RAG-backed demo and an evaluation loop. Its principal workflow collects and parses Labor Code articles, generates and quality-controls QA data, trains the model, serves answers with retrieved article context, and measures answer quality. README documents the end-to-end stages and production routing; sampled code supports data utilities, prompt/training behavior, answer generation, and judging. Some deployment and evaluation links are therefore documented rather than verified in sampled implementation.

Main entry points: [`data/processed`](https://github.com/markkentos/tk-assistant/tree/main/data/processed) (Processed datasets), [`data/scripts/generate_qa.py`](https://github.com/markkentos/tk-assistant/blob/main/data/scripts/generate_qa.py) (Generate QA), [`eval/judge.py`](https://github.com/markkentos/tk-assistant/blob/main/eval/judge.py) (LLM judge), [`src/generate_answers.py`](https://github.com/markkentos/tk-assistant/blob/main/src/generate_answers.py) (Answer generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Dataset pipeline"]
  node_download["Collect articles<br/>[download_tk.py]"]
  node_parse["Parse articles<br/>[parse_articles.py]"]
  node_qa_gen["Generate QA<br/>[generate_qa.py]"]
  node_filters["Filter and prescreen<br/>[filters.py]"]
  node_prescreen["LLM prescreen<br/>[prescreen.py]"]
  node_dedup["Deduplicate QA<br/>[dedup.py]"]
  node_human_review["Review and finalize"]
  node_split["Dataset splits<br/>[split_dataset.py]"]
  node_qa_store[("Processed datasets")]
end

subgraph group_model["Model workflow"]
  node_prompting["Prompt formatting<br/>[prompts.py]"]
  node_training["QLoRA training<br/>[train_qlora.py]"]
  node_answer_gen["Answer generation"]
end

subgraph group_serve["Serving and retrieval"]
  node_web["Demo interface<br/>[app.js]"]
  node_proxy["Request routing"]
  node_rag["RAG retrieval service<br/>[rag_service.py]"]
  node_llama["Model server"]
end

subgraph group_eval["Evaluation"]
  node_benchmark["Benchmark builder<br/>[build_benchmark.py]"]
  node_references["Reference answers<br/>[gen_references.py]"]
  node_judge["LLM judge<br/>[judge.py]"]
  node_comparison["Run comparison<br/>[compare.py]"]
  node_blind_review["Blind human review<br/>[blind_review.py]"]
end

subgraph group_shared["Shared utilities"]
  node_common["Pipeline utilities<br/>[common.py]"]
end

node_user(("Questioner"))
node_labor_code["Labor Code"]
node_llm_api["External LLM API"]

node_user -->|"asks"| node_web
node_web -.->|"sends request"| node_proxy
node_proxy -->|"routes /v1"| node_rag
node_rag -->|"forwards generation"| node_llama
node_rag -->|"retrieves articles"| node_qa_store
node_llama -.->|"returns answer"| node_user
node_labor_code -->|"provides text"| node_download
node_download -->|"fetches articles"| node_parse
node_parse -->|"stores articles"| node_qa_store
node_qa_store -->|"supplies articles"| node_qa_gen
node_qa_gen -->|"requests QA"| node_llm_api
node_qa_gen -->|"passes QA pairs"| node_filters
node_filters -->|"passes survivors"| node_prescreen
node_prescreen -.->|"requests screening"| node_llm_api
node_prescreen -->|"passes screened pairs"| node_dedup
node_dedup -->|"selects review set"| node_human_review
node_human_review -->|"finalizes pairs"| node_split
node_split -->|"writes splits"| node_qa_store
node_training -.->|"loads training data"| node_qa_store
node_training -->|"formats examples"| node_prompting
node_answer_gen -->|"formats prompts"| node_prompting
node_benchmark -->|"uses test split"| node_qa_store
node_benchmark -->|"provides questions"| node_references
node_references -->|"generates drafts"| node_llm_api
node_references -.->|"supplies references"| node_judge
node_answer_gen -->|"supplies answers"| node_judge
node_judge -->|"requests scoring"| node_llm_api
node_judge -->|"writes scores"| node_comparison
node_answer_gen -->|"supplies answer pairs"| node_blind_review
node_common -->|"supports file I/O"| node_qa_gen
node_common -->|"supports file I/O"| node_filters

click node_download "https://github.com/markkentos/tk-assistant/blob/main/data/scripts/download_tk.py"
click node_parse "https://github.com/markkentos/tk-assistant/blob/main/data/scripts/parse_articles.py"
click node_qa_gen "https://github.com/markkentos/tk-assistant/blob/main/data/scripts/generate_qa.py"
click node_filters "https://github.com/markkentos/tk-assistant/blob/main/data/scripts/filters.py"
click node_prescreen "https://github.com/markkentos/tk-assistant/blob/main/data/scripts/prescreen.py"
click node_dedup "https://github.com/markkentos/tk-assistant/blob/main/data/scripts/dedup.py"
click node_human_review "https://github.com/markkentos/tk-assistant/blob/main/data/scripts/finalize_dataset.py"
click node_split "https://github.com/markkentos/tk-assistant/blob/main/data/scripts/split_dataset.py"
click node_qa_store "https://github.com/markkentos/tk-assistant/tree/main/data/processed"
click node_prompting "https://github.com/markkentos/tk-assistant/blob/main/src/prompts.py"
click node_training "https://github.com/markkentos/tk-assistant/blob/main/src/train_qlora.py"
click node_answer_gen "https://github.com/markkentos/tk-assistant/blob/main/src/generate_answers.py"
click node_benchmark "https://github.com/markkentos/tk-assistant/blob/main/eval/build_benchmark.py"
click node_references "https://github.com/markkentos/tk-assistant/blob/main/eval/gen_references.py"
click node_judge "https://github.com/markkentos/tk-assistant/blob/main/eval/judge.py"
click node_comparison "https://github.com/markkentos/tk-assistant/blob/main/eval/compare.py"
click node_blind_review "https://github.com/markkentos/tk-assistant/blob/main/eval/blind_review.py"
click node_web "https://github.com/markkentos/tk-assistant/blob/main/deploy/web/app.js"
click node_proxy "https://github.com/markkentos/tk-assistant/blob/main/deploy/Caddyfile"
click node_rag "https://github.com/markkentos/tk-assistant/blob/main/deploy/rag/rag_service.py"
click node_common "https://github.com/markkentos/tk-assistant/blob/main/data/scripts/common.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_download,node_parse,node_qa_gen,node_filters,node_prescreen,node_dedup,node_human_review,node_split,node_qa_store toneBlue
class node_prompting,node_training,node_answer_gen toneAmber
class node_web,node_proxy,node_rag,node_llama,node_llm_api toneMint
class node_benchmark,node_references,node_judge,node_comparison,node_blind_review toneRose
class node_common,node_user,node_labor_code toneIndigo
```

## Components

### Dataset pipeline

- [Collect articles](https://github.com/markkentos/tk-assistant/blob/main/data/scripts/download_tk.py): `data/scripts/download_tk.py`
- [Parse articles](https://github.com/markkentos/tk-assistant/blob/main/data/scripts/parse_articles.py): `data/scripts/parse_articles.py`
- [Generate QA](https://github.com/markkentos/tk-assistant/blob/main/data/scripts/generate_qa.py): `data/scripts/generate_qa.py`
- [Filter and prescreen](https://github.com/markkentos/tk-assistant/blob/main/data/scripts/filters.py): `data/scripts/filters.py`
- [LLM prescreen](https://github.com/markkentos/tk-assistant/blob/main/data/scripts/prescreen.py): `data/scripts/prescreen.py`
- [Deduplicate QA](https://github.com/markkentos/tk-assistant/blob/main/data/scripts/dedup.py): `data/scripts/dedup.py`
- [Review and finalize](https://github.com/markkentos/tk-assistant/blob/main/data/scripts/finalize_dataset.py): `data/scripts/finalize_dataset.py`
- [Dataset splits](https://github.com/markkentos/tk-assistant/blob/main/data/scripts/split_dataset.py): `data/scripts/split_dataset.py`
- [Processed datasets](https://github.com/markkentos/tk-assistant/tree/main/data/processed): `data/processed`

### Model workflow

- [Prompt formatting](https://github.com/markkentos/tk-assistant/blob/main/src/prompts.py): `src/prompts.py`
- [QLoRA training](https://github.com/markkentos/tk-assistant/blob/main/src/train_qlora.py): `src/train_qlora.py`
- [Answer generation](https://github.com/markkentos/tk-assistant/blob/main/src/generate_answers.py): `src/generate_answers.py`

### Serving and retrieval

- [Demo interface](https://github.com/markkentos/tk-assistant/blob/main/deploy/web/app.js): `deploy/web/app.js`
- [Request routing](https://github.com/markkentos/tk-assistant/blob/main/deploy/Caddyfile): `deploy/Caddyfile`
- [RAG retrieval service](https://github.com/markkentos/tk-assistant/blob/main/deploy/rag/rag_service.py): `deploy/rag/rag_service.py`
- **Model server**

### Evaluation

- [Benchmark builder](https://github.com/markkentos/tk-assistant/blob/main/eval/build_benchmark.py): `eval/build_benchmark.py`
- [Reference answers](https://github.com/markkentos/tk-assistant/blob/main/eval/gen_references.py): `eval/gen_references.py`
- [LLM judge](https://github.com/markkentos/tk-assistant/blob/main/eval/judge.py): `eval/judge.py`
- [Run comparison](https://github.com/markkentos/tk-assistant/blob/main/eval/compare.py): `eval/compare.py`
- [Blind human review](https://github.com/markkentos/tk-assistant/blob/main/eval/blind_review.py): `eval/blind_review.py`

### Shared utilities

- [Pipeline utilities](https://github.com/markkentos/tk-assistant/blob/main/data/scripts/common.py): `data/scripts/common.py`

### Other components

- **Questioner**
- **Labor Code**
- **External LLM API**

## Connections

- Questioner → Demo interface: asks (evidence: `README.md`)
- Demo interface → Request routing: sends request (evidence: `README.md`)
- Request routing → RAG retrieval service: routes /v1 (evidence: `README.md`)
- RAG retrieval service → Model server: forwards generation (evidence: `README.md`)
- RAG retrieval service → Processed datasets: retrieves articles (evidence: `README.md`)
- Model server → Questioner: returns answer
- Labor Code → Collect articles: provides text (evidence: `README.md`)
- Collect articles → Parse articles: fetches articles (evidence: `README.md`)
- Parse articles → Processed datasets: stores articles (evidence: `README.md`)
- Processed datasets → Generate QA: supplies articles (evidence: `README.md`)
- Generate QA → External LLM API: requests QA (evidence: `data/scripts/generate_qa.py`)
- Generate QA → Filter and prescreen: passes QA pairs (evidence: `README.md`)
- Filter and prescreen → LLM prescreen: passes survivors (evidence: `README.md`)
- LLM prescreen → External LLM API: requests screening (evidence: `README.md`)
- LLM prescreen → Deduplicate QA: passes screened pairs (evidence: `README.md`)
- Deduplicate QA → Review and finalize: selects review set (evidence: `README.md`)
- Review and finalize → Dataset splits: finalizes pairs (evidence: `README.md`)
- Dataset splits → Processed datasets: writes splits (evidence: `README.md`)
- QLoRA training → Processed datasets: loads training data (evidence: `README.md`)
- QLoRA training → Prompt formatting: formats examples (evidence: `src/train_qlora.py`)
- Answer generation → Prompt formatting: formats prompts (evidence: `src/generate_answers.py`)
- Benchmark builder → Processed datasets: uses test split (evidence: `README.md`)
- Benchmark builder → Reference answers: provides questions (evidence: `eval/gen_references.py`)
- Reference answers → External LLM API: generates drafts (evidence: `eval/gen_references.py`)
- Reference answers → LLM judge: supplies references (evidence: `README.md`)
- Answer generation → LLM judge: supplies answers (evidence: `README.md`)
- LLM judge → External LLM API: requests scoring (evidence: `eval/judge.py`)
- LLM judge → Run comparison: writes scores (evidence: `eval/compare.py`)
- Answer generation → Blind human review: supplies answer pairs (evidence: `eval/blind_review.py`)
- Pipeline utilities → Generate QA: supports file I/O (evidence: `data/scripts/generate_qa.py`)
- Pipeline utilities → Filter and prescreen: supports file I/O (evidence: `data/scripts/filters.py`)
