Skip to content
Agentmart
Submit a tool

codebase-architecture

Designs module interfaces, deepens shallow modules, and installs enforceable repository guardrails and agent wayfinding.

Skill by mblode

IndexedMIT★ 162
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/mblode-codebase-architecture

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Designs module interfaces, deepens shallow modules, and installs enforceable repository guardrails and agent wayfinding. Use when asked to "design the architecture", "simplify our modules", "find shallow modules", "harden the repo", "gate an unattended agent fix job", or "triage alerts with an agent".

Use cases: design, agent-building

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/codebase-architecture

What's inside

Skill name
codebase-architecture
Description
Designs module interfaces, deepens shallow modules, and installs enforceable repository guardrails and agent wayfinding. Use when asked to "design the architecture", "simplify our modules", "find shallow modules", "harden the repo", "gate an unattended agent fix job", or "triage alerts with an agent".
License
MIT
Instructions
184 lines in SKILL.md · view on GitHub

Files (16)

  • SKILL.md
  • evals.json · evals/
  • evaluation-scenarios.md · evals/
  • agent-runtime.md · references/
  • api-design.md · references/
  • brief-conventions.md · references/
  • contagion-markers.md · references/
  • deepening-existing.md · references/
  • distributed-correctness.md · references/
  • domain-language.md · references/
  • enforcement-ladder.md · references/
  • guardrail-tooling.md · references/
  • stack-defaults.md · references/
  • verification-tiers.md · references/
  • vocabulary.md · references/
  • wayfinding.md · references/

SKILL.md (first lines)

# Codebase Architecture

Decide a TypeScript codebase's structure, improve it where change has become expensive, and make it hold. The target is a codebase a reader can hold in their head: few surfaces, one canonical way to do each job, and behaviour where you would first look for it.

- **IS:** folder structures, module interfaces, request context and middleware pipelines, frontend/backend boundaries; architecture briefs; domain language and decision records; domain-informed deepening; guardrail tooling, CI gates, and agent wayfinding.
- **IS NOT:** scaffolding a new repo (`scaffold-nextjs` for a Next.js turborepo, `scaffold-cli` for a TypeScript CLI), multi-tenant domain/isolation/routing (`multi-tenant-architecture`), the content of AGENTS.md itself (`agents-md`), a plan for one feature (`planning`), a diff-scoped cleanup pass (`tidy`), structural review of a local diff (`tidy`), or a product's own verify CLI, doctor command, and feature map (`app-verification`, call it by name).

## Contents

- Modes
- References
- Design mode (new codebase)
- Deepen mode (existing codebase)
- Harden mode (make it stick)
- Validation loop
- Output template
- Gotchas
- Related skills

## Modes

Pick by the problem, not by the artifact, and say which you picked.

| Mode | You are here when | Output |
|------|-------------------|--------|
| **Design** | Starting a new app, service, or surface, and the structure is not decided yet | An architecture brief |
| **Deepen** | The code works, but change is expensive: concepts scattered, seams leaking, one idea under three names | Ranked opportunities, then one migrated slice |
| **Harden** | The structure is decided and keeps decaying, or agents keep doing the wrong thing in this repo | Wired checks, markers, and recipes |

**Modes compose, and running more than one is normal.** Design ends in Harden, because a contract with no check is a suggestion. Deepen ends in Harden, so the new seam cannot decay back. Harden runs alone when the structure is already right and only the enforcement is missing, which is the common case in a repo that agents work in.

**When two look equally right, prefer Deepen.** "Agents keep using the old pattern" sounds like Harden, but if the cause is one concept living in two places, quarantine only freezes the duplicate: Deepen deletes it and Harden holds the line until that lands. Harden alone is right when the old thing genuinely has to stay.

**When you cannot write to the repo** (no checkout, read-only request, or a question rather than a change), each mode's output degrades to its plan: the brief, the ranked opportunities, or the named checks with their rungs. Say which checks remain unproven, since none of them are wired.

**As simple as possible, no simpler.** Every mode cuts: surfaces in Design, concepts in Deepen, dual paths and dormant config in Harden. The floor does not get cut: validation at trust boundaries, error handling that prevents data loss, security, accessibility, observability on anything deployed, and whatever was explicitly asked for. A simplification that reaches one of those is a bug. Where a corner is cut on purpose, mark it with its ceiling and upgrade path rather than leaving the next reader to guess whether it is finished.

Copy this to track progress, and delete the lines for modes you are not running:

```text
Codebase architecture progress:
- [ ] Modes chosen and stated (Design / Deepen / Harden)
- [ ] Design: assumptions stated, repo shape, every contract names its check, brief written
- [ ] Deepen: git hot spots, glossary, ranked opportunities with paths, one slice migrated
- [ ] Harden: existing checks surveyed, checks picked by failure, each landed green and proven to bite
- [ ] Validation loop run for the modes used; evidence recorded, N/A items named
```

## References

Load only when the condition applies.

| Reference | Mode | Read when |
|-----------|------|-----------|
| [references/vocabulary.md](references/vocabulary.md) | All | Before naming a module, interface, seam, or adapter in any output; it defines the deletion test |
| [references/stack-defaults.md](references/stack-defaults.md) | Design | Choosing libraries, tooling, or deploy targets |
| [references/api-design.md](references/api-design.md) | Design, Deepen | Designing endpoints, module interfaces, request context, error shapes, or forwarded credentials |
| [references/distributed-correctness.md](references/distributed-correctness.md) | Design, Deepen | The work provably touches an external system, webhook, retry, audit trail, or money. In Deepen you can grep for it; in Design it is a question about requirements, so confirm before loading rather than inferring it from the product's domain |
| [references/brief-conventions.md](references/brief-conventions.md) | Design | Writing the conventions, testing, quality-bar, or rollout and rollback sections of the brief |
| [references/deepening-existing.md](references/deepening-existing.md) | Deepen | Running Deepen: opportunity patterns, design it twice, ranking, measuring an agent-facing change, output template |
| [references/domain-language.md](references/domain-language.md) | Deepen | Writing or fixing a glossary, resolving naming divergence, recording a decision |
| [references/enforcement-ladder.md](references/enforcement-ladder.md) | Harden | Adding any check to a repo that already violates it |
| [references/guardrail-tooling.md](references/guardrail-tooling.md) | Harden | Choosing and wiring the actual checks: dead code, duplication, cycles, module and package boundaries, file size, staleness gates |
| [references/wayfinding.md](references/wayfinding.md) | Harden | Agents cannot find things, or keep re-deriving the same path |
| [references/contagion-markers.md](references/contagion-markers.md) | Harden | The repo has legacy, generated, dual-path, or deliberately simplified code |
| [references/verification-tiers.md](references/verification-tiers.md) | Harden | Defining which commands an agent should run, and when |
| [references/agent-runtime.md](references/agent-runtime.md) | Harden | Configuring the post-edit hook, the permission allowlist, or a job where an agent drafts fixes or triages alerts unattended |

## Design mode (new codebase)

Before any of this, ask whether each surface needs to exist. A module, service, app, or entrypoint that could be a folder in something that already ships is the cheapest architecture decision available, and the only one that stays cheap. Every surface you do accept pays the relationship cost in the surface-area budget (`brief-conventions.md`): name its owner, tests, observability, and deletion path before it goes in the brief.

1. Constraints first: product scope, team size, compliance/security, expected scale, deploy targets, required integrations, and quality bar. A one-line request supplies none of these, so assume the common case, state every assumption in the brief's first section, and invite correction. Ask outright only where a wrong guess would restructure the brief rather than extend it, which in practice is multi-tenancy and whether the API is public.
2. Choose repo shape:
   - `apps/` for deployable surfaces (`api`, `web`, `admin`).
   - `packages/` for shared libraries (`shared`, `ui`, `icons`, `auth`, `proto`).
3. Define backend module interfaces, each naming its enforcement (import-boundary lint or type check):
   - `handler`: transport only.
   - `service`: business orchestration.
   - `dao`: database access only; only DAOs import the db package, and each table has one owning module whose service is the only writer. Query rules in [references/api-design.md](references/api-design.md), "Data Access".
   - `mapper`: DB/proto/domain transformations.
   - `constants` and `types`: module-local contracts.
4. Define request context and middleware:
   - Carry `tenantId`, `userId`, and `traceId` in an AsyncLocalStorage-backed `RequestContext`, initialized in every entrypoint (RPC, HTTP, jobs, CLI) and read via `getContext()`. A threaded `ctx` parameter grows every signature, and adding one field later touches every call site. Implementation in [references/api-design.md](references/api-design.md).
   - Require an explicit auth policy per RPC method at registration; a method without one fails registration rather than defaulting to open.
   - Keep auth, logging, errors, and context in shared middleware, not per-handler code.
5. Define frontend boundaries (Next.js App Router default):
   - `app/` holds routing files only (`page`, `layout`, `loading`, `error`, `route`). Domain code lives in `src/modules/<name>/` behind its root files; UI private to one route goes in a `_components/` folder beside its page. A page that grows logic moves it to a module, not to a sibling file in `app/`.
   - Server Components by default; `"use client"` at the interactive leaves. Where a client wrapper needs server-rendered content, pass it in as `children`.
   - Server state in TanStack or Connect Query; client state in component state; MobX only for cross-cutting client state that fits neither. Each piece of data has one owner: server data mirrored into `useState`, or two stores synced with `useEffect`, is the sign that ownership is unclear.
   - `proxy.ts` (Next 16's name for `middleware.ts`) handles redirects, rewrites, and headers. Authorization is decided inside each route handler and Server Function, because a matcher-excluded path skips the proxy and Server Functions post to their page's route.
6. Testing and release:
   - Unit tests stay DB-free; integration/E2E run in parallel with dynamically generated IDs so runs never collide on fixtures.
   - Release in small, complete, reversible vertical slices with a rollback plan per change.
   - A slice is complete only when reliability, error paths, observability, and user-facing states are covered; deferring them to a polish pass is how they never ship.
7. Every contract in the brief names the lint rule, type check, or test that catches its violation, then continue into Harden mode to wire them.

## Deepen mode (existing codebase)

Goal: domain-informed deepening, not a rewrite. Load [references/deepening-existing.md](references/deepening-existing.md) for the analysis method, opportunity patterns, and output template.

1. **Map the domain language and decisions.** Read `CONTEXT.md`, `docs/adr/`, or local equivalents if present, then read the code for entities, actions, and contexts as the team names them. Note divergence (one concept, three names; or one name, three concepts). Format and ADR rules in [references/domain-language.md](references/domain-language.md).
2. **Scope the scan by where change lands.** Deepening pays off on code that keeps changing, so `git log --oneline` over a good stretch of history first and weight the files that keep coming up. An unscoped scan drifts into speculative cleanup.
3. **Find deepening opportunities.** Look for anemic concepts, shallow modules, leaking seams, naming divergence, duplicated concepts, primitive obsession, misplaced logic, and tests forced past the public interface. Record each with file paths, never a vague smell. Check deletion first on every candidate: a concept with no live caller, a flag whose branch never runs, a layer with one implementation. Deleting it is the deepening, and it is the only move that cannot make the codebase harder to read.
4. **Rank by leverage.** Prefer opportunities that pass the deletion test, localize named future changes, have low churn, meet a current requirement, and have a viable testing seam. Rank candidates before designing target interfaces; drop speculative cleanups. For the top candidate, design the interface twice before picking one.
5. **Migrate one vertical slice first.** Prove the highest-leverage move end to end through one slice before generalizing.
6. **Enforce the new seam** with lint, type, or test checks so it cannot decay, then roll out module by module. Continue into Harden mode for the enforcement rung and the check-bites test.

## Harden mode (make it stick)

Two halves: **guardrails** stop the wrong thing landing, **wayfinding** makes the right thing cheap to find. Both exist because agents arrive by grep, not by reading docs, so the warning has to live where they land and the rule has to be an exit code rather than a sentence someone might recall.

Reach for the strongest mechanism first: structure, then lint and CI, then prose, then human review; every review comment, incident, or repeated mistake is a missing check ([references/enforcement-ladder.md](references/enforcement-ladder.md)).

Steps 1 to 3 always run. Steps 4 to 6 run only when their condition holds, and a request to add one check stops at step 3. Running all six for every request loads most of the bundle and is the failure this mode is most prone to.

1. **Survey what exists.** Package scripts, CI steps, hook config, lint config, the instruction file, the docs index. Find three things: checks that run locally but do not gate the merge, checks that run in CI but cannot fail (`verification-tiers.md`, "Commands that lie"), and dormant config nobody invokes. Wire the first, fix the second, delete the third ([references/contagion-markers.md](references/contagion-markers.md)).
2. **Choose checks by the failure they prevent**, never by tool popularity. Categories and tools in [references/guardrail-tooling.md](references/guardrail-tooling.md). Pick the two or three failures this repo actually exhibits; installing the full set at once forces the weakest enforcement rung on all of them.
3. **Install each check:** pick an enforcement rung for the violations that already exist ([references/enforcement-ladder.md](references/enforcement-ladder.md)), ship it green, then prove it bites (run it, break it on purpose, watch it fail with a message naming the fix, revert). Wire it into both a pre-commit hook and CI.

From mblode/agent-skills, MIT.

More from mblode/agent-skills

Signals

Stars
162
Forks
14
Open issues
0
Last commit (this folder)
Oct 22, 2026 (5 days ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from mblode

Cite this page

codebase-architecture skill. Agent Mart. https://agentmart.dev/skills/mblode-codebase-architecture (last updated 2026-10-24)