Clean code and architecture playbook
Rules for code that people and AI agents can read, change and trust. Clean names, small functions, typed data, SOLID design and a numbered review.
- Required 10
- Recommended 74
- Avoid 4
A clean code and architecture playbook for any language. It covers code review, names, functions, comments, errors, coupling, SOLID design, data shapes, structure and dead code, domain models and concurrency. A chapter on system architecture covers quality goals and checked decisions, diagrams, consistency and failure between services. The last chapter keeps technical debt in a ranked register. The testing playbook covers how to test it.
Every rule has a check that a linter, a type checker or a test can run. Where no tool can decide, the code review chapter gives a numbered question to answer instead.
AI agents write code fast, and they copy what they see. Clean code gives them good patterns to copy, so every change keeps the codebase easy to read.
Chapters
Code review
Review the whole change against its base with numbered questions. Writing up and checking the findings is in the engineering review chapter.
- Recommended 6
Names and functions
Names that say what things are, and small functions that each do one thing. Short, shallow and with few arguments, so anyone can read them at a glance.
- Recommended 7
- Avoid 1
Comments
Let names and small functions carry the meaning. Keep a comment only for a reason the code cannot show, and let version control keep the history.
- Recommended 6
Errors and nulls
Signal failure with typed errors or results, not codes. Return empty lists instead of null, never swallow an error and release every resource you open.
- Required 5
- Recommended 4
- Avoid 1
Coupling
Let each module talk only to its direct neighbours. Make the order of calls impossible to get wrong, share no global state and hide the rest.
- Required 1
- Recommended 5
SOLID and DRY
Keep each piece of knowledge in one place and give each module one reason to change. Extend code by adding to it, not editing it.
- Recommended 8
Data shapes
Pass data as named, typed objects that say what they hold. Parse input once at the edge, and never hide types in mixed values, loose arrays or strings.
- Required 2
- Recommended 11
- Avoid 1
Structure
Point dependencies one way, group folders by feature, keep files easy to find, and delete code, flags and packages that nothing uses any more.
- Recommended 11
Domain model
Split the code into bounded contexts with their own words. Change aggregates only through their root, one per transaction. Translate outside models at the edge.
- Recommended 4
Concurrency
Await every async call and guard shared state. Pass a cancel signal down, start tasks in a scope that waits, and take locks in one order.
- Required 2
- Recommended 3
- Avoid 1
System architecture
Set quality goals with numbers and check each decision in the build. Draw the system as code, and choose how its parts stay consistent and fail apart.
- Recommended 5
Technical debt
Keep debt in a register in the repository, ranked by its monthly cost. Spend a set share of each cycle on it and record every shortcut when you take it.
- Recommended 4
This is a lot to check. An Expert can check it for you.
Related playbooks
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/architecture">Agent Wranglers clean code and architecture playbook</a>. In code you write, add a comment next to it with the same link.