Audit the codebase's architecture and propose concrete improvements. This is structural work, not style nitpicking.
Phase 1: Survey
Map the codebase before critiquing it.
- Entry points and data flow (where do requests/events enter, how do they propagate)
- Module boundaries and their dependencies (who imports whom)
- Layering: is there a clear separation between domain, application, infrastructure?
- State management: where does state live, who mutates it, what's the lifecycle?
- External integrations: databases, APIs, queues, filesystems
- Test structure: unit vs integration vs e2e, what's tested where
Report the map in 5-10 bullet points. If the codebase is huge, pick the subsystem most relevant to the user's request.
Phase 2: Diagnosis
Check the mapped subsystem against every category below; silence on a category means checked-and-clean, not skipped.
Identify real architectural problems. Focus on these categories:
Coupling issues
- Modules that shouldn't know about each other but do
- Circular dependencies
- Shared mutable state across boundaries
- "God objects": one class/module that touches everything
Cohesion issues
- Modules that mix unrelated responsibilities
- Business logic leaking into controllers/routes/views
- Infrastructure concerns (DB, HTTP) mixed with domain logic
Abstraction issues
- Wrong abstractions: interfaces with one implementation, factories that don't vary, premature generalization
- Missing abstractions: repeated patterns that should be unified
- Leaky abstractions: implementation details bleeding through interfaces
Boundary issues
- Missing or porous boundaries between bounded contexts
- Direct DB access from everywhere instead of a repository/service
- Public APIs that expose internal types
Testability issues
- Hard-to-test code due to hidden dependencies, global state, or tight coupling to infrastructure
- Tests that know too much about implementation
- No seams to inject fakes or stubs
Lifecycle / complexity debt
- Dead code paths
- Feature flags that never shipped or never got cleaned up
- Duplicate implementations of the same thing
- Configuration sprawl
For each issue: what is wrong, where it lives (file:line), why it matters (what it costs the team), and severity (critical / high / medium / low).
Phase 3: Recommendations
Propose changes in order of impact-to-effort ratio. For each:
- Change: concrete description (not "improve modularity", but "extract
PricingService from OrderController")
- Why: what problem it fixes
- Blast radius: how many files/callers change
- Risk: what could break, how to mitigate
- Test strategy: how you'd verify the refactor didn't regress behavior
- Scope: small (1-2 files), medium (single subsystem), large (cross-cutting)
Group into:
- Do now: high impact, low risk
- Plan for next sprint: high impact, higher risk or effort
- Don't do: tempting but not worth it (explain why)
Phase 4: Execution plan
If the user wants to proceed, pick the top 1-3 changes and outline the step-by-step execution. Prefer:
- Characterization tests first (lock in current behavior)
- Incremental refactors with tests passing at each step
- One PR per logical change, not one mega-PR
- Reversibility: each step should be independently mergeable and revertible
Ground rules
- Respect Chesterton's Fence. A module that looks "weird" may encode a hidden constraint; ask why it exists before proposing to remove or rewrite it.
- Aim for a codebase that's easier to change, not a textbook-pure one.
- Measure, don't guess. If you claim something is slow or complex, show the evidence (profiler, cyclomatic complexity, churn data).
- Justify every abstraction by a need that exists now, not a speculative future one.
Target: $ARGUMENTS
If no target is specified, audit the whole codebase rooted at the current working directory.
1---2name: improve-codebase-architecture3description: Audit the codebase's **architecture** and propose concrete improvements. This is structural work, not style nitpicking.4---56Audit the codebase's **architecture** and propose concrete improvements. This is structural work, not style nitpicking.78## Phase 1: Survey910Map the codebase before critiquing it.1112- Entry points and data flow (where do requests/events enter, how do they propagate)13- Module boundaries and their dependencies (who imports whom)14- Layering: is there a clear separation between domain, application, infrastructure?15- State management: where does state live, who mutates it, what's the lifecycle?16- External integrations: databases, APIs, queues, filesystems17- Test structure: unit vs integration vs e2e, what's tested where1819Report the map in 5-10 bullet points. If the codebase is huge, pick the subsystem most relevant to the user's request.2021## Phase 2: Diagnosis2223Check the mapped subsystem against every category below; silence on a category means checked-and-clean, not skipped.2425Identify real architectural problems. Focus on these categories:2627**Coupling issues**28- Modules that shouldn't know about each other but do29- Circular dependencies30- Shared mutable state across boundaries31- "God objects": one class/module that touches everything3233**Cohesion issues**34- Modules that mix unrelated responsibilities35- Business logic leaking into controllers/routes/views36- Infrastructure concerns (DB, HTTP) mixed with domain logic3738**Abstraction issues**39- Wrong abstractions: interfaces with one implementation, factories that don't vary, premature generalization40- Missing abstractions: repeated patterns that should be unified41- Leaky abstractions: implementation details bleeding through interfaces4243**Boundary issues**44- Missing or porous boundaries between bounded contexts45- Direct DB access from everywhere instead of a repository/service46- Public APIs that expose internal types4748**Testability issues**49- Hard-to-test code due to hidden dependencies, global state, or tight coupling to infrastructure50- Tests that know too much about implementation51- No seams to inject fakes or stubs5253**Lifecycle / complexity debt**54- Dead code paths55- Feature flags that never shipped or never got cleaned up56- Duplicate implementations of the same thing57- Configuration sprawl5859For each issue: **what** is wrong, **where** it lives (file:line), **why** it matters (what it costs the team), and **severity** (critical / high / medium / low).6061## Phase 3: Recommendations6263Propose changes in order of impact-to-effort ratio. For each:6465- **Change:** concrete description (not "improve modularity", but "extract `PricingService` from `OrderController`")66- **Why:** what problem it fixes67- **Blast radius:** how many files/callers change68- **Risk:** what could break, how to mitigate69- **Test strategy:** how you'd verify the refactor didn't regress behavior70- **Scope:** small (1-2 files), medium (single subsystem), large (cross-cutting)7172Group into:73- **Do now:** high impact, low risk74- **Plan for next sprint:** high impact, higher risk or effort75- **Don't do:** tempting but not worth it (explain why)7677## Phase 4: Execution plan7879If the user wants to proceed, pick the top 1-3 changes and outline the step-by-step execution. Prefer:80811. Characterization tests first (lock in current behavior)822. Incremental refactors with tests passing at each step833. One PR per logical change, not one mega-PR844. Reversibility: each step should be independently mergeable and revertible8586## Ground rules8788- **Respect Chesterton's Fence.** A module that looks "weird" may encode a hidden constraint; ask why it exists before proposing to remove or rewrite it.89- **Aim for a codebase that's easier to change, not a textbook-pure one.**90- **Measure, don't guess.** If you claim something is slow or complex, show the evidence (profiler, cyclomatic complexity, churn data).91- **Justify every abstraction by a need that exists now, not a speculative future one.**9293---9495Target: $ARGUMENTS9697If no target is specified, audit the whole codebase rooted at the current working directory.