|
| 1 | +--- |
| 2 | +name: improve-codebase-architecture |
| 3 | +description: Explore a codebase to find opportunities for architectural improvement, focusing on making the codebase more testable by deepening shallow modules. Use when user wants to improve architecture, find refactoring opportunities, consolidate tightly-coupled modules, or make a codebase more AI-navigable. |
| 4 | +--- |
| 5 | + |
| 6 | +# Improve Codebase Architecture |
| 7 | + |
| 8 | +Explore a codebase like an AI would, surface architectural friction, discover opportunities for improving testability, and propose module-deepening refactors as GitHub issue RFCs. |
| 9 | + |
| 10 | +A **deep module** (John Ousterhout, "A Philosophy of Software Design") has a small interface hiding a large implementation. Deep modules are more testable, more AI-navigable, and let you test at the boundary instead of inside. |
| 11 | + |
| 12 | +## Process |
| 13 | + |
| 14 | +### 1. Explore the codebase |
| 15 | + |
| 16 | +Use the Agent tool with subagent_type=Explore to navigate the codebase naturally. Do NOT follow rigid heuristics — explore organically and note where you experience friction: |
| 17 | + |
| 18 | +- Where does understanding one concept require bouncing between many small files? |
| 19 | +- Where are modules so shallow that the interface is nearly as complex as the implementation? |
| 20 | +- Where have pure functions been extracted just for testability, but the real bugs hide in how they're called? |
| 21 | +- Where do tightly-coupled modules create integration risk in the seams between them? |
| 22 | +- Which parts of the codebase are untested, or hard to test? |
| 23 | + |
| 24 | +The friction you encounter IS the signal. |
| 25 | + |
| 26 | +### 2. Present candidates |
| 27 | + |
| 28 | +Present a numbered list of deepening opportunities. For each candidate, show: |
| 29 | + |
| 30 | +- **Cluster**: Which modules/concepts are involved |
| 31 | +- **Why they're coupled**: Shared types, call patterns, co-ownership of a concept |
| 32 | +- **Dependency category**: See [REFERENCE.md](REFERENCE.md) for the four categories |
| 33 | +- **Test impact**: What existing tests would be replaced by boundary tests |
| 34 | + |
| 35 | +Do NOT propose interfaces yet. Ask the user: "Which of these would you like to explore?" |
| 36 | + |
| 37 | +### 3. User picks a candidate |
| 38 | + |
| 39 | +### 4. Frame the problem space |
| 40 | + |
| 41 | +Before spawning sub-agents, write a user-facing explanation of the problem space for the chosen candidate: |
| 42 | + |
| 43 | +- The constraints any new interface would need to satisfy |
| 44 | +- The dependencies it would need to rely on |
| 45 | +- A rough illustrative code sketch to make the constraints concrete — this is not a proposal, just a way to ground the constraints |
| 46 | + |
| 47 | +Show this to the user, then immediately proceed to Step 5. The user reads and thinks about the problem while the sub-agents work in parallel. |
| 48 | + |
| 49 | +### 5. Design multiple interfaces |
| 50 | + |
| 51 | +Spawn 3+ sub-agents in parallel using the Agent tool. Each must produce a **radically different** interface for the deepened module. |
| 52 | + |
| 53 | +Prompt each sub-agent with a separate technical brief (file paths, coupling details, dependency category, what's being hidden). This brief is independent of the user-facing explanation in Step 4. Give each agent a different design constraint: |
| 54 | + |
| 55 | +- Agent 1: "Minimize the interface — aim for 1-3 entry points max" |
| 56 | +- Agent 2: "Maximize flexibility — support many use cases and extension" |
| 57 | +- Agent 3: "Optimize for the most common caller — make the default case trivial" |
| 58 | +- Agent 4 (if applicable): "Design around the ports & adapters pattern for cross-boundary dependencies" |
| 59 | + |
| 60 | +Each sub-agent outputs: |
| 61 | + |
| 62 | +1. Interface signature (types, methods, params) |
| 63 | +2. Usage example showing how callers use it |
| 64 | +3. What complexity it hides internally |
| 65 | +4. Dependency strategy (how deps are handled — see [REFERENCE.md](REFERENCE.md)) |
| 66 | +5. Trade-offs |
| 67 | + |
| 68 | +Present designs sequentially, then compare them in prose. |
| 69 | + |
| 70 | +After comparing, give your own recommendation: which design you think is strongest and why. If elements from different designs would combine well, propose a hybrid. Be opinionated — the user wants a strong read, not just a menu. |
| 71 | + |
| 72 | +### 6. User picks an interface (or accepts recommendation) |
| 73 | + |
| 74 | +### 7. Create GitHub issue |
| 75 | + |
| 76 | +Create a refactor RFC as a GitHub issue using `gh issue create`. Use the template in [REFERENCE.md](REFERENCE.md). Do NOT ask the user to review before creating — just create it and share the URL. |
0 commit comments