Agent Wranglers

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

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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

All 88 rules on one page

This is a lot to check. An Expert can check it for you.

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.