Transform complexity into clarity with C4 model documentation and LLM integration
loko (Papa Loko) is a modern architecture documentation tool that brings the C4 model to life through conversational design with LLMs, powerful CLI workflows, and beautiful documentation generation.
π€ LLM-First Design - Design architecture conversationally with Claude, GPT, or Gemini via MCP
π Direct Editing - Edit markdown and D2 diagrams in your favorite editor
β‘ Real-Time Feedback - Watch mode rebuilds in <500ms with hot reload
π¨ Beautiful Output - Generate static sites, PDFs, and markdown documentation
π§ Powerful CLI - Scaffold, build, validate, and serve - all from the terminal
π³ Docker Ready - Official images with all dependencies included
π― Zero Config - Smart defaults with optional customization via TOML
π° Token Efficient - Progressive context loading + TOON format minimize LLM costs
macOS / Linux (Homebrew)
brew tap madstone-tech/tap
brew install lokoGo Install
go install github.com/madstone-tech/loko@latestDocker
docker pull ghcr.io/madstone-tech/loko:latest# Initialize a new project
loko init my-architecture
cd my-architecture
# Scaffold your first system
loko new system PaymentService
# Edit the generated files
vim src/PaymentService/system.md
vim src/PaymentService/system.d2
# Build and preview
loko serve
# Open http://localhost:8080That's it! You now have a live-reloading documentation site.
# Start MCP server
loko mcp
# In your LLM client (Claude, etc):
# "I'm building a payment processing system with an API and database"
# LLM uses loko to scaffold structure and create diagrams# Watch for changes
loko watch &
# Edit files in your editor
vim src/PaymentService/system.d2
# Automatically rebuilds and refreshes browser# Start API server
loko api
# Trigger builds via HTTP
curl -X POST http://localhost:8081/api/v1/buildContext
βββ System
βββ Container
βββ Component
my-architecture/
βββ loko.toml # Configuration
βββ src/ # Source documentation
β βββ context.md
β βββ context.d2
β βββ SystemName/
β βββ system.md
β βββ system.d2
β βββ ContainerName/
β βββ container.md
β βββ container.d2
βββ dist/ # Generated output
βββ index.html
loko follows Clean Architecture principles:
loko/
βββ cmd/ # CLI commands (thin layer)
β
βββ internal/
β βββ core/ # THE HEART - zero external dependencies
β β βββ entities/ # Domain objects: Project, System, Container
β β βββ usecases/ # Application logic + port interfaces
β β βββ errors/ # Domain-specific errors
β β
β βββ adapters/ # Infrastructure implementations
β β βββ config/ # TOML configuration
β β βββ filesystem/ # File operations
β β βββ d2/ # Diagram rendering
β β βββ encoding/ # JSON + TOON encoders
β β βββ html/ # Site builder
β β
β βββ mcp/ # MCP server + tools
β βββ api/ # HTTP API server
β βββ ui/ # Terminal UI (lipgloss)
β
βββ templates/ # Starter templates
βββ docs/ # Documentation + ADRs
loko is designed to minimize LLM token consumption:
# Quick overview (~200 tokens)
query_architecture --detail summary
# System hierarchy (~500 tokens)
query_architecture --detail structure
# Full details for one system (variable)
query_architecture --detail full --target PaymentServiceTOON reduces tokens by 30-40% for structured data:
# JSON: ~380 tokens
{"systems":[{"name":"PaymentService","containers":["API","DB"]},...]}
# TOON: ~220 tokens
systems[4]{name,containers}:
PaymentService,API|DB
OrderService,API|DB
...loko includes built-in templates powered by ason:
| Template | Use Case |
|---|---|
standard-3layer |
Traditional web apps (API β Service β Database) |
serverless |
AWS Lambda architectures (API Gateway, SQS, DynamoDB) |
# Use default template (standard-3layer)
loko new system PaymentService
# Use serverless template for AWS Lambda architectures
loko new system "Order Processing API" -template serverless
loko new container "API Handlers" -parent order-processing-api -template serverlessTemplates use ason's variable interpolation syntax for scaffolding. See ason documentation for template authoring.
Powered by D2 with caching:
# src/System/system.d2
User -> API: Uses
API -> Database: Queriesloko render src/System/system.d2
# Generates: dist/diagrams/system.svgloko build --format html # Static website
loko build --format markdown # Single README.md
loko build --format pdf # PDF documents (requires veve-cli)loko validate
# Checks for:
# - Orphaned references
# - Missing required files
# - C4 hierarchy violations
# - Broken diagram syntaxloko.toml (TOML format):
[project]
name = "my-architecture"
description = "System architecture documentation"
[paths]
source = "./src"
output = "./dist"
[d2]
theme = "neutral-default"
layout = "elk"
cache = true
[outputs.html]
enabled = true
navigation = "sidebar"
search = true
[build]
parallel = true
max_workers = 4See docs/configuration.md for all options.
loko exposes these tools for LLM interaction:
| Tool | Description |
|---|---|
query_project |
Get project metadata |
query_architecture |
Token-efficient architecture queries |
create_system |
Scaffold new system |
create_container |
Scaffold container |
create_component |
Scaffold component |
update_diagram |
Write D2 code to file |
build_docs |
Build documentation |
validate |
Check architecture consistency |
{
"name": "query_architecture",
"parameters": {
"scope": "project | system | container",
"target": "specific entity name",
"detail": "summary | structure | full",
"format": "json | toon",
"include_diagrams": false
}
}- Installation Guide
- Quick Start Tutorial
- Configuration Reference
- Template System
- MCP Integration
- API Reference
- Architecture Decision Records
Check out examples/ for complete projects:
- simple-project - Minimal C4 documentation
- 3layer-app - Standard web β API β database
- serverless - AWS Lambda architecture
# Initialize project
docker run -v $(pwd):/workspace ghcr.io/madstone-tech/loko init my-arch
# Build documentation
docker run -v $(pwd):/workspace ghcr.io/madstone-tech/loko build
# Serve with hot reload
docker run -v $(pwd):/workspace -p 8080:8080 ghcr.io/madstone-tech/loko servegit clone https://github.com/madstone-tech/loko
cd loko
go mod download
make test
go run main.go --helpSee CONTRIBUTING.md for development guidelines.
Comprehensive documentation is available in the docs/ directory:
- Quick Start Guide - Get running in 5 minutes
- MCP Integration - AI-assisted architecture design
- Configuration Reference - Complete loko.toml options
- MCP Setup Guide - Detailed MCP configuration
- Migration Guide v0.2.0 - Upgrade to qualified node IDs
- ADR-0001: Clean Architecture - Dependency inversion
- ADR-0002: Token-Efficient MCP - Minimizing LLM costs
- ADR-0003: TOON Format - Compact architecture notation
- ADR-0004: Graph Conventions - Node IDs and thread safety
- API Reference - HTTP API endpoints
- CHANGELOG - Version history and release notes
See the Documentation Index for the complete catalog.
Foundation (Complete)
- β Clean Architecture with 18 port interfaces
- β Domain entities (Project, System, Container, Component) with tests
- β CLI framework (Cobra + Viper) with shell completions
- β Template system with standard-3layer and serverless templates
Current: Handler Refactoring + TOON Alignment (#005)
- π‘ Extract business logic from CLI/MCP handlers into use cases
- π‘ Align TOON encoder with official TOON v3.0 specification
Remaining
- π² Scaffolding use cases with ason template engine adapter
- π² D2 diagram rendering with caching
- π² HTML site generation with watch mode
- π² MCP server with token-efficient queries
- π HTTP API server for CI/CD integration
- π PDF export via veve-cli
- π Multi-format export (HTML, Markdown, PDF)
- π Advanced validation rules
- π Architecture graph visualization
- π Diff and changelog generation
- π Plugin system
See specs/ for detailed feature specifications.
We welcome contributions! loko is building in public - see our development progress.
- π Bug reports β Open an issue
- π‘ Feature requests β Start a discussion
- π§ Pull requests β See CONTRIBUTING.md
MIT License - Copyright (c) 2025-2026 MADSTONE TECHNOLOGY
loko builds on excellent open-source tools:
- D2 - Declarative diagramming
- ason - Template scaffolding
- TOON - Token-efficient notation
- C4 Model - Architecture visualization approach
- Cobra - CLI framework
- Bubbletea - TUI framework
Papa Loko is the lwa (spirit) in Haitian Vodou who guards sacred knowledge, maintains tradition, and passes down wisdom to initiates. As the first houngan (priest), he is the keeper of the ritual knowledge that connects the physical and spiritual worlds.
Like Papa Loko, this tool acts as the guardian of your architectural wisdom - organizing knowledge, maintaining documentation traditions, and making complex systems understandable.
"Papa Loko, you're the wind, pushing us, and we become butterflies." π¦