Skip to main content

Sign in to CleanKata

Track your progress, earn XP, and unlock every lesson.

By signing in you agree to our Terms of Use and Privacy Policy.

One concept per lesson. No fluff.

Level up yourcode quality

Micro-lessons on clean code, design patterns, and clean architecture — with examples in Python and TypeScript.

Pick your language. One micro-lesson at a time — 5 to 12 minutes each.

Choose your language

Browse lessons
Did you know?

Developers spend 10× more time reading code than writing it. — Robert C. Martin

All lessons

Object Calisthenics

Use First-Class Collections

Any class containing a collection should have no other member variables — wrapping collections gives filtering, sorting, and rules a semantic and cohesive home.

Earn +70 XP7 min

Keep All Entities Small

No class over 50 lines, no package over 10 files — small classes fit on one screen, force focus, and naturally organize into cohesive packages.

Earn +60 XP6 min

Don't Abbreviate

Abbreviations mask deeper problems — if a name is too long to write out, the method has too many responsibilities. Names should be one or two clear words.

Earn +50 XP5 min

Don't Use the Else Keyword

Replace if/else with guard clauses and early returns — else is usually a sign of unclear flow that can be simplified into a straightforward sequence.

Earn +60 XP6 min

Don't Use Getters/Setters/Properties

Tell, don't ask — instead of getting data to make decisions outside the object, tell the object what to do and let it use its own data.

Earn +80 XP8 min

One Dot per Line

Based on the Law of Demeter — don't reach through an object's internals. Ask the object to do the work instead of navigating its parts.

Earn +70 XP7 min

One Level of Indentation per Method

Each method should do one thing at one level of abstraction — nested control structures are a sign to extract a method.

Earn +60 XP6 min

No Classes with More Than Two Instance Variables

Limiting state to two instance variables dramatically increases cohesion — if you need more, decompose into a hierarchy of collaborating objects.

Earn +70 XP7 min

Wrap All Primitives and Strings

A raw int or string has no domain meaning — wrapping it in a class like Money or Email lets the compiler enforce intent and gives behavior a natural home.

Earn +70 XP7 min

Clean Code

Class Organization

Classes should be small, focused, and have a single reason to change.

Earn +70 XP7 min

The Clean Code Mindset

Why clean code is a professional discipline — and how dirty code silently destroys teams and companies.

Earn +50 XP8 min

Clean Concurrency Strategies

Write concurrent code that is correct, readable, and free of subtle data-race bugs.

Earn +70 XP7 min

Clean Error Handling

Error handling is a separate concern — keep it isolated so your main algorithm stays readable.

Earn +60 XP6 min

Clean Unit Testing

Tests are first-class code — dirty tests become as costly to maintain as production code.

Earn +60 XP6 min

Comment Heuristics

Identify and eliminate bad comments; write the rare good one with precision.

Earn +50 XP5 min

Concurrency: Client-Server Model

Structure client-server concurrent systems to isolate shared state and avoid subtle threading bugs.

Earn +70 XP7 min

Concurrency: Deadlock & Starvation

Recognize and eliminate the four conditions that produce deadlock in concurrent systems.

Earn +70 XP7 min

Deadlock: The 4 Conditions

A deadlock requires all four Coffman conditions simultaneously — break any one and deadlock becomes impossible.

Earn +70 XP7 min

Concurrency: Jiggle Testing

Race conditions hide in timing gaps — shaking execution order with random yields and multi-platform runs forces them into the open.

Earn +70 XP7 min

Don't Repeat Yourself

🔒

Every piece of knowledge must have a single, authoritative representation in the codebase.

Requires 25 XP to unlock7 min

Duplication & Abstraction

🔒

Recognize hidden duplication and choose the right abstraction to eliminate it.

Requires 50 XP to unlock6 min

The 5S Philosophy in Code

🔒

How the Toyota 5S manufacturing philosophy maps to professional software craftsmanship — naming, organization, cleaning, standardization, and discipline.

Requires 75 XP to unlock6 min

Framework Analysis

🔒

Understand what a framework does before using it — read the source, not just the docs.

Requires 100 XP to unlock6 min

Function Heuristics

🔒

Apply the F1–F4 heuristics to keep functions minimal, focused, and side-effect-free.

Requires 125 XP to unlock5 min

Abstraction Levels & Dependencies

🔒

Keep high-level policy separate from low-level detail, and ensure base classes never depend on derived classes.

Requires 150 XP to unlock6 min

Coherence & Clarity

🔒

Apply the same pattern everywhere, avoid conceptual clutter, and never couple unrelated concerns.

Requires 175 XP to unlock6 min

Conventions & Magic Numbers

🔒

Follow team coding standards religiously and replace every magic literal with a named constant.

Requires 200 XP to unlock5 min

Environment & Truth

🔒

Build systems that compile in one step, run all tests in one step, and never lie through suppressed warnings.

Requires 225 XP to unlock6 min

Expressiveness & Algorithms

🔒

Use explanatory variables, precise names, and a deep understanding of the algorithm to make code speak for itself.

Requires 250 XP to unlock6 min

Feature Envy

🔒

A method that spends most of its time reading another class's data belongs in that class.

Requires 275 XP to unlock5 min

Logic & Polymorphism

🔒

Make all dependencies explicit, and replace if/switch chains with polymorphic dispatch.

Requires 300 XP to unlock6 min

Noise & Organization

🔒

Eliminate excessive information, dead code, and vertical distance to keep every file easy to scan.

Requires 325 XP to unlock6 min

Placement & Statics

🔒

Put every function in the class most interested in it, and keep static methods truly stateless utilities.

Requires 350 XP to unlock6 min

Selectors & Intent

🔒

Boolean and enum selector arguments obscure intent — split them into focused, well-named functions.

Requires 375 XP to unlock6 min

Heuristics Catalog Overview

🔒

A curated catalog of code smells and refactoring heuristics drawn from Clean Code chapter 17.

Requires 400 XP to unlock8 min

G16: The Obscured Intent

🔒

Code that tries to be clever is code that fails to communicate — density and brevity at the cost of clarity are not virtues.

Requires 425 XP to unlock5 min

G21: Understanding the Algorithm

🔒

Tests passing is not the same as understanding — clean code requires you to fully grasp why the algorithm works before you commit it.

Requires 450 XP to unlock5 min

G22: Logical to Physical Dependencies

🔒

Never let a module silently assume a value from another — make every dependency explicit and declared in code.

Requires 475 XP to unlock6 min

Java-Specific Heuristics (J1–J3)

🔒

Three Java-focused heuristics: avoid wildcard imports, never inherit constants, and prefer enums over integer constants.

Requires 500 XP to unlock5 min

Legacy Code Refactoring

🔒

Safely transform tangled legacy code by adding tests first and refactoring in small steps.

Requires 525 XP to unlock7 min

The Art of Naming

🔒

Write names that reveal intent, avoid confusion, and make code searchable.

Requires 550 XP to unlock5 min

Naming Heuristics

🔒

Apply the N1–N7 heuristics to write names that are accurate, unambiguous, and searchable.

Requires 575 XP to unlock6 min

The Necessary Evil of Comments

🔒

Code is the only source of truth — comments lie as the code evolves.

Requires 600 XP to unlock5 min

Objects vs Data Structures

🔒

Objects hide data behind behavior. Structures expose data. Mixing both creates hybrids nobody wants.

Requires 625 XP to unlock6 min

Programmer Ethics & Attitude

🔒

Quality is a professional responsibility — not something you deliver when time allows, but the non-negotiable minimum of your craft.

Requires 650 XP to unlock6 min

Pure Functions

🔒

A pure function always returns the same output for the same input and changes nothing outside itself.

Requires 675 XP to unlock7 min

Responsibility Selectors

🔒

Use the Single Responsibility heuristics to detect and split overloaded classes and modules.

Requires 700 XP to unlock6 min

SerialDate: Cleanup & Transformation

🔒

Apply successive refinement to the SerialDate class — test, rename, extract, and simplify.

Requires 725 XP to unlock7 min

SerialDate: Diagnosis

🔒

A case study in reading legacy code critically — find the smells before touching anything.

Requires 750 XP to unlock7 min

The 4 Rules of Simple Design

🔒

Kent Beck's four rules, in priority order, for a design that is always ready to evolve.

Requires 775 XP to unlock6 min

Small Functions

🔒

Functions should do one thing, do it well, and do it only.

Requires 800 XP to unlock6 min

Style & Format as Communication

🔒

Code formatting is a communication act — structure files so any developer can navigate them in seconds.

Requires 825 XP to unlock5 min

Successive Refinement

🔒

Start with working code, then refactor iteratively — never write clean code in one pass.

Requires 850 XP to unlock6 min

System Boundaries

🔒

Third-party code belongs at the edge — wrap it so it never pollutes your business logic.

Requires 875 XP to unlock6 min

The Three Laws of TDD

🔒

Master the red-green-refactor micro-cycle: write a failing test first, then only the code needed to pass it.

Requires 900 XP to unlock6 min

Testing Heuristics

🔒

Apply the T1–T9 heuristics to write complete, meaningful, and maintainable test suites.

Requires 925 XP to unlock6 min

Design Patterns

Abstract Factory: Families of Objects

Create families of related objects without specifying their concrete classes — guarantee compatibility between products from the same family.

Earn +80 XP8 min

Adapter: The Interface Translator

Make incompatible interfaces work together — wrap an old or external class behind the interface your system expects without modifying either side.

Earn +70 XP7 min

Bridge: Decoupling Abstraction

Split a large class into two independent hierarchies — abstraction and implementation — so both can evolve without affecting each other.

Earn +80 XP8 min

Builder: Step-by-Step Construction

Construct complex objects step by step — the same construction process can produce different representations using a fluent interface.

Earn +80 XP7 min

Chain of Responsibility

Pass a request along a chain of handlers — each handler decides to process it or pass it to the next, decoupling sender from receiver.

Earn +80 XP8 min

Command: Encapsulating Requests

Transform a request into a standalone object — enabling undo/redo, queuing, logging, and deferred execution of operations.

Earn +80 XP8 min

Composite: Tree Structures

Compose objects into tree structures and treat individual objects and groups uniformly — iterate a file system the same way whether it's a file or a folder.

Earn +80 XP8 min

Decorator: Adding Superpowers

Add behavior to objects dynamically by wrapping them — compose capabilities instead of creating an explosion of subclasses.

Earn +80 XP9 min

Facade: The Friendly Face of the System

Provide a simplified interface to a complex subsystem — hide the chaos behind a single clean entry point without removing the complexity for those who need it.

Earn +70 XP6 min

Factory Method: The Virtual Constructor

Delegate object creation to subclasses — decouple the client from the concrete classes it instantiates.

Earn +80 XP8 min

Flyweight: Sharing to Save Memory

🔒

Fit more objects in RAM by sharing common state — separate intrinsic (shared) from extrinsic (unique) data to avoid duplicating heavy objects.

Requires 25 XP to unlock8 min

Iterator: Traversing Collections

🔒

Traverse elements of any collection without exposing its internal structure — the client never needs to know if it's a list, tree, or graph.

Requires 50 XP to unlock8 min

Mediator: Centralized Communication

🔒

Restrict direct communication between objects — force them to collaborate through a mediator to reduce chaotic many-to-many dependencies.

Requires 75 XP to unlock8 min

Memento: Undo with Snapshots

🔒

Capture and restore an object's internal state without violating encapsulation — implement Undo by storing snapshots of past states.

Requires 100 XP to unlock8 min

Observer: The Subscription System

🔒

Let objects subscribe to events and be notified automatically — decouple event producers from consumers without either knowing about the other.

Requires 125 XP to unlock9 min

Prototype: Object Cloning

🔒

Copy existing objects without depending on their classes — clone complex configurations instead of rebuilding them from scratch.

Requires 150 XP to unlock8 min

Proxy: The Control Intermediary

🔒

Provide a substitute that controls access to another object — use for lazy loading, access control, logging, or caching without changing the real object.

Requires 175 XP to unlock8 min

Repository Pattern

🔒

Abstract data access behind an interface so your business logic never knows whether data comes from a database, cache, or API — and testing becomes a one-liner swap.

Requires 200 XP to unlock10 min

Singleton: The Single Instance

🔒

Ensure a class has only one instance and provide a global access point — but overuse creates hidden global state and makes testing painful.

Requires 225 XP to unlock6 min

State: Behavior Based on State

🔒

Allow an object to alter its behavior when its internal state changes — replace state conditionals with polymorphic state objects.

Requires 250 XP to unlock8 min

Strategy: Algorithm Swapping

🔒

Define a family of algorithms, encapsulate each in its own class, and make them interchangeable at runtime — eliminate conditionals by selecting behavior through composition.

Requires 275 XP to unlock8 min

Template Method: Algorithm Skeleton

🔒

Define the skeleton of an algorithm in a superclass, but let subclasses override specific steps without changing its structure.

Requires 300 XP to unlock8 min

Visitor: New Operations Without Changing Classes

🔒

Add new operations to an object hierarchy without modifying the classes — the visitor carries the operation, the elements just accept it.

Requires 325 XP to unlock8 min

Clean Architecture

ADP: The Acyclic Dependencies Principle

No cycles allowed in the component dependency graph — cycles cause the morning-after syndrome and prevent isolated builds and tests.

Earn +80 XP8 min

Architectural Boundaries: Drawing Lines

Architecture draws lines between what matters (business rules) and what doesn't (technical details) — these lines protect core business logic from changes in external tools.

Earn +70 XP7 min

What is Architecture? Lifecycle Support

Architecture's primary purpose is to support the system's lifecycle — development, deployment, operation, and maintenance — to maximize productivity and minimize lifetime cost.

Earn +60 XP6 min

Anatomy of a Boundary: Crossing Boundaries

When crossing an architectural boundary, source code dependencies must point opposite to the flow of control — polymorphism enforces this regardless of who calls whom.

Earn +80 XP8 min

Business Rules and Entities

Critical Business Rules would exist even without a computer — Entities encapsulate these rules and data, forming the most stable, UI-and-persistence-agnostic heart of the system.

Earn +70 XP7 min

Clean Embedded Architecture: Avoiding Firmware

Software doesn't wear out, but hardware becomes obsolete — a Hardware Abstraction Layer prevents business logic from becoming firmware trapped on a specific processor.

Earn +70 XP7 min

The Component Tension Diagram

REP, CCP, and CRP pull in opposite directions — architects must balance these tensions as the project evolves from development focus to reuse focus.

Earn +70 XP7 min

Components: The Unit of Deployment

Components are the smallest deployable units — JARs, DLLs, Gems — the building blocks of a plugin architecture where modules connect at runtime.

Earn +60 XP6 min

Component Cohesion: The Common Reuse Principle

Don't force users of a component to depend on things they don't need — depending on a component means depending on everything it contains.

Earn +70 XP7 min

Decoupling Modes: Source, Deployment, and Service

Decoupling can happen at source code, deployment, or service level — good architecture lets you start as a monolith and evolve into services if boundaries are well-defined.

Earn +70 XP7 min

The Dependency Rule in Clean Architecture

🔒

Source code dependencies can only point inward — nothing in an inner circle can know anything about an outer circle, keeping the business core stable and reusable.

Requires 25 XP to unlock8 min

The Details: Database, Web, and Frameworks

🔒

The database, web layer, and frameworks are delivery mechanisms — a good architect postpones these decisions and keeps business rules independent to avoid a costly technology marriage.

Requires 50 XP to unlock7 min

Device Independence

🔒

Tying business logic to specific I/O devices is a costly mistake — architecture should be agnostic to whether data comes from cards, terminals, files, or APIs.

Requires 75 XP to unlock6 min

DIP: The Dependency Inversion Principle

🔒

Source code dependencies should point only to abstractions — Abstract Factories create the architectural boundary between volatile concrete code and stable policy.

Requires 100 XP to unlock8 min

Dependency Inversion: Control Over Dependencies

🔒

With interfaces, architects make source-code dependencies point against the control flow, granting absolute power over module coupling.

Requires 125 XP to unlock8 min

The Eisenhower Matrix in Development

🔒

Architecture is important but rarely urgent. Developers must defend good structure against short-term business pressure.

Requires 150 XP to unlock6 min

Architecture Layers: Entities and Use Cases

🔒

Entities hold critical business rules that exist across the enterprise; Use Cases orchestrate application-specific flows and are isolated from UI and database changes.

Requires 175 XP to unlock7 min

Functional Programming: The Value of Immutability

🔒

Functional programming disciplines assignment. Immutability eliminates race conditions, deadlocks, and concurrent update issues at the architectural level.

Requires 200 XP to unlock7 min

The Goal of Architecture and Design

🔒

Design and architecture are the same thing — their true measure is the effort required to meet client needs while minimizing lifetime cost.

Requires 225 XP to unlock6 min

The Humble Object Pattern

🔒

Split hard-to-test from easy-to-test behavior — the Presenter prepares all logic into a testable ViewModel; the View is a humble object that only renders what it receives.

Requires 250 XP to unlock7 min

The Devil Is in the Implementation Details

🔒

The best architecture fails without disciplined use of access modifiers — the compiler is your strongest ally in enforcing Clean Architecture rules across the team.

Requires 275 XP to unlock7 min

Interface Adapters and Data Passing

🔒

Interface Adapters convert data between the format use cases understand and the format external systems need — boundaries are always crossed with simple DTOs, never raw entities or DB rows.

Requires 300 XP to unlock7 min

ISP: The Interface Segregation Principle

🔒

Don't depend on things you don't use — fat interfaces force unnecessary recompilation, coupling, and vulnerability to failures in unrelated code.

Requires 325 XP to unlock7 min

Keep Options Open

🔒

A good architect maximizes the number of decisions not yet made — separating policy from details so database and framework choices can be postponed until more is known.

Requires 350 XP to unlock7 min

Layer Decoupling

🔒

Separate what changes at different rates — UI, application business rules, domain business rules, and database each change for different reasons and should be horizontal layers.

Requires 375 XP to unlock7 min

LSP: The Liskov Substitution Principle

🔒

Subtypes must be substitutable for their base types — LSP violations at the architectural level force expensive special-case logic into the design.

Requires 400 XP to unlock7 min

The Main Component: The Ultimate Detail

🔒

Main is the dirtiest, lowest-level component — the entry point that wires all dependencies and hands control to the clean architecture above it.

Requires 425 XP to unlock6 min

The Main Sequence: The A/I Balance

🔒

Components should balance Abstraction (A) and Instability (I) — the Pain Zone (stable+concrete) and Uselessness Zone (abstract+unstable) are architectural anti-patterns to avoid.

Requires 450 XP to unlock8 min

OCP: The Open/Closed Principle

🔒

Software artifacts should be open for extension but closed for modification — adding new behavior should add code, not change existing code.

Requires 475 XP to unlock7 min

OOP: The Reality of Encapsulation

🔒

OOP didn't invent encapsulation — C had perfect encapsulation before C++ and Java actually weakened it with header file requirements.

Requires 500 XP to unlock7 min

Package by Component: The Hybrid Approach

🔒

Group all responsibility for a clean feature boundary into one package — internal persistence and logic stay private, the compiler enforces what's visible to the rest of the system.

Requires 525 XP to unlock7 min

Organizational Strategies: Package by Feature

🔒

Group code by domain feature — top-level packages reveal the business, every feature is co-located, and searchability dramatically improves as the system grows.

Requires 550 XP to unlock6 min

Organizational Strategies: Package by Layer

🔒

The simplest code organization groups by technical layer (web/service/repository) — easy to start but hides business intent and allows accidental cross-layer shortcuts.

Requires 575 XP to unlock6 min

Partial Boundaries: Anticipation Strategies

🔒

Full architectural boundaries are expensive — partial boundaries using Strategy or Facade patterns preserve future separation points without the full upfront cost.

Requires 600 XP to unlock7 min

The Peripheral Anti-Pattern

🔒

The peripheral anti-pattern occurs when infrastructure code talks directly to other infrastructure code, bypassing the domain — like the Paris ring road, traffic flows around the city instead of through it.

Requires 625 XP to unlock7 min

Policy and Level

🔒

Level is the distance from inputs and outputs — the farther from I/O, the higher the level. Source code dependencies should always point toward the highest-level, most stable policies.

Requires 650 XP to unlock7 min

Polymorphism: The Power of Plugins

🔒

Polymorphism lets you treat external dependencies — database, UI, I/O — as interchangeable plugins, making core logic device-independent.

Requires 675 XP to unlock8 min

Ports and Adapters (Hexagonal Architecture)

🔒

The inside is the domain; the outside is infrastructure — outside depends on inside, ports speak the domain's language, and adapters translate between domain and external systems.

Requires 700 XP to unlock8 min

Programming as Science: Falsifiability and Testing

🔒

Tests don't prove correctness — they prove absence of known incorrectness. Good architecture produces easily falsifiable modules.

Requires 725 XP to unlock7 min

Programming Paradigms: Discipline, Not Tools

🔒

The three paradigms — structured, object-oriented, and functional — impose discipline by removing capabilities, not adding them.

Requires 750 XP to unlock7 min

Component Cohesion: REP and CCP

🔒

REP groups classes released together; CCP groups classes that change together for the same reason — both mirror SRP at the component scale.

Requires 775 XP to unlock7 min

SAP: The Stable Abstractions Principle

🔒

A component should be as abstract as it is stable — the most stable components should be pure interfaces so they can be extended without modification.

Requires 800 XP to unlock7 min

Screaming Architecture

🔒

Your folder structure should reveal what the system does, not what framework it uses — a health system screams 'Health', not 'Rails'.

Requires 825 XP to unlock6 min

SDP: The Stable Dependencies Principle

🔒

Depend in the direction of stability — a volatile component should never be depended upon by a stable one, or that stability is permanently compromised.

Requires 850 XP to unlock7 min

Services and Microservices: Are They Architecture?

🔒

Services don't define architecture — a service with poor internal structure is just an expensive function call. True architectural boundaries can exist inside a monolith or across services.

Requires 875 XP to unlock7 min

SRP: The Single Responsibility Principle

🔒

A module should be responsible to only one actor — preventing changes for one department from accidentally breaking another.

Requires 900 XP to unlock7 min

Structured Programming: Discipline over Direct Control

🔒

Dijkstra proved unrestricted goto is harmful. Sequence, selection, and iteration alone are sufficient for correct, decomposable modules.

Requires 925 XP to unlock6 min

The Test Boundary

🔒

Tests are the outermost architectural circle — fragile tests that couple to implementation details make the system rigid; a Test API decouples test structure from application structure.

Requires 950 XP to unlock7 min

The Two Values of Software: Behavior vs Structure

🔒

Software derives value from behavior and structure. A perfectly working but rigid system will fail when requirements change.

Requires 975 XP to unlock6 min

Use Case Decoupling

🔒

Use cases are vertical slices that cut through all layers — decoupling them lets each evolve independently without one use case's changes colliding with another's.

Requires 1000 XP to unlock7 min