Case Study
ContextStrategies
Turn any codebase into AI-ready context with drift-safe tooling.
15.6K
Python LOC
9
Analyzers
4
UI Surfaces
v5.0.0
Version
Overview
What the product does and why I built it that way.
I built ctx-flatten because “copy files into the prompt” doesn’t scale. It turns a repo into a token-budgeted Markdown context you can paste into an LLM, then goes further: AI-powered focusing, drift-safe AST-based patching, nine static analysis dimensions, duplicate detection, and git-history dashboards—delivered as one modular Python package with CLI, TUI, FastAPI, and Streamlit surfaces.
Architecture
The system shape behind the product.
Modular monolith: one Python core powering four surfaces (CLI, TUI, API, dashboard) with optional AI, analysis, and history extras.
Interfaces
Interfaces
Typer CLI
Textual TUI
FastAPI API
Streamlit Dashboard
Core Engine
Core Engine
Repo Discovery
.gitignore Filtering
Token Budgeting
Markdown Renderer
AI Layer
AI Layer
pydantic-ai Agent
OpenRouter Provider
Focus + Patch Workflows
Analysis
Analysis
Architecture Analyzer
Complexity
Security (Bandit)
Documentation
Performance
Code Smells
Patterns
Test Coverage
Outputs
Outputs
Markdown Contexts
JSON Snapshots
DuckDB History DB
Reports
Next Step
Use it on your next repo
Install ctx-flatten, generate a context file, and keep your AI workflows grounded in real code with drift-safe patches and inspectable outputs.