# lakshit-chiranjiv/contextlab architecture

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

- Interactive diagram: https://gitdiagram.com/lakshit-chiranjiv/contextlab
- Repository: https://github.com/lakshit-chiranjiv/contextlab

## Overview

Context Lab is a Streamlit chat app for testing how context-management strategies shape multi-turn LLM conversations. In normal mode, the app selects a strategy, estimates the derived prompt’s tokens, calls Groq, displays turn statistics, and persists conversation data and run metrics. Compare Mode runs separate conversation threads through all three strategies. Session persistence and run logging are documented capabilities; the excerpts show the SQLite layer, but omit some normal-mode orchestration details, so those links rely on README documentation.

Main entry points: [`app.py`](https://github.com/lakshit-chiranjiv/contextlab/blob/main/app.py) (Single-strategy chat), [`services/llm_service.py`](https://github.com/lakshit-chiranjiv/contextlab/blob/main/services/llm_service.py) (Groq caller), [`db/database.py`](https://github.com/lakshit-chiranjiv/contextlab/blob/main/db/database.py) (SQLite persistence), [`strategies/summarization.py`](https://github.com/lakshit-chiranjiv/contextlab/blob/main/strategies/summarization.py) (Summarization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Chat experience"]
  node_app["Streamlit app<br/>[app.py]"]
  node_normal["Single-strategy chat<br/>[app.py]"]
  node_compare["Compare Mode<br/>[app.py]"]
  node_stats["Turn statistics<br/>[app.py]"]
end

subgraph group_strategies["Context strategies"]
  node_sliding["Sliding Window<br/>[sliding_window.py]"]
  node_summarization["Summarization<br/>[summarization.py]"]
  node_budget["Token Budget<br/>[token_budget.py]"]
end

subgraph group_services["LLM services"]
  node_tokens["Token estimation<br/>[token_service.py]"]
  node_llm["Groq caller<br/>[llm_service.py]"]
end

subgraph group_persistence["Persistence"]
  node_db[("SQLite persistence<br/>[database.py]")]
  node_sessions["Conversation sessions<br/>[database.py]"]
  node_runlog["Run log<br/>[database.py]"]
end

node_user(("Chat user"))
node_groq{{"Groq API"}}

node_user -->|"sends messages"| node_app
node_app -->|"dispatches chat"| node_normal
node_app -->|"runs strategies"| node_compare
node_normal -->|"applies strategy"| node_sliding
node_normal -->|"applies strategy"| node_summarization
node_normal -->|"applies strategy"| node_budget
node_compare -->|"applies strategy"| node_sliding
node_compare -->|"applies strategy"| node_summarization
node_compare -->|"applies strategy"| node_budget
node_normal -->|"estimates tokens"| node_tokens
node_compare -->|"estimates tokens"| node_tokens
node_budget -->|"counts tokens"| node_tokens
node_normal -->|"sends prompt"| node_llm
node_compare -->|"sends prompts"| node_llm
node_summarization -->|"requests summary"| node_llm
node_llm -->|"calls completions"| node_groq
node_app -->|"loads and saves"| node_db
node_db -->|"stores sessions"| node_sessions
node_db -->|"stores turn metrics"| node_runlog
node_app -->|"displays metrics"| node_stats

click node_app "https://github.com/lakshit-chiranjiv/contextlab/blob/main/app.py"
click node_normal "https://github.com/lakshit-chiranjiv/contextlab/blob/main/app.py"
click node_compare "https://github.com/lakshit-chiranjiv/contextlab/blob/main/app.py"
click node_stats "https://github.com/lakshit-chiranjiv/contextlab/blob/main/app.py"
click node_sliding "https://github.com/lakshit-chiranjiv/contextlab/blob/main/strategies/sliding_window.py"
click node_summarization "https://github.com/lakshit-chiranjiv/contextlab/blob/main/strategies/summarization.py"
click node_budget "https://github.com/lakshit-chiranjiv/contextlab/blob/main/strategies/token_budget.py"
click node_tokens "https://github.com/lakshit-chiranjiv/contextlab/blob/main/services/token_service.py"
click node_llm "https://github.com/lakshit-chiranjiv/contextlab/blob/main/services/llm_service.py"
click node_db "https://github.com/lakshit-chiranjiv/contextlab/blob/main/db/database.py"
click node_sessions "https://github.com/lakshit-chiranjiv/contextlab/blob/main/db/database.py"
click node_runlog "https://github.com/lakshit-chiranjiv/contextlab/blob/main/db/database.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_app,node_normal,node_compare,node_stats,node_user toneBlue
class node_sliding,node_summarization,node_budget toneAmber
class node_tokens,node_llm,node_groq toneMint
class node_db,node_sessions,node_runlog toneRose
```

## Components

### Chat experience

- [Streamlit app](https://github.com/lakshit-chiranjiv/contextlab/blob/main/app.py): `app.py`
- [Single-strategy chat](https://github.com/lakshit-chiranjiv/contextlab/blob/main/app.py): `app.py`
- [Compare Mode](https://github.com/lakshit-chiranjiv/contextlab/blob/main/app.py): `app.py`
- [Turn statistics](https://github.com/lakshit-chiranjiv/contextlab/blob/main/app.py): `app.py`

### Context strategies

- [Sliding Window](https://github.com/lakshit-chiranjiv/contextlab/blob/main/strategies/sliding_window.py): `strategies/sliding_window.py`
- [Summarization](https://github.com/lakshit-chiranjiv/contextlab/blob/main/strategies/summarization.py): `strategies/summarization.py`
- [Token Budget](https://github.com/lakshit-chiranjiv/contextlab/blob/main/strategies/token_budget.py): `strategies/token_budget.py`

### LLM services

- [Token estimation](https://github.com/lakshit-chiranjiv/contextlab/blob/main/services/token_service.py): `services/token_service.py`
- [Groq caller](https://github.com/lakshit-chiranjiv/contextlab/blob/main/services/llm_service.py): `services/llm_service.py`

### Persistence

- [SQLite persistence](https://github.com/lakshit-chiranjiv/contextlab/blob/main/db/database.py): `db/database.py`
- [Conversation sessions](https://github.com/lakshit-chiranjiv/contextlab/blob/main/db/database.py): `db/database.py`
- [Run log](https://github.com/lakshit-chiranjiv/contextlab/blob/main/db/database.py): `db/database.py`

### Other components

- **Chat user**
- **Groq API**

## Connections

- Chat user → Streamlit app: sends messages (evidence: `README.md`)
- Streamlit app → Single-strategy chat: dispatches chat (evidence: `README.md`)
- Streamlit app → Compare Mode: runs strategies (evidence: `app.py`)
- Single-strategy chat → Sliding Window: applies strategy (evidence: `app.py`)
- Single-strategy chat → Summarization: applies strategy (evidence: `app.py`)
- Single-strategy chat → Token Budget: applies strategy (evidence: `app.py`)
- Compare Mode → Sliding Window: applies strategy (evidence: `app.py`)
- Compare Mode → Summarization: applies strategy (evidence: `app.py`)
- Compare Mode → Token Budget: applies strategy (evidence: `app.py`)
- Single-strategy chat → Token estimation: estimates tokens (evidence: `README.md`)
- Compare Mode → Token estimation: estimates tokens (evidence: `app.py`)
- Token Budget → Token estimation: counts tokens (evidence: `strategies/token_budget.py`)
- Single-strategy chat → Groq caller: sends prompt (evidence: `README.md`)
- Compare Mode → Groq caller: sends prompts (evidence: `app.py`)
- Summarization → Groq caller: requests summary (evidence: `strategies/summarization.py`)
- Groq caller → Groq API: calls completions (evidence: `services/llm_service.py`)
- Streamlit app → SQLite persistence: loads and saves (evidence: `README.md`)
- SQLite persistence → Conversation sessions: stores sessions (evidence: `db/database.py`)
- SQLite persistence → Run log: stores turn metrics (evidence: `db/database.py`)
- Streamlit app → Turn statistics: displays metrics (evidence: `README.md`)
