Improve Codebase Architecture
Intent
Use this skill periodically (for example, weekly or after a burst of changes) to improve the structural quality of the codebase.
The goal is to make the code more “agent-friendly”: clear module boundaries, deeper units with simple interfaces, and less scattering of logic across many tiny files.
What to Look For
While exploring the repo, look for:
Scattered concepts
- Understanding one concept (e.g., “orders”, “search”, “auth”) requires jumping between many small files.
- Logic is split into thin wrappers and helpers that obscure the main flow.
Shallow modules
- Modules that do very little beyond delegating, with real complexity spread out elsewhere.
- Pure functions extracted solely for testability while the true behavior is in wiring code.
Tight coupling and integration risk
- Modules that know too much about each other’s internals.
- Cross-cutting concerns implemented ad-hoc in many places instead of via clear layers or utilities.
Workflow
Choose a target area
- Pick a feature, domain, or subsystem experiencing pain: hard to change, buggy, or confusing.
- Confirm with the user if they have specific hotspots they care about.
Map current structure
- Identify the main entry points (routes, handlers, top-level components, jobs).
- Trace how data and control flow through modules.
- Note files or functions that are frequently touched together.
Identify deepening opportunities
- Propose ways to:
- Merge shallow wrappers into a deeper module that owns a concept end-to-end.
- Introduce a clear service, use-case, or domain module that encapsulates messy flows.
- Extract cross-cutting concerns (logging, validation, auth) into well-defined layers.
Propose refactor plans
- For each opportunity, outline a small, testable refactor:
- Current situation (1–2 sentences).
- Proposed structure (e.g., “introduce
OrderService that owns X/Y/Z”).
- Expected benefits (testability, clarity, fewer hops).
- Keep each refactor small enough to fit in a single PR or issue where possible.
Connect to testing and TDD
- For each proposed deep module, describe how it would be tested (unit, integration, or end-to-end).
- Suggest where a
tdd-style workflow would help solidify new boundaries.
Output Format
When using this skill, summarize findings as:
## Architecture Findings
- [Finding 1: short title]
- Symptoms:
- Proposed change:
- Benefits:
- [Finding 2]
- Symptoms:
- Proposed change:
- Benefits:
You may optionally suggest related issues or PRs, or hand off to prd-to-issues if the refactor is large.
Style Guidelines
- Focus on clarity and leverage: a few well-chosen deep modules can simplify many features.
- Avoid massive, risky rewrites; prefer incremental, well-bounded improvements.
- Always ground recommendations in actual code you have inspected, not generic advice.
- Call out quick wins separately from larger, multi-step refactors.
1---2name: improve-codebase-architecture3description: Review and reshape the codebase into deeper, clearer modules with well-defined boundaries to make testing, reasoning, and AI-assisted changes easier, highlighting candidates for consolidation and simplification.4---56# Improve Codebase Architecture78## Intent910Use this skill periodically (for example, weekly or after a burst of changes) to improve the **structural quality** of the codebase. 1112The goal is to make the code more “agent-friendly”: clear module boundaries, deeper units with simple interfaces, and less scattering of logic across many tiny files.1314## What to Look For1516While exploring the repo, look for:17181. **Scattered concepts**19 - Understanding one concept (e.g., “orders”, “search”, “auth”) requires jumping between many small files. 20 - Logic is split into thin wrappers and helpers that obscure the main flow.21222. **Shallow modules**23 - Modules that do very little beyond delegating, with real complexity spread out elsewhere. 24 - Pure functions extracted solely for testability while the true behavior is in wiring code.25263. **Tight coupling and integration risk**27 - Modules that know too much about each other’s internals. 28 - Cross-cutting concerns implemented ad-hoc in many places instead of via clear layers or utilities.2930## Workflow31321. **Choose a target area**33 - Pick a feature, domain, or subsystem experiencing pain: hard to change, buggy, or confusing. 34 - Confirm with the user if they have specific hotspots they care about.35362. **Map current structure**37 - Identify the main entry points (routes, handlers, top-level components, jobs). 38 - Trace how data and control flow through modules. 39 - Note files or functions that are frequently touched together.40413. **Identify deepening opportunities**42 - Propose ways to: 43 - Merge shallow wrappers into a deeper module that owns a concept end-to-end. 44 - Introduce a clear service, use-case, or domain module that encapsulates messy flows. 45 - Extract cross-cutting concerns (logging, validation, auth) into well-defined layers.46474. **Propose refactor plans**48 - For each opportunity, outline a small, testable refactor: 49 - Current situation (1–2 sentences). 50 - Proposed structure (e.g., “introduce `OrderService` that owns X/Y/Z”). 51 - Expected benefits (testability, clarity, fewer hops). 52 - Keep each refactor small enough to fit in a single PR or issue where possible.53545. **Connect to testing and TDD**55 - For each proposed deep module, describe how it would be tested (unit, integration, or end-to-end). 56 - Suggest where a `tdd`-style workflow would help solidify new boundaries.5758## Output Format5960When using this skill, summarize findings as:6162```markdown63## Architecture Findings64- [Finding 1: short title]65 - Symptoms:66 - Proposed change:67 - Benefits:6869- [Finding 2]70 - Symptoms:71 - Proposed change:72 - Benefits:73```7475You may optionally suggest related issues or PRs, or hand off to `prd-to-issues` if the refactor is large.7677## Style Guidelines7879- Focus on **clarity and leverage**: a few well-chosen deep modules can simplify many features. 80- Avoid massive, risky rewrites; prefer incremental, well-bounded improvements. 81- Always ground recommendations in actual code you have inspected, not generic advice. 82- Call out quick wins separately from larger, multi-step refactors.83