forgecommandline 0.8.0__py3-none-any.whl

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.
Files changed (113) hide show
  1. forgecli/__init__.py +2 -0
  2. forgecli/ads.py +322 -0
  3. forgecli/agent.py +1093 -0
  4. forgecli/art.py +574 -0
  5. forgecli/attach.py +246 -0
  6. forgecli/brief.py +215 -0
  7. forgecli/browsercheck.py +99 -0
  8. forgecli/checkpoints.py +81 -0
  9. forgecli/city.py +833 -0
  10. forgecli/cli.py +1668 -0
  11. forgecli/config.py +194 -0
  12. forgecli/courier.py +177 -0
  13. forgecli/courier_data.py +164 -0
  14. forgecli/courier_hd.py +431 -0
  15. forgecli/courier_hd_data.bin +0 -0
  16. forgecli/courier_hd_data.py +19 -0
  17. forgecli/ghlogin.py +76 -0
  18. forgecli/github.py +54 -0
  19. forgecli/guards.py +403 -0
  20. forgecli/hooks.py +50 -0
  21. forgecli/httpapi.py +434 -0
  22. forgecli/images.py +110 -0
  23. forgecli/keys.py +152 -0
  24. forgecli/keyvault.py +320 -0
  25. forgecli/mcp.py +674 -0
  26. forgecli/memory.py +42 -0
  27. forgecli/openapi.py +331 -0
  28. forgecli/parallel.py +308 -0
  29. forgecli/prices.py +72 -0
  30. forgecli/procs.py +144 -0
  31. forgecli/providers.py +758 -0
  32. forgecli/quality.py +192 -0
  33. forgecli/repomap.py +78 -0
  34. forgecli/roster.py +227 -0
  35. forgecli/safety.py +93 -0
  36. forgecli/sandbox.py +83 -0
  37. forgecli/sessions.py +97 -0
  38. forgecli/skills.py +446 -0
  39. forgecli/tools.py +1184 -0
  40. forgecli/ui.py +860 -0
  41. forgecli/worktrees.py +79 -0
  42. forgecommandline-0.8.0.data/data/skills/commit/SKILL.md +14 -0
  43. forgecommandline-0.8.0.data/data/skills/debug/SKILL.md +17 -0
  44. forgecommandline-0.8.0.data/data/skills/explain/SKILL.md +14 -0
  45. forgecommandline-0.8.0.data/data/skills/init/SKILL.md +19 -0
  46. forgecommandline-0.8.0.data/data/skills/library/LICENSES/agent-skills-MIT.txt +21 -0
  47. forgecommandline-0.8.0.data/data/skills/library/LICENSES/wondelai-MIT.txt +23 -0
  48. forgecommandline-0.8.0.data/data/skills/library/README.md +9 -0
  49. forgecommandline-0.8.0.data/data/skills/library/_references/accessibility-checklist.md +160 -0
  50. forgecommandline-0.8.0.data/data/skills/library/_references/definition-of-done.md +67 -0
  51. forgecommandline-0.8.0.data/data/skills/library/_references/observability-checklist.md +92 -0
  52. forgecommandline-0.8.0.data/data/skills/library/_references/orchestration-patterns.md +370 -0
  53. forgecommandline-0.8.0.data/data/skills/library/_references/performance-checklist.md +238 -0
  54. forgecommandline-0.8.0.data/data/skills/library/_references/security-checklist.md +248 -0
  55. forgecommandline-0.8.0.data/data/skills/library/_references/testing-patterns.md +235 -0
  56. forgecommandline-0.8.0.data/data/skills/library/api-and-interface-design/SKILL.md +367 -0
  57. forgecommandline-0.8.0.data/data/skills/library/architecture-optimization/SKILL.md +279 -0
  58. forgecommandline-0.8.0.data/data/skills/library/architecture-optimization/references/artifact-templates.md +157 -0
  59. forgecommandline-0.8.0.data/data/skills/library/architecture-optimization/references/methods.md +87 -0
  60. forgecommandline-0.8.0.data/data/skills/library/awwwards-tier-web-application/SKILL.md +877 -0
  61. forgecommandline-0.8.0.data/data/skills/library/browser-testing-with-devtools/SKILL.md +317 -0
  62. forgecommandline-0.8.0.data/data/skills/library/ci-cd-and-automation/SKILL.md +390 -0
  63. forgecommandline-0.8.0.data/data/skills/library/code-review-and-quality/SKILL.md +398 -0
  64. forgecommandline-0.8.0.data/data/skills/library/code-simplification/SKILL.md +331 -0
  65. forgecommandline-0.8.0.data/data/skills/library/constraint-driven-development/SKILL.md +311 -0
  66. forgecommandline-0.8.0.data/data/skills/library/constraint-driven-development/references/floor-guard.md +182 -0
  67. forgecommandline-0.8.0.data/data/skills/library/context-engineering/SKILL.md +353 -0
  68. forgecommandline-0.8.0.data/data/skills/library/debugging-and-error-recovery/SKILL.md +300 -0
  69. forgecommandline-0.8.0.data/data/skills/library/deprecation-and-migration/SKILL.md +247 -0
  70. forgecommandline-0.8.0.data/data/skills/library/documentation-and-adrs/SKILL.md +297 -0
  71. forgecommandline-0.8.0.data/data/skills/library/doubt-driven-development/SKILL.md +243 -0
  72. forgecommandline-0.8.0.data/data/skills/library/frontend-ui-engineering/SKILL.md +340 -0
  73. forgecommandline-0.8.0.data/data/skills/library/git-workflow-and-versioning/SKILL.md +355 -0
  74. forgecommandline-0.8.0.data/data/skills/library/idea-refine/SKILL.md +193 -0
  75. forgecommandline-0.8.0.data/data/skills/library/idea-refine/examples.md +238 -0
  76. forgecommandline-0.8.0.data/data/skills/library/idea-refine/frameworks.md +99 -0
  77. forgecommandline-0.8.0.data/data/skills/library/idea-refine/refinement-criteria.md +113 -0
  78. forgecommandline-0.8.0.data/data/skills/library/idea-refine/scripts/idea-refine.sh +15 -0
  79. forgecommandline-0.8.0.data/data/skills/library/improve-code-quality/SKILL.md +275 -0
  80. forgecommandline-0.8.0.data/data/skills/library/improve-code-quality/references/artifact-templates.md +101 -0
  81. forgecommandline-0.8.0.data/data/skills/library/incremental-implementation/SKILL.md +249 -0
  82. forgecommandline-0.8.0.data/data/skills/library/interview-me/SKILL.md +235 -0
  83. forgecommandline-0.8.0.data/data/skills/library/observability-and-instrumentation/SKILL.md +238 -0
  84. forgecommandline-0.8.0.data/data/skills/library/performance-optimization/SKILL.md +267 -0
  85. forgecommandline-0.8.0.data/data/skills/library/performance-optimization/references/optimization-patterns.md +250 -0
  86. forgecommandline-0.8.0.data/data/skills/library/planning-and-task-breakdown/SKILL.md +257 -0
  87. forgecommandline-0.8.0.data/data/skills/library/remove-technical-debt/SKILL.md +203 -0
  88. forgecommandline-0.8.0.data/data/skills/library/remove-technical-debt/references/artifact-templates.md +79 -0
  89. forgecommandline-0.8.0.data/data/skills/library/security-and-hardening/SKILL.md +216 -0
  90. forgecommandline-0.8.0.data/data/skills/library/security-and-hardening/references/hardening-patterns.md +324 -0
  91. forgecommandline-0.8.0.data/data/skills/library/shipping-and-launch/SKILL.md +336 -0
  92. forgecommandline-0.8.0.data/data/skills/library/source-driven-development/SKILL.md +216 -0
  93. forgecommandline-0.8.0.data/data/skills/library/spec-driven-development/SKILL.md +259 -0
  94. forgecommandline-0.8.0.data/data/skills/library/system-design/SKILL.md +207 -0
  95. forgecommandline-0.8.0.data/data/skills/library/system-design/references/building-blocks.md +272 -0
  96. forgecommandline-0.8.0.data/data/skills/library/system-design/references/common-designs.md +257 -0
  97. forgecommandline-0.8.0.data/data/skills/library/system-design/references/database-scaling.md +295 -0
  98. forgecommandline-0.8.0.data/data/skills/library/system-design/references/estimation-numbers.md +250 -0
  99. forgecommandline-0.8.0.data/data/skills/library/system-design/references/four-step-process.md +286 -0
  100. forgecommandline-0.8.0.data/data/skills/library/system-design/references/reliability-operations.md +373 -0
  101. forgecommandline-0.8.0.data/data/skills/library/test-driven-development/SKILL.md +398 -0
  102. forgecommandline-0.8.0.data/data/skills/library/using-agent-skills/SKILL.md +192 -0
  103. forgecommandline-0.8.0.data/data/skills/review/SKILL.md +16 -0
  104. forgecommandline-0.8.0.data/data/skills/run/SKILL.md +17 -0
  105. forgecommandline-0.8.0.data/data/skills/security-review/SKILL.md +20 -0
  106. forgecommandline-0.8.0.data/data/skills/simplify/SKILL.md +18 -0
  107. forgecommandline-0.8.0.data/data/skills/test/SKILL.md +16 -0
  108. forgecommandline-0.8.0.data/data/skills/web-build/SKILL.md +25 -0
  109. forgecommandline-0.8.0.dist-info/METADATA +357 -0
  110. forgecommandline-0.8.0.dist-info/RECORD +113 -0
  111. forgecommandline-0.8.0.dist-info/WHEEL +5 -0
  112. forgecommandline-0.8.0.dist-info/entry_points.txt +2 -0
  113. forgecommandline-0.8.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,259 @@
1
+ ---
2
+ name: spec-driven-development
3
+ description: Creates specs before coding. Use when starting a new project, feature, or significant change and no specification exists yet. Use when drafting a PRD or requirements document with objectives and scope, or when requirements are unclear, ambiguous, or only exist as a vague idea. Use when a single requirement spans several independently testable capabilities and needs decomposing into a capability map of modules before specifying.
4
+ ---
5
+
6
+ # Spec-Driven Development
7
+
8
+ ## Overview
9
+
10
+ Write a structured specification before writing any code. The spec is the shared source of truth between you and the human engineer — it defines what we're building, why, and how we'll know it's done. Code without a spec is guessing.
11
+
12
+ ## When to Use
13
+
14
+ - Starting a new project or feature
15
+ - Requirements are ambiguous or incomplete
16
+ - The change touches multiple files or modules
17
+ - You're about to make an architectural decision
18
+ - The task would take more than 30 minutes to implement
19
+
20
+ **When NOT to use:** Single-line fixes, typo corrections, or changes where requirements are unambiguous and self-contained.
21
+
22
+ ## The Gated Workflow
23
+
24
+ Spec-driven development has four phases, preceded by a scope check (Phase 0) that activates only when one request bundles several independently testable capabilities. Do not advance to the next phase until the current one is validated.
25
+
26
+ ```
27
+ SPECIFY ──→ PLAN ──→ TASKS ──→ IMPLEMENT
28
+ │ │ │ │
29
+ ▼ ▼ ▼ ▼
30
+ Human Human Human Human
31
+ reviews reviews reviews reviews
32
+ ```
33
+
34
+ ### Phase 0: Scope Check
35
+
36
+ Most requests describe one capability. If this one does, skip this phase and go straight to Specify — Phase 0 exists for the exception, not the rule, and it puts no hierarchy on single-capability features.
37
+
38
+ **Detection.** Decompose before specifying when a single requirement bundles several independently testable capabilities:
39
+
40
+ - The requirement names distinct capabilities with their own consumers or data (e.g. identity, billing, notifications, reporting)
41
+ - Acceptance criteria cluster into groups that could ship and be verified separately
42
+ - One capability could be cut or replaced without rewriting the others' requirements
43
+
44
+ **Propose a capability map before writing any spec.** Small and reviewable — a module table plus a build order, not a project plan:
45
+
46
+ ```markdown
47
+ # Capability Map: [Initiative Name]
48
+
49
+ | Module id | Responsibility | Depends on |
50
+ |---|---|---|
51
+ | identity | Accounts, sessions, SSO | — |
52
+ | billing | Plans, invoices, payments | identity |
53
+ | notifications | Email and webhook fan-out | identity |
54
+ | reporting | Usage dashboards | billing, notifications |
55
+
56
+ Build order: identity → billing, notifications → reporting
57
+ ```
58
+
59
+ - **Stable module ids.** Kebab-case, chosen once, never renamed mid-initiative. Specs, plans, and downstream commands select work by these ids instead of guessing which spec is active.
60
+ - **Dependency direction, no cycles.** Arrows point one way. If two modules each need the other, they are one module.
61
+ - **Interfaces live at the boundary.** The map records that `billing` depends on `identity`; the contract between them belongs in the provider module's spec (see `api-and-interface-design` for designing it).
62
+
63
+ **The map is gated like every phase.** The human reviews module boundaries, dependency direction, and build order before any module spec is written. Getting the map wrong is expensive; reviewing ten lines is not.
64
+
65
+ **Then recurse per module.** Run Specify → Plan → Tasks → Implement for each module in dependency order. Each module gets its own spec, scoped to that module's objective, boundaries, and success criteria. Save the approved map at the project root and each module's spec alongside it, named by module id (`SPEC-identity.md`, `SPEC-billing.md`) — the map, not filename guessing, is the index of what exists.
66
+
67
+ ### Phase 1: Specify
68
+
69
+ Start with a high-level vision. Ask the human clarifying questions until requirements are concrete.
70
+
71
+ **Surface assumptions immediately.** Before writing any spec content, list what you're assuming:
72
+
73
+ ```
74
+ ASSUMPTIONS I'M MAKING:
75
+ 1. This is a web application (not native mobile)
76
+ 2. Authentication uses session-based cookies (not JWT)
77
+ 3. The database is PostgreSQL (based on existing Prisma schema)
78
+ 4. We're targeting modern browsers only (no IE11)
79
+ → Correct me now or I'll proceed with these.
80
+ ```
81
+
82
+ Don't silently fill in ambiguous requirements. The spec's entire purpose is to surface misunderstandings *before* code gets written — assumptions are the most dangerous form of misunderstanding.
83
+
84
+ **Write a spec document covering these six core areas:**
85
+
86
+ 1. **Objective** — What are we building and why? Who is the user? What does success look like?
87
+
88
+ 2. **Commands** — Full executable commands with flags, not just tool names.
89
+ ```
90
+ Build: npm run build
91
+ Test: npm test -- --coverage
92
+ Lint: npm run lint --fix
93
+ Dev: npm run dev
94
+ ```
95
+
96
+ 3. **Project Structure** — Where source code lives, where tests go, where docs belong.
97
+ ```
98
+ src/ → Application source code
99
+ src/components → React components
100
+ src/lib → Shared utilities
101
+ tests/ → Unit and integration tests
102
+ e2e/ → End-to-end tests
103
+ docs/ → Documentation
104
+ ```
105
+
106
+ 4. **Code Style** — One real code snippet showing your style beats three paragraphs describing it. Include naming conventions, formatting rules, and examples of good output.
107
+
108
+ 5. **Testing Strategy** — What framework, where tests live, coverage expectations, which test levels for which concerns.
109
+
110
+ 6. **Boundaries** — Three-tier system:
111
+ - **Always do:** Run tests before commits, follow naming conventions, validate inputs
112
+ - **Ask first:** Database schema changes, adding dependencies, changing CI config
113
+ - **Never do:** Commit secrets, edit vendor directories, remove failing tests without approval
114
+
115
+ **Spec template:**
116
+
117
+ ```markdown
118
+ # Spec: [Project/Feature Name]
119
+
120
+ ## Objective
121
+ [What we're building and why. User stories or acceptance criteria.]
122
+
123
+ ## Tech Stack
124
+ [Framework, language, key dependencies with versions]
125
+
126
+ ## Commands
127
+ [Build, test, lint, dev — full commands]
128
+
129
+ ## Project Structure
130
+ [Directory layout with descriptions]
131
+
132
+ ## Code Style
133
+ [Example snippet + key conventions]
134
+
135
+ ## Testing Strategy
136
+ [Framework, test locations, coverage requirements, test levels]
137
+
138
+ ## Boundaries
139
+ - Always: [...]
140
+ - Ask first: [...]
141
+ - Never: [...]
142
+
143
+ ## Success Criteria
144
+ [How we'll know this is done — specific, testable conditions]
145
+
146
+ ## Open Questions
147
+ [Anything unresolved that needs human input]
148
+ ```
149
+
150
+ **External spec tools:** This workflow is format-agnostic. If the project
151
+ already uses OpenSpec or another specification system, keep that system's
152
+ artifact format and storage conventions instead of creating a duplicate
153
+ `SPEC.md`. This skill owns the clarification, content, and approval gates; the
154
+ external tool owns how the approved spec is represented.
155
+
156
+ **Reframe instructions as success criteria.** When receiving vague requirements, translate them into concrete conditions:
157
+
158
+ ```
159
+ REQUIREMENT: "Make the dashboard faster"
160
+
161
+ REFRAMED SUCCESS CRITERIA:
162
+ - Dashboard LCP < 2.5s on 4G connection
163
+ - Initial data load completes in < 500ms
164
+ - No layout shift during load (CLS < 0.1)
165
+ → Are these the right targets?
166
+ ```
167
+
168
+ This lets you loop, retry, and problem-solve toward a clear goal rather than guessing what "faster" means.
169
+
170
+ **Stop after writing the spec (CRITICAL).** Once the spec is saved:
171
+
172
+ 1. Summarize it and list any Open Questions.
173
+ 2. Ask the human to approve it or request changes.
174
+ 3. **STOP YOUR TURN IMMEDIATELY.** Do NOT start Phase 2, invoke `planning-and-task-breakdown`, or write code in this turn. Planning starts only after the human approves the spec in a later turn.
175
+
176
+ ### Phase 2: Plan
177
+
178
+ With the validated spec, generate a technical implementation plan:
179
+
180
+ 1. Identify the major components and their dependencies
181
+ 2. Determine the implementation order (what must be built first)
182
+ 3. Note risks and mitigation strategies
183
+ 4. Identify what can be built in parallel vs. what must be sequential
184
+ 5. Define verification checkpoints between phases
185
+
186
+ > Follow `planning-and-task-breakdown` for the dependency-graph mapping and vertical-slicing mechanics behind these steps; it is the canonical source. The bullets above are a lightweight summary; if they ever diverge, `planning-and-task-breakdown` takes precedence.
187
+ >
188
+ > **Output convention:** Save the plan to `tasks/plan.md` and record the task list in the task list target defined by `planning-and-task-breakdown` (default `tasks/todo.md`; projects may designate an external tracker instead). Create `tasks/` if it does not exist. Downstream commands (`/build`, etc.) expect these defaults.
189
+
190
+ The plan should be reviewable: the human should be able to read it and say "yes, that's the right approach" or "no, change X."
191
+
192
+ ### Phase 3: Tasks
193
+
194
+ Break the plan into discrete, implementable tasks:
195
+
196
+ - Each task should be completable in a single focused session
197
+ - Each task has explicit acceptance criteria
198
+ - Each task includes a verification step (test, build, manual check)
199
+ - Tasks are ordered by dependency, not by perceived importance
200
+ - No task should require changing more than ~5 files
201
+
202
+ > Follow `planning-and-task-breakdown` for the full task-sizing and dependency-ordering mechanics; it is the canonical source. The template below is a lightweight inline form; if they ever diverge, `planning-and-task-breakdown` takes precedence.
203
+
204
+ **Task template:**
205
+ ```markdown
206
+ - [ ] Task: [Description]
207
+ - Acceptance: [What must be true when done]
208
+ - Verify: [How to confirm — test command, build, manual check]
209
+ - Files: [Which files will be touched]
210
+ ```
211
+
212
+ ### Phase 4: Implement
213
+
214
+ Execute tasks one at a time following `skills/incremental-implementation/SKILL.md` (`incremental-implementation`) and `skills/test-driven-development/SKILL.md` (`test-driven-development`). Use `skills/context-engineering/SKILL.md` (`context-engineering`) to load the right spec sections and source files at each step rather than flooding the agent with the entire spec.
215
+
216
+ ## Keeping the Spec Alive
217
+
218
+ The spec is a living document, not a one-time artifact:
219
+
220
+ - **Update when decisions change** — If you discover the data model needs to change, update the spec first, then implement.
221
+ - **Update when scope changes** — Features added or cut should be reflected in the spec.
222
+ - **Commit the spec** — The spec belongs in version control alongside the code.
223
+ - **Reference the spec in PRs** — Link back to the spec section that each PR implements.
224
+
225
+ ## Common Rationalizations
226
+
227
+ | Rationalization | Reality |
228
+ |---|---|
229
+ | "This is simple, I don't need a spec" | Simple tasks don't need *long* specs, but they still need acceptance criteria. A two-line spec is fine. |
230
+ | "I'll write the spec after I code it" | That's documentation, not specification. The spec's value is in forcing clarity *before* code. |
231
+ | "The spec will slow us down" | A 15-minute spec prevents hours of rework. Waterfall in 15 minutes beats debugging in 15 hours. |
232
+ | "Requirements will change anyway" | That's why the spec is a living document. An outdated spec is still better than no spec. |
233
+ | "The user knows what they want" | Even clear requests have implicit assumptions. The spec surfaces those assumptions. |
234
+ | "It's one big feature; splitting it is overhead" | If acceptance criteria cluster into independently testable groups, a monolithic spec forces every downstream task to reason over the whole contract. A ten-line capability map is the cheap alternative. |
235
+ | "I'll decompose during planning" | Planning slices tasks within a spec. By then the oversized artifact already exists — module boundaries and dependency direction must be decided before the spec is written, not after. |
236
+
237
+ ## Red Flags
238
+
239
+ - Starting to write code without any written requirements
240
+ - Asking "should I just start building?" before clarifying what "done" means
241
+ - Implementing features not mentioned in any spec or task list
242
+ - Making architectural decisions without documenting them
243
+ - Skipping the spec because "it's obvious what to build"
244
+ - Writing the spec and starting the plan or code in the same turn
245
+ - One spec whose requirements span several independently testable capabilities
246
+ - Module boundaries or build order decided implicitly during implementation because no capability map was approved up front
247
+
248
+ ## Verification
249
+
250
+ Before proceeding to implementation, confirm:
251
+
252
+ - [ ] The spec covers all six core areas
253
+ - [ ] The human has reviewed and approved the spec
254
+ - [ ] The turn ended after saving the spec; approval came in a later turn
255
+ - [ ] Success criteria are specific and testable
256
+ - [ ] Boundaries (Always/Ask First/Never) are defined
257
+ - [ ] The spec is saved to a file in the repository
258
+ - [ ] If the request bundles several independently testable capabilities, a capability map (module ids, dependency direction, build order) was approved before any module spec was written
259
+ - [ ] Every module spec traces to a module id in the approved map
@@ -0,0 +1,207 @@
1
+ ---
2
+ name: system-design
3
+ description: 'Design scalable distributed systems using structured approaches for load balancing, caching, database scaling, and message queues. Use when the user mentions "system design", "scale this", "high availability", "rate limiter", "design a URL shortener", "design Twitter", "design Uber", "design a news feed", "system design interview", "capacity planning", or "distributed architecture". Also trigger when estimating infrastructure requirements, choosing between microservices and monoliths, or designing for millions of concurrent users. Covers common system designs (TinyURL, feeds, chat) and back-of-the-envelope estimation. For data fundamentals, see ddia-systems. For resilience, see release-it.'
4
+ license: MIT
5
+ metadata:
6
+ author: wondelai
7
+ version: "1.4.1"
8
+ ---
9
+
10
+ # System Design Framework
11
+
12
+ A structured approach to designing large-scale distributed systems. Apply these principles when architecting new services, reviewing designs, estimating capacity, or preparing for system design discussions.
13
+
14
+ ## Core Principle
15
+
16
+ **Start with requirements, not solutions.** Jumping to architecture before understanding constraints produces over- or under-engineered systems. Scalable systems are assembled from well-understood building blocks (load balancers, caches, queues, databases, CDNs) — the skill lies in choosing the right blocks, sizing them with estimates, and owning the tradeoffs each choice introduces.
17
+
18
+ ## Scoring
19
+
20
+ **Goal: 10/10.** Score a design by how many of the eight Quick Diagnostic rows it satisfies — `score = round(passed / 8 × 10)`: 9-10 = all/nearly all rows pass — explicit requirements, real estimates, redundancy, a stated DB-scaling and caching strategy, async via queues, monitoring, and a deployment plan, with tradeoffs named; 5-6 = the design works but skips estimation, redundancy, or operations; <=3 = architecture proposed before requirements or estimates exist. Always state the current score, name the failing diagnostic rows, and give the specific fix for each.
21
+
22
+ ## The System Design Framework
23
+
24
+ Six areas for building reliable, scalable distributed systems:
25
+
26
+ ### 1. The Four-Step Process
27
+
28
+ **Core concept:** Every design follows four stages: (1) understand the problem and establish scope, (2) propose a high-level design and get buy-in, (3) dive deep into critical components, (4) wrap up with tradeoffs and future improvements.
29
+
30
+ **Why it works:** Without structure, designs either stay too abstract or get lost in premature detail. The four steps invest time proportionally — broad strokes first, depth where it matters.
31
+
32
+ **Key insights:**
33
+ - Step 1 (~5-10 min): clarifying questions, functional and non-functional requirements, agreed scale (DAU, QPS, storage)
34
+ - Step 2 (~15-20 min): high-level diagram with APIs, services, data stores, data flow arrows
35
+ - Step 3 (~15-20 min): design the 2-3 hardest or most critical components in detail
36
+ - Step 4 (~5 min): tradeoffs, bottlenecks, future improvements
37
+ - Never skip Step 1 — ambiguous scope wastes all downstream effort; get explicit agreement on assumptions
38
+
39
+ **Code applications:**
40
+
41
+ | Context | Pattern | Example |
42
+ |---------|---------|---------|
43
+ | **New service kickoff** | One-page design doc covering all four steps before coding | Requirements, API contract, data model, capacity estimate, then implementation |
44
+ | **Architecture review** | Walk reviewers through the steps sequentially | Scope, diagram, deep-dive on riskiest component, open questions |
45
+ | **Incident postmortem** | Trace the failure through the four-step lens | Which requirement was missed? Which block failed? What tradeoff bit us? |
46
+
47
+ See [references/four-step-process.md](references/four-step-process.md) when running a design end-to-end — per-stage time allocation, example clarifying questions, and tips for each of the four steps.
48
+
49
+ ### 2. Back-of-the-Envelope Estimation
50
+
51
+ **Core concept:** Use powers of two, latency numbers, and simple arithmetic to estimate QPS, storage, bandwidth, and server count before committing to an architecture.
52
+
53
+ **Why it works:** Estimation prevents over-provisioning (wasted money) and under-provisioning (outages under load). A 2-minute calculation can save weeks of rework.
54
+
55
+ **Key insights:**
56
+ - Powers of two: 2^10 ≈ 1 thousand, 2^20 ≈ 1 million, 2^30 ≈ 1 billion, 2^40 ≈ 1 trillion
57
+ - Latency: memory read ~100 ns, SSD read ~100 us, disk seek ~10 ms, same-datacenter round trip ~0.5 ms, cross-continent ~150 ms
58
+ - Availability nines: 99.9% = 8.77 hours downtime/year; 99.99% = 52.6 minutes/year
59
+ - QPS: DAU x actions-per-day / 86,400 seconds; peak is typically 2-5x average
60
+ - Storage: records-per-day x record-size x retention
61
+ - Round aggressively — the goal is order of magnitude, not precision
62
+
63
+ **Code applications:**
64
+
65
+ | Context | Pattern | Example |
66
+ |---------|---------|---------|
67
+ | **Capacity planning** | Estimate QPS, multiply by growth factor | 100M DAU x 5 actions / 86400 = ~5,800 QPS avg, ~30K peak |
68
+ | **Storage budgeting** | Per-record size x volume x retention | 500M tweets/day x 300 bytes x 365 days = ~55 TB/year |
69
+ | **SLA definition** | Convert nines to allowed downtime | Four nines = ~52 minutes downtime per year |
70
+
71
+ See [references/estimation-numbers.md](references/estimation-numbers.md) when sizing a system — full latency table, availability-nines table, and worked QPS/storage/bandwidth calculations.
72
+
73
+ ### 3. Building Blocks
74
+
75
+ **Core concept:** Scalable systems are assembled from a standard toolkit: DNS, CDN, load balancers, reverse proxies, application servers, caches, message queues, and consistent hashing.
76
+
77
+ **Why it works:** Each block trades one cost for another (a cache trades freshness for read speed; a queue trades latency for decoupling), so introduce a block only once its specific bottleneck appears — adding all of them up front just multiplies failure modes.
78
+
79
+ **Key insights:**
80
+ - Load balancers: L4 (transport layer — fast, simple) vs L7 (application layer — content-aware routing)
81
+ - Cache layers: client, CDN, web server, application (Redis/Memcached), database query cache
82
+ - Cache strategies: cache-aside (app manages), read-through, write-through (synchronous), write-behind (asynchronous)
83
+ - Message queues (Kafka, RabbitMQ, SQS): decouple producers from consumers, absorb spikes, enable async processing
84
+ - Consistent hashing: distributes keys across nodes with minimal redistribution when nodes change
85
+
86
+ **Code applications:**
87
+
88
+ | Context | Pattern | Example |
89
+ |---------|---------|---------|
90
+ | **Read-heavy workload** | Cache-aside Redis in front of database | Cache user profiles with TTL; invalidate on write |
91
+ | **Traffic spikes** | Message queue between API and workers | Enqueue image-resize jobs; workers pull at their own pace |
92
+ | **Global users** | CDN for static assets | Serve JS/CSS/images from edge; origin serves only API |
93
+ | **Uneven load** | Consistent hashing for shard assignment | Adding a node moves only ~1/n keys |
94
+
95
+ See [references/building-blocks.md](references/building-blocks.md) when choosing components — how each of DNS, CDN, load balancers, caching strategies, message queues, and consistent hashing works and when to introduce it.
96
+
97
+ ### 4. Database Design and Scaling
98
+
99
+ **Core concept:** Choose SQL vs NoSQL based on data shape and access patterns; scale vertically first, then horizontally (replication and sharding) when vertical limits are reached.
100
+
101
+ **Why it works:** The database is usually the first bottleneck. Understanding replication, sharding, and denormalization tradeoffs delays expensive re-architectures and makes growth deliberate.
102
+
103
+ **Key insights:**
104
+ - Vertical scaling is simpler but has a ceiling; horizontal is harder but nearly unlimited
105
+ - Replication: leader-follower (one writer, many readers) for read-heavy; multi-leader for multi-region writes
106
+ - Sharding: hash-based (even distribution, hard range queries), range-based (easy ranges, hotspot risk), directory-based (flexible, extra lookup)
107
+ - SQL for ACID transactions, joins, defined schema; NoSQL for flexible schema, horizontal scale, very high write throughput
108
+ - Denormalization trades storage and write complexity for read speed — use when reads dominate and data changes rarely
109
+ - Celebrity/hotspot problem: one hot shard needs secondary partitioning or a cache layer
110
+
111
+ **Code applications:**
112
+
113
+ | Context | Pattern | Example |
114
+ |---------|---------|---------|
115
+ | **Read-heavy API** | Leader-follower with read replicas | Reads to replicas, writes to leader; accept slight lag |
116
+ | **User data at scale** | Hash-based sharding on user_id | hash(user_id) % num_shards; even, independent shards |
117
+ | **Analytics dashboard** | Denormalized materialized views | Pre-join and aggregate nightly; serve from materialized table |
118
+
119
+ See [references/database-scaling.md](references/database-scaling.md) when the database is the bottleneck — replication topologies, the three sharding strategies compared, denormalization tradeoffs, and a SQL-vs-NoSQL selection guide.
120
+
121
+ ### 5. Common System Designs
122
+
123
+ **Core concept:** Most systems are variations of a small set of well-known designs: URL shortener, rate limiter, notification system, news feed, chat, search autocomplete, web crawler, unique ID generator.
124
+
125
+ **Why it works:** A mental library of known designs lets you recognize which pattern a new problem resembles and adapt it, rather than inventing from scratch.
126
+
127
+ **Key insights:**
128
+ - URL shortener: base62 encoding, key-value store, 301 vs 302 redirect tradeoff (caching vs analytics)
129
+ - Rate limiter: token bucket or sliding window at the gateway; return 429 with Retry-After
130
+ - News feed: fanout-on-write (push at post time) vs fanout-on-read (pull at read time); hybrid for celebrities
131
+ - Chat: WebSocket for real-time bidirectional messages, queue for delivery guarantees, heartbeat presence service
132
+ - Autocomplete: trie of top-k frequent queries; precompute and cache popular prefixes
133
+ - Web crawler: BFS with URL frontier, politeness (robots.txt, per-domain rate limit), dedup via content hash
134
+ - Unique IDs: UUID (simple, no coordination) vs Snowflake (64-bit, time-sortable, datacenter-aware)
135
+
136
+ **Code applications:**
137
+
138
+ | Context | Pattern | Example |
139
+ |---------|---------|---------|
140
+ | **Short link service** | Base62-encode auto-increment ID or hash | `https://short.ly/a1B2c3` maps to a key-value row |
141
+ | **API protection** | Token bucket at gateway | 100 tokens/min per key; steady refill; reject with 429 |
142
+ | **Social feed** | Hybrid fanout | Precompute feeds for <10K-follower accounts; merge celebrity posts at read time |
143
+
144
+ See [references/common-designs.md](references/common-designs.md) when a problem resembles a known design — full walkthroughs of URL shortener, rate limiter, news feed, chat, autocomplete, web crawler, and unique ID generator.
145
+
146
+ ### 6. Reliability and Operations
147
+
148
+ **Core concept:** A system is only as good as its ability to stay up, recover, and be observed. Health checks, monitoring, logging, and deployment strategies are first-class design concerns, not afterthoughts.
149
+
150
+ **Why it works:** Production systems fail in ways diagrams never predict. Operational readiness — metrics, alerts, rollback plans, redundancy — determines whether a failure is a blip or an outage.
151
+
152
+ **Key insights:**
153
+ - Health checks: liveness (is the process alive?) and readiness (can it serve traffic?) — Kubernetes uses both
154
+ - Three pillars of observability: metrics (Prometheus, Datadog), logging (ELK, CloudWatch), tracing (Jaeger, Zipkin)
155
+ - Deployments: rolling (gradual), blue-green (instant switch between identical environments), canary (small percentage first)
156
+ - Disaster recovery: RPO (acceptable data loss) and RTO (acceptable recovery time) drive backup and failover strategy
157
+ - Multi-datacenter: active-passive (failover) or active-active (requires data sync and conflict resolution)
158
+ - Autoscaling: scale on CPU, memory, queue depth, or custom metrics; always set min and max counts
159
+
160
+ **Code applications:**
161
+
162
+ | Context | Pattern | Example |
163
+ |---------|---------|---------|
164
+ | **Zero-downtime deploy** | Blue-green with health check gates | Switch to green after checks pass; keep blue as instant rollback |
165
+ | **Gradual rollout** | Canary with metric comparison | 5% traffic to new version; compare errors and latency; promote or rollback |
166
+ | **Data safety** | Define RPO/RTO, implement accordingly | RPO 1 hour = hourly backups; RTO 5 min = automated failover |
167
+
168
+ See [references/reliability-operations.md](references/reliability-operations.md) when hardening for production — health-check patterns, the observability pillars, deployment strategies, disaster-recovery (RPO/RTO), and autoscaling.
169
+
170
+ ## Common Mistakes
171
+
172
+ | Mistake | Why It Fails | Fix |
173
+ |---------|-------------|------|
174
+ | **Architecture before requirements** | Solves the wrong problem, misses constraints | Spend the first 5-10 minutes on scope: features, scale, SLA |
175
+ | **No estimation** | Provisioning off by orders of magnitude | Estimate QPS, storage, bandwidth before choosing components |
176
+ | **Single point of failure** | One component takes down the system | Redundancy at every layer: multi-server, multi-AZ, multi-region |
177
+ | **Premature sharding** | Huge operational complexity before it's needed | Vertical first, read replicas, cache aggressively, shard last |
178
+ | **Caching without invalidation** | Stale data causes bugs and confusion | Define TTL; cache-aside with explicit invalidation on writes |
179
+ | **Synchronous calls everywhere** | One slow service cascades latency to all callers | Queues for non-latency-critical paths; timeouts on sync calls |
180
+ | **Ignoring hotspots** | One shard or key hammered, others idle | Detect hot keys; add secondary partitioning or local caches |
181
+ | **No monitoring or alerting** | Users find failures before you do | Instrument metrics, logs, and traces from day one |
182
+
183
+ ## Quick Diagnostic
184
+
185
+ | Question | If No | Action |
186
+ |----------|-------|--------|
187
+ | Are functional and non-functional requirements listed? | Design rests on assumptions | Write down features, DAU, QPS, storage, latency and availability SLAs |
188
+ | Is there a QPS and storage estimate? | Capacity is a guess | DAU x actions / 86400 for QPS; records x size x retention for storage |
189
+ | Is every component redundant? | Single points of failure | Add replicas, failover, or multi-AZ per component |
190
+ | Is the database scaling strategy defined? | You hit a wall under growth | Vertical first, then read replicas, then sharding with a clear shard key |
191
+ | Is there a cache for read-heavy paths? | Database takes unnecessary load | Redis/Memcached cache-aside with defined TTL |
192
+ | Are async paths using queues? | Tight coupling, cascading failures | Decouple with Kafka/SQS for jobs, notifications, analytics |
193
+ | Is there a monitoring and alerting plan? | Blind to production failures | Define metrics, log aggregation, tracing, alert thresholds |
194
+ | Is the deployment strategy defined? | Risky all-at-once releases | Rolling, blue-green, or canary with automated rollback |
195
+
196
+ ## Further Reading
197
+
198
+ For the complete guides with detailed diagrams and walkthroughs:
199
+
200
+ - [*"System Design Interview -- An Insider's Guide"*](https://www.amazon.com/System-Design-Interview-insiders-Second/dp/B08CMF2CQF?tag=wondelai00-20) by Alex Xu (Volume 1)
201
+ - [*"System Design Interview -- An Insider's Guide: Volume 2"*](https://www.amazon.com/System-Design-Interview-Insiders-Guide/dp/1736049119?tag=wondelai00-20) by Alex Xu (Volume 2)
202
+ - [*"Designing Data-Intensive Applications"*](https://www.amazon.com/Designing-Data-Intensive-Applications-Reliable-Maintainable/dp/1449373321?tag=wondelai00-20) by Martin Kleppmann (data systems fundamentals)
203
+ - [ByteByteGo](https://bytebytego.com/) -- Alex Xu's platform with visual system design explanations
204
+
205
+ ## About the Author
206
+
207
+ **Alex Xu** is a software engineer who previously worked at Twitter, Apple, and Oracle, and the creator of ByteByteGo. His two-volume *System Design Interview* series, with over 500,000 copies sold, turned system design into a learnable, repeatable skill through structured thinking, estimation, and clear communication.