@mriekki/lean 0.4.2 → 0.4.4

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,333 @@
1
+ ---
2
+ name: system-lab
3
+ description: "Optional evidence-backed advanced system-design lab for architecture, runtime flows, APIs, failures, capacity, performance, observability, security, messaging, deployment, testing, evolution, debugging, and interview practice."
4
+ argument-hint: "[architecture|runtime|api|failure|capacity|performance|observability|security|messaging|deployment|testing|debug|changes|evolve|compare|interview|topic] [work-item]"
5
+ user-invocable: true
6
+ disable-model-invocation: true
7
+ ---
8
+
9
+ # System Lab
10
+
11
+ `/system-lab` is an optional advanced learning surface built from current repository/runtime evidence. It complements `/coach`; it does not replace the engineering workflow or authorize implementation changes.
12
+
13
+ For detailed usage, model semantics, and examples, read `docs/process/SYSTEM_DESIGN_LEARNING_WORKBENCH.md` in a greenfield consumer (or canonical `core/process/SYSTEM_DESIGN_LEARNING_WORKBENCH.md`).
14
+
15
+ ## 1. Core contract
16
+
17
+ - Start from the current repository and the minimum safe evidence needed for the requested lens.
18
+ - Treat the repository/runtime/configuration evidence as authoritative; generated diagrams are disposable projections, never a second source of truth.
19
+ - Re-discover evidence whenever the lab is invoked. Do not make the human remember to refresh or rebuild a diagram.
20
+ - Prefer the distributed `tools/lean-system-lab/system-workbench.py` when present. It always rebuilds its model from current evidence and may compare with its prior disposable snapshot.
21
+ - Never inspect Production credentials, Production data, or secret values.
22
+ - Do not change production code, configuration, infrastructure, schemas, data, or deployment state while in System Lab mode.
23
+ - Do not claim runtime behavior from static topology alone. Label evidence precisely.
24
+ - Discovered implementation defects return to the normal engineering workflow; do not silently fix them here.
25
+ - Learning is optional and never blocks delivery.
26
+
27
+ ## 2. Evidence labels
28
+
29
+ Use these labels consistently:
30
+
31
+ ```text
32
+ CONFIRMED BY CODE — directly observed in source/configuration/tests
33
+ CONFIRMED BY RUNTIME — directly observed in safe runtime/telemetry evidence
34
+ DOCUMENTED INTENT — stated in project documentation/ADR/requirements
35
+ INFERRED — reasonable interpretation from incomplete evidence
36
+ UNKNOWN — evidence is insufficient
37
+ LEARNER ASSUMPTION — value supplied for a design/capacity exercise
38
+ ```
39
+
40
+ A diagram edge is not automatically proof that a runtime call occurred. A dependency discovered from configuration/package references may still be only structural evidence.
41
+
42
+ ## 3. System-design competencies
43
+
44
+ Assess independently rather than using one generic "system design level":
45
+
46
+ ```text
47
+ requirements + scope framing
48
+ capacity estimation + workload modeling
49
+ API + contract design
50
+ service/module decomposition
51
+ data/storage selection
52
+ caching
53
+ messaging + asynchronous workflows
54
+ consistency + distributed coordination
55
+ scaling + partitioning
56
+ availability + fault tolerance
57
+ latency + performance
58
+ runtime/deployment topology
59
+ observability + SLO reasoning
60
+ security + abuse resistance
61
+ cost/complexity awareness
62
+ architecture evolution
63
+ incident/debug reasoning
64
+ testing/verification strategy
65
+ tradeoff defense
66
+ interview communication
67
+ ```
68
+
69
+ Use the common L1-L6 levels, but record evidence per competency.
70
+
71
+ ## 4. Architecture lenses
72
+
73
+ Treat one system model as the basis for multiple views:
74
+
75
+ ```text
76
+ STRUCTURE components and dependencies
77
+ RUNTIME request/event path for a scenario
78
+ API contracts, boundaries, callers, downstreams
79
+ DATA stateful components and data movement
80
+ SCALE load assumptions and bottleneck questions
81
+ FAILURE failure domains and propagation hypotheses
82
+ CONSISTENCY places state may disagree or ordering/idempotency matters
83
+ PERFORMANCE latency budgets, fan-out, saturation, timeout/retry behavior
84
+ OBSERVABILITY metrics/logs/traces/SLO evidence and gaps
85
+ SECURITY trust boundaries, authn/authz, secrets/PII exposure, abuse controls
86
+ MESSAGING producers/consumers, delivery semantics, ordering, retries, DLQ
87
+ DEPLOYMENT processes/containers/nodes/environments and rollout concerns
88
+ TESTING verification boundaries and untested risk
89
+ CHANGES architecture impact of the current/recent work item
90
+ EVOLUTION what complexity becomes justified as constraints change
91
+ ```
92
+
93
+ If evidence for a lens is absent, show the gap instead of inventing detail.
94
+
95
+ ## 5. Interactive workbench
96
+
97
+ When `tools/lean-system-lab/system-workbench.py` exists, prefer it for a current project snapshot.
98
+
99
+ The tool is read-only and dependency-free. It:
100
+
101
+ - scans current repository evidence for application/service/frontend/library/datastore/cache/messaging/external/deployment/test signals;
102
+ - records provenance for inferred components and dependencies;
103
+ - generates a stable evidence fingerprint and current Git commit when available;
104
+ - automatically compares with the prior disposable snapshot in the selected output directory;
105
+ - accepts optional explicit model JSON for richer known architecture, scenarios, failure behavior, decisions, SLOs, and metadata;
106
+ - accepts changed-file paths so a delivered work item can be overlaid on the architecture;
107
+ - creates self-contained `index.html` plus `workbench.json`;
108
+ - supports draggable nodes, search, zoom, clickable nodes/edges, scenario highlighting, lens switching, change overlays, failure exploration, capacity calculations, latency budgets, scale/evolution prompts, design drills, and interview perturbations.
109
+
110
+ Generate into a stable per-repository temp/cache directory so the prior disposable snapshot can be used for change comparison. Do not commit generated output unless explicitly requested.
111
+
112
+ ## 6. Scenario-to-architecture tracing
113
+
114
+ For a scenario such as checkout, authentication, background processing, or notification:
115
+
116
+ ```text
117
+ entry point
118
+ → participating components
119
+ → synchronous calls
120
+ → state reads/writes
121
+ → asynchronous messages
122
+ → external dependencies
123
+ → user-visible/result state
124
+ ```
125
+
126
+ Highlight only evidence-backed participants. If the sequence is inferred from topology rather than captured runtime evidence, say so.
127
+
128
+ Ask the learner to explain the path before filling gaps when that improves learning.
129
+
130
+ ## 7. Prediction before reveal
131
+
132
+ For advanced learning, default to making the human predict before revealing the explanation when practical.
133
+
134
+ Examples:
135
+
136
+ ```text
137
+ What fails if this dependency times out?
138
+ Which component becomes the bottleneck at 10x traffic?
139
+ Where can duplicate delivery cause damage?
140
+ Which signal would distinguish database latency from downstream latency?
141
+ What consistency guarantee does the requirement actually need?
142
+ ```
143
+
144
+ Do not turn every interaction into a quiz. Explanation-first remains valid when explicitly requested.
145
+
146
+ ## 8. Failure and debugging mode
147
+
148
+ Failure mode should distinguish verified behavior from topological hypotheses.
149
+
150
+ ```text
151
+ symptom/failure injection
152
+ → learner predicts impact
153
+ → identify failure boundary
154
+ → likely propagation
155
+ → distinguishing telemetry/evidence
156
+ → resilience behavior
157
+ → user-visible effect
158
+ → prevention/design alternatives
159
+ ```
160
+
161
+ Useful perturbations include database/cache/queue/dependency unavailability, slow dependency, duplicate/delayed/out-of-order messages, retry amplification, queue backlog, regional failure, network partition, bad deployment, and traffic spikes.
162
+
163
+ For `/system-lab debug`, reveal evidence incrementally and ask what evidence the learner would inspect next. Do not implement the fix in learning mode.
164
+
165
+ ## 9. Capacity and performance mode
166
+
167
+ Use explicit learner/design assumptions, not invented production numbers.
168
+
169
+ Connect:
170
+
171
+ ```text
172
+ DAU / active users
173
+ requests per user
174
+ peak multiplier
175
+ read/write mix
176
+ payload size
177
+ retention
178
+ fan-out
179
+ latency/SLO target
180
+ ```
181
+
182
+ with derived average/peak RPS, write RPS, bandwidth, storage growth, and latency-budget reasoning. Explain simplifying assumptions.
183
+
184
+ A scale slider or changed workload is a prompt to re-evaluate bottlenecks and complexity; it is not proof that a specific technology is required.
185
+
186
+ ## 10. Distributed-systems and messaging mode
187
+
188
+ Practice:
189
+
190
+ - strong/eventual/read-after-write consistency;
191
+ - optimistic concurrency and conflict handling;
192
+ - idempotency and deduplication;
193
+ - at-least-once delivery and the limits of "exactly once" claims;
194
+ - ordering and partitioning;
195
+ - retry/backoff/DLQ behavior;
196
+ - outbox/inbox patterns;
197
+ - sagas/compensation;
198
+ - distributed locks only when justified.
199
+
200
+ Use timelines when helpful. Make the learner reason about state before and after duplicate, delayed, failed, or reordered events.
201
+
202
+ ## 11. API, security, observability, testing, and deployment lenses
203
+
204
+ API:
205
+ - contract shape, validation, versioning, auth, errors, pagination, idempotency, downstream coupling.
206
+
207
+ Security:
208
+ - trust boundaries, public exposure, authentication, authorization, secret handling, PII/data classification, replay/abuse/rate limiting.
209
+
210
+ Observability:
211
+ - logs, metrics, traces, SLOs, correlation, dependency health, saturation/queue depth, evidence gaps.
212
+
213
+ Testing:
214
+ - unit/integration/contract/e2e boundaries, failure-path coverage, architecture risks not currently exercised.
215
+
216
+ Deployment:
217
+ - artifact/process/container topology, environment/config boundaries, health/readiness, scaling, rollout/rollback, region/failure-domain assumptions.
218
+
219
+ Treat missing evidence as a learning question, not a defect by itself.
220
+
221
+ ## 12. Architecture evolution and counterfactuals
222
+
223
+ Use the current system as the baseline and explore changes such as:
224
+
225
+ ```text
226
+ remove the cache
227
+ make a synchronous path asynchronous
228
+ increase traffic 10x/100x
229
+ move from SQLite to a server database
230
+ introduce multi-region requirements
231
+ split or recombine a service
232
+ add a queue/search/object store/CDN
233
+ tighten latency/availability/privacy requirements
234
+ ```
235
+
236
+ For each evolution:
237
+
238
+ ```text
239
+ problem/evidence
240
+ → change
241
+ → expected benefit
242
+ → new complexity/failure modes
243
+ → migration path
244
+ → when NOT to do it
245
+ ```
246
+
247
+ Prefer evolutionary design over cargo-cult complexity.
248
+
249
+ ## 13. Tradeoff and "why not?" drills
250
+
251
+ Challenge choices with credible alternatives:
252
+
253
+ ```text
254
+ Why not a monolith?
255
+ Why not microservices?
256
+ Why not Kafka/a queue?
257
+ Why not synchronous HTTP?
258
+ Why not cache this?
259
+ Why not shard now?
260
+ Why not retry here?
261
+ Why not use the existing relational database?
262
+ ```
263
+
264
+ The goal is to defend the simplest design that satisfies current constraints, then adapt when constraints materially change.
265
+
266
+ ## 14. Architecture decisions
267
+
268
+ When ADRs or documented decisions exist, connect diagram components/edges to them. For each major choice discuss:
269
+
270
+ ```text
271
+ context
272
+ chosen decision
273
+ alternatives
274
+ tradeoffs
275
+ consequences
276
+ revisit trigger
277
+ ```
278
+
279
+ Do not silently create durable ADRs in learning mode.
280
+
281
+ ## 15. Change-focused learning
282
+
283
+ `/system-lab changes <work-item>` should focus on the accepted/delivered change set when evidence is available.
284
+
285
+ Show:
286
+
287
+ - added/removed/changed components and dependencies;
288
+ - affected runtime/data/message paths;
289
+ - newly introduced or materially changed failure modes;
290
+ - new security/observability/performance/testing questions;
291
+ - architecture decisions or assumptions worth explaining.
292
+
293
+ A changed file is evidence that a component was touched, not proof that its runtime behavior changed. Keep that distinction visible.
294
+
295
+ ## 16. Interview mode
296
+
297
+ Make the human drive:
298
+
299
+ ```text
300
+ requirements
301
+ → constraints + scale assumptions
302
+ → API/contracts
303
+ → data/storage
304
+ → high-level architecture
305
+ → deep dive
306
+ → bottleneck/failure analysis
307
+ → consistency/reliability
308
+ → security/observability
309
+ → evolution
310
+ → tradeoff defense
311
+ ```
312
+
313
+ Perturb one material constraint at a time: 20x traffic, multi-region, strict data residency, unreliable dependency, tighter p99, zero-downtime migration, duplicate delivery, cost pressure, or new abuse threat.
314
+
315
+ Score/coach the independent system-design competencies rather than assigning one generic score.
316
+
317
+ ## 17. Cross-lab navigation
318
+
319
+ System Lab owns system context; Database Lab owns schema/query/ORM/plan depth.
320
+
321
+ When a system node represents a database, explicitly offer `/db-lab` for deeper relational/query evidence. When `/db-lab` reaches system-level concerns such as service boundaries, traffic, availability, or end-to-end runtime flow, offer `/system-lab`.
322
+
323
+ Do not duplicate database internals inside System Lab or architecture reasoning inside Database Lab.
324
+
325
+ ## 18. Delivery-completion visibility
326
+
327
+ After successful delivery, Lean may recommend the labs as optional learning while the change is fresh.
328
+
329
+ - If database-related evidence changed, make `/db-lab` or `/db-lab changes <work-item>` visibly recommended.
330
+ - If architecture/runtime/API/messaging/deployment/security/observability behavior changed, make `/system-lab` or `/system-lab changes <work-item>` visibly recommended.
331
+ - If neither is especially relevant, the labs may remain visible as available options without claiming the ticket changed them.
332
+ - Never use user-facing wording such as "rebuild the diagram" or "refresh the database model". Running a lab already means inspect current evidence and generate the current view.
333
+ - Best-effort disposable artifact generation after delivery is allowed when safe and cheap, but failure to generate a learning artifact never changes delivery state.