forgedock 1.0.4 → 1.0.6

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.
@@ -0,0 +1,245 @@
1
+ ---
2
+ authority: required
3
+ scope: agent
4
+ applies_to: [work-on, review-pr, orchestrate, quality-gate, issue, milestone]
5
+ ---
6
+
7
+ # Using ForgeDock — Authoritative Pipeline Reference
8
+
9
+ ForgeDock is an autonomous development pipeline for Claude Code. It turns GitHub issues into the persistent context layer — agents investigate, build, review, and merge code with minimal human intervention.
10
+
11
+ ---
12
+
13
+ ## Core Principle
14
+
15
+ **GitHub issues are the persistent memory.** Every significant action is written back to the issue as a structured comment. If a session is interrupted, the next session re-reads the issue's comments and labels to reconstruct where it left off.
16
+
17
+ ---
18
+
19
+ ## Pipeline Architecture
20
+
21
+ The `/work-on` command runs the full lifecycle. A single invocation may span multiple Claude sessions — each picks up from the last state.
22
+
23
+ ### Phase Sequence
24
+
25
+ | Phase | Name | What Happens |
26
+ |-------|------|-------------|
27
+ | 0 | Context Load | Read `forge.yaml`, load issue state, classify lane |
28
+ | 1 | Investigation | Validate the issue, find root cause, read affected files |
29
+ | 2 | Decomposition | (Optional) Split large issues into sub-issues |
30
+ | 3A–3M | Build | Contract → Context → Architecture → Implement → Quality Gate → Commit |
31
+ | 4 | PR Creation | Push branch, create PR targeting the correct base branch |
32
+ | 5 | Auto-Review | Run `/review-pr --auto-merge`; domain agents review; PR merges |
33
+ | 6 | Close & Cleanup | Close issue, update project board, remove worktree |
34
+ | 7 | Trajectory | Post pipeline summary; terminal state |
35
+
36
+ ### Terminal States
37
+
38
+ The pipeline stops only when one of these labels is present:
39
+ - `workflow:merged` — PR merged, issue closed
40
+ - `workflow:invalid` — issue confirmed as not valid
41
+ - `needs-human` — blocker requires manual intervention
42
+ - `workflow:decomposed` — sub-issues spawned; each runs its own pipeline
43
+
44
+ ---
45
+
46
+ ## Lane Types
47
+
48
+ Issues route to different PR targets based on their milestone:
49
+
50
+ | Lane | Trigger | PR Target | Branch Prefix |
51
+ |------|---------|-----------|---------------|
52
+ | **Fast Lane** | Issue has no milestone | `staging` | `fix/` or `feat/` |
53
+ | **Feature Lane** | Issue has a milestone | `milestone/{slug}` | `fix/` or `feat/` |
54
+
55
+ **Never target `main` directly.** PRs go to `staging` (fast lane) or `milestone/*` (feature lane). Main receives changes only through the staging→main deploy process.
56
+
57
+ ---
58
+
59
+ ## Command Reference
60
+
61
+ ### `/work-on [issue_number]`
62
+
63
+ Runs the full pipeline for a single issue. Invoke repeatedly until the issue reaches a terminal state.
64
+
65
+ ```bash
66
+ # Pick up specific issue
67
+ /work-on 258
68
+
69
+ # Pick highest-priority open issue automatically
70
+ /work-on next
71
+ ```
72
+
73
+ **Resume behavior**: If `/work-on` was interrupted, re-invoking it reads the issue's existing comments and labels to determine which phase to resume from. No manual state management needed.
74
+
75
+ ### `/orchestrate [milestone_slug]`
76
+
77
+ Orchestrates parallel work on an entire milestone — spawns sub-agents, each running `/work-on` for a separate issue.
78
+
79
+ ```bash
80
+ /orchestrate milestone user-auth-v2
81
+ ```
82
+
83
+ ### `/review-pr [PR_number]`
84
+
85
+ Runs a multi-agent code review on a PR. 9 domain agents (API, frontend, security, infra, database, etc.) each review their area. Findings become separate GitHub issues.
86
+
87
+ ```bash
88
+ /review-pr 42
89
+ /review-pr staging # review the staging→main PR
90
+ ```
91
+
92
+ **Review findings are NOT merge blockers.** They become separate issues to fix in subsequent PRs.
93
+
94
+ ### `/issue [description]`
95
+
96
+ Creates a well-structured GitHub issue with all mandatory pipeline sections. Reads code before creating the issue to ensure file paths are accurate.
97
+
98
+ ```bash
99
+ /issue the billing page crashes when credits hit zero
100
+ /issue feat: add dark mode toggle to dashboard settings
101
+ ```
102
+
103
+ ### `/milestone [action] [name]`
104
+
105
+ Creates and manages milestones — the top-level planning layer.
106
+
107
+ ```bash
108
+ /milestone create "User Auth v2"
109
+ /milestone ship user-auth-v2
110
+ ```
111
+
112
+ ### `/quality-gate [files...]`
113
+
114
+ Runs automated checks on changed files: dead code, missing error handling, security anti-patterns, performance footguns.
115
+
116
+ ### `/analytics`
117
+
118
+ Pulls production analytics from configured sources (GSC, GA4, Umami, Clarity, Cloudflare, Stripe). Generates insights and creates actionable GitHub issues.
119
+
120
+ ### `/cleanup`
121
+
122
+ Sweeps closed issues for stale labels, prunes worktrees, cleans up stale branches.
123
+
124
+ ### `/deploy-info`
125
+
126
+ Shows what will deploy next — diffs staging vs main with issue/PR summary, risk assessment, and deploy checklist.
127
+
128
+ ### `/audit [issue_or_run]`
129
+
130
+ Traces a production issue or pipeline failure end-to-end through GitHub artifacts.
131
+
132
+ ### `/audit-agents`
133
+
134
+ Analyzes agent output from an orchestration run — timeline, stall detection, active vs idle time.
135
+
136
+ ---
137
+
138
+ ## Phase 3 Build Sub-Phases
139
+
140
+ When building, these sub-phases run in order. Every sub-phase is mandatory:
141
+
142
+ ```
143
+ 3A Re-read issue state from GitHub
144
+ 3B Classify task type (bug/feature/refactor/docs/investigation)
145
+ 3C Post Builder Contract (deliverables, acceptance criteria)
146
+ 3C.5 Context gathering (past review findings, related code paths)
147
+ 3C.6 Architecture plan (affected paths, implementation order, risk assessment)
148
+ 3D Set workflow:building label
149
+ 3E Create git worktree from source branch
150
+ 3F Implement (follow architect plan; read context before writing code)
151
+ 3F.5 Env/config completeness check
152
+ 3G Quality gate (up to 3 iterations to fix findings)
153
+ 3H Format and verify (black/isort/py_compile for Python; prettier/tsc for TypeScript)
154
+ 3I Frontend proxy wiring check (if TypeScript files changed)
155
+ 3I.5 Database configuration advisory (if DB engine patterns changed)
156
+ 3J Deployment completeness check (if new env vars introduced)
157
+ 3K Commit (conventional commit message with issue reference)
158
+ 3L Update issue body (check off completed items)
159
+ 3M Post implementation comment (FORGE:BUILDER)
160
+ ```
161
+
162
+ ---
163
+
164
+ ## Workflow Labels
165
+
166
+ Labels track pipeline state. Do not manually modify `workflow:*` labels — the pipeline manages them.
167
+
168
+ | Label | Meaning |
169
+ |-------|---------|
170
+ | `workflow:investigating` | Phase 1 in progress |
171
+ | `workflow:ready-to-build` | Investigation complete; build queued |
172
+ | `workflow:building` | Phase 3 in progress |
173
+ | `workflow:in-review` | PR created; awaiting review |
174
+ | `workflow:merged` | Pipeline complete; PR merged |
175
+ | `workflow:invalid` | Issue closed as not valid |
176
+ | `workflow:decomposed` | Issue split into sub-issues |
177
+ | `needs-human` | Pipeline stalled; manual action required |
178
+
179
+ ---
180
+
181
+ ## forge.yaml Configuration
182
+
183
+ `forge.yaml` at the project root configures all pipeline variables. Required sections:
184
+
185
+ - `project` — GitHub owner, repo name
186
+ - `paths` — local repo root, worktree base directory
187
+ - `branches` — default, staging, feature pattern
188
+
189
+ Optional sections:
190
+ - `project_board` — GitHub Projects v2 integration
191
+ - `review` — tech stack context for review agents
192
+ - `services` — analytics/monitoring endpoints
193
+ - `repos` — multi-repo satellite routing
194
+
195
+ Generate or update `forge.yaml`:
196
+
197
+ ```bash
198
+ npx forgedock init # interactive setup
199
+ npx forgedock docs init # scaffold devdocs directory
200
+ ```
201
+
202
+ ---
203
+
204
+ ## Compaction Resilience
205
+
206
+ ForgeDock is designed to survive session interruptions:
207
+
208
+ 1. Every significant step writes state to GitHub (comments + labels)
209
+ 2. Re-reading the issue at the start of each phase reconstructs all context
210
+ 3. A new session can pick up any interrupted pipeline by re-running `/work-on {number}`
211
+
212
+ **Never rely on in-memory state across phase boundaries.** Read from GitHub.
213
+
214
+ ---
215
+
216
+ ## Multi-Repo Routing
217
+
218
+ When `forge.yaml → repos.satellites` is configured, issue numbers can be prefixed to route to satellite repos:
219
+
220
+ ```bash
221
+ /work-on mcp:5 # routes to satellite repo with prefix "mcp"
222
+ /work-on sdk:12 # routes to satellite repo with prefix "sdk"
223
+ /work-on 42 # routes to default repo
224
+ ```
225
+
226
+ ---
227
+
228
+ ## Idempotency Rules
229
+
230
+ - Re-invoking `/work-on` on a completed issue is safe — it reads the terminal label and stops
231
+ - Creating a worktree that already exists: the pipeline reuses it
232
+ - Posting a duplicate phase comment: the pipeline checks for existing comments before posting
233
+ - Quality gate running on already-clean code: it passes immediately
234
+
235
+ ---
236
+
237
+ ## Common Troubleshooting
238
+
239
+ | Symptom | Cause | Resolution |
240
+ |---------|-------|------------|
241
+ | Issue stuck at `workflow:investigating` | Investigation comment missing `<!-- INVESTIGATION:COMPLETE -->` | Re-run `/work-on` — partial comments are detected and deleted |
242
+ | Merge conflict on PR | Branch diverged from base | Post comment, add `needs-human`; never auto-resolve |
243
+ | `needs-human` label set | Pipeline encountered a blocker | Read the issue comments for the specific blocker |
244
+ | Worktree already exists | Previous run was interrupted mid-build | Re-run — worktree is reused if branch is correct |
245
+ | Sub-issue pipeline not started | Parent was decomposed | Run `/work-on {sub_issue_number}` for each sub-issue |
@@ -0,0 +1,325 @@
1
+ ---
2
+ authority: required
3
+ scope: agent
4
+ applies_to: [work-on, review-pr, issue, orchestrate, quality-gate, cleanup]
5
+ ---
6
+
7
+ # Using GitHub — Authoritative Conventions Reference
8
+
9
+ This document defines how agents and developers interact with GitHub in this project. These conventions ensure the ForgeDock pipeline functions correctly and that the issue/PR/branch graph remains navigable.
10
+
11
+ ---
12
+
13
+ ## Core Principle
14
+
15
+ **Issues are the unit of work.** Every change — bug fix, feature, refactor — starts as a GitHub issue and ends as a merged PR that closes it. No direct pushes to `main` or `staging`. No PRs without a linked issue (except hotfixes with explicit justification).
16
+
17
+ ---
18
+
19
+ ## GitHub CLI (`gh`) Usage
20
+
21
+ ### Authentication
22
+
23
+ ```bash
24
+ gh auth status # verify authentication
25
+ gh auth login # authenticate if needed
26
+ ```
27
+
28
+ ### Common Flags
29
+
30
+ All commands that target a specific repository use the `-R owner/repo` flag. In ForgeDock pipelines, this is resolved from `forge.yaml`:
31
+
32
+ ```bash
33
+ GH_REPO=$(yq '.project.owner + "/" + .project.repo' forge.yaml)
34
+ GH_FLAG="-R $GH_REPO"
35
+
36
+ # Example usage
37
+ gh issue view 42 $GH_FLAG
38
+ gh pr list $GH_FLAG --state open
39
+ ```
40
+
41
+ ---
42
+
43
+ ## Issue Conventions
44
+
45
+ ### Creating Issues
46
+
47
+ Issues MUST have these four sections for pipeline compatibility:
48
+
49
+ ```markdown
50
+ ## Problem
51
+ {1-3 sentences — what is wrong or missing}
52
+
53
+ ## Affected Files
54
+ {numbered list of file paths that need changes}
55
+
56
+ ## Acceptance Criteria
57
+ - [ ] {specific, testable criterion}
58
+
59
+ ## Expected Behavior
60
+ {what should happen after the fix/feature is implemented}
61
+ ```
62
+
63
+ Use the `/issue` command to create issues — it reads code before writing, enforces structure, and checks for duplicates automatically.
64
+
65
+ ### Title Format
66
+
67
+ ```
68
+ {prefix}: {concise description}
69
+ {prefix}({scope}): {concise description}
70
+ ```
71
+
72
+ | Prefix | Use for |
73
+ |--------|---------|
74
+ | `fix:` | Bug fixes |
75
+ | `feat:` | New features |
76
+ | `refactor:` | Code restructuring, no behavior change |
77
+ | `docs:` | Documentation changes |
78
+ | `chore:` | Maintenance (version bumps, CI config) |
79
+ | `investigate:` | Research/audit tasks |
80
+
81
+ **Max 80 characters.** Be specific: `fix(billing): division by zero when user credits reach 0` not `fix: billing bug`.
82
+
83
+ ### Labels
84
+
85
+ **Priority labels** (required on all issues):
86
+
87
+ | Label | When to use |
88
+ |-------|------------|
89
+ | `priority:P0` | Production down, data loss, security vulnerability |
90
+ | `priority:P1` | Significant user-facing bug, deploy blocked |
91
+ | `priority:P2` | Minor bug, non-critical enhancement (default) |
92
+ | `priority:P3` | Cosmetic, nice-to-have, low-impact |
93
+
94
+ **Category labels** (required, one per issue):
95
+
96
+ `bug`, `enhancement`, `feature`, `refactor`, `docs`, `infra`, `performance`, `security`, `ux`, `dead-code`, `review-finding`, `audit-finding`
97
+
98
+ **Workflow labels** (managed by pipeline — do not set manually):
99
+
100
+ `workflow:investigating`, `workflow:ready-to-build`, `workflow:building`, `workflow:in-review`, `workflow:merged`, `workflow:invalid`, `workflow:decomposed`, `needs-human`
101
+
102
+ ### Checking for Duplicates
103
+
104
+ Always check before creating:
105
+
106
+ ```bash
107
+ gh issue list $GH_FLAG --state open --search "{keywords}" --limit 20 \
108
+ --json number,title,labels --jq '.[] | "#\(.number) \(.title)"'
109
+
110
+ gh issue list $GH_FLAG --state closed --search "{keywords}" --limit 10 \
111
+ --json number,title --jq '.[] | "#\(.number) [closed] \(.title)"'
112
+ ```
113
+
114
+ ---
115
+
116
+ ## Branch Naming
117
+
118
+ ### Conventions
119
+
120
+ | Type | Pattern | Example |
121
+ |------|---------|---------|
122
+ | Bug fix | `fix/{slug}-{issue_number}` | `fix/billing-zero-credits-42` |
123
+ | Feature | `feat/{slug}-{issue_number}` | `feat/dark-mode-toggle-58` |
124
+ | Fast lane (any) | `fix/` or `feat/` prefix | (same as above) |
125
+ | Feature lane | `feat/{slug}-{issue_number}` on `milestone/{slug}` branch | — |
126
+
127
+ **Slug rules**: lowercase, hyphenated, max 40 chars, derived from issue title.
128
+
129
+ ### Source Branch Rules
130
+
131
+ | Lane | Issue has milestone? | Branch from |
132
+ |------|---------------------|------------|
133
+ | Fast | No | `origin/staging` |
134
+ | Feature | Yes | `origin/milestone/{slug}` |
135
+ | Review-finding | Has `Code branch: \`{branch}\`` in body | `origin/{branch}` |
136
+
137
+ ### Git Worktrees
138
+
139
+ ForgeDock uses git worktrees for isolation. Each issue gets its own worktree:
140
+
141
+ ```bash
142
+ WORKTREE_PATH="{repo_root}/.claude/worktrees/{branch}"
143
+ git worktree add "$WORKTREE_PATH" -b "{branch}" origin/{source_branch}
144
+ ```
145
+
146
+ **Never work directly in the main repo checkout when a worktree exists.** All file reads, writes, and git operations for an active issue happen in the worktree.
147
+
148
+ ---
149
+
150
+ ## PR Conventions
151
+
152
+ ### Target Branch Rules
153
+
154
+ | Situation | PR Base |
155
+ |-----------|---------|
156
+ | Fast-lane issue (no milestone) | `staging` |
157
+ | Feature-lane issue (has milestone) | `milestone/{slug}` |
158
+ | **NEVER** | `main` |
159
+
160
+ `main` receives changes only through the staging review process (`/review-pr staging`).
161
+
162
+ ### PR Body Structure
163
+
164
+ ```markdown
165
+ ## Summary
166
+ {1-3 sentences describing what changed and why}
167
+
168
+ ## Changes
169
+ - {file or component}: {what changed}
170
+ - {file or component}: {what changed}
171
+
172
+ ## Testing
173
+ - [ ] {test scenario 1}
174
+ - [ ] {test scenario 2}
175
+
176
+ ---
177
+ Closes #{issue_number}
178
+ **Implementation branch**: `{branch}`
179
+ **Base**: `{pr_base}`
180
+ ```
181
+
182
+ **`Closes #{N}` does not auto-close** for non-default-branch PRs. The pipeline explicitly closes the issue after merge.
183
+
184
+ ### PR Title Format
185
+
186
+ ```
187
+ {Fix|Feat|Refactor|Docs}: {description}
188
+ ```
189
+
190
+ Capitalize the prefix. Match the issue prefix. Examples:
191
+ - `Fix: billing division by zero when user credits reach 0`
192
+ - `Feat: dark mode toggle for dashboard settings`
193
+
194
+ ---
195
+
196
+ ## Commit Conventions
197
+
198
+ ### Format
199
+
200
+ ```
201
+ {type}({scope}): {description} (#{issue_number})
202
+ ```
203
+
204
+ | Field | Rules |
205
+ |-------|-------|
206
+ | `type` | `fix`, `feat`, `refactor`, `docs`, `chore`, `test` |
207
+ | `scope` | optional; component name in parentheses |
208
+ | `description` | imperative mood, lowercase, no period, under 72 chars |
209
+ | `#{issue_number}` | always reference the issue |
210
+
211
+ ### Examples
212
+
213
+ ```
214
+ fix(billing): prevent division by zero when user credits reach 0 (#42)
215
+ feat(dashboard): add dark mode toggle to settings page (#58)
216
+ refactor(api): extract pagination logic into shared utility (#71)
217
+ docs(config): document devdocs frontmatter authority field (#258)
218
+ chore: bump version to 1.2.0 [skip ci]
219
+ ```
220
+
221
+ ### Multi-line Commits
222
+
223
+ When more context is needed:
224
+
225
+ ```
226
+ fix(api): handle null response from external payment provider (#99)
227
+
228
+ The Stripe webhook handler did not handle the case where the payment
229
+ provider returns a null payment_intent. Added null guard and fallback
230
+ to pending state with retry scheduling.
231
+ ```
232
+
233
+ ### Rules
234
+
235
+ - **Imperative mood**: "add" not "added", "fix" not "fixed"
236
+ - **No period** at the end
237
+ - **Under 72 characters** on the first line
238
+ - **Always reference the issue**: `(#{N})`
239
+ - **`[skip ci]`**: only for pure documentation or version bump commits
240
+
241
+ ---
242
+
243
+ ## Label Management
244
+
245
+ ### Creating Missing Labels
246
+
247
+ ```bash
248
+ gh label create "workflow:investigating" --color "1D76DB" -R $GH_REPO
249
+ gh label create "priority:P2" --color "FBCA04" -R $GH_REPO
250
+ gh label create "review-finding" --color "D93F0B" -R $GH_REPO
251
+ ```
252
+
253
+ ### Bulk Label Sync
254
+
255
+ Use `/cleanup` to sweep for stale labels, missing workflow states, and project board gaps.
256
+
257
+ ---
258
+
259
+ ## Project Board Integration
260
+
261
+ ForgeDock commands automatically update the GitHub Projects v2 board when `project_board` is configured in `forge.yaml`. Status moves through: Todo → In Progress → Done.
262
+
263
+ To manually add an issue to the board:
264
+
265
+ ```bash
266
+ gh project item-add {project_number} --owner {owner} --url "{issue_url}"
267
+ ```
268
+
269
+ ---
270
+
271
+ ## Common gh CLI Patterns
272
+
273
+ ### View Issue with Comments
274
+
275
+ ```bash
276
+ gh issue view {number} $GH_FLAG --json number,title,body,labels,state,comments
277
+ gh api repos/{GH_REPO}/issues/{number}/comments \
278
+ --jq '.[] | {id: .id, author: .user.login, body: (.body | .[0:200])}'
279
+ ```
280
+
281
+ ### Find PRs for a Branch
282
+
283
+ ```bash
284
+ gh pr list $GH_FLAG --head {branch} --json number,state,title
285
+ ```
286
+
287
+ ### Close Issue with Comment
288
+
289
+ ```bash
290
+ gh issue close {number} $GH_FLAG \
291
+ --comment "Closed: PR #{pr_number} merged to \`{base}\`. Closes #{number}."
292
+ ```
293
+
294
+ ### Merge PR
295
+
296
+ ```bash
297
+ gh pr merge {pr_number} $GH_FLAG --merge --auto
298
+ ```
299
+
300
+ ### Check PR Status
301
+
302
+ ```bash
303
+ gh pr view {pr_number} $GH_FLAG --json state,mergedAt,mergeable,mergeStateStatus \
304
+ --jq '{state, mergedAt, mergeable, mergeStateStatus}'
305
+ ```
306
+
307
+ ### Edit Issue Labels
308
+
309
+ ```bash
310
+ gh issue edit {number} $GH_FLAG \
311
+ --add-label "workflow:building" \
312
+ --remove-label "workflow:ready-to-build"
313
+ ```
314
+
315
+ ---
316
+
317
+ ## Safety Rules
318
+
319
+ 1. **Never push to `main` directly.** Even hotfixes go through a PR.
320
+ 2. **Never force-push to shared branches** (`main`, `staging`, `milestone/*`) without explicit human approval.
321
+ 3. **Never use `--no-verify`** to skip hooks unless explicitly asked.
322
+ 4. **Always check mergeability** before posting a review verdict: `gh pr view {N} --json mergeable,mergeStateStatus`.
323
+ 5. **Never create duplicate issues.** Check open AND closed issues before creating.
324
+ 6. **Never fabricate file paths.** Verify with `git show origin/{branch}:{filepath}` before listing a file in an issue.
325
+ 7. **Review findings are NOT merge blockers.** They become separate issues to fix later.
@@ -0,0 +1,122 @@
1
+ ---
2
+ authority: required
3
+ scope: project
4
+ applies_to: [work-on, review-pr, issue, orchestrate]
5
+ ---
6
+
7
+ # System Architecture
8
+
9
+ This file describes the system architecture and domain organization for this project. Pipeline agents read this file to understand how components relate, where boundaries lie, and which files belong to which domain.
10
+
11
+ ---
12
+
13
+ ## Instructions
14
+
15
+ Replace the placeholder content below with your project's actual architecture. Be specific about:
16
+ - Service/layer boundaries (what each component owns)
17
+ - Data flows (how data moves between components)
18
+ - Domain file locations (where to find code for each domain)
19
+
20
+ ---
21
+
22
+ ## High-Level Architecture
23
+
24
+ > Describe the system at a high level. What are the major components and how do they interact?
25
+
26
+ ```
27
+ {e.g.:
28
+ Frontend (Next.js)
29
+ ↓ /api/* proxy
30
+ API Service (FastAPI)
31
+ ↓ ↓
32
+ PostgreSQL Redis
33
+ ↓
34
+ Worker Service (Celery)
35
+ ↓
36
+ External APIs (Stripe, etc.)
37
+ }
38
+ ```
39
+
40
+ **Key architectural decisions**:
41
+ - {e.g., "All external API calls are proxied through the API service — the frontend never calls third-party APIs directly"}
42
+ - {e.g., "Workers and API share the same database but have separate connection pools"}
43
+ - {e.g., "Deploy uses blue/green — two containers run simultaneously during deploy, Traefik switches traffic"}
44
+
45
+ ---
46
+
47
+ ## Domains and File Locations
48
+
49
+ > Map each domain to its directory structure. Agents use this to find the right files quickly.
50
+
51
+ ### {Domain 1, e.g., "Authentication"}
52
+
53
+ **Responsibility**: {What this domain owns — be specific}
54
+ **Location**: `{e.g., services/api/app/auth/}`
55
+ **Key files**:
56
+ - `{filepath}` — {what it does}
57
+ - `{filepath}` — {what it does}
58
+
59
+ ### {Domain 2, e.g., "Billing & Subscriptions"}
60
+
61
+ **Responsibility**: {What this domain owns}
62
+ **Location**: `{e.g., services/api/app/billing/}`
63
+ **Key files**:
64
+ - `{filepath}` — {what it does}
65
+ - `{filepath}` — {what it does}
66
+
67
+ ### {Domain 3, e.g., "Frontend — Dashboard"}
68
+
69
+ **Responsibility**: {What this domain owns}
70
+ **Location**: `{e.g., web/src/app/dashboard/}`
71
+ **Key files**:
72
+ - `{filepath}` — {what it does}
73
+
74
+ ---
75
+
76
+ ## Data Flow
77
+
78
+ > Describe how data moves through the system for the most important operations.
79
+
80
+ ### {Key operation, e.g., "User creates a subscription"}
81
+
82
+ ```
83
+ 1. Frontend: POST /api/subscriptions
84
+ 2. API: Validate request → call Stripe
85
+ 3. Stripe: Returns subscription object
86
+ 4. API: Write to PostgreSQL (subscriptions table)
87
+ 5. API: Publish event to Redis queue
88
+ 6. Worker: Consume event → send confirmation email
89
+ ```
90
+
91
+ ---
92
+
93
+ ## Deployment Architecture
94
+
95
+ > How does the system deploy in production?
96
+
97
+ **Environment**: {e.g., single VPS, multi-region, serverless}
98
+ **Containers**: {e.g., api-blue, api-green, web, worker, postgres, redis, traefik}
99
+ **Deploy process**: {e.g., "GitHub Actions SSH → pull latest → docker compose up --force-recreate"}
100
+ **Database**: {e.g., "PostgreSQL in Docker with named volume; backups to S3 daily"}
101
+ **Secrets**: {e.g., "SOPS-encrypted secrets in infra/secrets/prod.enc.yaml; decrypted by deploy script"}
102
+
103
+ ---
104
+
105
+ ## Cross-Domain Constraints for Agents
106
+
107
+ > Rules that apply across domain boundaries — agents must follow these when building.
108
+
109
+ - {e.g., "Services never import from each other — communication is through the database or queue only"}
110
+ - {e.g., "Frontend components in `components/ui/` are shared across authenticated and public routes — never add auth-dependent hooks without a null-context guard"}
111
+ - {e.g., "All cross-service events must be idempotent — workers may process the same message more than once"}
112
+ - {e.g., "Database schema changes require a migration file — never modify the schema directly"}
113
+
114
+ ---
115
+
116
+ ## Known Architectural Footguns
117
+
118
+ > Document recurring patterns that cause bugs in this codebase. Agents read this before investigating and building.
119
+
120
+ - {e.g., "Docker named volumes are created as root-owned — always chown in the entrypoint before privilege drop"}
121
+ - {e.g., "The frontend dev server proxies /api/* to port 8000, but production uses Traefik — never hardcode ports in frontend code"}
122
+ - {e.g., "`appleboy/ssh-action` preprocesses `{{` as Go templates before SSH — use `jq` instead of docker format strings"}