system-design-audit
Audit a codebase — a single directory, a service, or a whole repo — against system design principles from Designing Data-Intensive Applications, Clean Architecture, and Release It!, and report violations. Checks data modeling, storage and indexing, replication and partitioning, transactions and isolation, failure handling and idempotency, messaging and streams, caching, API and layer boundaries, plus redundancy and inefficiency in the code itself. Use this whenever the user asks to audit, review, or assess a system's design, architecture, scalability, data layer, or "is this production-ready / will this scale"; when they point at a directory and ask what's wrong with the design; when they mention race conditions, consistency, sharding, hot partitions, retries, duplicate messages, cache invalidation, N+1 queries, coupling, or layering; and proactively before a service ships or gets scaled up. Read-only — it reports findings and never edits code. DO NOT USE for pure formatting or style nits, test-suite review, dependency upgrades, UI/frontend visual design, or writing new features from scratch.
- License 许可
- MIT
- 最近更新
- 2026-10-10
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- system-design-audit
- license
- MIT
- metadata
- { "version": "1.0.0" }
- description
- Audit a codebase — a single directory, a service, or a whole repo — against system design principles from Designing Data-Intensive Applications, Clean Architecture, and Release It!, and report violations. Checks data modeling, storage and indexing, replication and partitioning, transactions and isolation, failure handling and idempotency, messaging and streams, caching, API and layer boundaries, plus redundancy and inefficiency in the code itself. Use this whenever the user asks to audit, review, or assess a system's design, architecture, scalability, data layer, or "is this production-ready / will this scale"; when they point at a directory and ask what's wrong with the design; when they mention race conditions, consistency, sharding, hot partitions, retries, duplicate messages, cache invalidation, N+1 queries, coupling, or layering; and proactively before a service ships or gets scaled up. Read-only — it reports findings and never edits code. DO NOT USE for pure formatting or style nits, test-suite review, dependency upgrades, UI/frontend visual design, or writing new features from scratch.
02 资源文件 10
- 参考文档evals/evals.json4.7 KB
- 参考文档references/architecture-boundaries.md9.5 KB
- 参考文档references/audit-checklist.md6.7 KB
- 参考文档references/data-modeling.md7.2 KB
- 参考文档references/messaging-and-streams.md8.2 KB
- 参考文档references/redundancy-and-efficiency.md9.4 KB
- 参考文档references/reliability-and-failure.md7.8 KB
- 参考文档references/replication-partitioning.md7.7 KB
- 参考文档references/storage-and-indexing.md6.8 KB
- 参考文档references/transactions-consistency.md9.1 KB
03 SKILL.md 正文
System Design Audit
You are auditing a codebase the way a staff engineer reviews a system before it carries real load. The goal is not to list style nits — it is to find the places where the design will produce wrong data, lost data, an outage, an unscalable bottleneck, or a change nobody can safely make, and to say so with enough precision that someone can act on it.
This skill is read-only. You produce a findings report. You do not edit source files, run migrations, or refactor. If the user asks you to fix something afterward, that is a separate request they can make once they've seen the report.
Why findings-only, and why severity matters
An audit that dumps forty observations of equal weight is worse than useless — the reader can't tell the lost-update bug from the naming quibble, so they act on neither. Every finding you report costs the reader attention. Spend that budget on things that change behaviour under load, under failure, or under change. A finding that survives the question "what breaks, concretely, and when?" is worth reporting. One that doesn't is noise.
Process
1. Scope
Establish exactly what you're auditing before you read deeply.
- If the user named a path, audit that path. If they named a service or module, resolve it to a path first.
- If they said "the whole thing," start at the repo root but still audit in slices — a whole-repo audit that treats every file equally will run out of attention before it reaches the important code.
- Ask only if the target is genuinely ambiguous. A reasonable default (the main source directory, excluding vendored deps, build output, and generated code) beats a blocking question.
State the scope in one line at the top of your report so the reader knows what you did and did not look at.
2. Map the system
Before judging anything, build a picture of what this system is. Read entry points, config, schema/migrations, and dependency manifests. You are looking for:
- Data stores — which engines, what schemas, what indexes, what migrations.
- Boundaries — HTTP/RPC handlers, event consumers, scheduled jobs, CLI entry points. These are where the system meets the outside world and where most design assumptions get violated.
- State that crosses a process boundary — queues, caches, shared tables, external APIs. Every one of these can fail independently, and the code either accounts for that or doesn't.
- Concurrency — anything that can run twice at once: multiple replicas, worker pools, retried requests, cron overlapping itself.
- Scale signals — table sizes, fan-out patterns, loops over collections that grow with users or time.
Write down what the system's implicit assumptions are. Most serious findings are an assumption the code makes that reality won't honour: "reads see writes immediately," "this message arrives once," "this loop is over a small list," "only one process touches this row."
3. Route to the relevant checks
Load only the reference files that match what you actually found in step 2. Reading all of them for a stateless CLI tool wastes context and dilutes the report.
| If the system has… | Read |
|---|---|
| A database, schema, or migrations | references/data-modeling.md |
| Queries, indexes, ORMs, reporting | references/storage-and-indexing.md |
| Replicas, shards, caches, multi-region | references/replication-partitioning.md |
| Transactions, money, counters, concurrent writes | references/transactions-consistency.md |
| Network calls, retries, timeouts, external APIs | references/reliability-and-failure.md |
| Queues, events, streams, background jobs, webhooks | references/messaging-and-streams.md |
| Layers, modules, services, dependency injection | references/architecture-boundaries.md |
| Any code at all | references/redundancy-and-efficiency.md |
references/audit-checklist.md is the condensed pass — the question list to sweep once you've read the relevant domain files. Read it last, as the check that you didn't miss a category.
4. Verify before reporting
A finding you haven't verified in the code is a guess, and guesses destroy the report's credibility faster than missing findings do. For each candidate:
- Locate it. You need a real
file:line. If you can't point at the code, you don't have a finding. - Trace the failure. Describe the concrete sequence that produces the bad outcome — two requests interleaving, a retry after a timeout, a partition hitting one shard. If you can't construct the sequence, the finding is speculative; either drop it or mark it explicitly as a question.
- Check for an existing mitigation. The unique index, the advisory lock, the
idempotency key, the
SELECT … FOR UPDATEmay be somewhere you haven't looked. Search for it before claiming its absence. Falsely reporting a fixed problem trains the reader to ignore you. - Respect deliberate tradeoffs. If an ADR, comment, or README explains why something is the way it is, that's a decision, not a defect. You may still flag it if the tradeoff has since become dangerous — but engage with the stated reasoning rather than ignoring it.
5. Report
Use the structure below. It exists so the reader can triage in thirty seconds and then drill in.
# System Design Audit — <scope>
**Scope:** <paths audited, and what was deliberately excluded>
**Stack:** <languages, datastores, queues, caches observed>
**Overall:** <2–4 sentences. What kind of system is this, what shape is it in,
and what is the single most important thing to fix?>
## Findings
### [CRITICAL] <One-line claim>
- **Where:** `path/to/file.ext:120-134`
- **Principle:** <the design principle violated, named plainly — "Read-after-write
consistency", "Lost update", "The dependency rule". No book or chapter here.>
- **What happens:** <the concrete failure sequence — inputs, interleaving, and the wrong outcome>
- **Trigger:** <what conditions surface it: concurrency, scale, a retry, a replica lag spike>
- **Direction:** <what a fix looks like, 1–3 sentences. Not a patch — a direction.>
### [HIGH] …
### [MEDIUM] …
### [LOW] …
## Observations
<Things worth knowing that aren't defects: risky-but-deliberate tradeoffs,
missing signals you'd want (no metrics on the queue depth), places the design
is good and shouldn't be disturbed.>
## Not assessed
<Honest list of what you couldn't reach: config not in the repo, infra defined
elsewhere, a subsystem out of scope. This matters — silence here reads as
"clean," which is a lie.>
## Further reading
If you want to go deeper on the principles behind the findings above:
<Book Name: Chapter N, Chapter M — one short phrase naming the topics covered>
Keep citations out of the findings
Name the principle in plain language inside each finding. A reader working through a CRITICAL wants the mechanism and the fix, and a parenthetical chapter reference interrupts that without helping them act. Collect the sources once, at the end, in the Further reading section — that way they're there for whoever wants them and invisible to whoever doesn't.
Build that list from the references you actually loaded, and only for topics that produced findings. Citing a chapter you didn't draw on is padding. Use this mapping:
| Topic in your findings | Cite |
|---|---|
| Data models, document vs relational | Designing Data-Intensive Applications: Chapter 2 |
| Indexes, query cost, OLTP vs OLAP | Designing Data-Intensive Applications: Chapter 3 |
| Encoding, schema evolution, compatibility | Designing Data-Intensive Applications: Chapter 4 |
| Replication lag, read-after-write, failover | Designing Data-Intensive Applications: Chapter 5 |
| Partitioning, skew, rebalancing | Designing Data-Intensive Applications: Chapter 6 |
| Transactions, isolation, lost updates, write skew | Designing Data-Intensive Applications: Chapter 7 |
| Timeouts, clocks, partial failure | Designing Data-Intensive Applications: Chapter 8 |
| Consistency guarantees, consensus, distributed locks | Designing Data-Intensive Applications: Chapter 9 |
| Batch processing | Designing Data-Intensive Applications: Chapter 10 |
| Queues, streams, delivery semantics, outbox | Designing Data-Intensive Applications: Chapter 11 |
| Layer boundaries, the dependency rule | Clean Architecture: Chapters 17–22 |
| Component coupling and cohesion | Clean Architecture: Chapters 13–14 |
| Retries, circuit breakers, bulkheads, degradation | Release It!: Chapters 4–5 |
| Module depth, interface design | A Philosophy of Software Design: Chapters 4–6 |
| Duplication, naming, function design | Clean Code: Chapters 2–3, 17 |
| Refactoring mechanics and smells | Refactoring: Chapter 3 |
Format it as one line per book, chapters comma-separated:
**Further reading**
- Designing Data-Intensive Applications: Chapter 5, Chapter 7, Chapter 11 —
replication lag, lost updates, and delivery semantics.
- Clean Architecture: Chapters 17–22 — the dependency rule.
- Release It!: Chapters 4–5 — timeouts and cascading failure.
Severity
Rank by blast radius × likelihood, not by how interesting the problem is.
- CRITICAL — Data is silently lost, corrupted, or wrong; or the system takes a full outage under conditions that will occur normally. Money, auth, and durability bugs live here.
- HIGH — Fails under realistic load, concurrency, or a single dependency's failure. Not happening yet, but it will, and recovery is manual.
- MEDIUM — A design flaw with real cost: a bottleneck that will need rearchitecting, a boundary violation that will make the next change expensive.
- LOW — Genuine improvement, no failure mode. Keep these few; if you have more than a handful, you're padding.
If nothing critical exists, say so plainly. "No critical findings" is a valuable result, and a report that manufactures a CRITICAL to seem thorough is worse than one that reports honestly.
What separates a good finding from a bad one
Bad: "The orders table lacks an index on user_id, which may cause slow
queries."
Why it's bad: no location, no failure sequence, hedged with "may," and it might already be covered by a composite index the auditor didn't check.
Good: "OrderRepository.findByUser (src/orders/repo.go:88) filters on
user_id with no matching index — the only index on orders is the primary key
(migrations/003_orders.sql:12). Every call is a full table scan. At the current
~2M rows this is already ~400ms; it degrades linearly with order volume and will
lock up the connection pool once the dashboard, which calls this per page load,
sees concurrent traffic."
Why it's good: exact location, evidence that the mitigation genuinely isn't there, the mechanism, and the specific conditions that turn it into an outage.
Apply the same standard to design-level findings. "This violates the dependency
rule" means nothing on its own; "domain/invoice.py:14 imports the SQLAlchemy
session directly, so the invoice calculation rules can't be tested or reused
without a live database, and swapping the store means editing domain logic" is a
finding.
Things that reliably go wrong, and are easy to miss
These are the patterns worth actively hunting rather than waiting to stumble on. Full treatment is in the reference files; this is the "look here first" list.
- Read-modify-write without protection. Fetch a row, compute in application code, write it back. Correct with one process, silently wrong with two. Money and counters are where this hurts.
- Retries without idempotency. Any network call that can time out will be retried — by a client, a proxy, a queue, or a human. If the handler isn't idempotent, retries duplicate the effect.
- At-least-once treated as exactly-once. Nearly every queue redelivers. Consumers that assume single delivery corrupt state on every redelivery.
- Unbounded anything. Queries without limits, queues without depth caps,
in-memory collections that grow with traffic,
forloops over "all users." These work in dev and fall over in production. - Reads routed to a replica right after a write. The write succeeded, the read doesn't see it, the user is told their action failed.
- Cache invalidation with no ordering guarantee. Populate and invalidate racing produces a cache entry that never expires and never matches reality.
- A partition key with skew. Tenant ID, country,
status = 'active'— any key where one value dominates makes one shard the whole system. - The dependency rule pointing outward. Business logic importing the framework, the ORM, or the HTTP layer. Everything downstream — testing, reuse, replacement — gets harder.
- Schema changes assuming a synchronised deploy. During any rolling deploy, old and new code run at once against one schema. A change that only works after everything restarts causes errors in the window.
Self-check before delivering
Read your own report as the engineer who owns this code:
- Does every finding have a real
file:lineyou actually opened? - Can you state the failure sequence for each one, concretely?
- Did you search for the mitigation before claiming it's missing?
- Is the severity ranking honest — would you defend a CRITICAL in review?
- Did you say what you didn't look at?
- Is the top finding actually the most important thing? The reader's attention is highest on the first item; put the right thing there.
- Did you avoid editing anything?