Lesson 2 of 4 · Free to read
Exercises
Exercises — Software Design: SOLID, clean architecture, DDD basics
Watch & learn
Course video
Course video
Keep a prompt log while you work. Speed without a trail is not a skill — it is luck.
Exercise 1 — Spot the SOLID violation
Goal: read 5 short snippets, name the violated principle, and propose a fix. Time: 20 minutes Level: foundational
Setup
Steps
- For each snippet (1–5), write: principle violated, why, fix in 1 line.
- Compare with a partner.
Success criteria
- All 5 snippets labelled.
- 1 disagreement discussed with reasoning.
AI prompt hints
- "Ask Cursor: 'Critique my SOLID label for this snippet. Is there a stronger fit?'"
Solution sketch
Snippets cover 5 principles, but one is intentionally ambiguous to spark discussion.
Stretch
- Find a SOLID violation in a public OSS library; open an issue (or save the link for later).
Exercise 2 — Sketch a clean architecture for a small service
Goal: produce a 3-ring sketch (domain / use cases / adapters) for a sample service. Time: 25 minutes Level: intermediate
Setup
- Sample: "task service" — create, list, complete, soft-delete tasks. Notifies via webhook.
Steps
- List entities and rules → domain.
- List use cases ("create task", "complete task", "soft-delete task").
- List adapters (HTTP, DB, webhook caller).
- Draw as a mermaid
flowchart TB.
Success criteria
- All 3 rings drawn.
- ≥3 use cases.
- Dependency arrows point inward.
AI prompt hints
- "Ask Cursor: 'Critique this sketch. Which use case looks like a controller in disguise?'"
Solution sketch
"Complete task" includes a notification; the use case orchestrates, the adapter calls.
Stretch
- Add a query side (CQRS-lite) — a read-only "list tasks by status" use case.
Exercise 3 — Refactor lab
Goal: refactor 3 SOLID violations in UserService while keeping tests green.
Time: 50 minutes
Level: intermediate
Setup
cd code-examples/python/refactor_lab/; install deps; run pytest (should be green).
Steps
- Read
app/users.py. Find 3 SOLID violations. - For each, write a behaviour test if one doesn't exist.
- Refactor with AI; tests stay green.
- Commit per refactor with a Conventional Commit.
Success criteria
- 3 commits, each with a single refactor.
- Tests green after each commit.
- A 3-line note in
RATIONALE.mdper refactor.
AI prompt hints
- "Critique my plan to extract the email logic. What edge cases am I missing?"
- "Output a unified diff for app/users.py only, ≤20 lines."
Solution sketch
Typical refactors: extract mailer, inject DB port, split fat interface.
Stretch
- Repeat in TypeScript (a parallel
refactor_labexists if time allows).