# hritxxxk/koda architecture

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

- Interactive diagram: https://gitdiagram.com/hritxxxk/koda
- Repository: https://github.com/hritxxxk/koda

## Overview

1. **What this repository is**
   - `Koda` is a **local practice tool** for DSA and SQL problems.
   - It is not a server-based application; the architecture is centered on a **CLI/TUI workflow** running on the user’s machine.

2. **Primary entrypoint**
   - The user starts the app with `koda start` or `python -m src.ai_dsa.cli start`.
   - `src/ai_dsa/cli.py` is the main command surface and likely coordinates startup, mode selection, and the handoff into the interactive UI.

3. **Interactive experience layer**
   - `src/ai_dsa/tui.py` is the user-facing interface for solving problems.
   - This layer is the boundary where the user submits answers, views prompts, receives feedback, and navigates between problem states.

4. **Problem content as local data**
   - The repository stores practice content in `data/`.
   - `data/problems/*.toml` contains DSA problem definitions like `two-sum` and `merge-sort`.
   - `data/sql/*.toml` contains SQL exercises like `find-customers-with-recent-orders`.
   - These files are the app’s content source, so problem delivery is file-based rather than remote API-driven.

5. **Core domain model**
   - `src/ai_dsa/models.py` likely defines the problem, solution, and session entities shared across the app.
   - This is the main internal contract between the content loader, UI, sandbox, recommendation logic, and persistence/telemetry.

6. **Encoding and parsing boundary**
   - `src/ai_dsa/codec.py` likely handles conversion between TOML/content formats and Python objects.
   - This module is the ingestion boundary for the problem files under `data/`, and probably also handles any serialization of notes or session artifacts.

7. **Execution and validation subsystems**
   - `src/ai_dsa/sandbox.py` and `src/ai_dsa/sql_sandbox.py` separate execution for code-style DSA answers and SQL answers.
   - This split is important architecturally: DSA solutions and SQL queries have different runtime rules, inputs, and validation paths.
   - These sandboxes are the place where user-submitted work is safely tested against expected behavior.

8. **Quality-checking and feedback**
   - `src/ai_dsa/linter.py` and `src/ai_dsa/profiler.py` suggest static and performance-oriented feedback.
   - The linter likely checks style or structural issues, while the profiler focuses on runtime characteristics or complexity signals.
   - Together they provide feedback beyond simple pass/fail validation.

9. **AI integration boundary**
   - `src/ai_dsa/providers.py` abstracts external AI provider access.
   - The README says the default provider is **Ollama** and can be configured via `.env`, so the app is designed to work with multiple AI backends.
   - `src/ai_dsa/recommender.py` likely uses the provider abstraction to generate hints, recommendations, or next-step guidance.

10. **Persistence and user memory**
   - `src/ai_dsa/database.py`, `src/ai_dsa/notes.py`, and `src/ai_dsa/telemetry.py` form the app’s state and history layer.
   - `database.py` suggests local storage for sessions, progress, or metadata.
   - `notes.py` likely stores user annotations tied to problems.
   - `telemetry.py` likely records usage or outcome events for diagnostics or product insight.

11. **Typical data flow**
   - A user starts the CLI.
   - The app loads problem definitions from `data/` through the codec/models layer.
   - The UI presents a selected exercise.
   - The user submits a solution or query.
   - The sandbox validates it; the linter/profiler may enrich feedback.
   - The recommender may consult an AI provider for hints.
   - Notes, results, and telemetry are persisted locally.

12. **Operational shape**
   - This is a **single-package Python application** with editable installation via `pyproject.toml` and `requirements.txt`.
   - There is no evidence of separate backend/frontend services, queues, or remote databases in the repository tree.
   - The main architectural boundaries are therefore: **content files**, **interactive UI**, **execution sandboxes**, **AI provider adapter**, and **local persistence/telemetry**.

Main entry points: [`src/ai_dsa/tui.py`](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/tui.py) (TUI), [`src/ai_dsa/codec.py`](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/codec.py) (Codec), [`src/ai_dsa/sandbox.py`](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/sandbox.py) (DSA sandbox), [`src/ai_dsa/recommender.py`](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/recommender.py) (Recommender)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_cli["CLI + UI"]
  node_n_cli["CLI<br/>command surface<br/>[cli.py]"]
  node_n_tui["TUI<br/>interactive UI<br/>[tui.py]"]
end

subgraph group_g_content["Local content"]
  node_n_models["Models<br/>domain model<br/>[models.py]"]
  node_n_codec["Codec<br/>content parser<br/>[codec.py]"]
  node_n_data_problems["DSA data<br/>problem files"]
  node_n_data_sql["SQL data<br/>sql files"]
end

subgraph group_g_validate["Validation"]
  node_n_sandbox["DSA sandbox<br/>code executor<br/>[sandbox.py]"]
  node_n_sql_sandbox["SQL sandbox<br/>query validator<br/>[sql_sandbox.py]"]
  node_n_linter["Linter<br/>static checks<br/>[linter.py]"]
  node_n_profiler["Profiler<br/>performance feedback<br/>[profiler.py]"]
end

subgraph group_g_ai["AI guidance"]
  node_n_providers["Providers<br/>ai adapter<br/>[providers.py]"]
  node_n_recommender["Recommender<br/>hint engine<br/>[recommender.py]"]
end

subgraph group_g_state["Local state"]
  node_n_database[("Database<br/>local storage<br/>[database.py]")]
  node_n_notes["Notes<br/>user memory<br/>[notes.py]"]
  node_n_telemetry["Telemetry<br/>event log<br/>[telemetry.py]"]
end

node_n_cli -->|"launches"| node_n_tui
node_n_cli -->|"loads content"| node_n_codec
node_n_tui -->|"uses"| node_n_models
node_n_codec -->|"produces"| node_n_models
node_n_codec -->|"reads"| node_n_data_problems
node_n_codec -->|"reads"| node_n_data_sql
node_n_tui -->|"validates"| node_n_sandbox
node_n_tui -->|"validates"| node_n_sql_sandbox
node_n_sandbox -->|"enriches"| node_n_linter
node_n_sandbox -->|"enriches"| node_n_profiler
node_n_sql_sandbox -->|"enriches"| node_n_linter
node_n_recommender -->|"queries"| node_n_providers
node_n_tui -->|"requests help"| node_n_recommender
node_n_recommender -->|"consults"| node_n_models
node_n_tui -->|"persists"| node_n_database
node_n_notes -->|"stores"| node_n_database
node_n_telemetry -->|"stores"| node_n_database
node_n_tui -->|"uses"| node_n_notes
node_n_tui -->|"emits"| node_n_telemetry

click node_n_cli "https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/cli.py"
click node_n_tui "https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/tui.py"
click node_n_models "https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/models.py"
click node_n_codec "https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/codec.py"
click node_n_data_problems "https://github.com/hritxxxk/koda/tree/main/data/problems"
click node_n_data_sql "https://github.com/hritxxxk/koda/tree/main/data/sql"
click node_n_sandbox "https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/sandbox.py"
click node_n_sql_sandbox "https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/sql_sandbox.py"
click node_n_linter "https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/linter.py"
click node_n_profiler "https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/profiler.py"
click node_n_providers "https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/providers.py"
click node_n_recommender "https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/recommender.py"
click node_n_database "https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/database.py"
click node_n_notes "https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/notes.py"
click node_n_telemetry "https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/telemetry.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_n_cli,node_n_tui toneBlue
class node_n_models,node_n_codec,node_n_data_problems,node_n_data_sql toneAmber
class node_n_sandbox,node_n_sql_sandbox,node_n_linter,node_n_profiler toneMint
class node_n_providers,node_n_recommender toneRose
class node_n_database,node_n_notes,node_n_telemetry toneIndigo
```

## Components

### CLI + UI

User entrypoint and interactive problem-solving interface.

- [CLI](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/cli.py): command surface · Main entrypoint for starting and routing the app. · `src/ai_dsa/cli.py`
- [TUI](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/tui.py): interactive UI · User-facing workflow for solving and reviewing problems. · `src/ai_dsa/tui.py`

### Local content

Problem definitions and format conversion boundary.

- [Models](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/models.py): domain model · Shared problem, solution, and session entities. · `src/ai_dsa/models.py`
- [Codec](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/codec.py): content parser · Converts TOML/problem data to and from Python objects. · `src/ai_dsa/codec.py`
- [DSA data](https://github.com/hritxxxk/koda/tree/main/data/problems): problem files · Local DSA practice content stored as TOML. · `data/problems`
- [SQL data](https://github.com/hritxxxk/koda/tree/main/data/sql): sql files · Local SQL practice content stored as TOML. · `data/sql`

### Validation

Execution, linting, profiling, and feedback generation.

- [DSA sandbox](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/sandbox.py): code executor · Runs and validates code-style submissions against expected behavior. · `src/ai_dsa/sandbox.py`
- [SQL sandbox](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/sql_sandbox.py): query validator · Executes and checks SQL submissions separately from code problems. · `src/ai_dsa/sql_sandbox.py`
- [Linter](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/linter.py): static checks · Provides structural or style-oriented feedback on submissions. · `src/ai_dsa/linter.py`
- [Profiler](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/profiler.py): performance feedback · Adds runtime or complexity-oriented feedback. · `src/ai_dsa/profiler.py`

### AI guidance

Provider abstraction and recommendation logic.

- [Providers](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/providers.py): ai adapter · Abstracts external AI backends such as Ollama. · `src/ai_dsa/providers.py`
- [Recommender](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/recommender.py): hint engine · Generates hints, guidance, or next-step suggestions. · `src/ai_dsa/recommender.py`

### Local state

Persistence, notes, and telemetry.

- [Database](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/database.py): local storage · Stores local progress, session, or metadata state. · `src/ai_dsa/database.py`
- [Notes](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/notes.py): user memory · Persists annotations tied to problems or sessions. · `src/ai_dsa/notes.py`
- [Telemetry](https://github.com/hritxxxk/koda/blob/main/src/ai_dsa/telemetry.py): event log · Records usage and outcome events locally. · `src/ai_dsa/telemetry.py`

## Connections

- CLI → TUI: launches · CLI starts the interactive experience.
- CLI → Codec: loads content · Startup uses the codec boundary to ingest local practice files.
- TUI → Models: uses · UI renders and updates shared domain entities.
- Codec → Models: produces · Parsed content becomes domain objects.
- Codec → DSA data: reads · DSA problems are sourced from local TOML files.
- Codec → SQL data: reads · SQL exercises are sourced from local TOML files.
- TUI → DSA sandbox: validates · Interactive DSA submissions are executed and checked.
- TUI → SQL sandbox: validates · Interactive SQL submissions use the SQL execution path.
- DSA sandbox → Linter: enriches · Code validation can include lint-style feedback.
- DSA sandbox → Profiler: enriches · Code validation can include performance feedback.
- SQL sandbox → Linter: enriches · SQL validation can include feedback checks.
- Recommender → Providers: queries · Recommendations are generated through provider abstraction.
- TUI → Recommender: requests help · UI can ask for hints or guidance during solving.
- Recommender → Models: consults · Recommendations are grounded in the current problem/session model.
- TUI → Database: persists · UI stores progress and session state locally.
- Notes → Database: stores · Notes are saved in the local persistence layer.
- Telemetry → Database: stores · Telemetry events are recorded locally.
- TUI → Notes: uses · Users can attach notes while solving.
- TUI → Telemetry: emits · Interactive actions produce telemetry events.
