CompCode Academy

Lesson 2 of 4 · Free to read

Exercises

Exercises — Software Design: SOLID, clean architecture, DDD basics

Watch & learn

Course video

Open on YouTube
SOLID Principles (Uncle Bob) — Design principles AI-generated code often violates.

Course video

Open on YouTube
Stop Vibe Coding. Use This Instead. — Spec-driven recovery from “accept all” failure modes.

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

  1. For each snippet (1–5), write: principle violated, why, fix in 1 line.
  2. 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

  1. List entities and rules → domain.
  2. List use cases ("create task", "complete task", "soft-delete task").
  3. List adapters (HTTP, DB, webhook caller).
  4. 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

  1. Read app/users.py. Find 3 SOLID violations.
  2. For each, write a behaviour test if one doesn't exist.
  3. Refactor with AI; tests stay green.
  4. 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.md per 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_lab exists if time allows).

New free lessons and course updates. Unsubscribe from any email.