# khadir-syed/k_ai-basics architecture

> Architecture diagram of the GitHub repository khadir-syed/k_ai-basics, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/khadir-syed/k_ai-basics
- Repository: https://github.com/khadir-syed/k_ai-basics
- Video tour (about a minute): https://gitdiagram.com/khadir-syed/k_ai-basics/video

## Overview

k_ai-basics is a collection of ten self-contained, runnable AI concept demos, not a shared framework. The main workflow is to choose a demo, provide an example or your own input, and inspect its explanation or output in a terminal or browser. The demos cover tokenization, retrieval, tool use and routing, context limits, hallucination, prompt design and injection, PII redaction, and agent handoffs. Browser pages run demo code locally through Pyodide; some terminal demos also offer optional live-LLM modes. Browser wiring is sampled for several demos and otherwise follows the README’s stated browser capability.

Main entry points: [`web`](https://github.com/khadir-syed/k_ai-basics/tree/main/web) (Browser Runners), [`02-mini-rag/ask.py`](https://github.com/khadir-syed/k_ai-basics/blob/main/02-mini-rag/ask.py) (Document Retrieval), [`04-router-playground/router.py`](https://github.com/khadir-syed/k_ai-basics/blob/main/04-router-playground/router.py) (Skill Routing), [`06-hallucination-demo/compare.py`](https://github.com/khadir-syed/k_ai-basics/blob/main/06-hallucination-demo/compare.py) (Hallucination Comparison)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_concepts["Core AI Concepts"]
  node_tokenizer["Tokenization<br/>[run.py]"]
  node_rag["Document Retrieval<br/>[ask.py]"]
  node_trace["Agent Trace<br/>[trace.py]"]
  node_router["Skill Routing<br/>[router.py]"]
  node_context["Context Window<br/>[explore.py]"]
end

subgraph group_reliability["Reliability And Agents"]
  node_hallucination["Hallucination Comparison<br/>[compare.py]"]
  node_prompts["Prompt Playground<br/>[playground.py]"]
  node_injection["Injection Demo<br/>[inject.py]"]
  node_redaction["PII Redaction<br/>[redact.py]"]
  node_handoff["Agent Handoff<br/>[handoff.py]"]
end

subgraph group_browser["Browser Experience"]
  node_web_entry["Browser Demo Index<br/>[index.html]"]
  node_web_apps["Browser Runners"]
end

subgraph group_integrations["Optional AI"]
  node_llm["LLM Helper<br/>[llm.py]"]
end

node_learner(("Learner"))
node_ai_service{{"AI Service"}}

node_learner -->|"opens"| node_web_entry
node_web_entry -->|"offers demos"| node_web_apps
node_web_apps -->|"runs locally"| node_tokenizer
node_web_apps -->|"runs locally"| node_rag
node_web_apps -->|"runs locally"| node_trace
node_web_apps -->|"runs locally"| node_router
node_web_apps -->|"runs locally"| node_context
node_web_apps -->|"runs locally"| node_hallucination
node_web_apps -->|"runs locally"| node_prompts
node_web_apps -->|"runs locally"| node_injection
node_web_apps -->|"runs locally"| node_redaction
node_web_apps -->|"runs locally"| node_handoff
node_learner -->|"runs CLI"| node_tokenizer
node_learner -->|"runs CLI"| node_rag
node_learner -->|"runs CLI"| node_trace
node_learner -->|"runs CLI"| node_router
node_learner -->|"runs CLI"| node_context
node_learner -->|"runs CLI"| node_hallucination
node_learner -->|"runs CLI"| node_prompts
node_learner -->|"runs CLI"| node_injection
node_learner -->|"runs CLI"| node_redaction
node_learner -->|"runs CLI"| node_handoff
node_rag -.->|"optional request"| node_llm
node_router -.->|"optional routing"| node_ai_service
node_hallucination -.->|"optional answer"| node_ai_service
node_prompts -.->|"optional answers"| node_ai_service
node_injection -.->|"optional agent"| node_ai_service
node_handoff -.->|"optional agents"| node_ai_service
node_llm -.->|"sends prompt"| node_ai_service

click node_tokenizer "https://github.com/khadir-syed/k_ai-basics/blob/main/01-tokenizer-playground/run.py"
click node_rag "https://github.com/khadir-syed/k_ai-basics/blob/main/02-mini-rag/ask.py"
click node_trace "https://github.com/khadir-syed/k_ai-basics/blob/main/03-agent-trace/trace.py"
click node_router "https://github.com/khadir-syed/k_ai-basics/blob/main/04-router-playground/router.py"
click node_context "https://github.com/khadir-syed/k_ai-basics/blob/main/05-context-window/explore.py"
click node_hallucination "https://github.com/khadir-syed/k_ai-basics/blob/main/06-hallucination-demo/compare.py"
click node_prompts "https://github.com/khadir-syed/k_ai-basics/blob/main/07-prompt-playground/playground.py"
click node_injection "https://github.com/khadir-syed/k_ai-basics/blob/main/08-prompt-injection/inject.py"
click node_redaction "https://github.com/khadir-syed/k_ai-basics/blob/main/09-pii-redaction/redact.py"
click node_handoff "https://github.com/khadir-syed/k_ai-basics/blob/main/10-multi-agent-handoff/handoff.py"
click node_web_entry "https://github.com/khadir-syed/k_ai-basics/blob/main/web/index.html"
click node_web_apps "https://github.com/khadir-syed/k_ai-basics/tree/main/web"
click node_llm "https://github.com/khadir-syed/k_ai-basics/blob/main/02-mini-rag/llm.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_tokenizer,node_rag,node_trace,node_router,node_context toneBlue
class node_hallucination,node_prompts,node_injection,node_redaction,node_handoff toneAmber
class node_web_entry,node_web_apps toneMint
class node_llm toneRose
class node_learner,node_ai_service toneIndigo
```

## Components

### Core AI Concepts

- [Tokenization](https://github.com/khadir-syed/k_ai-basics/blob/main/01-tokenizer-playground/run.py): `01-tokenizer-playground/run.py`
- [Document Retrieval](https://github.com/khadir-syed/k_ai-basics/blob/main/02-mini-rag/ask.py): `02-mini-rag/ask.py`
- [Agent Trace](https://github.com/khadir-syed/k_ai-basics/blob/main/03-agent-trace/trace.py): `03-agent-trace/trace.py`
- [Skill Routing](https://github.com/khadir-syed/k_ai-basics/blob/main/04-router-playground/router.py): `04-router-playground/router.py`
- [Context Window](https://github.com/khadir-syed/k_ai-basics/blob/main/05-context-window/explore.py): `05-context-window/explore.py`

### Reliability And Agents

- [Hallucination Comparison](https://github.com/khadir-syed/k_ai-basics/blob/main/06-hallucination-demo/compare.py): `06-hallucination-demo/compare.py`
- [Prompt Playground](https://github.com/khadir-syed/k_ai-basics/blob/main/07-prompt-playground/playground.py): `07-prompt-playground/playground.py`
- [Injection Demo](https://github.com/khadir-syed/k_ai-basics/blob/main/08-prompt-injection/inject.py): `08-prompt-injection/inject.py`
- [PII Redaction](https://github.com/khadir-syed/k_ai-basics/blob/main/09-pii-redaction/redact.py): `09-pii-redaction/redact.py`
- [Agent Handoff](https://github.com/khadir-syed/k_ai-basics/blob/main/10-multi-agent-handoff/handoff.py): `10-multi-agent-handoff/handoff.py`

### Browser Experience

- [Browser Demo Index](https://github.com/khadir-syed/k_ai-basics/blob/main/web/index.html): `web/index.html`
- [Browser Runners](https://github.com/khadir-syed/k_ai-basics/tree/main/web): `web`

### Optional AI

- [LLM Helper](https://github.com/khadir-syed/k_ai-basics/blob/main/02-mini-rag/llm.py): `02-mini-rag/llm.py`

### Other components

- **Learner**
- **AI Service**

## Connections

- Learner → Browser Demo Index: opens
- Browser Demo Index → Browser Runners: offers demos
- Browser Runners → Tokenization: runs locally
- Browser Runners → Document Retrieval: runs locally
- Browser Runners → Agent Trace: runs locally
- Browser Runners → Skill Routing: runs locally
- Browser Runners → Context Window: runs locally
- Browser Runners → Hallucination Comparison: runs locally
- Browser Runners → Prompt Playground: runs locally
- Browser Runners → Injection Demo: runs locally
- Browser Runners → PII Redaction: runs locally
- Browser Runners → Agent Handoff: runs locally
- Learner → Tokenization: runs CLI
- Learner → Document Retrieval: runs CLI
- Learner → Agent Trace: runs CLI
- Learner → Skill Routing: runs CLI
- Learner → Context Window: runs CLI
- Learner → Hallucination Comparison: runs CLI
- Learner → Prompt Playground: runs CLI
- Learner → Injection Demo: runs CLI
- Learner → PII Redaction: runs CLI
- Learner → Agent Handoff: runs CLI
- Document Retrieval → LLM Helper: optional request
- Skill Routing → AI Service: optional routing
- Hallucination Comparison → AI Service: optional answer
- Prompt Playground → AI Service: optional answers
- Injection Demo → AI Service: optional agent
- Agent Handoff → AI Service: optional agents
- LLM Helper → AI Service: sends prompt
