@drafthq/draft 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +38 -0
- package/.claude-plugin/plugin.json +26 -0
- package/LICENSE +21 -0
- package/README.md +272 -0
- package/bin/README.md +49 -0
- package/cli/bin/draft.js +13 -0
- package/cli/src/cli.js +113 -0
- package/cli/src/hosts/claude-code.js +46 -0
- package/cli/src/hosts/codex.js +33 -0
- package/cli/src/hosts/cursor.js +50 -0
- package/cli/src/hosts/index.js +24 -0
- package/cli/src/hosts/opencode.js +39 -0
- package/cli/src/installer.js +61 -0
- package/cli/src/lib/fsx.js +34 -0
- package/cli/src/lib/graph.js +23 -0
- package/cli/src/lib/log.js +32 -0
- package/cli/src/lib/paths.js +14 -0
- package/core/agents/architect.md +338 -0
- package/core/agents/debugger.md +193 -0
- package/core/agents/ops.md +104 -0
- package/core/agents/planner.md +158 -0
- package/core/agents/rca.md +314 -0
- package/core/agents/reviewer.md +256 -0
- package/core/agents/writer.md +110 -0
- package/core/guardrails/README.md +4 -0
- package/core/guardrails/code-quality.md +4 -0
- package/core/guardrails/dependency-triage.md +4 -0
- package/core/guardrails/design-norms.md +4 -0
- package/core/guardrails/language-standards.md +4 -0
- package/core/guardrails/review-checks.md +4 -0
- package/core/guardrails/secure-patterns.md +4 -0
- package/core/guardrails/security.md +4 -0
- package/core/guardrails.md +22 -0
- package/core/knowledge-base.md +127 -0
- package/core/methodology.md +1221 -0
- package/core/shared/condensation.md +224 -0
- package/core/shared/context-verify.md +44 -0
- package/core/shared/cross-skill-dispatch.md +127 -0
- package/core/shared/discovery-schema.md +75 -0
- package/core/shared/draft-context-loading.md +282 -0
- package/core/shared/git-report-metadata.md +106 -0
- package/core/shared/graph-query.md +239 -0
- package/core/shared/graph-usage-report.md +22 -0
- package/core/shared/jira-sync.md +170 -0
- package/core/shared/parallel-analysis.md +386 -0
- package/core/shared/parallel-fanout.md +10 -0
- package/core/shared/pattern-learning.md +146 -0
- package/core/shared/red-flags.md +58 -0
- package/core/shared/template-contract.md +22 -0
- package/core/shared/template-hygiene.md +10 -0
- package/core/shared/tool-resolver.md +10 -0
- package/core/shared/vcs-commands.md +97 -0
- package/core/shared/verification-gates.md +47 -0
- package/core/templates/CHANGELOG.md +70 -0
- package/core/templates/ai-context-export.md +8 -0
- package/core/templates/ai-context.md +270 -0
- package/core/templates/ai-profile.md +41 -0
- package/core/templates/architecture.md +203 -0
- package/core/templates/dependency-graph.md +103 -0
- package/core/templates/discovery.md +79 -0
- package/core/templates/guardrails.md +143 -0
- package/core/templates/hld.md +327 -0
- package/core/templates/intake-questions.md +403 -0
- package/core/templates/jira.md +119 -0
- package/core/templates/lld.md +283 -0
- package/core/templates/metadata.json +66 -0
- package/core/templates/plan.md +130 -0
- package/core/templates/product.md +110 -0
- package/core/templates/rca.md +86 -0
- package/core/templates/root-architecture.md +127 -0
- package/core/templates/root-product.md +53 -0
- package/core/templates/root-tech-stack.md +117 -0
- package/core/templates/service-index.md +55 -0
- package/core/templates/session-summary.md +8 -0
- package/core/templates/spec.md +165 -0
- package/core/templates/tech-matrix.md +101 -0
- package/core/templates/tech-stack.md +169 -0
- package/core/templates/track-architecture.md +311 -0
- package/core/templates/workflow.md +187 -0
- package/integrations/agents/AGENTS.md +24384 -0
- package/integrations/copilot/.github/copilot-instructions.md +24384 -0
- package/integrations/gemini/.gemini.md +26 -0
- package/package.json +53 -0
- package/scripts/fetch-memory-engine.sh +116 -0
- package/scripts/lib.sh +256 -0
- package/scripts/tools/_lib.sh +220 -0
- package/scripts/tools/adr-index.sh +117 -0
- package/scripts/tools/check-graph-usage-report.sh +95 -0
- package/scripts/tools/check-scope-conflicts.sh +139 -0
- package/scripts/tools/check-skill-line-caps.sh +115 -0
- package/scripts/tools/check-template-noop.sh +87 -0
- package/scripts/tools/check-track-hygiene.sh +230 -0
- package/scripts/tools/classify-files.sh +231 -0
- package/scripts/tools/cycle-detect.sh +75 -0
- package/scripts/tools/detect-test-framework.sh +135 -0
- package/scripts/tools/diff-templates-vs-tracks.sh +176 -0
- package/scripts/tools/emit-skill-metrics.sh +71 -0
- package/scripts/tools/fix-whitespace.sh +192 -0
- package/scripts/tools/freshness-check.sh +143 -0
- package/scripts/tools/git-metadata.sh +203 -0
- package/scripts/tools/graph-callers.sh +74 -0
- package/scripts/tools/graph-impact.sh +93 -0
- package/scripts/tools/graph-snapshot.sh +102 -0
- package/scripts/tools/hotspot-rank.sh +75 -0
- package/scripts/tools/manage-symlinks.sh +85 -0
- package/scripts/tools/mermaid-from-graph.sh +92 -0
- package/scripts/tools/migrate-track-frontmatter.sh +241 -0
- package/scripts/tools/parse-git-log.sh +135 -0
- package/scripts/tools/parse-reports.sh +114 -0
- package/scripts/tools/render-track.sh +145 -0
- package/scripts/tools/run-coverage.sh +153 -0
- package/scripts/tools/scan-markers.sh +144 -0
- package/scripts/tools/skill-caps.conf +24 -0
- package/scripts/tools/validate-frontmatter.sh +125 -0
- package/scripts/tools/verify-citations.sh +250 -0
- package/scripts/tools/verify-doc-anchors.sh +204 -0
- package/scripts/tools/verify-graph-binary.sh +154 -0
- package/skills/GRAPH.md +332 -0
- package/skills/adr/SKILL.md +374 -0
- package/skills/assist-review/SKILL.md +49 -0
- package/skills/bughunt/SKILL.md +668 -0
- package/skills/bughunt/references/regression-tests.md +399 -0
- package/skills/change/SKILL.md +267 -0
- package/skills/coverage/SKILL.md +336 -0
- package/skills/debug/SKILL.md +201 -0
- package/skills/decompose/SKILL.md +656 -0
- package/skills/deep-review/SKILL.md +326 -0
- package/skills/deploy-checklist/SKILL.md +254 -0
- package/skills/discover/SKILL.md +66 -0
- package/skills/docs/SKILL.md +42 -0
- package/skills/documentation/SKILL.md +197 -0
- package/skills/draft/SKILL.md +177 -0
- package/skills/draft/context-files.md +57 -0
- package/skills/draft/intent-mapping.md +37 -0
- package/skills/draft/quality-guide.md +51 -0
- package/skills/graph/SKILL.md +107 -0
- package/skills/impact/SKILL.md +86 -0
- package/skills/implement/SKILL.md +794 -0
- package/skills/incident-response/SKILL.md +245 -0
- package/skills/index/SKILL.md +848 -0
- package/skills/init/SKILL.md +1784 -0
- package/skills/init/references/architecture-spec.md +1259 -0
- package/skills/integrations/SKILL.md +53 -0
- package/skills/jira/SKILL.md +577 -0
- package/skills/jira/references/review.md +1322 -0
- package/skills/learn/SKILL.md +478 -0
- package/skills/new-track/SKILL.md +841 -0
- package/skills/ops/SKILL.md +57 -0
- package/skills/plan/SKILL.md +60 -0
- package/skills/quick-review/SKILL.md +216 -0
- package/skills/revert/SKILL.md +178 -0
- package/skills/review/SKILL.md +1114 -0
- package/skills/standup/SKILL.md +183 -0
- package/skills/status/SKILL.md +183 -0
- package/skills/tech-debt/SKILL.md +318 -0
- package/skills/testing-strategy/SKILL.md +195 -0
- package/skills/tour/SKILL.md +38 -0
- package/skills/upload/SKILL.md +117 -0
|
@@ -0,0 +1,1259 @@
|
|
|
1
|
+
## architecture.md Specification (Supplementary Notes)
|
|
2
|
+
|
|
3
|
+
> **DEPRECATED for structure.** The authoritative contract is `core/templates/architecture.md` (10-section graph-primary). If anything below conflicts with that template or `skills/init/SKILL.md`, the template wins.
|
|
4
|
+
|
|
5
|
+
Generate `draft/architecture.md` — a graph-primary human-readable engineering reference.
|
|
6
|
+
|
|
7
|
+
**Output format**:
|
|
8
|
+
- Markdown report with Mermaid diagrams, tables, and code blocks
|
|
9
|
+
- **Target length: fidelity-first** — cover all 10 mandatory sections with graph-grounded accuracy and diagram correctness
|
|
10
|
+
- End the document with: `"End of analysis. Queries should reference the .ai-context.md file for token efficiency."`
|
|
11
|
+
|
|
12
|
+
**CRITICAL — Template Structure Compliance:**
|
|
13
|
+
- The output MUST use the EXACT 10-section structure from `core/templates/architecture.md` (§1–§10)
|
|
14
|
+
- Do NOT create freeform/custom section names or resurrect 28-section numbering
|
|
15
|
+
- Do NOT skip mandatory sections — if a section does not apply, include the heading with "N/A — {reason}"
|
|
16
|
+
- The knowledge graph (`draft/graph/`) is the **deterministic ground truth** for structure (modules, dependencies, public surfaces, edges, hotspots). LLM synthesis exists to interpret the graph into actionable behavioral understanding — primarily through accurate diagrams — plus minimal narrative that does not contradict the graph.
|
|
17
|
+
- **Diagrams over prose volume.** Prefer one correct workflow/state/sequence diagram per major module or operational model over long responsibility paragraphs. A 20-line Mermaid diagram that faithfully reflects real call paths and state transitions from the graph is more valuable for downstream code generation than 300 words of generic description.
|
|
18
|
+
- **Accuracy and fidelity to graph + host index > historical length targets.** It is acceptable (and preferred) for sections to be short when the graph block + diagrams already convey the design.
|
|
19
|
+
- **No contradiction with graph.** Any prose claim about module boundaries, dependencies, entry points, or public API must be consistent with the corresponding graph record. Discrepancies must be noted explicitly.
|
|
20
|
+
- Sub-modules receive depth only when the graph shows clear internal boundaries (distinct public surface or high internal fan-in). Depth is bounded by observable graph structure, never by a desire for exhaustive enumeration.
|
|
21
|
+
|
|
22
|
+
### MANDATORY Header Format
|
|
23
|
+
|
|
24
|
+
**CRITICAL**: Every architecture.md file MUST start with this exact structure. Gather git metadata first, then fill in placeholders.
|
|
25
|
+
|
|
26
|
+
```markdown
|
|
27
|
+
---
|
|
28
|
+
project: "{PROJECT_NAME}"
|
|
29
|
+
module: "root"
|
|
30
|
+
generated_by: "draft:init"
|
|
31
|
+
generated_at: "{ISO_TIMESTAMP}"
|
|
32
|
+
git:
|
|
33
|
+
branch: "{LOCAL_BRANCH}"
|
|
34
|
+
remote: "{REMOTE/BRANCH}"
|
|
35
|
+
commit: "{FULL_SHA}"
|
|
36
|
+
commit_short: "{SHORT_SHA}"
|
|
37
|
+
commit_date: "{COMMIT_DATE}"
|
|
38
|
+
commit_message: "{COMMIT_MESSAGE}"
|
|
39
|
+
dirty: {true|false}
|
|
40
|
+
synced_to_commit: "{FULL_SHA}"
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
# Architecture: {PROJECT_NAME}
|
|
44
|
+
|
|
45
|
+
> Comprehensive human-readable engineering reference.
|
|
46
|
+
> For token-optimized AI context, see `draft/.ai-context.md`.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Table of Contents
|
|
51
|
+
|
|
52
|
+
1. [Executive Summary](#1-executive-summary)
|
|
53
|
+
2. [AI Agent Quick Reference](#2-ai-agent-quick-reference)
|
|
54
|
+
3. [System Identity & Purpose](#3-system-identity--purpose)
|
|
55
|
+
... (continue with all 28 sections + appendices)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Do NOT skip the YAML frontmatter. It enables incremental refresh tracking.**
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### Report Structure — Follow This Exact Section Ordering
|
|
63
|
+
|
|
64
|
+
_(Skip or adapt sections per the Adaptive Sections table above.)_
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
### 1. Executive Summary
|
|
69
|
+
|
|
70
|
+
Write **one paragraph** that states:
|
|
71
|
+
- What the module IS (identity)
|
|
72
|
+
- What it DOES (responsibilities)
|
|
73
|
+
- Its role in the larger system
|
|
74
|
+
|
|
75
|
+
Follow with a **Key Facts** bullet list:
|
|
76
|
+
- Primary language(s) and version
|
|
77
|
+
- Binary / entry-point / package name
|
|
78
|
+
- Architecture style (e.g., distributed master/worker, client-server, daemon, library, microservice, monolith, serverless, CLI tool)
|
|
79
|
+
- Generational variants if any (V1 / V2 / legacy + modern)
|
|
80
|
+
- Approximate count of major sub-components, plugins, handlers, or endpoints
|
|
81
|
+
- Primary data sources (what it reads from — databases, message queues, APIs, files)
|
|
82
|
+
- Primary action targets (what it writes to / calls — databases, downstream services, files)
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
### 2. AI Agent Quick Reference
|
|
87
|
+
|
|
88
|
+
A compact block optimized for fast AI-agent context loading. Fill in every field that applies; mark others as "N/A":
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
**Module** : {PROJECT_NAME}
|
|
92
|
+
**Root Path** : ./
|
|
93
|
+
**Language** : (e.g., C++17, Go 1.21, Python 3.12, TypeScript 5.3, Rust 1.75, Java 21)
|
|
94
|
+
**Build** : (e.g., `bazel build //path:target`, `npm run build`, `cargo build`,
|
|
95
|
+
`./gradlew build`, `mvn package`, `make`, `pip install -e .`)
|
|
96
|
+
**Test** : (e.g., `bazel test //path/...:all`, `npm test`, `pytest`, `cargo test`,
|
|
97
|
+
`go test ./...`, `mvn test`)
|
|
98
|
+
**Entry Point** : (file → class/function, e.g., `main.go → main()`, `app.py → create_app()`,
|
|
99
|
+
`index.ts → bootstrap()`, `Main.java → main()`)
|
|
100
|
+
**Config System** : (e.g., gflags in flags.cc, .env + config.yaml, Spring application.yml,
|
|
101
|
+
environment variables, Viper config)
|
|
102
|
+
**Extension Point** : (interface to implement + where to register, or "N/A" if not applicable)
|
|
103
|
+
**API Definition** : (e.g., .proto files, OpenAPI spec, GraphQL schema, or "N/A")
|
|
104
|
+
**Key Config Prefix**: (e.g., `MODULE_*` env vars, `module.*` YAML keys, `--module-*` CLI flags)
|
|
105
|
+
|
|
106
|
+
**Before Making Changes, Always:**
|
|
107
|
+
1. (Primary invariant check — the #1 thing that must not break)
|
|
108
|
+
2. (Thread-safety / async-safety consideration, or "single-threaded — no concerns")
|
|
109
|
+
3. (Test command to run after changes)
|
|
110
|
+
4. (API / schema versioning rule, if applicable)
|
|
111
|
+
|
|
112
|
+
**Never:**
|
|
113
|
+
- (Critical safety rule 1 — e.g., "never delete data without tombstone check")
|
|
114
|
+
- (Critical safety rule 2 — e.g., "never bypass auth middleware")
|
|
115
|
+
- (Critical safety rule 3 — e.g., "never modify proto field numbers")
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
### 3. System Identity & Purpose
|
|
121
|
+
|
|
122
|
+
- **What {PROJECT_NAME} Does** — numbered list of core responsibilities.
|
|
123
|
+
- **Why {PROJECT_NAME} Exists** — the business / system problem it solves, including what would go wrong without it. Frame in terms of:
|
|
124
|
+
- Data integrity
|
|
125
|
+
- Performance / efficiency
|
|
126
|
+
- Compliance / correctness
|
|
127
|
+
- Operational safety
|
|
128
|
+
- User experience (if user-facing)
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
### 4. Architecture Overview
|
|
133
|
+
|
|
134
|
+
**Expected length: 2-3 pages with diagrams**
|
|
135
|
+
|
|
136
|
+
#### 4.1 High-Level Topology
|
|
137
|
+
|
|
138
|
+
**MANDATORY: Generate a Mermaid `flowchart TD` diagram** showing:
|
|
139
|
+
- The main process / service and its internal components (as nested subgraphs)
|
|
140
|
+
- External services and dependencies (as a separate subgraph)
|
|
141
|
+
- Directional arrows showing primary data / control flow
|
|
142
|
+
|
|
143
|
+
Example structure (adapt to actual codebase):
|
|
144
|
+
```mermaid
|
|
145
|
+
flowchart TD
|
|
146
|
+
subgraph Service["MyService"]
|
|
147
|
+
A[API Layer] --> B[Business Logic]
|
|
148
|
+
B --> C[Data Access]
|
|
149
|
+
end
|
|
150
|
+
subgraph External["External Dependencies"]
|
|
151
|
+
D[(Database)]
|
|
152
|
+
E[Cache]
|
|
153
|
+
end
|
|
154
|
+
C --> D
|
|
155
|
+
B --> E
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### 4.4 Module Dependency Graph (graph-derived, auto-refreshed)
|
|
159
|
+
|
|
160
|
+
Write the `GRAPH:module-deps` injection slot into architecture.md:
|
|
161
|
+
|
|
162
|
+
If graph build succeeded (Step 1.4.7 completed), write the populated slot content using the diagram from Step 1.4.7. If filtered (>30 modules), include the filter note. Dashed edges indicate circular dependencies.
|
|
163
|
+
|
|
164
|
+
If graph binary was not found: write the slot with placeholder body so draft:index can populate it later:
|
|
165
|
+
```
|
|
166
|
+
<!-- GRAPH:module-deps:START -->
|
|
167
|
+
[Graph data unavailable — run draft:index to populate after graph binary is installed]
|
|
168
|
+
<!-- GRAPH:module-deps:END -->
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
The slot markers MUST always be written — they are required for draft:index refresh to function.
|
|
172
|
+
|
|
173
|
+
#### 4.2 Process Lifecycle (or Usage Lifecycle for libraries)
|
|
174
|
+
|
|
175
|
+
Numbered steps from startup to steady state. Reference the entry-point source file.
|
|
176
|
+
|
|
177
|
+
For services/daemons: binary start → config load → dependency init → server listen → event loop.
|
|
178
|
+
For libraries: import → configure → initialize → use → teardown.
|
|
179
|
+
For CLI tools: parse args → validate → execute → output → exit.
|
|
180
|
+
|
|
181
|
+
**Include 5-10 numbered steps with file:line references.**
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
### 5. Component Map & Interactions
|
|
186
|
+
|
|
187
|
+
#### 5.1 Top-Level Orchestrator
|
|
188
|
+
|
|
189
|
+
For the main controller / manager / app class:
|
|
190
|
+
- Describe its role in one sentence.
|
|
191
|
+
- **Owned Components** — table:
|
|
192
|
+
|
|
193
|
+
| Component | Type | Purpose |
|
|
194
|
+
|-----------|------|---------|
|
|
195
|
+
|
|
196
|
+
- **Initialization Stages** — Mermaid `flowchart TD` showing the state machine from uninitialized to fully ready (if applicable — skip for simple modules).
|
|
197
|
+
|
|
198
|
+
#### 5.2 Dependency Injection / Wiring Pattern
|
|
199
|
+
|
|
200
|
+
Describe how components reference each other. Common patterns to look for:
|
|
201
|
+
- Constructor injection (Spring, Guice, etc.)
|
|
202
|
+
- Service locator / context struct (C++ pattern)
|
|
203
|
+
- Module system (Python, Node.js imports)
|
|
204
|
+
- Dependency injection container (NestJS, .NET, Dagger)
|
|
205
|
+
- Global singletons / registries
|
|
206
|
+
|
|
207
|
+
List all injection tokens, getter categories, or module exports.
|
|
208
|
+
|
|
209
|
+
#### 5.3 Interaction Matrix
|
|
210
|
+
|
|
211
|
+
Table showing which components communicate with which:
|
|
212
|
+
|
|
213
|
+
| | Comp A | Comp B | Comp C | ... |
|
|
214
|
+
|---|---|---|---|---|
|
|
215
|
+
| Comp A | — | ✓ | ✓(RPC) | |
|
|
216
|
+
| Comp B | ✓ | — | | ✓(HTTP) |
|
|
217
|
+
|
|
218
|
+
Use ✓ for direct calls, ✓(RPC) for remote procedure calls, ✓(HTTP) for REST calls, ✓(queue) for message queue, ✓(DB) for shared database, ✓(event) for event bus.
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
### 6. Core Operational Flows, Lifecycles & State Machines
|
|
223
|
+
|
|
224
|
+
> **Source:** llm-synthesis + graph (primary structural truth) + full project index from host environment
|
|
225
|
+
> **Required:** high+ (this is one of the highest-ROI sections for any downstream coding assistant)
|
|
226
|
+
> **Length:** 2–5 high-quality behavioral diagrams + minimal supporting prose
|
|
227
|
+
> **N/A when:** the system is trivial (single linear script with no meaningful state or branching) — write explicit N/A.
|
|
228
|
+
> **Verification:** diagram fidelity to graph + indexed understanding + citation-check
|
|
229
|
+
|
|
230
|
+
**Purpose**: This section captures the **real behavioral architecture** — the primary ways the system moves through time, state, and control flow. It is more valuable for correct code generation and modification than static component descriptions.
|
|
231
|
+
|
|
232
|
+
The LLM **must** combine:
|
|
233
|
+
- The deterministic knowledge graph (modules, edges, entry points, public surfaces, hotspots, call targets)
|
|
234
|
+
- Its full indexed project understanding from the host Cursor / Claude Code / Copilot environment
|
|
235
|
+
- Targeted source reads only for confirmation and detail
|
|
236
|
+
|
|
237
|
+
to identify and accurately diagram the most important operational models.
|
|
238
|
+
|
|
239
|
+
### 6.1 Primary Operational Models (MANDATORY — 2 to 5 diagrams)
|
|
240
|
+
|
|
241
|
+
Synthesize the 2–5 most important operational views for the system. Typical candidates:
|
|
242
|
+
|
|
243
|
+
- The dominant request / job / user-action lifecycle (end-to-end, with decision points and error paths)
|
|
244
|
+
- Main state machine(s) for stateful components or the overall system
|
|
245
|
+
- Critical background / async / batch / worker pipelines
|
|
246
|
+
- Startup / initialization / shutdown lifecycle (especially valuable for services and tooling)
|
|
247
|
+
- For plugin / meta-tooling / agent platforms: the core execution or dispatch model (skill/command/agent lifecycle, frontmatter contract enforcement, generation/condensation pipeline, parallel analysis protocol, track/decompose/implement lifecycle, etc.)
|
|
248
|
+
|
|
249
|
+
Each diagram must be a **stateDiagram-v2**, **sequenceDiagram**, or detailed **flowchart** containing:
|
|
250
|
+
- Real actor / state / stage names from the actual codebase
|
|
251
|
+
- Labeled transitions using actual function, message, or event names where possible
|
|
252
|
+
- `alt` / `opt` / `loop` / `critical` where branching, repetition, or error handling exists
|
|
253
|
+
|
|
254
|
+
Prioritize **accuracy and usefulness for future code generation** over visual polish. A correct diagram of the real initialization sequence or request dispatch path is far more valuable than a generic "data flow" picture.
|
|
255
|
+
|
|
256
|
+
### 6.2 Error & Recovery Paths
|
|
257
|
+
|
|
258
|
+
For every primary flow above, explicitly surface (in prose or inside the diagrams) the main error classification, retry/backoff, circuit-breaker, fallback, and recovery behaviors.
|
|
259
|
+
|
|
260
|
+
### 6.3 Cross-Cutting Concerns in Flows
|
|
261
|
+
|
|
262
|
+
Only when material: authentication/authorization checkpoints, distributed transaction boundaries, observability hooks, rate limiting, idempotency, cancellation, or resource lifecycle rules that appear inside the operational models.
|
|
263
|
+
|
|
264
|
+
**For plugin platforms and meta-tooling projects**: This section must include clear diagrams of the primary internal processes (initialization with graph gate, skill/agent/command dispatch and frontmatter enforcement, condensation + profile derivation, parallel reader→synthesis protocol, etc.). These diagrams document how the platform itself executes.
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
### 7. Core Modules Deep Dive
|
|
269
|
+
|
|
270
|
+
> **Source:** graph (primary structural truth) + llm-synthesis (secondary, minimal)
|
|
271
|
+
> **Required:** always
|
|
272
|
+
> **Length:** Graph block + one high-signal workflow/state diagram + ≤80 words synthesis per module
|
|
273
|
+
> **N/A when:** never
|
|
274
|
+
> **Verification:** graph-fence fidelity + diagram correctness + citation-check
|
|
275
|
+
|
|
276
|
+
**Core rule:** The graph is the source of truth for structure. LLM synthesis exists only to interpret the graph into actionable design understanding — primarily via one accurate workflow or state diagram per module — plus tiny supporting notes. The previous volume-oriented deep-dive expectations are superseded.
|
|
277
|
+
|
|
278
|
+
For each module in `draft/graph/architecture.json` (`.packages[]`), produce a subsection whose **primary content** is the deterministic graph block followed by one synthesized behavioral diagram. Every module gets a slot; do not sample. The block's fan-in/out and node counts come from `.packages[]`; public API and key call edges come from live per-package queries (`scripts/tools/graph-callers.sh`, `graph-impact.sh`) and `hotspots.jsonl`.
|
|
279
|
+
|
|
280
|
+
#### 7.{N} {module-name}
|
|
281
|
+
|
|
282
|
+
<!-- GRAPH:module-deep/{module-name}:START -->
|
|
283
|
+
<!-- Rendered deterministic block: package name, node count, public API list, fan-in/fan-out (from
|
|
284
|
+
architecture.json .packages), hotspot fan-in (from hotspots.jsonl), key call edges (from
|
|
285
|
+
graph-callers.sh/graph-impact.sh), entry points if known. No LLM prose inside fence. -->
|
|
286
|
+
<!-- GRAPH:module-deep/{module-name}:END -->
|
|
287
|
+
|
|
288
|
+
**Role** (≤25 words, derived strictly from graph role + primary source files read).
|
|
289
|
+
|
|
290
|
+
**Primary Workflow / State** (MANDATORY — one diagram per module)
|
|
291
|
+
Synthesize a single, accurate Mermaid diagram (`stateDiagram-v2`, `sequenceDiagram`, or `flowchart LR/TD` with clear stages) that captures the dominant control flow, data transformation pipeline, or lifecycle state machine for this module, grounded in the call graph / entry points / public surface from the graph record. Label transitions with the actual function or message names where possible. This diagram is more important than any prose.
|
|
292
|
+
|
|
293
|
+
**Public Surface** (from graph `public_api` + verified source). Enumerate only the highest-fan-in or architecturally significant symbols. Format: `symbol (kind) — path:line`. No exhaustive dump of every getter.
|
|
294
|
+
|
|
295
|
+
**Design Notes** (≤80 words total). Only what the graph + one or two key source reads reveal about invariants, error boundaries, or concurrency that is not already visible in the graph block or the workflow diagram. Cite specific `path:line`.
|
|
296
|
+
|
|
297
|
+
**Sub-modules / Subsystems**. Recurse **only** when the graph shows a clear internal boundary (distinct public surface or high internal fan-in). Each child follows the identical pattern (graph block + one workflow diagram + minimal notes). Depth is strictly bounded by observable graph structure, never by a desire for "completeness."
|
|
298
|
+
|
|
299
|
+
**Anti-pattern:** Do not emit long "Responsibilities" paragraphs or exhaustive file lists. If the graph block + one workflow diagram already communicate the design, the synthesis may be two sentences. Accuracy and diagram correctness are the success criteria.
|
|
300
|
+
|
|
301
|
+
#### Sub-Module Guidance (when graph justifies recursion)
|
|
302
|
+
|
|
303
|
+
When a module has clear internal structure visible in `draft/graph/architecture.json` (`.packages` fan-in/out) or live per-package queries:
|
|
304
|
+
- Create `##### 7.X.Y {Parent}/{Child}` subsections only for children that have their own meaningful public surface or high internal fan-in.
|
|
305
|
+
- Each sub-module subsection follows the same compact pattern: graph facts + **one mandatory workflow/state diagram** + ≤60 words Design Notes.
|
|
306
|
+
- Do not descend further unless the child itself shows additional clear boundaries in the graph data.
|
|
307
|
+
- For ops/handler directories that are primary extension points, a short numbered operation catalog is acceptable even if small.
|
|
308
|
+
|
|
309
|
+
**Never** produce the old exhaustive "Source Files + list ALL responsibilities + 5+ operations + full mechanisms" template unless the module is genuinely tiny and the extra detail adds unique value not visible in the graph + diagram. The graph + one excellent diagram is the required primary artifact.
|
|
310
|
+
**Key Operations / Methods**:
|
|
311
|
+
|
|
312
|
+
| Op / Method | Signature | Description |
|
|
313
|
+
|-------------|-----------|-------------|
|
|
314
|
+
| `methodName` | `(input: Type) → ReturnType` | What it does |
|
|
315
|
+
| (enumerate ALL public methods — at least 5 entries) | | |
|
|
316
|
+
|
|
317
|
+
**Interaction with Sibling Sub-Modules**:
|
|
318
|
+
- Calls `{sibling}/` for {purpose}
|
|
319
|
+
- Called by `{sibling}/` when {trigger}
|
|
320
|
+
- Shares `{base|common}/` types: {list key shared types}
|
|
321
|
+
|
|
322
|
+
**State Machine** (if stateful):
|
|
323
|
+
[Mermaid stateDiagram-v2]
|
|
324
|
+
|
|
325
|
+
**Notable Mechanisms**: {caching, retry, batching, scheduling, etc.}
|
|
326
|
+
|
|
327
|
+
**Error Handling**: How errors propagate within this sub-module and to the parent.
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
#### Per-Sub-Module Template (Medium — 10–49 files)
|
|
331
|
+
|
|
332
|
+
```markdown
|
|
333
|
+
##### 7.X.Y {ParentModule}/{SubModuleName}
|
|
334
|
+
|
|
335
|
+
**Role**: {2-3 sentence description}.
|
|
336
|
+
|
|
337
|
+
**Key Operations**:
|
|
338
|
+
|
|
339
|
+
| Op / Method | Source File | Description |
|
|
340
|
+
|-------------|-------------|-------------|
|
|
341
|
+
| (at least 5 entries with real data) | | |
|
|
342
|
+
|
|
343
|
+
**Notable Mechanisms**: {1-2 bullet points on key internal behavior}
|
|
344
|
+
|
|
345
|
+
**Key Interface** (code snippet from actual source):
|
|
346
|
+
```{language}
|
|
347
|
+
// actual code from the interface header, 10-20 lines
|
|
348
|
+
```
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
#### Operation Catalog Template (for ops/handler directories)
|
|
352
|
+
|
|
353
|
+
Regardless of tier, any directory whose name contains `ops`, `handlers`, `executors`, `workers`, `actions`, or `commands` MUST get a full enumeration:
|
|
354
|
+
|
|
355
|
+
```markdown
|
|
356
|
+
##### 7.X.Y {Module}/{SubModule}/ops — Operation Catalog
|
|
357
|
+
|
|
358
|
+
| # | Operation | Source File | Lines | Description |
|
|
359
|
+
|---|-----------|-------------|-------|-------------|
|
|
360
|
+
| 1 | `ArchiveFilesOp` | `icebox/master/ops/archive_files_op.cc` | 2100 | Archives files to cloud vault |
|
|
361
|
+
| 2 | `CancelJobOp` | `icebox/master/ops/cancel_job_op.cc` | 450 | Cancels running archive job |
|
|
362
|
+
| ... | (enumerate ALL — no sampling, no "and others") | | | |
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
Use `draft/graph/modules/{module}.jsonl` to get the complete file list with line counts. Use `draft/graph/hotspots.jsonl` to flag high-complexity operations.
|
|
366
|
+
|
|
367
|
+
#### Example: Full Sub-Module Treatment for `icebox/` (917 files)
|
|
368
|
+
|
|
369
|
+
For a module like `icebox/` with sub-directories `master/` (200+ files), `slave/` (150+ files), `client/` (20 files), `base/` (40 files):
|
|
370
|
+
|
|
371
|
+
```
|
|
372
|
+
#### 7.3 icebox
|
|
373
|
+
[Top-level module deep-dive: role, overall architecture diagram, cross-sub-module interaction]
|
|
374
|
+
|
|
375
|
+
##### 7.3.1 icebox/master (Large — 200+ files → full deep-dive)
|
|
376
|
+
[Full template: role, responsibilities, key ops table, state machine, mechanisms]
|
|
377
|
+
|
|
378
|
+
##### 7.3.1.1 icebox/master/ops — Operation Catalog
|
|
379
|
+
[Numbered table of ALL 60+ operations with file, lines, description]
|
|
380
|
+
|
|
381
|
+
##### 7.3.2 icebox/slave (Large — 150+ files → full deep-dive)
|
|
382
|
+
[Full template: role, responsibilities, key ops table, mechanisms]
|
|
383
|
+
|
|
384
|
+
##### 7.3.2.1 icebox/slave/ops — Operation Catalog
|
|
385
|
+
[Numbered table of ALL slave operations]
|
|
386
|
+
|
|
387
|
+
##### 7.3.3 icebox/base (Medium — 40 files → summary deep-dive)
|
|
388
|
+
[Summary: role, key ops table, one code snippet]
|
|
389
|
+
|
|
390
|
+
##### 7.3.4 icebox/client (Medium — 20 files → summary deep-dive)
|
|
391
|
+
[Summary: role, key ops table, interface snippet]
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
This produces 300–500+ lines for `icebox/` alone, which is proportional to its 917-file complexity.
|
|
395
|
+
|
|
396
|
+
**MANDATORY for stateful modules and sub-modules**: Include a `stateDiagram-v2` showing state transitions:
|
|
397
|
+
```mermaid
|
|
398
|
+
stateDiagram-v2
|
|
399
|
+
[*] --> Idle
|
|
400
|
+
Idle --> Processing: start()
|
|
401
|
+
Processing --> Completed: success
|
|
402
|
+
Processing --> Failed: error
|
|
403
|
+
Failed --> Idle: retry()
|
|
404
|
+
Completed --> [*]
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
#### Section 7 Graph Fidelity + Diagram Check (MANDATORY)
|
|
408
|
+
|
|
409
|
+
After writing Section 7, run these checks before proceeding. **If any check fails, STOP and fix.**
|
|
410
|
+
|
|
411
|
+
**Check 1 — Graph block present and faithful for every module:**
|
|
412
|
+
Every top-level module from `draft/graph/architecture.json` (`.packages`) has its `<!-- GRAPH:module-deep/...:START --> ... <!-- GRAPH:module-deep/...:END -->` fence rendered verbatim. No LLM prose inside the fence. No modules missing.
|
|
413
|
+
|
|
414
|
+
**Check 2 — One mandatory workflow/state diagram per module:**
|
|
415
|
+
Every `#### 7.X` (and every `##### 7.X.Y` that the graph justified) contains exactly one high-signal `Primary Workflow / State` Mermaid diagram (`stateDiagram-v2`, `sequenceDiagram`, or clear `flowchart`). The diagram must reflect facts from the module's graph record (entry points, public symbols, call targets). Generic placeholder diagrams fail this check.
|
|
416
|
+
|
|
417
|
+
**Check 3 — Role ≤25 words + Design Notes ≤80 words:**
|
|
418
|
+
Role is one tight sentence. Design Notes are ≤80 words and cite specific `path:line` only for observations not already visible in the graph block or the diagram. Long prose paragraphs or "Responsibilities" lists fail this check.
|
|
419
|
+
|
|
420
|
+
**Check 4 — No contradiction with graph:**
|
|
421
|
+
Any prose claim (dependencies, public surface, entry points, sub-module boundaries) must be consistent with the corresponding graph record. If source reading revealed behavior the graph did not capture, the discrepancy is noted explicitly rather than silently overriding the graph.
|
|
422
|
+
|
|
423
|
+
**Check 5 — No exhaustive file lists or volume padding:**
|
|
424
|
+
The section does not lead with "Source Files:" tables or "enumerate ALL" language. If the graph + one diagram already communicate the design, extra prose is minimal. Historical line-count or "at least 5 operations" quotas are ignored.
|
|
425
|
+
|
|
426
|
+
**Check 6 — Sub-module recursion is graph-bounded:**
|
|
427
|
+
Deeper `#####` subsections exist only where the graph data shows distinct internal public surface or high fan-in. No descent "because the module is large."
|
|
428
|
+
|
|
429
|
+
---
|
|
430
|
+
|
|
431
|
+
### 8. Concurrency Model & Thread Safety
|
|
432
|
+
|
|
433
|
+
_(For single-threaded or simple modules, state that explicitly and skip the detailed subsections.)_
|
|
434
|
+
|
|
435
|
+
- **Execution Model** — single-threaded, multi-threaded, async/await, actor model, goroutine-based, event-loop, etc.
|
|
436
|
+
- **Thread / Worker Pool Map** — table:
|
|
437
|
+
|
|
438
|
+
| Pool / Executor | Purpose | What Runs On It |
|
|
439
|
+
|-----------------|---------|-----------------|
|
|
440
|
+
|
|
441
|
+
- **Thread Affinity / Safety Rules** — which objects are single-threaded vs. thread-safe; which methods must be called from which context.
|
|
442
|
+
- **Locking Strategy** — what locks / mutexes / semaphores exist, their granularity, and ordering rules to prevent deadlocks.
|
|
443
|
+
- **Async Patterns** — how callbacks / promises / futures / channels chain; proper cancellation; timeout handling; lifetime management.
|
|
444
|
+
- **Common Concurrency Pitfalls** — specific anti-patterns to avoid in this codebase.
|
|
445
|
+
|
|
446
|
+
---
|
|
447
|
+
|
|
448
|
+
### 9. Framework & Extension Points
|
|
449
|
+
|
|
450
|
+
_(Skip if the module has no plugin / handler / middleware / algorithm system.)_
|
|
451
|
+
|
|
452
|
+
#### 9.1 Plugin / Handler / Middleware Types
|
|
453
|
+
|
|
454
|
+
Table:
|
|
455
|
+
|
|
456
|
+
| Type | Interface / Base Class | Description |
|
|
457
|
+
|------|----------------------|-------------|
|
|
458
|
+
|
|
459
|
+
#### 9.2 Registry / Registration Mechanism
|
|
460
|
+
|
|
461
|
+
Describe how plugins are registered. Common patterns:
|
|
462
|
+
- Explicit registry calls in an init file
|
|
463
|
+
- Decorator / annotation-based auto-registration
|
|
464
|
+
- Convention-based discovery (file naming, directory scanning)
|
|
465
|
+
- Configuration-driven (list in YAML / JSON)
|
|
466
|
+
- Self-registration via static initializers or module init
|
|
467
|
+
|
|
468
|
+
#### 9.3 Per-Plugin Metadata
|
|
469
|
+
|
|
470
|
+
Table of all properties stored per registered plugin:
|
|
471
|
+
|
|
472
|
+
| Property | Type | Description |
|
|
473
|
+
|----------|------|-------------|
|
|
474
|
+
|
|
475
|
+
#### 9.4 Core Interfaces
|
|
476
|
+
|
|
477
|
+
For each interface, show the key method signatures as **code blocks** with inline comments explaining inputs, outputs, and optional hooks. Use actual code from the codebase.
|
|
478
|
+
|
|
479
|
+
#### 9.5 Universal / Shared Data Types
|
|
480
|
+
|
|
481
|
+
Describe any type-erased, generic, or shared containers used across interfaces.
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
485
|
+
### 10. Full Catalog of Implementations
|
|
486
|
+
|
|
487
|
+
_(Skip if Section 9 was skipped AND the codebase has no operation/handler pattern.)_
|
|
488
|
+
|
|
489
|
+
#### 10.1 Legacy / V1 Implementations (if applicable)
|
|
490
|
+
|
|
491
|
+
Numbered table:
|
|
492
|
+
|
|
493
|
+
| # | Name | Type | Data Sources |
|
|
494
|
+
|---|------|------|--------------|
|
|
495
|
+
|
|
496
|
+
#### 10.2 Current Implementations
|
|
497
|
+
|
|
498
|
+
Table grouped by category:
|
|
499
|
+
|
|
500
|
+
| Category | Implementations |
|
|
501
|
+
|----------|-----------------|
|
|
502
|
+
|
|
503
|
+
Include architecturally significant implementations (high fan-in, core extension points, or primary execution paths). Exhaustive enumeration of every helper class is not required when the graph + operational diagrams already surface the important ones.
|
|
504
|
+
|
|
505
|
+
#### 10.3 Sub-Module Operation Catalogs
|
|
506
|
+
|
|
507
|
+
**When the graph identifies operation/handler directories as primary extension points**, provide a short numbered catalog of the key operations (focus on the highest-fan-in or most architecturally central ones; exhaustive listing of every internal helper is not required):
|
|
508
|
+
|
|
509
|
+
```markdown
|
|
510
|
+
##### 10.3.X {Module}/{SubModule} Operations
|
|
511
|
+
|
|
512
|
+
| # | Operation | Source File | Lines | Description |
|
|
513
|
+
|---|-----------|-------------|-------|-------------|
|
|
514
|
+
| 1 | ArchiveFilesOp | `icebox/master/ops/archive_files_op.cc` | 2100 | Archives files to cloud vault |
|
|
515
|
+
| 2 | CancelJobOp | `icebox/master/ops/cancel_job_op.cc` | 450 | Cancels running archive job |
|
|
516
|
+
| (enumerate ALL — use graph hotspots.jsonl and per-module JSONL for file list and line counts) |
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
> **MANDATORY (graph data)**: Read `draft/graph/modules/{module}.jsonl` to get the complete file
|
|
520
|
+
> list with line counts. Filter for files in operation sub-directories (paths containing `/ops/`,
|
|
521
|
+
> `/handlers/`, `/executors/`, `/workers/`). Use `draft/graph/hotspots.jsonl` to flag
|
|
522
|
+
> high-complexity operations (high line count or fanIn). Do NOT skip this step — incomplete
|
|
523
|
+
> catalogs cause AI agents to reinvent existing functionality.
|
|
524
|
+
|
|
525
|
+
**Why this matters**: Operation classes are the primary extension points in large systems. Engineers adding new functionality need to know what operations already exist, their complexity, and which files to use as templates. Missing even one operation from the catalog means the AI may suggest reinventing existing functionality.
|
|
526
|
+
|
|
527
|
+
---
|
|
528
|
+
|
|
529
|
+
### 11. Secondary Subsystem (V2 / Redesign)
|
|
530
|
+
|
|
531
|
+
_(Skip if there is no major generational redesign or parallel subsystem.)_
|
|
532
|
+
|
|
533
|
+
- **Architecture** — Mermaid flowchart of the redesigned subsystem.
|
|
534
|
+
- **Key Differences** — comparison table:
|
|
535
|
+
|
|
536
|
+
| Aspect | V1 / Legacy | V2 / Current |
|
|
537
|
+
|--------|------------|-------------|
|
|
538
|
+
|
|
539
|
+
- **Framework Details** — list key source files and their roles.
|
|
540
|
+
- **Advanced Features** — multi-tenant, cloud, distributed, or other capabilities absent in V1.
|
|
541
|
+
|
|
542
|
+
---
|
|
543
|
+
|
|
544
|
+
### 12. API & Interface Definitions
|
|
545
|
+
|
|
546
|
+
_(Adapt title and content based on what the module uses.)_
|
|
547
|
+
|
|
548
|
+
#### 12.1 RPC / REST / GraphQL Endpoints
|
|
549
|
+
|
|
550
|
+
Table:
|
|
551
|
+
|
|
552
|
+
| Endpoint / RPC | Method / Direction | Purpose |
|
|
553
|
+
|----------------|-------------------|---------|
|
|
554
|
+
|
|
555
|
+
#### 12.2 Key Data Models / Messages / Schemas
|
|
556
|
+
|
|
557
|
+
Table:
|
|
558
|
+
|
|
559
|
+
| Model / Message / Schema | Purpose |
|
|
560
|
+
|--------------------------|---------|
|
|
561
|
+
|
|
562
|
+
#### 12.3 External-Facing API (if distinct from internal)
|
|
563
|
+
|
|
564
|
+
List endpoints grouped by function. Reference the actual definition files:
|
|
565
|
+
- `.proto` files for gRPC / protobuf
|
|
566
|
+
- OpenAPI / Swagger specs for REST
|
|
567
|
+
- GraphQL schema files
|
|
568
|
+
- TypeScript type definitions for SDK / client libraries
|
|
569
|
+
- JSON Schema files
|
|
570
|
+
|
|
571
|
+
---
|
|
572
|
+
|
|
573
|
+
### 13. External Dependencies
|
|
574
|
+
|
|
575
|
+
#### 13.1 Service Dependencies
|
|
576
|
+
|
|
577
|
+
Table:
|
|
578
|
+
|
|
579
|
+
| Service / System | Library / Client Path | Usage |
|
|
580
|
+
|------------------|----------------------|-------|
|
|
581
|
+
|
|
582
|
+
(Databases, message queues, caches, peer services, cloud APIs, etc.)
|
|
583
|
+
|
|
584
|
+
#### 13.2 Sub-components of Major Dependencies
|
|
585
|
+
|
|
586
|
+
Table:
|
|
587
|
+
|
|
588
|
+
| Component | Usage |
|
|
589
|
+
|-----------|-------|
|
|
590
|
+
|
|
591
|
+
(e.g., if it depends on a storage service, list which sub-libraries or SDK modules it uses.)
|
|
592
|
+
|
|
593
|
+
#### 13.3 Infrastructure / Utility Libraries
|
|
594
|
+
|
|
595
|
+
Table:
|
|
596
|
+
|
|
597
|
+
| Library / Package | Usage |
|
|
598
|
+
|-------------------|-------|
|
|
599
|
+
|
|
600
|
+
(HTTP frameworks, ORM, serialization, logging, metrics, auth, crypto, test utilities, etc.)
|
|
601
|
+
|
|
602
|
+
---
|
|
603
|
+
|
|
604
|
+
### 14. Cross-Module Integration Points
|
|
605
|
+
|
|
606
|
+
**Expected length: 2-4 pages with 2-3 sequence diagrams**
|
|
607
|
+
|
|
608
|
+
For each external service this module interacts with:
|
|
609
|
+
|
|
610
|
+
- **Contract** — what this module expects (API version, response format, latency SLA).
|
|
611
|
+
- **Failure Isolation** — what happens when the dependency is down or slow.
|
|
612
|
+
- **Version Coupling** — compatibility requirements between module versions.
|
|
613
|
+
- **Shared Schemas** — which definition files are shared and who owns them.
|
|
614
|
+
- **Integration Test Coverage** — how the integration is tested.
|
|
615
|
+
|
|
616
|
+
**MANDATORY: Include 2-3 Mermaid sequence diagrams** for the most important cross-module flows:
|
|
617
|
+
|
|
618
|
+
```mermaid
|
|
619
|
+
sequenceDiagram
|
|
620
|
+
participant Client
|
|
621
|
+
participant API
|
|
622
|
+
participant Service
|
|
623
|
+
participant Database
|
|
624
|
+
|
|
625
|
+
Client->>API: POST /resource {payload}
|
|
626
|
+
API->>Service: validate(payload)
|
|
627
|
+
Service->>Database: INSERT
|
|
628
|
+
Database-->>Service: id
|
|
629
|
+
Service-->>API: ResourceCreated
|
|
630
|
+
API-->>Client: 201 {id, resource}
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
Each sequence diagram MUST show:
|
|
634
|
+
- All participant lifelines (components / services)
|
|
635
|
+
- Request → response arrows with payload descriptions
|
|
636
|
+
- Conditional branches (alt/opt blocks) where logic diverges
|
|
637
|
+
- Loop blocks for retry or iteration logic
|
|
638
|
+
- Error paths (not just happy path)
|
|
639
|
+
|
|
640
|
+
---
|
|
641
|
+
|
|
642
|
+
### 15. Critical Invariants & Safety Rules
|
|
643
|
+
|
|
644
|
+
**Expected length: 2-3 pages (8-15 invariants)**
|
|
645
|
+
|
|
646
|
+
**CRITICAL SECTION**: This section prevents AI agents from making dangerous changes. Be EXHAUSTIVE.
|
|
647
|
+
|
|
648
|
+
For each invariant, provide COMPLETE documentation:
|
|
649
|
+
|
|
650
|
+
#### Invariant Template
|
|
651
|
+
|
|
652
|
+
```markdown
|
|
653
|
+
#### [Category] Invariant Name
|
|
654
|
+
|
|
655
|
+
**What**: Clear statement of the invariant (what must always be true).
|
|
656
|
+
|
|
657
|
+
**Why**: What breaks if violated:
|
|
658
|
+
- Specific failure mode (data loss, corruption, crash, security breach, etc.)
|
|
659
|
+
- Blast radius (single user, all users, entire system)
|
|
660
|
+
- Recovery difficulty (automatic, manual intervention, unrecoverable)
|
|
661
|
+
|
|
662
|
+
**Where Enforced**:
|
|
663
|
+
- `path/to/file.ext:linenum` — `functionName()` — how it checks
|
|
664
|
+
- `path/to/another.ext:linenum` — secondary enforcement
|
|
665
|
+
|
|
666
|
+
**Common Violation Patterns**:
|
|
667
|
+
1. How someone might accidentally break this
|
|
668
|
+
2. Another way it could be violated
|
|
669
|
+
3. Edge case that's easy to miss
|
|
670
|
+
|
|
671
|
+
**Safe Modification Guide**: If you need to change code near this invariant, do X not Y.
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
#### Required Categories (enumerate ALL that apply)
|
|
675
|
+
|
|
676
|
+
1. **Data Safety Invariants** (prevent data loss / corruption)
|
|
677
|
+
- Transaction boundaries
|
|
678
|
+
- Foreign key relationships
|
|
679
|
+
- Data validation rules
|
|
680
|
+
|
|
681
|
+
2. **Security Invariants** (auth, authz, input validation)
|
|
682
|
+
- Authentication requirements
|
|
683
|
+
- Authorization checks
|
|
684
|
+
- Input sanitization boundaries
|
|
685
|
+
|
|
686
|
+
3. **Concurrency Invariants** (lock ordering, thread affinity)
|
|
687
|
+
- Lock acquisition order
|
|
688
|
+
- Thread-confined objects
|
|
689
|
+
- Atomic operation requirements
|
|
690
|
+
|
|
691
|
+
4. **Ordering / Sequencing Invariants** (must-happen-before)
|
|
692
|
+
- Initialization order dependencies
|
|
693
|
+
- Event ordering requirements
|
|
694
|
+
- State machine transitions
|
|
695
|
+
|
|
696
|
+
5. **Idempotency Requirements** (safe to retry?)
|
|
697
|
+
- Which operations are idempotent
|
|
698
|
+
- Which require deduplication
|
|
699
|
+
- Retry safety rules
|
|
700
|
+
|
|
701
|
+
6. **Backward-Compatibility Rules** (schema evolution, API versioning)
|
|
702
|
+
- Field addition/removal rules
|
|
703
|
+
- Version negotiation requirements
|
|
704
|
+
- Migration requirements
|
|
705
|
+
|
|
706
|
+
---
|
|
707
|
+
|
|
708
|
+
### 16. Security Architecture
|
|
709
|
+
|
|
710
|
+
- **Authentication & Initialization**: How identity is established (key exchange, tokens, certificates).
|
|
711
|
+
- **Authorization Enforcement**: Where permission checks happen (middleware, service layer, decorators).
|
|
712
|
+
- **Data Sanitization**: Input validation boundaries and sanitization logic.
|
|
713
|
+
- **Secrets Management**: How keys/credentials are loaded and used (never hardcoded!).
|
|
714
|
+
- **Network Security**: TLS termination, mTLS, allowlists/blocklists.
|
|
715
|
+
|
|
716
|
+
---
|
|
717
|
+
|
|
718
|
+
### 17. Observability & Telemetry
|
|
719
|
+
|
|
720
|
+
- **Logging Strategy**:
|
|
721
|
+
- Key log levels and when used.
|
|
722
|
+
- Structured logging keys (e.g., `request_id`, `user_id`, `trace_id`).
|
|
723
|
+
- **Distributed Tracing**:
|
|
724
|
+
- Probes / Spans: Where trace context is extracted and injected.
|
|
725
|
+
- Context propagation mechanism.
|
|
726
|
+
- **Metrics**:
|
|
727
|
+
- Key counters, gauges, and histograms defined in this module.
|
|
728
|
+
- Health check endpoints and logic (liveness vs. readiness).
|
|
729
|
+
|
|
730
|
+
---
|
|
731
|
+
|
|
732
|
+
### 18. Error Handling & Failure Modes
|
|
733
|
+
|
|
734
|
+
- **Error Propagation Model** — how errors flow through the system. Common patterns:
|
|
735
|
+
- Return codes / error types (Go, Rust)
|
|
736
|
+
- Exceptions (Python, Java, C++)
|
|
737
|
+
- Result/Either monads (Rust, functional)
|
|
738
|
+
- Callback error arguments (Node.js)
|
|
739
|
+
- Error proto / error response objects (gRPC, REST)
|
|
740
|
+
|
|
741
|
+
Show the canonical error-handling pattern with a real code example from the codebase.
|
|
742
|
+
|
|
743
|
+
- **Retry Semantics** — table:
|
|
744
|
+
|
|
745
|
+
| Operation | Retry Policy | Backoff | Max Attempts |
|
|
746
|
+
|-----------|-------------|---------|--------------|
|
|
747
|
+
|
|
748
|
+
- **Common Failure Modes** — table:
|
|
749
|
+
|
|
750
|
+
| Failure Scenario | Symptoms | Root Cause | Recovery |
|
|
751
|
+
|------------------|----------|------------|----------|
|
|
752
|
+
|
|
753
|
+
- **Alerting / Monitoring** — what conditions trigger alerts, severity mapping.
|
|
754
|
+
- **Graceful Degradation** — behavior when dependencies are unavailable.
|
|
755
|
+
|
|
756
|
+
---
|
|
757
|
+
|
|
758
|
+
### 19. State Management & Persistence
|
|
759
|
+
|
|
760
|
+
- **State Inventory** — table:
|
|
761
|
+
|
|
762
|
+
| State | Storage | Durability | Recovery Mechanism |
|
|
763
|
+
|-------|---------|------------|-------------------|
|
|
764
|
+
|
|
765
|
+
(Storage examples: in-memory, Redis, PostgreSQL, file on disk, S3, environment variable, etc.)
|
|
766
|
+
|
|
767
|
+
- **Persistence Formats** — what is serialized, where, and in what format (protobuf, JSON, MessagePack, SQL rows, Avro, WAL, etc.).
|
|
768
|
+
- **Recovery Sequences** — what happens on crash-restart, how state is reconstructed.
|
|
769
|
+
- **Schema / State Migration** — how persistent state evolves across versions, migration mechanism (SQL migrations, proto field evolution, versioned keys, etc.).
|
|
770
|
+
|
|
771
|
+
---
|
|
772
|
+
|
|
773
|
+
### 20. Reusable Modules for Future Projects
|
|
774
|
+
|
|
775
|
+
Rate reusability with stars (★). Three tiers:
|
|
776
|
+
|
|
777
|
+
#### 20.1 Highly Reusable (Framework-Level) — ★★★★★
|
|
778
|
+
|
|
779
|
+
Table:
|
|
780
|
+
|
|
781
|
+
| Module | Path | Description |
|
|
782
|
+
|--------|------|-------------|
|
|
783
|
+
|
|
784
|
+
#### 20.2 Moderately Reusable (Pattern-Level) — ★★★★
|
|
785
|
+
|
|
786
|
+
Table:
|
|
787
|
+
|
|
788
|
+
| Module | Path |
|
|
789
|
+
|--------|------|
|
|
790
|
+
|
|
791
|
+
#### 20.3 Pattern Templates (Design-Level) — ★★★
|
|
792
|
+
|
|
793
|
+
Table:
|
|
794
|
+
|
|
795
|
+
| Pattern | Where Used | Description |
|
|
796
|
+
|---------|-----------|-------------|
|
|
797
|
+
|
|
798
|
+
---
|
|
799
|
+
|
|
800
|
+
### 21. Key Design Patterns
|
|
801
|
+
|
|
802
|
+
**Expected length: 2-4 pages with code snippets**
|
|
803
|
+
|
|
804
|
+
For each significant pattern (typically 4–8), provide a COMPLETE writeup:
|
|
805
|
+
|
|
806
|
+
#### Per-Pattern Template
|
|
807
|
+
|
|
808
|
+
```markdown
|
|
809
|
+
#### 21.X {PatternName} Pattern
|
|
810
|
+
|
|
811
|
+
**Description**: 2-4 sentences explaining the pattern and why it's used here.
|
|
812
|
+
|
|
813
|
+
**Where Used**:
|
|
814
|
+
- `path/to/file1.ext:linenum` — context
|
|
815
|
+
- `path/to/file2.ext:linenum` — context
|
|
816
|
+
|
|
817
|
+
**Implementation** (actual code from codebase):
|
|
818
|
+
```{language}
|
|
819
|
+
// Actual code snippet showing the pattern
|
|
820
|
+
// Include 10-30 lines, not just 2-3
|
|
821
|
+
// Add inline comments explaining key parts
|
|
822
|
+
```
|
|
823
|
+
|
|
824
|
+
**Anti-Pattern to Avoid**:
|
|
825
|
+
```{language}
|
|
826
|
+
// Show what NOT to do
|
|
827
|
+
// This helps AI agents avoid common mistakes
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
**When to Apply**: Guidance on when new code should use this pattern.
|
|
831
|
+
```
|
|
832
|
+
|
|
833
|
+
**MANDATORY**: Code snippets must be ACTUAL CODE from the codebase, not pseudocode or simplified examples. Include enough context (10-30 lines) to understand the pattern.
|
|
834
|
+
|
|
835
|
+
---
|
|
836
|
+
|
|
837
|
+
### 22. Configuration & Tuning
|
|
838
|
+
|
|
839
|
+
#### 22.1 Key Configuration Parameters
|
|
840
|
+
|
|
841
|
+
Table (aim for the 10–20 most important):
|
|
842
|
+
|
|
843
|
+
| Parameter / Flag / Env Var | Default | Purpose |
|
|
844
|
+
|----------------------------|---------|---------|
|
|
845
|
+
|
|
846
|
+
Look for configuration in ALL of these locations:
|
|
847
|
+
- CLI flags / arguments (gflags, argparse, cobra, clap, etc.)
|
|
848
|
+
- Environment variables
|
|
849
|
+
- Config files (YAML, TOML, JSON, .env, .ini, application.properties)
|
|
850
|
+
- Feature flags / remote config
|
|
851
|
+
- Constants in code that are clearly tuning knobs
|
|
852
|
+
|
|
853
|
+
#### 22.2 Scheduling / Periodic Configuration
|
|
854
|
+
|
|
855
|
+
Describe how recurring work is configured (cron jobs, intervals, frequencies, tickers, scheduled tasks, background workers).
|
|
856
|
+
|
|
857
|
+
#### 22.3 Relevant Config Code
|
|
858
|
+
|
|
859
|
+
Show any configuration-related enums, structs, schemas, or validation logic as code blocks.
|
|
860
|
+
|
|
861
|
+
---
|
|
862
|
+
|
|
863
|
+
### 23. Performance Characteristics & Hot Paths
|
|
864
|
+
|
|
865
|
+
- **Hot Paths** — identify performance-critical code paths with file references.
|
|
866
|
+
- **Scaling Dimensions** — table:
|
|
867
|
+
|
|
868
|
+
| Dimension | Scales With | Bottleneck |
|
|
869
|
+
|-----------|------------|------------|
|
|
870
|
+
|
|
871
|
+
- **Memory Profile** — large memory consumers, budgets, OOM risks.
|
|
872
|
+
- **I/O Patterns** — disk I/O, network I/O, database queries, and their expected characteristics.
|
|
873
|
+
- **Known Performance Pitfalls** — specific scenarios that cause degradation.
|
|
874
|
+
|
|
875
|
+
---
|
|
876
|
+
|
|
877
|
+
### 24. How to Extend — Step-by-Step Cookbooks
|
|
878
|
+
|
|
879
|
+
For each major extension point, provide a numbered, file-by-file cookbook that an AI agent can follow mechanically. Adapt the cookbook titles to match the module's actual extension points.
|
|
880
|
+
|
|
881
|
+
#### 24.1 "How to Add a New [Plugin / Handler / Algorithm / Middleware / Endpoint / ...]"
|
|
882
|
+
|
|
883
|
+
1. File to create and naming convention (path)
|
|
884
|
+
2. Interface / base class to implement (required vs. optional methods)
|
|
885
|
+
3. Where to register (registry file, module init, decorator, config entry)
|
|
886
|
+
4. Build / package dependencies to add
|
|
887
|
+
5. Configuration to add (if any)
|
|
888
|
+
6. Tests required (minimum expectations)
|
|
889
|
+
7. Schema / API definition changes needed (if any)
|
|
890
|
+
8. **Minimal working example** — the simplest possible implementation that compiles / runs and passes tests
|
|
891
|
+
|
|
892
|
+
#### 24.2 "How to Add a New API Endpoint"
|
|
893
|
+
|
|
894
|
+
1. Definition file to modify (proto, OpenAPI, GraphQL schema, route file)
|
|
895
|
+
2. Handler / controller implementation to create or extend
|
|
896
|
+
3. Client / SDK changes needed (if applicable)
|
|
897
|
+
4. Validation and auth requirements
|
|
898
|
+
5. Testing approach
|
|
899
|
+
|
|
900
|
+
#### 24.3 "How to Add a New Data Source / Sink / Integration"
|
|
901
|
+
|
|
902
|
+
1. Client / adapter to create
|
|
903
|
+
2. Registration / configuration mechanism
|
|
904
|
+
3. Serialization / schema requirements
|
|
905
|
+
4. Error handling and retry requirements
|
|
906
|
+
5. Testing approach (mocks, test containers, etc.)
|
|
907
|
+
|
|
908
|
+
---
|
|
909
|
+
|
|
910
|
+
### 25. Build System & Development Workflow
|
|
911
|
+
|
|
912
|
+
- **Build System** — identify what is used:
|
|
913
|
+
- C/C++: Bazel, CMake, Make, Meson, Buck
|
|
914
|
+
- Go: `go build`, Bazel
|
|
915
|
+
- Python: pip, poetry, setuptools, conda
|
|
916
|
+
- Java/Kotlin: Maven, Gradle, Bazel
|
|
917
|
+
- TypeScript/JavaScript: npm, yarn, pnpm, Vite, webpack, esbuild
|
|
918
|
+
- Rust: Cargo
|
|
919
|
+
- Other: specify
|
|
920
|
+
|
|
921
|
+
- **Key Build Targets / Scripts** — table:
|
|
922
|
+
|
|
923
|
+
| Target / Script | Type | What It Builds / Does |
|
|
924
|
+
|-----------------|------|----------------------|
|
|
925
|
+
|
|
926
|
+
- **How to Build**:
|
|
927
|
+
- Full module: `(command)`
|
|
928
|
+
- Single component: `(command)`
|
|
929
|
+
- With debug symbols / development mode: `(command)`
|
|
930
|
+
|
|
931
|
+
- **How to Run Tests**:
|
|
932
|
+
- Full suite: `(command)`
|
|
933
|
+
- Single test file / case: `(command with example)`
|
|
934
|
+
- With sanitizers / coverage / verbose logging: `(command)`
|
|
935
|
+
|
|
936
|
+
- **How to Run Locally** (if applicable):
|
|
937
|
+
- Development server / process: `(command)`
|
|
938
|
+
- Required environment setup (databases, env vars, config files)
|
|
939
|
+
|
|
940
|
+
- **Common Build Issues** — known gotchas (dependency ordering, code generation, platform-specific issues, etc.).
|
|
941
|
+
|
|
942
|
+
- **Code Style & Naming Conventions** — file naming, class/function naming, package/module naming, config key naming conventions specific to this module.
|
|
943
|
+
|
|
944
|
+
- **CI/CD Integration** — what runs in pre-submit / PR checks, what runs nightly.
|
|
945
|
+
|
|
946
|
+
---
|
|
947
|
+
|
|
948
|
+
### 26. Testing Infrastructure
|
|
949
|
+
|
|
950
|
+
- **Test Framework** — identify what is used (GTest, pytest, Jest, JUnit, Go testing, Rust #[test], etc.) and describe any custom test harness or utilities. Reference key test infrastructure files.
|
|
951
|
+
|
|
952
|
+
- **Test Patterns** — bullet list of notable techniques:
|
|
953
|
+
- Mock / stub / fake injection points
|
|
954
|
+
- In-memory substitutes for external services
|
|
955
|
+
- Test data builders / factories / fixtures
|
|
956
|
+
- Integration test setup (test containers, embedded databases, mock servers)
|
|
957
|
+
- Test synchronization mechanisms (completion notifiers, latches, waitgroups)
|
|
958
|
+
- Snapshot / golden-file testing
|
|
959
|
+
- Property-based / fuzz testing (if present)
|
|
960
|
+
|
|
961
|
+
- **Test-to-Feature Mapping**:
|
|
962
|
+
| Feature | Test Suite Path |
|
|
963
|
+
|---------|-----------------|
|
|
964
|
+
| (e.g. User Login) | `tests/auth/test_login.py` |
|
|
965
|
+
| (e.g. Payment Processing) | `src/payments/tests/` |
|
|
966
|
+
|
|
967
|
+
- **Test Coverage Expectations** — what should be tested for new code.
|
|
968
|
+
|
|
969
|
+
---
|
|
970
|
+
|
|
971
|
+
### 27. Known Technical Debt & Limitations
|
|
972
|
+
|
|
973
|
+
- **Deprecated Code** — components marked for removal, migration status.
|
|
974
|
+
- **Known Workarounds** — significant TODO / FIXME / HACK comments with context.
|
|
975
|
+
- **Scaling Limitations** — known ceilings and their causes.
|
|
976
|
+
- **Complexity Hotspots** — Identify "God Classes", files >1000 lines, or functions with high cyclomatic complexity (deep nesting).
|
|
977
|
+
- **Design Compromises** — decisions made for expediency that should be revisited.
|
|
978
|
+
- **Migration Status** — if a V1→V2 or legacy→modern migration is in progress, document what has migrated and what has not.
|
|
979
|
+
|
|
980
|
+
---
|
|
981
|
+
|
|
982
|
+
### 28. Glossary
|
|
983
|
+
|
|
984
|
+
Table:
|
|
985
|
+
|
|
986
|
+
| Term | Definition |
|
|
987
|
+
|------|-----------|
|
|
988
|
+
|
|
989
|
+
Include ALL domain-specific terms used in the report (aim for 15–30 terms).
|
|
990
|
+
Definitions should be concise (1–2 sentences) and self-contained.
|
|
991
|
+
Include both technical terms and business/domain terms.
|
|
992
|
+
|
|
993
|
+
---
|
|
994
|
+
|
|
995
|
+
### Appendix A: File Structure Summary
|
|
996
|
+
|
|
997
|
+
Full directory tree using `├──` / `└──` notation. Each file or directory gets a brief inline annotation: `← description`. Go 2–3 levels deep for all subdirectories.
|
|
998
|
+
|
|
999
|
+
---
|
|
1000
|
+
|
|
1001
|
+
### Appendix B: Data Source → Implementation Mapping
|
|
1002
|
+
|
|
1003
|
+
Table:
|
|
1004
|
+
|
|
1005
|
+
| Data Source | Implementations / Handlers Reading It |
|
|
1006
|
+
|-------------|--------------------------------------|
|
|
1007
|
+
|
|
1008
|
+
Cover ALL data sources consumed by the module (database tables, message topics, API endpoints, file paths, config keys, etc.).
|
|
1009
|
+
|
|
1010
|
+
---
|
|
1011
|
+
|
|
1012
|
+
### Appendix C: Output Flow — Implementation to Target
|
|
1013
|
+
|
|
1014
|
+
Table:
|
|
1015
|
+
|
|
1016
|
+
| Implementation / Handler | Output Type | Target API / System |
|
|
1017
|
+
|--------------------------|------------|-------------------|
|
|
1018
|
+
|
|
1019
|
+
Map every implementation to its outputs and the external APIs / systems it calls or writes to.
|
|
1020
|
+
|
|
1021
|
+
---
|
|
1022
|
+
|
|
1023
|
+
### Appendix D: Mermaid Sequence Diagrams — Critical Flows
|
|
1024
|
+
|
|
1025
|
+
**MANDATORY: Provide 2-3 detailed Mermaid sequence diagrams** for the most complex flows.
|
|
1026
|
+
|
|
1027
|
+
Each diagram MUST include:
|
|
1028
|
+
- **All participant lifelines** (every component/service involved)
|
|
1029
|
+
- **Request → response arrows** with actual payload descriptions (not just "data")
|
|
1030
|
+
- **Conditional branches** using `alt`/`opt` blocks for different paths
|
|
1031
|
+
- **Loop blocks** for retry logic or iteration
|
|
1032
|
+
- **Notes** explaining non-obvious steps
|
|
1033
|
+
|
|
1034
|
+
Example of REQUIRED detail level:
|
|
1035
|
+
|
|
1036
|
+
```mermaid
|
|
1037
|
+
sequenceDiagram
|
|
1038
|
+
participant User
|
|
1039
|
+
participant API
|
|
1040
|
+
participant AuthService
|
|
1041
|
+
participant UserDB
|
|
1042
|
+
participant Cache
|
|
1043
|
+
|
|
1044
|
+
User->>API: POST /login {email, password}
|
|
1045
|
+
API->>AuthService: authenticate(email, password)
|
|
1046
|
+
|
|
1047
|
+
AuthService->>Cache: get(email)
|
|
1048
|
+
alt Cache Hit
|
|
1049
|
+
Cache-->>AuthService: cachedUser
|
|
1050
|
+
else Cache Miss
|
|
1051
|
+
AuthService->>UserDB: SELECT * FROM users WHERE email=?
|
|
1052
|
+
UserDB-->>AuthService: userRecord
|
|
1053
|
+
AuthService->>Cache: set(email, userRecord, TTL=300)
|
|
1054
|
+
end
|
|
1055
|
+
|
|
1056
|
+
AuthService->>AuthService: verifyPassword(password, hash)
|
|
1057
|
+
|
|
1058
|
+
alt Password Valid
|
|
1059
|
+
AuthService->>AuthService: generateJWT(userId, roles)
|
|
1060
|
+
AuthService-->>API: {token, expiresAt}
|
|
1061
|
+
API-->>User: 200 {token, user}
|
|
1062
|
+
else Password Invalid
|
|
1063
|
+
AuthService-->>API: AuthenticationError
|
|
1064
|
+
API-->>User: 401 {error: "Invalid credentials"}
|
|
1065
|
+
end
|
|
1066
|
+
```
|
|
1067
|
+
|
|
1068
|
+
**Do NOT provide simplified diagrams. Each diagram should be 20-40 lines of Mermaid code.**
|
|
1069
|
+
|
|
1070
|
+
---
|
|
1071
|
+
|
|
1072
|
+
### Appendix E: Proto Service Map (graph-derived)
|
|
1073
|
+
|
|
1074
|
+
Write the `GRAPH:proto-map` injection slot into architecture.md.
|
|
1075
|
+
|
|
1076
|
+
If graph build succeeded and proto files exist (Step 1.4.7 completed), write the populated slot content using the diagram from Step 1.4.7.
|
|
1077
|
+
|
|
1078
|
+
If graph binary was not found or no proto files exist, write the slot with placeholder:
|
|
1079
|
+
```
|
|
1080
|
+
<!-- GRAPH:proto-map:START -->
|
|
1081
|
+
[Graph data unavailable — run draft:index to populate after graph binary is installed]
|
|
1082
|
+
<!-- GRAPH:proto-map:END -->
|
|
1083
|
+
```
|
|
1084
|
+
|
|
1085
|
+
The slot markers MUST always be written — they are required for draft:index refresh to function.
|
|
1086
|
+
|
|
1087
|
+
---
|
|
1088
|
+
|
|
1089
|
+
### Expected Output Summary — Hard Minimum Thresholds
|
|
1090
|
+
|
|
1091
|
+
Before finalizing architecture.md, verify your output meets these quality gates. These are **depth and coverage checks** — the goal is a document that genuinely captures the codebase, not one that hits a line count by repeating names.
|
|
1092
|
+
|
|
1093
|
+
**Depth gates (content quality — these matter most):**
|
|
1094
|
+
|
|
1095
|
+
| Gate | FAIL condition | How to fix |
|
|
1096
|
+
|------|---------------|------------|
|
|
1097
|
+
| **Module coverage** | Any module in the top-20 fan-in list has no `#### 7.X` section | Add the missing deep-dive — read source if needed |
|
|
1098
|
+
| **Module depth** | Any top-level module section contains fewer than 150 words of prose (not counting tables/code) | Expand from source — re-read implementation files |
|
|
1099
|
+
| **Sub-module depth** | Any Large sub-module (50+ files) has no `##### 7.X.Y` section | Add sub-module deep-dive |
|
|
1100
|
+
| **No placeholder prose** | Any section contains "See X/", "similar to above", or bulleted file lists with no explanation | Replace with real content from source |
|
|
1101
|
+
| **Invariants grounded** | §15 lists fewer than 5 invariants traceable to actual source assertions or comments | Read source assertions; add real invariants |
|
|
1102
|
+
| **Data flow traced** | §6 contains no sequence diagram or step-by-step trace of at least one core request path | Read entry-point and pipeline source; write the trace |
|
|
1103
|
+
| **Code snippets real** | Any code block contains pseudocode or placeholder | Replace with actual code from source |
|
|
1104
|
+
| **All sections present** | Any of the 28 sections + 4 appendices is missing or contains only a heading | Fill with real content or state explicitly why it does not apply |
|
|
1105
|
+
|
|
1106
|
+
**Coverage scale targets** (use as a sanity check, not a hard gate — a shorter document with real depth passes; a longer document with padding fails):
|
|
1107
|
+
|
|
1108
|
+
| Tier | Label | Expected scale of §7 | Expected total scale |
|
|
1109
|
+
|------|--------|----------------------|----------------------|
|
|
1110
|
+
| 1 | micro | 3–5 modules × 150+ words | compact but complete |
|
|
1111
|
+
| 2 | small | 5–10 modules × 150+ words | substantial |
|
|
1112
|
+
| 3 | medium | 10–15 modules × 200+ words | thorough |
|
|
1113
|
+
| 4 | large | 15–20 modules × 250+ words | extensive |
|
|
1114
|
+
| 5 | XL | 20+ modules × 300+ words | exhaustive |
|
|
1115
|
+
|
|
1116
|
+
**A document that fails depth gates but hits line counts is still INCOMPLETE. A document that passes all depth gates but is shorter than expected is ACCEPTABLE.**
|
|
1117
|
+
|
|
1118
|
+
**If any depth gate fails: re-read source for the failing sections and expand. Do NOT proceed to .ai-context.md generation until all depth gates pass.**
|
|
1119
|
+
|
|
1120
|
+
**Checklist additions:**
|
|
1121
|
+
- [ ] Graph injection slots populated (GRAPH:module-deps, GRAPH:hotspots, GRAPH:proto-map) if schema.yaml exists
|
|
1122
|
+
- [ ] At least 28 + 5 appendices present (including new Appendix E)
|
|
1123
|
+
|
|
1124
|
+
---
|
|
1125
|
+
|
|
1126
|
+
### Quality Requirements
|
|
1127
|
+
|
|
1128
|
+
- Every claim must be traceable to a specific source file.
|
|
1129
|
+
- Mermaid diagrams must be syntactically valid.
|
|
1130
|
+
- Tables must have consistent column alignment.
|
|
1131
|
+
- Code snippets must be actual code from the codebase (with added inline comments for clarity), not pseudocode.
|
|
1132
|
+
- The report should be comprehensive — all sections with real data, no placeholders.
|
|
1133
|
+
- Prefer depth over brevity — this is a reference document, not a summary.
|
|
1134
|
+
- Include ALL instances (handlers, endpoints, schemas, dependencies) — do not sample or abbreviate.
|
|
1135
|
+
- When a section does not apply (per the Adaptive Sections table), state explicitly that it is skipped and why, rather than silently omitting it.
|
|
1136
|
+
|
|
1137
|
+
---
|
|
1138
|
+
|
|
1139
|
+
### Section Priority Guide
|
|
1140
|
+
|
|
1141
|
+
This table identifies which sections require the MOST depth and WHY. High-priority sections should never be abbreviated.
|
|
1142
|
+
|
|
1143
|
+
| # | Section | Depth | Diagram Required | Why This Matters |
|
|
1144
|
+
|---|---------|-------|------------------|------------------|
|
|
1145
|
+
| 1 | Executive Summary | Medium | No | Quick orientation — keep concise |
|
|
1146
|
+
| 2 | AI Agent Quick Reference | High | No | **Fast context priming** — fill ALL fields |
|
|
1147
|
+
| 3 | System Identity & Purpose | Medium | No | The "why" — 2-3 paragraphs sufficient |
|
|
1148
|
+
| 4 | Architecture Overview | **HIGH** | **YES: flowchart TD** | Visual mental model — diagram is mandatory |
|
|
1149
|
+
| 5 | Component Map & Interactions | **HIGH** | **YES: flowchart + matrix** | Know what talks to what |
|
|
1150
|
+
| 6 | Core Operational Flows, Lifecycles & State Machines | **HIGHEST** | **YES: 2–5 high-fidelity behavioral diagrams (state/sequence/flow)** | The behavioral architecture that coding assistants need most for correct implementation and modification. Highest ROI section for downstream accuracy. |
|
|
1151
|
+
| 7 | Core Modules Deep Dive | High | **YES: one workflow/state diagram per module** | Graph block primary + one diagram per module + ≤80 words synthesis. Sub-modules only when graph shows clear boundaries. |
|
|
1152
|
+
| 3.3 | Initialization Sequence | **HIGH** | **YES: sequenceDiagram** | Startup failure diagnosis — init order, dependency gates, failure paths |
|
|
1153
|
+
| 8 | Concurrency Model | High | **YES: flowchart TD** | **Prevents wrong-executor bugs** in generated code — topology must be visible |
|
|
1154
|
+
| 9 | Framework & Extension Points | High | No | Understand the plugin architecture |
|
|
1155
|
+
| 10 | Full Catalog of Implementations | Medium | No | Architecturally significant implementations and extension points (graph hotspots + public surfaces). Exhaustive helper enumeration not required. |
|
|
1156
|
+
| 11 | Secondary Subsystem (V2) | Medium | YES: flowchart | Only if V1/V2 split exists |
|
|
1157
|
+
| 12 | API & Interface Definitions | High | No | Public API surface from graph + verified source (highest-fan-in symbols first) |
|
|
1158
|
+
| 13 | External Dependencies | High | No | ALL external services/libs |
|
|
1159
|
+
| 14 | Cross-Module Integration | **HIGH** | **YES: sequence diagrams** | 2-3 sequence diagrams mandatory |
|
|
1160
|
+
| 15 | Critical Invariants | **HIGH** | No | **Prevents dangerous changes** — 8-15 invariants |
|
|
1161
|
+
| 16 | Security Architecture | Medium | No | Protocol & safety analysis |
|
|
1162
|
+
| 17 | Observability & Telemetry | Medium | No | Production readiness |
|
|
1163
|
+
| 18 | Error Handling & Failure Modes | High | **YES: flowchart TD** | Failure decision tree — AI agents need the visual, not just retry tables |
|
|
1164
|
+
| 19 | State Management | High | No | Crash recovery understanding |
|
|
1165
|
+
| 20 | Reusable Modules | Low | No | Engineer-facing only |
|
|
1166
|
+
| 21 | Key Design Patterns | High | No | **Code snippets required** — actual code |
|
|
1167
|
+
| 22 | Configuration & Tuning | High | No | 10-20 most important parameters |
|
|
1168
|
+
| 23 | Performance Characteristics | Medium | No | Engineer-facing |
|
|
1169
|
+
| 24 | How to Extend (Cookbooks) | **HIGH** | No | **Step-by-step guides** — AI agents need this |
|
|
1170
|
+
| 25 | Build System & Dev Workflow | High | No | Produce correct build commands |
|
|
1171
|
+
| 26 | Testing Infrastructure | High | No | Know how to test changes |
|
|
1172
|
+
| 27 | Tech Debt & Limitations | Medium | No | Avoid deprecated foundations |
|
|
1173
|
+
| 28 | Glossary | Medium | No | 15-30 domain terms |
|
|
1174
|
+
| A | File Structure | High | No | Full tree with annotations |
|
|
1175
|
+
| B | Data Source Mapping | High | No | Cross-reference: who reads what |
|
|
1176
|
+
| C | Output Flow Mapping | High | No | Cross-reference: who writes what |
|
|
1177
|
+
| D | Sequence Diagrams | **HIGH** | **YES: 2-3 diagrams** | Complex multi-step flows |
|
|
1178
|
+
|
|
1179
|
+
### Diagram Checklist
|
|
1180
|
+
|
|
1181
|
+
Before completing architecture.md, verify these diagrams exist:
|
|
1182
|
+
|
|
1183
|
+
- [ ] **Section 3.3**: Initialization sequence diagram — `sequenceDiagram` showing config load → dependency init → server bind → readiness gate, with `alt` blocks for each failure path
|
|
1184
|
+
- [ ] **Section 4.1**: High-level topology flowchart (flowchart TD)
|
|
1185
|
+
- [ ] **Section 5.1**: Initialization stages state machine (if applicable)
|
|
1186
|
+
- [ ] **Section 6**: Separate flowchart for EACH major data-flow path (typically 3-5 diagrams)
|
|
1187
|
+
- [ ] **Section 7**: State machine for each stateful module AND sub-module (stateDiagram-v2)
|
|
1188
|
+
- [ ] **Section 7**: Internal architecture diagram for modules with 200+ files (flowchart showing sub-module relationships)
|
|
1189
|
+
- [ ] **Section 7**: Sub-module interaction diagrams for Large sub-modules with sibling coordination patterns
|
|
1190
|
+
- [ ] **Section 7.4**: Execution topology diagram — `flowchart TD` mapping all thread pools / goroutines / actors and the queues / channels between them, with lock ordering annotated (or explicit "Single-threaded" statement if N/A)
|
|
1191
|
+
- [ ] **Section 11**: V2 architecture flowchart (if V1/V2 split exists)
|
|
1192
|
+
- [ ] **Section 14**: Sequence diagram for top 2-3 cross-module flows
|
|
1193
|
+
- [ ] **Section 16.2**: Failure decision tree — `flowchart TD` tracing error classification → retry → circuit breaker → fallback for the primary operation type
|
|
1194
|
+
- [ ] **Appendix D**: 2-3 detailed sequence diagrams with payloads
|
|
1195
|
+
|
|
1196
|
+
### Anti-Pattern Detection (Run Before Writing)
|
|
1197
|
+
|
|
1198
|
+
**MANDATORY**: Before writing architecture.md (or before finalizing each pass in the Large Codebase Generation Protocol), scan your draft for these FAILURE indicators. If ANY failure is detected, fix it BEFORE writing.
|
|
1199
|
+
|
|
1200
|
+
**FAILURE 1 — Copy-Paste Modules:**
|
|
1201
|
+
Detection: 3+ modules in Section 7 share identical or near-identical Responsibilities, description, or "Anchor files" text.
|
|
1202
|
+
Example of failure: Multiple modules all saying "Responsibilities: Implement subsystem ops, expose RPC stubs, consume ComponentContext getters."
|
|
1203
|
+
Fix: For each duplicated module, read its actual source files (interface header + one implementation file minimum) and rewrite the description to reflect what the module UNIQUELY does. Every module in a codebase does something different — describe THAT difference.
|
|
1204
|
+
|
|
1205
|
+
**FAILURE 2 — Skeleton Sequence Diagrams:**
|
|
1206
|
+
Detection: Any `sequenceDiagram` block has fewer than 15 lines of Mermaid code.
|
|
1207
|
+
Example of failure: A 5-line diagram showing `A->>B: request` / `B-->>A: response` with no payloads, no error paths, no conditional branches.
|
|
1208
|
+
Fix: Add actual payload descriptions on arrows, `alt`/`opt` blocks for conditional paths, `loop` blocks for retry logic, `Note` annotations for non-obvious steps. Target 25-40 lines per diagram.
|
|
1209
|
+
|
|
1210
|
+
**FAILURE 3 — Empty Appendices:**
|
|
1211
|
+
Detection: Appendix B, C, or D tables have fewer than 10 data rows.
|
|
1212
|
+
Fix: Cross-reference ALL data sources (Appendix B), ALL implementation outputs (Appendix C), and add 2-3 detailed sequence diagrams to Appendix D. Use graph data (`architecture.json` `.packages`/`.routes`) to enumerate exhaustively.
|
|
1213
|
+
|
|
1214
|
+
**FAILURE 4 — Missing Sub-Modules:**
|
|
1215
|
+
Detection: A module with 100+ source files (check graph data) has no Sub-Module Structure table.
|
|
1216
|
+
Fix: Read `draft/graph/modules/{name}.jsonl`, group files by immediate sub-directory, and generate the table with file counts and one-line role descriptions per sub-directory.
|
|
1217
|
+
|
|
1218
|
+
**FAILURE 4b — Shallow Sub-Module Treatment:**
|
|
1219
|
+
Detection: Large sub-modules (50+ files) listed only as table rows with no dedicated deep-dive subsection. Or ops/handler directories have no operation catalog.
|
|
1220
|
+
Example of failure: `icebox/master/` (200+ files) appears only as a row in icebox's sub-module table with "Scheduling, job management, coordination" — no `##### 7.X.Y` subsection, no key operations table, no responsibilities list.
|
|
1221
|
+
Fix: Apply the tiered sub-module analysis. For each Large sub-module, create a `##### 7.X.Y` subsection using the full sub-module deep-dive template. For each ops/handler directory, create a numbered operation catalog. Read the sub-module's interface header and implementation files before writing.
|
|
1222
|
+
|
|
1223
|
+
**FAILURE 5 — Missing Operational Diagrams:**
|
|
1224
|
+
Detection: Any of these three diagrams is absent from the document:
|
|
1225
|
+
- §3.3 initialization sequence diagram
|
|
1226
|
+
- §7.4 execution topology diagram
|
|
1227
|
+
- §16.2 failure decision tree
|
|
1228
|
+
Fix: These diagrams cannot be skipped. For single-threaded services with no concurrency, §7.4 must explicitly state "Single-threaded — no topology diagram" rather than omitting the section. For trivially simple error handling (no retries, no circuit breaker), §16.2 can be a minimal 3-node flowchart (attempt → success/error) — the section must still exist with a diagram.
|
|
1229
|
+
|
|
1230
|
+
**FAILURE 6 — No Real Code:**
|
|
1231
|
+
Detection: Code snippets are generic patterns, pseudocode, or contain only comments / TODOs. No actual code from the codebase appears.
|
|
1232
|
+
Fix: Read actual source files and extract 10-30 line snippets that illustrate design patterns, error handling, or key interfaces. Include the file path and line range.
|
|
1233
|
+
|
|
1234
|
+
**FAILURE 7 — Placeholder Tables:**
|
|
1235
|
+
Detection: Table cells contain only "See X/" directory references, "follow BUILD patterns", or similar deflections instead of real data.
|
|
1236
|
+
Fix: Read the referenced files and populate the table with specific names, types, signatures, descriptions, and file paths.
|
|
1237
|
+
|
|
1238
|
+
---
|
|
1239
|
+
|
|
1240
|
+
### Self-Check Before Completion
|
|
1241
|
+
|
|
1242
|
+
Run this checklist before writing architecture.md:
|
|
1243
|
+
|
|
1244
|
+
- [ ] **Line count**: At least 1500 lines (2500+ for 500+ file codebases)
|
|
1245
|
+
- [ ] **Diagram count**: At least 10 Mermaid diagrams present (15+ target)
|
|
1246
|
+
- [ ] **Table population**: ALL tables have real data, not placeholders — minimum 20 tables with 3+ data rows
|
|
1247
|
+
- [ ] **Code snippets**: At least 8 actual code snippets from codebase, not pseudocode
|
|
1248
|
+
- [ ] **Exhaustive enumeration**: No "and others", "etc.", "similar to above", "follow patterns"
|
|
1249
|
+
- [ ] **N/A sections**: Explicitly state why skipped, not silently omitted
|
|
1250
|
+
- [ ] **File references**: At least 100 backtick-quoted file path references
|
|
1251
|
+
- [ ] **Module uniqueness**: Every Section 7 module AND sub-module has UNIQUE description text — no copy-paste
|
|
1252
|
+
- [ ] **Sub-module depth**: Every Large sub-module (50+ files) has its own ##### deep-dive subsection; every ops/handler dir has a numbered catalog
|
|
1253
|
+
- [ ] **Sequence diagram depth**: Every sequence diagram has 15+ lines with payloads and alt/opt blocks
|
|
1254
|
+
- [ ] **Glossary completeness**: At least 20 terms defined
|
|
1255
|
+
- [ ] **Anti-patterns clear**: All anti-pattern checks above pass (including FAILURE 4b — Shallow Sub-Module Treatment)
|
|
1256
|
+
|
|
1257
|
+
**After completing analysis AND passing all checks: Write this content to `draft/architecture.md` using the Write tool. This is the PRIMARY output. Then run the Condensation Subroutine to derive .ai-context.md.**
|
|
1258
|
+
|
|
1259
|
+
---
|