lgtm-specs 0.0.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.
Files changed (212) hide show
  1. package/.claude/settings.local.json +14 -0
  2. package/.gemini/README.md +8 -0
  3. package/.gemini/config.yaml +20 -0
  4. package/.gemini/styleguide.md +35 -0
  5. package/.github/workflows/README.md +5 -0
  6. package/.github/workflows/release.yml +52 -0
  7. package/.github/workflows/validate.yml +27 -0
  8. package/.prettierignore +4 -0
  9. package/.prettierrc +1 -0
  10. package/AGENTS.md +151 -0
  11. package/README.md +98 -0
  12. package/VERSION +1 -0
  13. package/agents/README.md +73 -0
  14. package/agents/modes/README.md +9 -0
  15. package/agents/modes/build.md +88 -0
  16. package/agents/modes/hack.md +76 -0
  17. package/agents/modes/review.md +79 -0
  18. package/agents/roles/builder.md +75 -0
  19. package/agents/roles/counsel.md +96 -0
  20. package/agents/roles/explorer.md +77 -0
  21. package/agents/roles/lead.md +76 -0
  22. package/agents/roles/librarian.md +63 -0
  23. package/agents/roles/planner.md +75 -0
  24. package/agents/roles/reviewer/BASE.md +9 -0
  25. package/agents/roles/reviewer/OUTPUT_FORMAT.md +4 -0
  26. package/agents/roles/reviewer/README.md +48 -0
  27. package/agents/roles/reviewer/lite.md +51 -0
  28. package/agents/roles/reviewer/logic.md +48 -0
  29. package/agents/roles/reviewer/performance.md +45 -0
  30. package/agents/roles/reviewer/plan.md +52 -0
  31. package/agents/roles/reviewer/quality.md +49 -0
  32. package/agents/roles/reviewer/security.md +47 -0
  33. package/agents/roles/reviewer/test.md +48 -0
  34. package/agents/templates/README.md +6 -0
  35. package/agents/templates/mode.md +33 -0
  36. package/agents/templates/role.md +73 -0
  37. package/contribute/README.md +24 -0
  38. package/contribute/add-agent.md +29 -0
  39. package/contribute/add-ci.md +31 -0
  40. package/contribute/add-constitution.md +17 -0
  41. package/contribute/add-law.md +20 -0
  42. package/contribute/add-policy.md +27 -0
  43. package/contribute/checklist.md +42 -0
  44. package/contribute/maintenance.md +19 -0
  45. package/contribute/update-models.md +47 -0
  46. package/docs/README.md +13 -0
  47. package/docs/adr/0001-knowledge-engineering-workflow.md +22 -0
  48. package/docs/adr/0002-rule-hierarchy.md +25 -0
  49. package/docs/adr/0003-atomic-knowledge-graph.md +21 -0
  50. package/docs/adr/0004-identification-schema.md +22 -0
  51. package/docs/adr/0005-agent-specialization.md +39 -0
  52. package/docs/adr/0006-git-workflow-integrity.md +34 -0
  53. package/docs/adr/0007-operating-modes-and-gates.md +54 -0
  54. package/docs/adr/0008-rules-vs-workflows-boundary.md +64 -0
  55. package/docs/adr/README.md +14 -0
  56. package/docs/agent_architecture.md +164 -0
  57. package/docs/context_lifecycle.md +228 -0
  58. package/docs/engineering_principles.md +128 -0
  59. package/docs/local_policies.md +59 -0
  60. package/docs/meta/collaborative_dynamics.md +142 -0
  61. package/docs/meta/domains/README.md +8 -0
  62. package/docs/meta/domains/bitcoin/01-units.md +21 -0
  63. package/docs/meta/domains/bitcoin/02-broadcast-cancellation.md +20 -0
  64. package/docs/meta/domains/bitcoin/03-fee-rates-rounding.md +21 -0
  65. package/docs/meta/domains/bitcoin/04-confirmations-reorgs.md +20 -0
  66. package/docs/meta/domains/bitcoin/05-address-gap-limit.md +16 -0
  67. package/docs/meta/domains/bitcoin/06-relay-policy.md +27 -0
  68. package/docs/meta/domains/bitcoin/README.md +12 -0
  69. package/docs/meta/domains/git/01-workflow.md +89 -0
  70. package/docs/meta/domains/git/02-commits.md +57 -0
  71. package/docs/meta/domains/git/03-collaboration.md +40 -0
  72. package/docs/meta/domains/git/04-integrity.md +26 -0
  73. package/docs/meta/domains/git/05-configuration.md +209 -0
  74. package/docs/meta/domains/git/06-advanced.md +130 -0
  75. package/docs/meta/domains/git/README.md +29 -0
  76. package/docs/meta/industry_best_practices.md +555 -0
  77. package/docs/meta/languages/README.md +8 -0
  78. package/docs/meta/languages/go/01-concurrency.md +37 -0
  79. package/docs/meta/languages/go/02-api-design.md +30 -0
  80. package/docs/meta/languages/go/03-resilience.md +27 -0
  81. package/docs/meta/languages/go/04-errors.md +27 -0
  82. package/docs/meta/languages/go/05-performance.md +18 -0
  83. package/docs/meta/languages/go/06-safety.md +18 -0
  84. package/docs/meta/languages/go/07-testing.md +44 -0
  85. package/docs/meta/languages/go/08-config-layout.md +23 -0
  86. package/docs/meta/languages/go/README.md +14 -0
  87. package/docs/meta/languages/typescript/01-strictness.md +19 -0
  88. package/docs/meta/languages/typescript/02-immutability.md +15 -0
  89. package/docs/meta/languages/typescript/03-async.md +18 -0
  90. package/docs/meta/languages/typescript/04-design.md +19 -0
  91. package/docs/meta/languages/typescript/05-control-flow.md +11 -0
  92. package/docs/meta/languages/typescript/README.md +11 -0
  93. package/docs/meta/workflow.md +68 -0
  94. package/docs/philosophy.md +36 -0
  95. package/integrate/README.md +459 -0
  96. package/integrate/versioning.md +41 -0
  97. package/models/README.md +68 -0
  98. package/models/registry.yaml +55 -0
  99. package/package.json +11 -0
  100. package/rules/README.md +57 -0
  101. package/rules/RULE-00000-EXAMPLE.md +29 -0
  102. package/rules/constitution/CONS-00001-srp.md +40 -0
  103. package/rules/constitution/CONS-00002-ocp.md +43 -0
  104. package/rules/constitution/CONS-00003-lsp.md +44 -0
  105. package/rules/constitution/CONS-00004-isp.md +46 -0
  106. package/rules/constitution/CONS-00005-dip.md +37 -0
  107. package/rules/constitution/CONS-00006-dry.md +45 -0
  108. package/rules/constitution/CONS-00007-demeter.md +35 -0
  109. package/rules/constitution/CONS-00008-composition.md +44 -0
  110. package/rules/constitution/CONS-00009-deep-modules.md +39 -0
  111. package/rules/constitution/CONS-00010-kiss.md +47 -0
  112. package/rules/constitution/CONS-00011-yagni.md +49 -0
  113. package/rules/constitution/CONS-00012-cognitive-limits.md +28 -0
  114. package/rules/constitution/CONS-00013-boy-scout.md +27 -0
  115. package/rules/constitution/CONS-00014-broken-windows.md +35 -0
  116. package/rules/constitution/CONS-00015-safety.md +46 -0
  117. package/rules/constitution/CONS-00016-cqs.md +39 -0
  118. package/rules/constitution/CONS-00017-postel.md +35 -0
  119. package/rules/constitution/CONS-00018-cap.md +35 -0
  120. package/rules/constitution/CONS-00019-fallacies.md +37 -0
  121. package/rules/constitution/CONS-00020-shift-left.md +28 -0
  122. package/rules/constitution/CONS-00021-congruence.md +28 -0
  123. package/rules/constitution/CONS-00022-orthogonality.md +40 -0
  124. package/rules/constitution/CONS-00023-determinism.md +38 -0
  125. package/rules/constitution/CONS-00024-security.md +42 -0
  126. package/rules/constitution/CONS-00025-efficiency.md +38 -0
  127. package/rules/constitution/CONS-00026-resilience.md +41 -0
  128. package/rules/constitution/CONS-00027-transparency.md +40 -0
  129. package/rules/constitution/CONS-00028-evolvability.md +36 -0
  130. package/rules/constitution/CONS-00029-operability.md +36 -0
  131. package/rules/constitution/CONS-00030-rework-cycle.md +27 -0
  132. package/rules/constitution/CONS-00031-checklist.md +28 -0
  133. package/rules/constitution/CONS-00032-documentation.md +39 -0
  134. package/rules/constitution/README.md +52 -0
  135. package/rules/laws/README.md +15 -0
  136. package/rules/laws/bitcoin/BTC-00001-amounts-as-satoshis.md +39 -0
  137. package/rules/laws/bitcoin/BTC-00002-broadcast-not-cancelable.md +36 -0
  138. package/rules/laws/bitcoin/BTC-00003-fee-rate-math-rounding.md +37 -0
  139. package/rules/laws/bitcoin/BTC-00004-confirmations-and-reorgs.md +40 -0
  140. package/rules/laws/bitcoin/BTC-00005-address-gap-limit.md +37 -0
  141. package/rules/laws/bitcoin/BTC-00006-relay-is-policy-dependent.md +36 -0
  142. package/rules/laws/bitcoin/BTC-00007-dust-policy.md +36 -0
  143. package/rules/laws/bitcoin/BTC-00008-min-relay-fee.md +36 -0
  144. package/rules/laws/bitcoin/BTC-00009-feefilter.md +36 -0
  145. package/rules/laws/bitcoin/README.md +29 -0
  146. package/rules/laws/default.md +30 -0
  147. package/rules/laws/git/GIT-00001-atomic-commit.md +29 -0
  148. package/rules/laws/git/GIT-00002-imperative-subject.md +27 -0
  149. package/rules/laws/git/GIT-00003-formatting-50-72.md +28 -0
  150. package/rules/laws/git/GIT-00004-trunk-based.md +28 -0
  151. package/rules/laws/git/GIT-00005-public-immutability.md +26 -0
  152. package/rules/laws/git/GIT-00006-signing.md +27 -0
  153. package/rules/laws/git/GIT-00007-reviewer-capital.md +26 -0
  154. package/rules/laws/git/GIT-00008-patch-series.md +28 -0
  155. package/rules/laws/git/GIT-00009-branch-naming.md +28 -0
  156. package/rules/laws/git/GIT-00010-pr-hygiene.md +51 -0
  157. package/rules/laws/git/GIT-00011-merge-method.md +35 -0
  158. package/rules/laws/git/GIT-00012-conflict-resolution.md +35 -0
  159. package/rules/laws/git/GIT-00013-ignore-standards.md +38 -0
  160. package/rules/laws/git/GIT-00014-lfs-large-binaries.md +37 -0
  161. package/rules/laws/git/GIT-00015-git-hooks.md +35 -0
  162. package/rules/laws/git/GIT-00016-branch-protection.md +34 -0
  163. package/rules/laws/git/GIT-00017-secrets-management.md +34 -0
  164. package/rules/laws/git/GIT-00018-ci-enforcement.md +33 -0
  165. package/rules/laws/git/GIT-00019-review-checklist.md +39 -0
  166. package/rules/laws/git/GIT-00020-issue-references.md +34 -0
  167. package/rules/laws/git/GIT-00021-partial-staging.md +38 -0
  168. package/rules/laws/git/GIT-00022-feature-flags.md +33 -0
  169. package/rules/laws/git/GIT-00023-breaking-changes.md +41 -0
  170. package/rules/laws/git/GIT-00024-dependency-management.md +44 -0
  171. package/rules/laws/git/GIT-00025-large-repository-optimization.md +54 -0
  172. package/rules/laws/git/README.md +31 -0
  173. package/rules/laws/go/GO-00001-actor-model.md +51 -0
  174. package/rules/laws/go/GO-00002-api-design.md +37 -0
  175. package/rules/laws/go/GO-00003-error-handling.md +43 -0
  176. package/rules/laws/go/GO-00004-context.md +45 -0
  177. package/rules/laws/go/GO-00005-performance.md +40 -0
  178. package/rules/laws/go/GO-00006-packages.md +29 -0
  179. package/rules/laws/go/GO-00007-circuit-breakers.md +43 -0
  180. package/rules/laws/go/GO-00008-safety.md +39 -0
  181. package/rules/laws/go/GO-00009-table-driven-test.md +48 -0
  182. package/rules/laws/go/GO-00010-escape-analysis.md +37 -0
  183. package/rules/laws/go/GO-00011-retry.md +45 -0
  184. package/rules/laws/go/GO-00012-rate-limiting.md +42 -0
  185. package/rules/laws/go/GO-00013-io-buffering.md +43 -0
  186. package/rules/laws/go/GO-00014-memory-layout.md +41 -0
  187. package/rules/laws/go/GO-00015-aaa-pattern.md +49 -0
  188. package/rules/laws/go/GO-00016-test-libraries.md +35 -0
  189. package/rules/laws/go/GO-00017-comments.md +37 -0
  190. package/rules/laws/go/GO-00018-test-isolation.md +38 -0
  191. package/rules/laws/go/GO-00019-test-comments.md +36 -0
  192. package/rules/laws/go/GO-00020-mocking.md +36 -0
  193. package/rules/laws/go/GO-00021-configuration.md +36 -0
  194. package/rules/laws/go/GO-00022-observability.md +34 -0
  195. package/rules/laws/go/GO-00023-dependency-management.md +28 -0
  196. package/rules/laws/go/GO-00024-project-layout.md +30 -0
  197. package/rules/laws/go/GO-00025-concurrency-patterns.md +39 -0
  198. package/rules/laws/go/README.md +45 -0
  199. package/rules/laws/typescript/README.md +14 -0
  200. package/rules/laws/typescript/TS-00001-no-any.md +39 -0
  201. package/rules/laws/typescript/TS-00002-immutability.md +36 -0
  202. package/rules/laws/typescript/TS-00003-async.md +35 -0
  203. package/rules/laws/typescript/TS-00004-strict-null.md +38 -0
  204. package/rules/laws/typescript/TS-00005-unions.md +35 -0
  205. package/rules/laws/typescript/TS-00006-interface.md +38 -0
  206. package/rules/laws/typescript/TS-00007-generics.md +38 -0
  207. package/rules/laws/typescript/TS-00008-modules.md +28 -0
  208. package/rules/policies/README.md +12 -0
  209. package/rules/policies/default.md +28 -0
  210. package/scripts/README.md +45 -0
  211. package/scripts/generate_release_notes.py +376 -0
  212. package/scripts/validate_specs.py +730 -0
@@ -0,0 +1,555 @@
1
+ # Engineering Best Practices & Master Rule List
2
+
3
+ This document is the "Source of Truth" for all engineering standards enforced by LGTM. It groups principles by their intellectual lineage and provides primary source references.
4
+
5
+ **Table of Contents**
6
+
7
+ 1. [SOLID Principles](#1-solid-principles)
8
+ 2. [A Philosophy of Software Design](#2-a-philosophy-of-software-design)
9
+ 3. [Universal Fundamentals](#3-universal-fundamentals)
10
+ 4. [Pragmatic Programmer & Code Health](#4-pragmatic-programmer--code-health)
11
+ 5. [Systems Theory & Dynamics](#5-systems-theory--dynamics)
12
+ 6. [Formal Methods & Correctness](#6-formal-methods--correctness)
13
+ 7. [Distributed Systems](#7-distributed-systems)
14
+ 8. [Classic Engineering Wisdom](#8-classic-engineering-wisdom)
15
+ 9. [Security Engineering](#9-security-engineering)
16
+ 10. [Testing & Verification](#10-testing--verification)
17
+ 11. [Observability & Operations](#11-observability--operations)
18
+ 12. [Performance & Efficiency](#12-performance--efficiency)
19
+ 13. [Data Engineering](#13-data-engineering)
20
+ 14. [Delivery & Evolution](#14-delivery--evolution)
21
+ 15. [Dependency Management](#15-dependency-management)
22
+ 16. [API Design](#16-api-design)
23
+ 17. [Privacy & Compliance](#17-privacy--compliance)
24
+ 18. [Operational Reliability](#18-operational-reliability)
25
+
26
+ ---
27
+
28
+ # 1. SOLID Principles
29
+
30
+ _Source: [Robert C. Martin (Uncle Bob)](https://en.wikipedia.org/wiki/SOLID)_
31
+ A framework for managing dependencies and structural complexity in object-oriented design.
32
+
33
+ ## 1.1 Single Responsibility Principle (SRP)
34
+
35
+ **Definition**: A module should have one, and only one, reason to change.
36
+
37
+ - **Requirement**: A class handling business logic must NOT handle database queries directly.
38
+ - **Requirement**: All methods in a class should operate on the same set of state variables (High Cohesion).
39
+ - **Requirement**: Separate "Policy" (Business Rules) from "Mechanism" (IO/Frameworks).
40
+
41
+ ## 1.2 Open/Closed Principle (OCP)
42
+
43
+ **Definition**: Software entities should be open for extension but closed for modification.
44
+
45
+ - **Requirement**: Use interfaces or abstract classes to allow behavior changes.
46
+ - **Requirement**: Do not modify stable classes to add features if Inheritance or Decorators can be used.
47
+ - **Requirement**: Prefer injecting a Strategy object over adding `if/else` blocks for new cases.
48
+
49
+ ## 1.3 Liskov Substitution Principle (LSP)
50
+
51
+ **Definition**: Subtypes must be substitutable for their base types without altering correctness.
52
+
53
+ - **Requirement**: A subclass must accept the same inputs and guarantee the same post-conditions.
54
+ - **Requirement**: A subclass must not throw exceptions that are not part of the parent's contract.
55
+
56
+ ## 1.4 Interface Segregation Principle (ISP)
57
+
58
+ **Definition**: Clients should not be forced to depend on interfaces they do not use.
59
+
60
+ - **Requirement**: Split "God Interfaces" (e.g., `IUserHandler`) into role-specific ones (`IUserReader`).
61
+ - **Requirement**: Functions should accept the smallest interface possible (e.g., `func(Reader)` not `func(File)`).
62
+
63
+ ## 1.5 Dependency Inversion Principle (DIP)
64
+
65
+ **Definition**: High-level modules should not depend on low-level modules. Both should depend on abstractions.
66
+
67
+ - **Requirement**: Dependencies must be passed in (Dependency Injection), not instantiated internally.
68
+ - **Requirement**: Imports in domain logic should point to `types/` or `interfaces/`, not `infrastructure/`.
69
+
70
+ ---
71
+
72
+ # 2. A Philosophy of Software Design
73
+
74
+ _Source: [John Ousterhout](https://web.stanford.edu/~ouster/cgi-bin/aposd.php)_
75
+ A tactical approach to managing complexity by focusing on module depth and information hiding.
76
+
77
+ ## 2.1 Deep Modules
78
+
79
+ **Definition**: Interfaces must be significantly simpler than their implementations.
80
+
81
+ - **Requirement**: Maximize the amount of work done per line of interface code.
82
+ - **Requirement**: Reject "Shallow Modules" that add layers (cognitive load) without hiding significant complexity.
83
+ - **Requirement**: Reject pass-through methods that just delegate to another object with the same signature.
84
+
85
+ ## 2.2 Information Hiding
86
+
87
+ **Definition**: Design decisions should be encapsulated within modules and hidden from the outside.
88
+
89
+ - **Requirement**: Hide complex algorithms, data structures, and implementation details.
90
+ - **Requirement**: Avoid "Information Leakage" where internal choices are exposed through the interface.
91
+
92
+ ## 2.3 General-Purpose vs. Special-Purpose
93
+
94
+ **Definition**: Modules should be designed to be somewhat general-purpose to reduce the total number of modules.
95
+
96
+ - **Requirement**: Ask "What is the simplest interface that could solve this _and_ similar future problems?"
97
+ - **Requirement**: Avoid over-specialization that leads to a massive number of tiny, shallow classes.
98
+
99
+ ## 2.4 Defining Errors Out of Existence
100
+
101
+ **Definition**: The best way to handle errors is to design APIs so the error condition is impossible or part of the normal flow.
102
+
103
+ - **Requirement**: Use sensible defaults (e.g., empty string instead of error).
104
+ - **Requirement**: Design interfaces so the "error case" is a valid branch of logic.
105
+
106
+ ## 2.5 Design Twice
107
+
108
+ **Definition**: The first design is rarely the best. Always consider at least two distinct approaches.
109
+
110
+ - **Requirement**: For significant changes, document at least one alternative considered and rejected.
111
+
112
+ ## 2.6 Comment the Why, not the How
113
+
114
+ **Definition**: Comments should explain high-level intent and abstractions, not repeat the code.
115
+
116
+ - **Requirement**: Comments must reside at the Interface level (Docstrings).
117
+ - **Requirement**: Delete comments that merely restate the variable name or logic.
118
+
119
+ ---
120
+
121
+ # 3. Universal Fundamentals
122
+
123
+ _Source: Various / First Principles_
124
+ Core axioms that transcend specific languages.
125
+
126
+ ## 3.1 Principle of Least Astonishment (POLA)
127
+
128
+ _Source: [POLA Definition](https://en.wikipedia.org/wiki/Principle_of_least_astonishment)_
129
+ **Definition**: The behavior of a component should match the user's reasonable expectations.
130
+
131
+ - **Requirement**: Avoid "Magic" behavior (implicit side effects).
132
+ - **Requirement**: Naming must strictly match behavior (`get()` should not mutate).
133
+
134
+ ## 3.2 Locality of Behavior (LoB)
135
+
136
+ _Source: [htmx (Carson Gross)](https://htmx.org/essays/locality-of-behavior/)_
137
+ **Definition**: The behavior of a unit of code should be as obvious as possible by looking only at that unit.
138
+
139
+ - **Requirement**: Keep related code collocated.
140
+ - **Requirement**: Avoid "Action at a Distance" (modifying global state from a deep subroutine).
141
+
142
+ ## 3.3 Orthogonality
143
+
144
+ _Source: [The Pragmatic Programmer](https://en.wikipedia.org/wiki/The_Pragmatic_Programmer)_
145
+ **Definition**: Changes in one part of the system should not affect unrelated parts.
146
+
147
+ - **Requirement**: Decouple modules. A change to the UI rendering logic must not break the database query logic.
148
+ - **Requirement**: Use pure functions where possible to eliminate side effects.
149
+
150
+ ## 3.4 Idempotency
151
+
152
+ _Source: [API Design Principles](https://en.wikipedia.org/wiki/Idempotence)_
153
+ **Definition**: An operation can be applied multiple times without changing the result beyond the initial application.
154
+
155
+ - **Requirement**: Retries of failed operations must be safe.
156
+ - **Requirement**: APIs modifying state should ideally be idempotent.
157
+
158
+ ## 3.5 Explicitness
159
+
160
+ _Source: [Zen of Python](https://peps.python.org/pep-0020/)_
161
+ **Definition**: Magic is the enemy of maintainability. Implicit behavior increases mental load.
162
+
163
+ - **Requirement**: Explicit is better than implicit. No global state.
164
+ - **Requirement**: Dependencies and side effects must be visible in signatures.
165
+
166
+ ---
167
+
168
+ # 4. Pragmatic Programmer & Code Health
169
+
170
+ _Source: [Hunt & Thomas](https://en.wikipedia.org/wiki/The_Pragmatic_Programmer) / [Atul Gawande](https://en.wikipedia.org/wiki/The_Checklist_Manifesto)_
171
+ Tactical rules for maintaining code quality over time.
172
+
173
+ ## 4.1 The Boy Scout Rule
174
+
175
+ _Source: [Robert C. Martin](https://en.wikipedia.org/wiki/Robert_C._Martin)_
176
+ **Definition**: Always leave the code cleaner than you found it.
177
+
178
+ - **Requirement**: Fix existing lint warnings and bad names in the immediate context of your change.
179
+
180
+ ## 4.2 Broken Windows Theory
181
+
182
+ _Source: [Pragmatic Programmer](https://en.wikipedia.org/wiki/The_Pragmatic_Programmer)_
183
+ **Definition**: Bad designs left unrepaired encourage more bad designs.
184
+
185
+ - **Requirement**: Do not tolerate "hacks" in the core path. Fix or encapsulate immediately.
186
+
187
+ ## 4.3 Cognitive Limits (Batch Size)
188
+
189
+ _Source: [SmartBear Analysis](https://smartbear.com/learn/code-review/best-practices-for-peer-code-review/)_
190
+ **Definition**: Human review quality drops sharply as batch size increases.
191
+
192
+ - **Requirement**: Pull Requests should stay under 400 lines of code.
193
+ - **Requirement**: A single PR must tell a single, coherent story.
194
+
195
+ ## 4.4 The Checklist
196
+
197
+ _Source: [The Checklist Manifesto](https://en.wikipedia.org/wiki/The_Checklist_Manifesto)_
198
+ **Definition**: Rote verification should be offloaded to machines.
199
+
200
+ - **Requirement**: Automate formatting, linting, and imports.
201
+
202
+ ---
203
+
204
+ # 5. Systems Theory & Dynamics
205
+
206
+ _Source: [Melvin Conway](https://en.wikipedia.org/wiki/Conway%27s_law) / [Jay Forrester](https://en.wikipedia.org/wiki/System_dynamics)_
207
+ Understanding software development as a complex adaptive system.
208
+
209
+ ## 5.1 Shift Left
210
+
211
+ _Source: [Industrial Dynamics](https://en.wikipedia.org/wiki/Shift-left_testing)_
212
+ **Definition**: Verification activities should happen as early as possible.
213
+
214
+ - **Requirement**: Perform dependency impact analysis before writing code.
215
+
216
+ ## 5.2 Socio-Technical Congruence
217
+
218
+ _Source: [Conway's Law](https://en.wikipedia.org/wiki/Conway%27s_law)_
219
+ **Definition**: Code structure must align with team communication structure.
220
+
221
+ - **Requirement**: Flag tight coupling between modules owned by different teams.
222
+
223
+ ## 5.3 The Rework Cycle
224
+
225
+ _Source: [System Dynamics Modeling](https://en.wikipedia.org/wiki/The_Mythical_Man-Month)_
226
+ **Definition**: Hidden defects destroy velocity.
227
+
228
+ - **Requirement**: Prioritize paying down technical debt (Refactoring) to keep velocity stable.
229
+
230
+ ---
231
+
232
+ # 6. Formal Methods & Correctness
233
+
234
+ _Source: [Type Theory](https://en.wikipedia.org/wiki/Type_theory) / [Jon Postel](https://en.wikipedia.org/wiki/Robustness_principle)_
235
+ Ensuring code behaves correctly by construction.
236
+
237
+ ## 6.1 Safety by Design
238
+
239
+ **Definition**: Illegal states should be unrepresentable.
240
+
241
+ - **Requirement**: Use Algebraic Data Types (Unions) for state.
242
+ - **Requirement**: Prefer immutable data structures.
243
+
244
+ ## 6.2 Command-Query Separation (CQS)
245
+
246
+ _Source: [Bertrand Meyer](https://en.wikipedia.org/wiki/Command%E2%80%93query_separation)_
247
+ **Definition**: Methods must either perform an action (Command) or return data (Query).
248
+
249
+ - **Requirement**: A method returning a value should be "Pure" (no observable side effects).
250
+
251
+ ## 6.3 Postel's Law
252
+
253
+ _Source: [Robustness Principle](https://en.wikipedia.org/wiki/Robustness_principle)_
254
+ **Definition**: Be conservative in what you do, liberal in what you accept.
255
+
256
+ - **Requirement**: Validate external inputs at the boundary.
257
+ - **Requirement**: Return strictly-typed structures.
258
+
259
+ ---
260
+
261
+ # 7. Distributed Systems
262
+
263
+ _Source: [Eric Brewer](https://en.wikipedia.org/wiki/CAP_theorem) / [L. Peter Deutsch](https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing)_
264
+ Rules for code that crosses network boundaries.
265
+
266
+ ## 7.1 CAP & PACELC
267
+
268
+ _Source: [CAP Theorem](https://en.wikipedia.org/wiki/CAP_theorem) / [PACELC](https://en.wikipedia.org/wiki/PACELC_theorem)_
269
+ **Definition**: Distributed systems must explicitly choose between Consistency and Availability.
270
+
271
+ - **Requirement**: Document the consistency model for every distributed component.
272
+
273
+ ## 7.2 Fallacies of Distributed Computing
274
+
275
+ _Source: [The 8 Fallacies](https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing)_
276
+ **Definition**: False assumptions that L. Peter Deutsch and colleagues identified as the root of most distributed system failures.
277
+
278
+ - **Requirement**: You must actively design mitigation for _each_ of these false assumptions:
279
+ 1. **The network is reliable.** (Mitigation: Retries, Acknowledgements)
280
+ 2. **Latency is zero.** (Mitigation: Batching, Parallelism, Caching)
281
+ 3. **Bandwidth is infinite.** (Mitigation: Compression, Binary Formats)
282
+ 4. **The network is secure.** (Mitigation: TLS, Zero Trust, Authentication)
283
+ 5. **Topology doesn't change.** (Mitigation: Service Discovery, DNS)
284
+ 6. **There is one administrator.** (Mitigation: Decoupling, Versioning, Permissions)
285
+ 7. **Transport cost is zero.** (Mitigation: Serialization efficiency)
286
+ 8. **The network is homogeneous.** (Mitigation: Standards-based protocols, Interoperability)
287
+
288
+ ---
289
+
290
+ # 8. Classic Engineering Wisdom
291
+
292
+ _Source: [Extreme Programming](https://en.wikipedia.org/wiki/Extreme_programming) / [Lockheed Skunk Works](https://en.wikipedia.org/wiki/KISS_principle)_
293
+
294
+ ## 8.1 KISS (Keep It Simple, Stupid)
295
+
296
+ _Source: [Kelly Johnson](https://en.wikipedia.org/wiki/KISS_principle)_
297
+ **Definition**: Complexity is a cost; avoid it unless justified by value.
298
+
299
+ - **Requirement**: Do not build a factory for a single implementation.
300
+
301
+ ## 8.2 YAGNI (You Aren't Gonna Need It)
302
+
303
+ _Source: [YAGNI Definition](https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it)_
304
+ **Definition**: Do not implement functionality until it is necessary.
305
+
306
+ - **Requirement**: Remove unused functions, variables, or files (Dead Code).
307
+ - **Requirement**: Reject "Extensibility Hooks" that have no immediate use case.
308
+
309
+ ## 8.3 DRY (Don't Repeat Yourself)
310
+
311
+ _Source: [The Pragmatic Programmer](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself)_
312
+ **Definition**: Every piece of knowledge must have a single, authoritative representation.
313
+
314
+ - **Requirement**: Data schemas must be defined once (Single Source of Truth).
315
+ - **Exception**: Tolerate "Accidental Duplication" if the reasons for change differ.
316
+
317
+ ## 8.4 Law of Demeter
318
+
319
+ _Source: [Law of Demeter](https://en.wikipedia.org/wiki/Law_of_Demeter)_
320
+ **Definition**: A module should not know about the innards of the objects it manipulates.
321
+
322
+ - **Requirement**: Avoid method chaining that traverses structure (`a.b().c()`).
323
+
324
+ ---
325
+
326
+ # 9. Security Engineering
327
+
328
+ _Source: [OWASP](https://owasp.org/www-project-top-ten/) / [Saltzer and Schroeder](https://en.wikipedia.org/wiki/Saltzer_and_Schroeder%27s_design_principles)_
329
+
330
+ ## 9.1 Principle of Least Privilege
331
+
332
+ **Definition**: A subject should be given only those privileges needed for it to complete its task.
333
+
334
+ - **Requirement**: Services must run with minimal IAM permissions.
335
+ - **Requirement**: Database users must not have `DROP` privileges unless required for migrations.
336
+
337
+ ## 9.2 Defense in Depth
338
+
339
+ **Definition**: Redundant security controls to mitigate failure of a single control.
340
+
341
+ - **Requirement**: Do not rely solely on the firewall; authenticate internally (Zero Trust).
342
+ - **Requirement**: Validate input at both the API Gateway and the Service level.
343
+
344
+ ## 9.3 Secure Defaults
345
+
346
+ **Definition**: Systems should be secure "out of the box".
347
+
348
+ - **Requirement**: Ports should be closed by default.
349
+ - **Requirement**: Passwords must be hashed (bcrypt/argon2) by default.
350
+
351
+ ## 9.4 Input Validation
352
+
353
+ **Definition**: Never trust external input.
354
+
355
+ - **Requirement**: Validate logic at the earliest entry point.
356
+ - **Requirement**: Use allow-lists (valid chars) over deny-lists.
357
+
358
+ ---
359
+
360
+ # 10. Testing & Verification
361
+
362
+ _Source: [The Test Pyramid](https://martinfowler.com/articles/practical-test-pyramid.html)_
363
+
364
+ ## 10.1 The Test Pyramid
365
+
366
+ **Definition**: Balance test types for speed and confidence (Unit > Integration > E2E).
367
+
368
+ - **Requirement**: Logic-heavy modules must have unit tests covering all branches.
369
+ - **Requirement**: Integration tests verify the contract between modules.
370
+
371
+ ## 10.2 Determinism & Isolation
372
+
373
+ **Definition**: Tests must produce the same result every run, regardless of order or environment.
374
+
375
+ - **Requirement**: Mock network calls and randomness (Time, UUIDs) in unit tests.
376
+ - **Requirement**: Tests must clean up their own data (no leaking state).
377
+
378
+ ## 10.3 Property-Based Testing
379
+
380
+ **Definition**: Verify general properties (invariants) over generated inputs rather than specific examples.
381
+
382
+ - **Requirement**: Use fuzzing/property testing for parsers and critical logic.
383
+
384
+ ---
385
+
386
+ # 11. Observability & Operations
387
+
388
+ _Source: [Google SRE Book](https://sre.google/sre-book/monitoring-distributed-systems/)_
389
+
390
+ ## 11.1 Telemetry by Design
391
+
392
+ **Definition**: You cannot operate what you cannot see.
393
+
394
+ - **Requirement**: Every service must emit standard metrics (Latency, Traffic, Errors, Saturation).
395
+ - **Requirement**: Use structured logging (JSON) with correlation IDs for tracing.
396
+
397
+ ## 11.2 Alert Hygiene
398
+
399
+ **Definition**: Alerts should be actionable and urgent.
400
+
401
+ - **Requirement**: Alert on symptoms (User Pain), not causes (High CPU).
402
+ - **Requirement**: Every alert must have a link to a Runbook.
403
+
404
+ ---
405
+
406
+ # 12. Performance & Efficiency
407
+
408
+ _Source: [Knuth](https://en.wikipedia.org/wiki/Donald_Knuth) / [Brendan Gregg](https://www.brendangregg.com/)_
409
+
410
+ ## 12.1 Algorithmic Complexity (Big O)
411
+
412
+ **Definition**: Understanding how resource usage scales with input size.
413
+
414
+ - **Requirement**: Avoid N+1 query problems in loops.
415
+ - **Requirement**: Identify and mitigate O(n^2) or worse algorithms in hot paths.
416
+
417
+ ## 12.2 Caching Strategy
418
+
419
+ **Definition**: Storing results to avoid repeated work.
420
+
421
+ - **Requirement**: Every cache must have an eviction policy (TTL/LRU).
422
+ - **Requirement**: Handle cache stampedes (locking or probabilistic expiry).
423
+
424
+ ## 12.3 Profiling First
425
+
426
+ **Definition**: Optimization without measurement is premature.
427
+
428
+ - **Requirement**: Do not optimize code without a profile showing it is a bottleneck.
429
+
430
+ ---
431
+
432
+ # 13. Data Engineering
433
+
434
+ _Source: [Database Reliability Engineering](https://shop.oreilly.com/product/0636920059714.do)_
435
+
436
+ ## 13.1 Schema Evolution
437
+
438
+ **Definition**: Data outlives code. Schemas must evolve without downtime.
439
+
440
+ - **Requirement**: Migrations must be backward-compatible (Add column -> Deploy Code -> Drop column).
441
+ - **Requirement**: Avoid `SELECT *` to allow schema expansion.
442
+
443
+ ## 13.2 Data Integrity
444
+
445
+ **Definition**: Ensuring accuracy and consistency of data.
446
+
447
+ - **Requirement**: Use Foreign Keys and Constraints to enforce integrity at the DB level.
448
+ - **Requirement**: Define clear transactional boundaries (ACID) for critical mutations.
449
+
450
+ ---
451
+
452
+ # 14. Delivery & Evolution
453
+
454
+ _Source: [Accelerate (DORA)](https://dora.dev/)_
455
+
456
+ ## 14.1 Feature Flags
457
+
458
+ **Definition**: Decoupling deployment from release.
459
+
460
+ - **Requirement**: Wrap new features in flags to allow safe rollback and incremental rollout.
461
+ - **Requirement**: Delete flags once the feature is stable (Flag Debt).
462
+
463
+ ## 14.2 Semantic Versioning
464
+
465
+ **Definition**: Version numbers convey meaning about compatibility.
466
+
467
+ - **Requirement**: Breaking changes must bump the Major version.
468
+ - **Requirement**: Public APIs must be stable within a Major version.
469
+
470
+ ## 14.3 Deprecation Policy
471
+
472
+ **Definition**: Managing the end-of-life of features.
473
+
474
+ - **Requirement**: Mark deprecated features with a clear warning and a removal date.
475
+ - **Requirement**: Provide an automated migration path where possible.
476
+
477
+ ---
478
+
479
+ # 15. Dependency Management
480
+
481
+ _Source: [Supply Chain Levels for Software Artifacts (SLSA)](https://slsa.dev/)_
482
+
483
+ ## 15.1 Dependency Hygiene
484
+
485
+ **Definition**: Minimizing risk from external code.
486
+
487
+ - **Requirement**: Pin versions using lockfiles.
488
+ - **Requirement**: Regularly audit for security vulnerabilities (e.g., `npm audit`).
489
+
490
+ ## 15.2 Supply Chain Integrity
491
+
492
+ **Definition**: Ensuring build artifacts are trustworthy.
493
+
494
+ - **Requirement**: Generate Software Bill of Materials (SBOMs).
495
+ - **Requirement**: Verify checksums of downloaded packages.
496
+
497
+ ---
498
+
499
+ # 16. API Design
500
+
501
+ _Source: [Microsoft REST API Guidelines](https://github.com/microsoft/api-guidelines)_
502
+
503
+ ## 16.1 Contract Stability
504
+
505
+ **Definition**: An API is a promise.
506
+
507
+ - **Requirement**: Do not change public signatures without a major version bump.
508
+ - **Requirement**: Use "Consumer-Driven Contracts" to verify integrations.
509
+
510
+ ## 16.2 Versioning Strategy
511
+
512
+ **Definition**: Managing change over time.
513
+
514
+ - **Requirement**: Use explicit versioning in URL or Header (`/v1/resource`).
515
+ - **Requirement**: Maintain at least one previous version for a deprecation period.
516
+
517
+ ---
518
+
519
+ # 17. Privacy & Compliance
520
+
521
+ _Source: [GDPR](https://gdpr-info.eu/) / [Privacy by Design](https://en.wikipedia.org/wiki/Privacy_by_design)_
522
+
523
+ ## 17.1 Data Minimization
524
+
525
+ **Definition**: Collect only what is absolutely necessary.
526
+
527
+ - **Requirement**: Do not store PII (Personally Identifiable Information) unless critical.
528
+ - **Requirement**: Define retention policies for all data.
529
+
530
+ ## 17.2 PII Handling
531
+
532
+ **Definition**: Protecting user data.
533
+
534
+ - **Requirement**: Encrypt PII at rest and in transit.
535
+ - **Requirement**: Log anonymized IDs, never raw user data (e.g., email).
536
+
537
+ ---
538
+
539
+ # 18. Operational Reliability
540
+
541
+ _Source: [Netflix Engineering](https://netflixtechblog.com/)_
542
+
543
+ ## 18.1 Backpressure & Load Shedding
544
+
545
+ **Definition**: Protecting the system from overload.
546
+
547
+ - **Requirement**: Reject excess traffic gracefully (HTTP 429) rather than crashing.
548
+ - **Requirement**: Implement client-side exponential backoff.
549
+
550
+ ## 18.2 Chaos Engineering
551
+
552
+ **Definition**: Proactive testing of failure modes.
553
+
554
+ - **Requirement**: Verify system behavior when dependencies go down.
555
+ - **Requirement**: Test rollback procedures regularly.
@@ -0,0 +1,8 @@
1
+ # Language Standards (Meta)
2
+
3
+ This directory contains the "Source of Truth" meta-documents for specific languages. These documents aggregate knowledge from official style guides, engineering blogs, and seminal books.
4
+
5
+ ## Index
6
+
7
+ - **[Go](go/README.md)**: Based on _Effective Go_ and _btcwallet_.
8
+ - **[TypeScript](typescript/README.md)**: Based on _Total TypeScript_ and _Google Style Guide_.
@@ -0,0 +1,37 @@
1
+ # Concurrency Architecture (The Actor Model)
2
+
3
+ **Source**: [btcwallet Engineering Guide](https://github.com/btcsuite/btcwallet/blob/master/docs/developer/ENGINEERING_GUIDE.md)
4
+
5
+ ## 1. The Core Philosophy
6
+
7
+ > "Do not communicate by sharing memory; instead, share memory by communicating."
8
+
9
+ Instead of protecting shared state with complex locks (which lead to deadlocks and race conditions), we isolate state within a single, long-running goroutine (the "Actor"). This Actor owns its data exclusively and processes requests sequentially via channels.
10
+
11
+ ## 2. Patterns
12
+
13
+ ### The Pipeline
14
+
15
+ Break complex processing into linear stages.
16
+
17
+ - **Structure**: `Source -> Stage A -> Stage B -> Sink`
18
+ - **Example**: Reading a file, parsing JSON, validating data, and saving to DB should be separate stages connected by channels.
19
+
20
+ ### Fan-Out / Fan-In
21
+
22
+ Parallelize work by distributing it to a pool of workers.
23
+
24
+ - **Fan-Out**: A distributor sends jobs to `N` worker goroutines.
25
+ - **Fan-In**: A single collector aggregates results from the workers.
26
+ - **Constraint**: Always use a bounded channel or a semaphore to prevent unbounded concurrency.
27
+
28
+ ## 3. Lifecycle Safety
29
+
30
+ **Rule**: Never start a goroutine without knowing how it will stop.
31
+
32
+ - **Mechanism**: Every long-running loop must check `ctx.Done()` or a `quit` channel.
33
+ - **Anti-Pattern**: `go func() { for { ... } }()` (This is a leak).
34
+
35
+ ## 4. Modern Patterns (Go 1.22+)
36
+
37
+ - **Loop Variables**: Go 1.22+ fixed the loop variable capture bug. Do NOT use `v := v` inside loops anymore.
@@ -0,0 +1,30 @@
1
+ # API & Package Design
2
+
3
+ **Source**: [btcwallet Engineering Guide](https://github.com/btcsuite/btcwallet/blob/master/docs/developer/ENGINEERING_GUIDE.md)
4
+
5
+ ## 1. Clean Packages
6
+
7
+ - **Naming**: A package name must describe _what it provides_, not _what it contains_.
8
+ - **Bad**: `utils`, `common`, `helpers` (Buckets of junk).
9
+ - **Good**: `cryptography`, `httpclient`, `auth`.
10
+ - **Structure**: Use `internal/` for any code that is not part of your public stability contract.
11
+
12
+ ## 2. Interface Design
13
+
14
+ **Rule**: "Accept Interfaces, Return Structs."
15
+
16
+ - **Why**: Accepting an interface allows the caller to pass any implementation (mock, file, network). Returning a struct allows you to add methods to the result later without breaking consumers.
17
+ - **Example**:
18
+
19
+ ```go
20
+ // Bad: Returns an interface, locking the implementation
21
+ func NewStore() Storage { ... }
22
+
23
+ // Good: Returns a concrete type, accepts an interface
24
+ func Save(w io.Writer, data []byte) { ... }
25
+ ```
26
+
27
+ ## 3. Documentation (Godoc)
28
+
29
+ - **Requirement**: Every exported symbol must have a comment starting with the symbol name.
30
+ - **Style**: Explain _why_, not just _what_. "Returns ErrNotFound" is better than "Returns error."
@@ -0,0 +1,27 @@
1
+ # Resilience Patterns
2
+
3
+ **Source**: [btcwallet Engineering Guide](https://github.com/btcsuite/btcwallet/blob/master/docs/developer/ENGINEERING_GUIDE.md)
4
+
5
+ ## 1. Context Propagation ("The Red Thread")
6
+
7
+ Every function that performs I/O or long-running work **MUST** accept `context.Context` as its first argument.
8
+
9
+ - **Usage**: Use it for timeouts, deadlines, and cancellation.
10
+ - **Group Management**: Use `golang.org/x/sync/errgroup` to manage a set of goroutines. If one fails, the context is canceled, and all others abort.
11
+
12
+ ## 2. Circuit Breakers & Rate Limiting
13
+
14
+ - **Circuit Breakers**: If a dependency is down, fail fast. Do not wait for a 30s timeout on every request.
15
+ - **Rate Limiting**: Protect your own resources. Reject requests if you are overloaded (`golang.org/x/time/rate`).
16
+
17
+ ## 3. Retry with Backoff
18
+
19
+ Never retry immediately in a loop (Thundering Herd).
20
+
21
+ - **Requirement**: Use exponential backoff (e.g., 1s, 2s, 4s) with jitter.
22
+
23
+ ## 4. Observability (Slog)
24
+
25
+ - **Standard**: Use `log/slog` (Go 1.21+).
26
+ - **Structure**: Log machine-readable key-values, not formatted strings.
27
+ - **Levels**: `Info` (State change), `Error` (Actionable), `Debug` (Granular).
@@ -0,0 +1,27 @@
1
+ # Error Handling
2
+
3
+ **Source**: [btcwallet Engineering Guide](https://github.com/btcsuite/btcwallet/blob/master/docs/developer/ENGINEERING_GUIDE.md)
4
+
5
+ ## 1. Contextual Wrapping
6
+
7
+ Never return a raw error from a dependency. The caller needs to know _where_ and _why_ it failed.
8
+
9
+ - **Bad**: `return err`
10
+ - **Good**: `return fmt.Errorf("failed to parse config file %s: %w", filename, err)`
11
+
12
+ ## 2. Sentinel Errors
13
+
14
+ Define specific errors as variables so callers can check for them using `errors.Is`.
15
+
16
+ - **Example**: `var ErrUserNotFound = errors.New("user not found")`
17
+
18
+ ## 3. Zero Errors
19
+
20
+ Design APIs where errors are impossible for common cases.
21
+
22
+ - **Pattern**: Instead of returning an error on a cache miss, return `(value, found)` boolean.
23
+
24
+ ## 4. Modern Patterns
25
+
26
+ - **Check**: Use `errors.Is(err, Target)` and `errors.As(err, &Target)`. Never use `==` or type assertions on errors directly.
27
+ - **Aggregation**: Use `errors.Join(err1, err2)` (Go 1.20+) for defer cleanup errors.