Software ArchitectureVol. 13 · Part XIII
0 / 0

Shelves / Software Architecture

SA·143

Software Architecture Projects

Seven build-it-yourself projects that take the tiffin centre's codebase from working to well-designed and keep it that way: a code-health baseline with hotspots, a SOLID refactoring proved by contract tests, a pattern toolkit for resilience, a domain model with protected invariants, a hexagonal modular monolith with enforced boundaries, a measured service extraction, and an architecture decision log with fitness functions, each with milestones, measurable definitions of done and stretch goals.

11 topics · ~6 min read · 5-question quiz
Updated Suggest a correction

How to approach the projects

One codebase, improved and protected

The labs in this volume measured one idea at a time. These projects apply them to one codebase: the tiffin centre's ordering, kitchen, billing and delivery code from earlier volumes, or an application you maintain. Use any language; the tools have equivalents everywhere: radon/lizard/SonarQube for complexity, git history for hotspots, pytest/JUnit/Go tests with Hypothesis/jqwik/rapid for properties, import-linter/ArchUnit/Spring Modulith/go-arch-lint for dependency rules, and Markdown ADRs in the repository.

# Project Main chapters Roughly
1 A code-health baseline Start Here, 135 a weekend
2 SOLID refactoring with contract tests 136 1 week
3 A pattern toolkit for resilience 137 1 week
4 A domain model that protects itself 138 1–2 weeks
5 A hexagonal modular monolith 139, 140 2 weeks
6 A measured service extraction 141 1–2 weeks
7 Decisions recorded and enforced 142, LLD ongoing

New to design? Do them in order. Experienced? Start with project 1's hotspots and project 7's decision log, then pick the project that targets your codebase's worst hotspot.

The working method

  1. Measure first: complexity, hotspots, test speed, dependency graph.
  2. Refactor in small, behaviour-preserving steps with differential or characterization tests; behaviour changes go in separate commits.
  3. Turn each design rule into a check that runs in CI.
  4. Record each significant decision as an ADR with revisit conditions.
  5. Measure again and write the before/after in the project README.

The seven projects

Project 1: a code-health baseline

Goal. Know where the codebase is costly to change, with numbers.

Milestones. Complexity per function (radon, lizard) → churn per file from git history → hotspot ranking (churn × complexity) → change coupling (files that change together) → a one-page report: top five hotspots and why each is complex (essential vs accidental).

Done when. The report is reproducible by one script; the team agrees the top three hotspots match where changes hurt; each hotspot has a planned action or a written reason to leave it.

Stretch. Track the hotspot scores monthly and plot them; correlate with bug-fix commits per file.

Project 2: SOLID refactoring with contract tests

Goal. Refactor the worst hotspot so new variants arrive as new code, and prove substitutability.

Milestones. Characterization tests for the hotspot → differential tests comparing old and new on generated inputs, plus boundary examples → extract strategies/handlers for the varying behaviour (payment methods, pricing rules) → interfaces sized to their clients → contract tests run against every implementation → dependencies injected at a composition root.

Done when. The hotspot's max complexity drops below 10; adding a new variant touches no existing function (shown by a diff); contract tests run against every implementation including a deliberately broken one that fails them; unit tests run without a database.

Stretch. Run mutation testing (Volume 11) on the refactored module and kill all non-equivalent survivors.

Project 3: a pattern toolkit for resilience

Goal. Reusable decorators for calling external dependencies, composed deliberately.

Milestones. One interface per external dependency (supplier, payment gateway, SMS) → decorators for timeout, retry with jitter and budget, circuit breaker, cache and metrics → a documented composition order with a test per order-sensitive behaviour → an adapter wrapping a real SDK behind the interface.

Done when. With a fake dependency failing 30% of calls, the composed client meets a stated success rate; the cache reduces calls by the measured hit ratio; swapping decorator order breaks a named test; per-call overhead is measured and negligible next to the dependency.

Stretch. Replace hand-written decorators with a library (Resilience4j, Polly, tenacity) and compare code size and behaviour.

Project 4: a domain model that protects itself

Goal. The core domain (orders, payments, refunds, slots) as aggregates that can't be put into invalid states.

Milestones. Event storming with a domain expert (or a colleague playing one) → bounded contexts and a context map → aggregates with private state and intention-revealing methods → value objects for money, quantities and time slots → stateful property tests of every invariant → optimistic concurrency in the repository.

Done when. A stateful property test with at least 1,000 random command sequences finds no invariant violation; the same test finds violations when one guard is removed; two concurrent refunds that together exceed the payment are rejected by the version check.

Stretch. Add domain events and a projection for the kitchen's view, kept consistent through the outbox (Volume 12, chapter 131).

Project 5: a hexagonal modular monolith

Goal. One deployable with domain cores free of infrastructure and modules that talk only through APIs.

Milestones. Modules from the bounded contexts → per module: core with ports, adapters at the edge → module public APIs; internals private → schema per module with per-module database roles → dependency contracts (core purity, public APIs only, no cycles) in CI → an in-process event bus for cross-module reactions.

Done when. All contracts pass; a pull request that imports another module's internals or creates a cycle fails CI with the offending line; a module's role can't query another module's schema; each module's core tests run with in-memory adapters, and each adapter has its own integration tests.

Stretch. Use Spring Modulith (or equivalent) to generate module documentation and verify the structure, and compare with your hand-written contracts.

Project 6: a measured service extraction

Goal. Extract one module into a service for a concrete reason, and measure what it cost and gained.

Milestones. An ADR naming the driver (independent scaling, release cadence, isolation) and success measures → the module's API reimplemented as a remote client with timeouts, retries and idempotency → contract tests between caller and service → tracing across the boundary → a fan-out and failure experiment (like chapter 141's) on the real call paths → DORA metrics for the owning team before and after.

Done when. Callers didn't change beyond swapping the client; p50, p99 and success rates of the affected pages are measured before and after; a failure of the new service degrades the page instead of failing it; the ADR's success measures are reported honestly, including if the extraction didn't pay off.

Stretch. Add hedging for the service's slowest call and measure p99 and extra load.

Project 7: decisions recorded and enforced

Goal. An architecture decision log that explains the system, with fitness functions that keep it true.

Milestones. ADRs for the ten most significant existing decisions (reconstructed with the people who made them) → a decision matrix with sensitivity analysis for the next big decision → a fitness-function suite in CI: dependency rules, complexity ratchets, latency budgets from load tests, size limits → each fitness function linked to its ADR → a quarterly review of revisit conditions.

Done when. A new engineer can answer five "why is it like this?" questions from the log alone; the fitness suite runs in CI under five minutes and ratchets never loosen without a new ADR; one decision has been deliberately revisited and superseded.

Stretch. Run a lightweight ATAM session for one quality attribute (availability or modifiability) and record the sensitivity and trade-off points it found.

Tracking your progress

Portfolio checklist

Keep the reports, tests, contracts, ADRs and fitness functions in the repository, with a README per project. Architecture evidence is measured change cost: "top hotspot CCN 34 → 8; new payment method added with 0 edited functions; contract tests catch 2 broken implementations; 1,000 random command sequences, 0 invariant violations; 6 dependency contracts in CI, 3 violations blocked this quarter; extraction: p99 +12 ms, deploys/week 2 → 9; 14 ADRs, 1 superseded" is what makes the portfolio credible.

Mapping to mastery levels

Completing projects 1–3 with their checks puts you at L2 across the volume. Doing their stretch goals and explaining every mechanism is L3–L4. Designing and defending projects 4–7 (domain models, modular boundaries, extraction decisions and an enforced decision log) is L5 work, the level senior, staff and architect interviews probe.