Architecture Overview
Crush follows a classic layered architecture, organized top-down into four distinct layers:
- Presentation Layer — TUI Model (Bubble Tea), Dialogs, Chat View
- Application Layer — App (dependency injection), Coordinator (Agent), Session Service
- Domain Layer — Agent (AI core), Tools (20+ tools), Message (messaging system)
- Infrastructure Layer — Config, Database (SQLite), LSP/MCP (external integrations)
config(configuration management)agent(AI core), which depends onlsp,tools, andmessagesession(session management), which depends onpermission- Language — Go 1.25+ (performance, concurrency, native support)
- AI framework — fantasy (the official Charm AI framework)
- Model management — catwalk (multi-model abstraction layer)
- TUI framework — Bubble Tea (the official Charm TUI framework)
- Terminal styling — Lipgloss (the official Charm styling library)
- Database — SQLite via the pure-Go
moderncdriver (embedded, no dependencies) - LSP — powernap + jsonrpc2 (lightweight LSP client)
- MCP — go-sdk (the official Model Context Protocol SDK)
Module Dependencies
The dependency graph starts at the cmd entry point and flows into app. From there it branches into three top-level subsystems:
The message subsystem further branches into db, pubsub, csync, and oauth.
Request Processing Flow
1. User input 2. TUI Model (Bubble Tea) — receives input and validates format 3. App.Run() — creates or retrieves a session and routes to the Coordinator 4. Coordinator.Run() — builds the prompt, selects a model, and adds context 5. SessionAgent.Run() — calls the LLM API, parses the response, and handles tool calls 6. Tool Execution — performs permission checks, runs the tool, and returns results 7. Message Service (persistence) — saves messages and tool calls 8. TUI Update — renders messages and tool results 9. Response returned to the user
Core Technology Stack
*This article is Chapter 11 of the 'Crush from Beginner to Master' series.*