Deepen architecture

From danielvm-git/bigpowers · View interactive version

Deepen architecture is an AI agent skill from the GitHub repository danielvm-git/bigpowers. Find deepening opportunities in a codebase, informed by the domain language in specs/tech-architecture/tech-stack.md and the decisions in specs/adr/. Use when the user wants to improve architecture, find refactoring opportunities, consolidate tightly-coupled modules, or make a codebase more testable

How to use this skill

Skill file

Deepen Architecture

Surface architectural friction and propose deepening opportunities — refactors that turn shallow modules into deep ones. The aim is testability and AI-navigability.

Distinct from define-language and model-domain: Use this skill to find module-level refactoring opportunities in the codebase. Use define-language to produce a canonical glossary of terms. Use model-domain to stress-test a plan through a domain-model interview.

HARD GATE — Deep modules must solve a forcing function, not just be "nice abstractions." If you cannot articulate why the abstraction exists, it is premature.

Glossary

Use these terms exactly in every suggestion. Consistent language is the point — don't drift into "component," "service," "API," or "boundary." Full definitions in LANGUAGE.md.

Key principles (see LANGUAGE.md for the full list):

This skill is _informed_ by the project's domain model — specs/tech-architecture/tech-stack.md and any specs/adr/. The domain language gives names to good seams; ADRs record decisions the skill should not re-litigate. See CONTEXT-FORMAT.md and ADR-FORMAT.md.

Process

1. Explore

Read existing documentation first:

If any of these files don't exist, proceed silently — don't flag their absence or suggest creating them upfront.

Look-here-first (churn heuristic): Before organic exploration, rank candidate modules by recent commit frequency. High-churn files are architectural friction magnets — start there.

bash scripts/bp-churn-rank.sh --since 90.days --limit 20

Then use the Agent tool with subagent_type=Explore to walk the codebase. Don't follow rigid heuristics — explore organically and note where you experience friction:

Apply the deletion test to anything you suspect is shallow.

2. Module Depth score

For each candidate module, assign a Module Depth score (1–5, Ousterhout):

| Score | Meaning |

|-------|---------|

| 1 | Shallow — interface complexity ≈ implementation |

| 3 | Balanced |

| 5 | Deep — small interface, substantial hidden behavior |

Include the score in each candidate row. Prioritize score ≤ 2 for deepening.

3. Present candidates

Present a numbered list of deepening opportunities. For each candidate:

Use specs/tech-architecture/tech-stack.md vocabulary for the domain, and LANGUAGE.md vocabulary for the architecture.

ADR conflicts: if a candidate contradicts an existing ADR, only surface it when the friction is real enough to warrant revisiting the ADR. Mark it clearly. Don't list every theoretical refactor an ADR forbids.

Do NOT propose interfaces yet. Ask the user: "Which of these would you like to explore?"

4. Grilling loop

Once the user picks a candidate, drop into a grilling conversation. Walk the design tree with them — constraints, dependencies, the shape of the deepened module, what sits behind the seam, what tests survive.

Side effects happen inline as decisions crystallize:

5. Import-boundary hygiene (e45s14)

When a deepening move splits or merges modules, update specs/import-boundaries.json (Playwright DEPS.list pattern) — declare which scripts/lib/*.sh files may source which peers. CI enforces via:

bash scripts/check-import-boundaries.sh

Run the check before proposing cross-module source edges. Convention docs alone do not authorize new imports; the allowlist must list them.

Verify

→ verify: test -f specs/import-boundaries.json && bash scripts/check-import-boundaries.sh

<!-- story: e07s02 -->


Deepening

How to deepen a cluster of shallow modules safely, given its dependencies. Assumes the vocabulary in LANGUAGE.md — module, interface, seam, adapter.

Dependency categories

When assessing a candidate for deepening, classify its dependencies. The category determines how the deepened module is tested across its seam.

1. In-process

Pure computation, in-memory state, no I/O. Always deepenable — merge the modules and test through the new interface directly. No adapter needed.

2. Local-substitutable

Dependencies that have local test stand-ins (PGLite for Postgres, in-memory filesystem). Deepenable if the stand-in exists. The deepened module is tested with the stand-in running in the test suite. The seam is internal; no port at the module's external interface.

3. Remote but owned (Ports & Adapters)

Your own services across a network boundary (microservices, internal APIs). Define a port (interface) at the seam. The deep module owns the logic; the transport is injected as an adapter. Tests use an in-memory adapter. Production uses an HTTP/gRPC/queue adapter.

Recommendation shape: "Define a port at the seam, implement an HTTP adapter for production and an in-memory adapter for testing, so the logic sits in one deep module even though it's deployed across a network."

4. True external (Mock)

Third-party services (Stripe, Twilio, etc.) you don't control. The deepened module takes the external dependency as an injected port; tests provide a mock adapter.

Seam discipline

Testing strategy: replace, don't layer


Interface Design

When the user wants to explore alternative interfaces for a chosen deepening candidate, use this parallel sub-agent pattern. Based on "Design It Twice" (Ousterhout) — your first idea is unlikely to be the best.

Uses the vocabulary in LANGUAGE.md — module, interface, seam, adapter, leverage.

Process

1. Frame the problem space

Before spawning sub-agents, write a user-facing explanation of the problem space for the chosen candidate:

Show this to the user, then immediately proceed to Step 2. The user reads and thinks while the sub-agents work in parallel.

2. Spawn sub-agents

Spawn 3+ sub-agents in parallel using the Agent tool. Each must produce a radically different interface for the deepened module.

Prompt each sub-agent with a separate technical brief (file paths, coupling details, dependency category from DEEPENING.md, what sits behind the seam). The brief is independent of the user-facing problem-space explanation in Step 1. Give each agent a different design constraint:

Include both LANGUAGE.md vocabulary and CONTEXT.md vocabulary in the brief so each sub-agent names things consistently with the architecture language and the project's domain language.

Each sub-agent outputs:

  1. Interface (types, methods, params — plus invariants, ordering, error modes)
  2. Usage example showing how callers use it
  3. What the implementation hides behind the seam
  4. Dependency strategy and adapters (see DEEPENING.md)
  5. Trade-offs — where leverage is high, where it's thin

3. Present and compare

Present designs sequentially so the user can absorb each one, then compare them in prose. Contrast by depth (leverage at the interface), locality (where change concentrates), and seam placement.

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 a menu.


Language

Shared vocabulary for every suggestion this skill makes. Use these terms exactly — don't substitute "component," "service," "API," or "boundary." Consistent language is the whole point.

Terms

Module

Anything with an interface and an implementation. Deliberately scale-agnostic — applies equally to a function, class, package, or tier-spanning slice.

_Avoid_: unit, component, service.

Interface

Everything a caller must know to use the module correctly. Includes the type signature, but also invariants, ordering constraints, error modes, required configuration, and performance characteristics.

_Avoid_: API, signature (too narrow — those refer only to the type-level surface).

Implementation

What's inside a module — its body of code. Distinct from Adapter: a thing can be a small adapter with a large implementation (a Postgres repo) or a large adapter with a small implementation (an in-memory fake). Reach for "adapter" when the seam is the topic; "implementation" otherwise.

Depth

Leverage at the interface — the amount of behaviour a caller (or test) can exercise per unit of interface they have to learn. A module is deep when a large amount of behaviour sits behind a small interface. A module is shallow when the interface is nearly as complex as the implementation.

Seam _(from Michael Feathers)_

A place where you can alter behaviour without editing in that place. The location at which a module's interface lives. Choosing where to put the seam is its own design decision, distinct from what goes behind it.

_Avoid_: boundary (overloaded with DDD's bounded context).

Adapter

A concrete thing that satisfies an interface at a seam. Describes role (what slot it fills), not substance (what's inside).

Leverage

What callers get from depth. More capability per unit of interface they have to learn. One implementation pays back across N call sites and M tests.

Locality

What maintainers get from depth. Change, bugs, knowledge, and verification concentrate at one place rather than spreading across callers. Fix once, fixed everywhere.

Principles

Relationships

Rejected framings

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.