@aicgen/aicgen 1.0.0-beta.1

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 (287) hide show
  1. package/.claude/agents/architecture-reviewer.md +88 -0
  2. package/.claude/agents/guideline-checker.md +73 -0
  3. package/.claude/agents/security-auditor.md +108 -0
  4. package/.claude/guidelines/api-design.md +645 -0
  5. package/.claude/guidelines/architecture.md +2503 -0
  6. package/.claude/guidelines/best-practices.md +618 -0
  7. package/.claude/guidelines/code-style.md +304 -0
  8. package/.claude/guidelines/design-patterns.md +573 -0
  9. package/.claude/guidelines/devops.md +226 -0
  10. package/.claude/guidelines/error-handling.md +413 -0
  11. package/.claude/guidelines/language.md +782 -0
  12. package/.claude/guidelines/performance.md +706 -0
  13. package/.claude/guidelines/security.md +583 -0
  14. package/.claude/guidelines/testing.md +568 -0
  15. package/.claude/settings.json +98 -0
  16. package/.claude/settings.local.json +8 -0
  17. package/.env.example +23 -0
  18. package/.eslintrc.json +28 -0
  19. package/.github/workflows/release.yml +180 -0
  20. package/.github/workflows/test.yml +81 -0
  21. package/.gitmodules +3 -0
  22. package/.vs/ProjectSettings.json +3 -0
  23. package/.vs/VSWorkspaceState.json +16 -0
  24. package/.vs/aicgen.slnx/FileContentIndex/5f0ce2a3-fd68-4863-9e23-e428cf1794e3.vsidx +0 -0
  25. package/.vs/aicgen.slnx/v18/.wsuo +0 -0
  26. package/.vs/aicgen.slnx/v18/DocumentLayout.json +54 -0
  27. package/.vs/slnx.sqlite +0 -0
  28. package/AGENTS.md +121 -0
  29. package/CLAUDE.md +36 -0
  30. package/CONTRIBUTING.md +821 -0
  31. package/LICENSE +21 -0
  32. package/README.md +199 -0
  33. package/assets/icon.svg +34 -0
  34. package/assets/logo.svg +41 -0
  35. package/bun.lock +848 -0
  36. package/data/LICENSE +21 -0
  37. package/data/README.md +203 -0
  38. package/data/api/basics.md +292 -0
  39. package/data/api/index.md +8 -0
  40. package/data/api/pagination.md +142 -0
  41. package/data/api/rest.md +137 -0
  42. package/data/api/versioning.md +60 -0
  43. package/data/architecture/clean-architecture/index.md +7 -0
  44. package/data/architecture/clean-architecture/layers.md +111 -0
  45. package/data/architecture/ddd/index.md +8 -0
  46. package/data/architecture/ddd/strategic.md +89 -0
  47. package/data/architecture/ddd/tactical.md +132 -0
  48. package/data/architecture/event-driven/index.md +7 -0
  49. package/data/architecture/event-driven/messaging.md +242 -0
  50. package/data/architecture/event-driven/patterns.md +129 -0
  51. package/data/architecture/feature-toggles/index.md +7 -0
  52. package/data/architecture/feature-toggles/patterns.md +73 -0
  53. package/data/architecture/gui/index.md +7 -0
  54. package/data/architecture/gui/patterns.md +132 -0
  55. package/data/architecture/hexagonal/ports-adapters.md +132 -0
  56. package/data/architecture/index.md +12 -0
  57. package/data/architecture/layered/index.md +7 -0
  58. package/data/architecture/layered/layers.md +100 -0
  59. package/data/architecture/microservices/api-gateway.md +56 -0
  60. package/data/architecture/microservices/boundaries.md +80 -0
  61. package/data/architecture/microservices/communication.md +97 -0
  62. package/data/architecture/microservices/data.md +92 -0
  63. package/data/architecture/microservices/index.md +11 -0
  64. package/data/architecture/microservices/resilience.md +111 -0
  65. package/data/architecture/modular-monolith/boundaries.md +133 -0
  66. package/data/architecture/modular-monolith/structure.md +131 -0
  67. package/data/architecture/serverless/best-practices.md +322 -0
  68. package/data/architecture/serverless/index.md +7 -0
  69. package/data/architecture/serverless/patterns.md +80 -0
  70. package/data/architecture/solid/index.md +7 -0
  71. package/data/architecture/solid/principles.md +187 -0
  72. package/data/database/basics.md +365 -0
  73. package/data/database/design-patterns.md +68 -0
  74. package/data/database/index.md +8 -0
  75. package/data/database/indexing.md +136 -0
  76. package/data/database/nosql.md +223 -0
  77. package/data/database/schema.md +137 -0
  78. package/data/devops/ci-cd.md +66 -0
  79. package/data/devops/index.md +8 -0
  80. package/data/devops/observability.md +73 -0
  81. package/data/devops/practices.md +77 -0
  82. package/data/error-handling/basics.md +222 -0
  83. package/data/error-handling/index.md +7 -0
  84. package/data/error-handling/strategy.md +185 -0
  85. package/data/guideline-mappings.yml +1077 -0
  86. package/data/index.md +3 -0
  87. package/data/language/csharp/basics.md +210 -0
  88. package/data/language/csharp/testing.md +252 -0
  89. package/data/language/go/basics.md +158 -0
  90. package/data/language/go/testing.md +192 -0
  91. package/data/language/index.md +14 -0
  92. package/data/language/java/basics.md +184 -0
  93. package/data/language/java/testing.md +273 -0
  94. package/data/language/javascript/basics.md +217 -0
  95. package/data/language/javascript/testing.md +269 -0
  96. package/data/language/python/async.md +100 -0
  97. package/data/language/python/basics.md +100 -0
  98. package/data/language/python/index.md +10 -0
  99. package/data/language/python/testing.md +125 -0
  100. package/data/language/python/types.md +99 -0
  101. package/data/language/ruby/basics.md +227 -0
  102. package/data/language/ruby/testing.md +267 -0
  103. package/data/language/rust/basics.md +175 -0
  104. package/data/language/rust/testing.md +219 -0
  105. package/data/language/typescript/async.md +103 -0
  106. package/data/language/typescript/basics.md +87 -0
  107. package/data/language/typescript/config.md +95 -0
  108. package/data/language/typescript/error-handling.md +98 -0
  109. package/data/language/typescript/generics.md +85 -0
  110. package/data/language/typescript/index.md +14 -0
  111. package/data/language/typescript/interfaces-types.md +83 -0
  112. package/data/language/typescript/performance.md +103 -0
  113. package/data/language/typescript/testing.md +98 -0
  114. package/data/patterns/base-patterns.md +105 -0
  115. package/data/patterns/concurrency.md +87 -0
  116. package/data/patterns/data-access.md +83 -0
  117. package/data/patterns/distribution.md +86 -0
  118. package/data/patterns/domain-logic.md +81 -0
  119. package/data/patterns/gof.md +109 -0
  120. package/data/patterns/index.md +12 -0
  121. package/data/performance/async.md +148 -0
  122. package/data/performance/basics.md +324 -0
  123. package/data/performance/caching-strategies.md +68 -0
  124. package/data/performance/caching.md +152 -0
  125. package/data/performance/index.md +8 -0
  126. package/data/practices/code-review.md +52 -0
  127. package/data/practices/documentation.md +260 -0
  128. package/data/practices/index.md +11 -0
  129. package/data/practices/planning.md +142 -0
  130. package/data/practices/refactoring.md +91 -0
  131. package/data/practices/version-control.md +55 -0
  132. package/data/security/auth-jwt.md +159 -0
  133. package/data/security/headers.md +143 -0
  134. package/data/security/index.md +10 -0
  135. package/data/security/injection.md +119 -0
  136. package/data/security/secrets.md +148 -0
  137. package/data/style/index.md +8 -0
  138. package/data/style/naming.md +136 -0
  139. package/data/style/organization.md +162 -0
  140. package/data/templates/agents/architecture-reviewer.md +88 -0
  141. package/data/templates/agents/guideline-checker.md +73 -0
  142. package/data/templates/agents/security-auditor.md +108 -0
  143. package/data/templates/antigravity/rules/architecture.md.hbs +5 -0
  144. package/data/templates/antigravity/rules/code-style.md.hbs +5 -0
  145. package/data/templates/antigravity/rules/language.md.hbs +5 -0
  146. package/data/templates/antigravity/rules/performance.md.hbs +5 -0
  147. package/data/templates/antigravity/rules/security.md.hbs +5 -0
  148. package/data/templates/antigravity/rules/testing.md.hbs +5 -0
  149. package/data/templates/antigravity/workflows/add-documentation.md.hbs +23 -0
  150. package/data/templates/antigravity/workflows/generate-integration-tests.md.hbs +17 -0
  151. package/data/templates/antigravity/workflows/generate-unit-tests.md.hbs +20 -0
  152. package/data/templates/antigravity/workflows/performance-audit.md.hbs +24 -0
  153. package/data/templates/antigravity/workflows/refactor-extract-module.md.hbs +17 -0
  154. package/data/templates/antigravity/workflows/security-audit.md.hbs +20 -0
  155. package/data/templates/hooks/formatting.json +26 -0
  156. package/data/templates/hooks/security.json +35 -0
  157. package/data/templates/hooks/testing.json +17 -0
  158. package/data/testing/basics.md +151 -0
  159. package/data/testing/index.md +9 -0
  160. package/data/testing/integration.md +159 -0
  161. package/data/testing/unit-fundamentals.md +128 -0
  162. package/data/testing/unit-mocking.md +116 -0
  163. package/data/version.json +49 -0
  164. package/dist/commands/init.d.ts +8 -0
  165. package/dist/commands/init.d.ts.map +1 -0
  166. package/dist/commands/init.js +46 -0
  167. package/dist/commands/init.js.map +1 -0
  168. package/dist/config/profiles.d.ts +4 -0
  169. package/dist/config/profiles.d.ts.map +1 -0
  170. package/dist/config/profiles.js +30 -0
  171. package/dist/config/profiles.js.map +1 -0
  172. package/dist/config/settings.d.ts +7 -0
  173. package/dist/config/settings.d.ts.map +1 -0
  174. package/dist/config/settings.js +7 -0
  175. package/dist/config/settings.js.map +1 -0
  176. package/dist/index.d.ts +3 -0
  177. package/dist/index.d.ts.map +1 -0
  178. package/dist/index.js +58489 -0
  179. package/dist/index.js.map +1 -0
  180. package/dist/models/guideline.d.ts +15 -0
  181. package/dist/models/guideline.d.ts.map +1 -0
  182. package/dist/models/guideline.js +2 -0
  183. package/dist/models/guideline.js.map +1 -0
  184. package/dist/models/preference.d.ts +9 -0
  185. package/dist/models/preference.d.ts.map +1 -0
  186. package/dist/models/preference.js +2 -0
  187. package/dist/models/preference.js.map +1 -0
  188. package/dist/models/profile.d.ts +9 -0
  189. package/dist/models/profile.d.ts.map +1 -0
  190. package/dist/models/profile.js +2 -0
  191. package/dist/models/profile.js.map +1 -0
  192. package/dist/models/project.d.ts +13 -0
  193. package/dist/models/project.d.ts.map +1 -0
  194. package/dist/models/project.js +2 -0
  195. package/dist/models/project.js.map +1 -0
  196. package/dist/services/ai/anthropic.d.ts +7 -0
  197. package/dist/services/ai/anthropic.d.ts.map +1 -0
  198. package/dist/services/ai/anthropic.js +39 -0
  199. package/dist/services/ai/anthropic.js.map +1 -0
  200. package/dist/services/generator.d.ts +2 -0
  201. package/dist/services/generator.d.ts.map +1 -0
  202. package/dist/services/generator.js +4 -0
  203. package/dist/services/generator.js.map +1 -0
  204. package/dist/services/learner.d.ts +2 -0
  205. package/dist/services/learner.d.ts.map +1 -0
  206. package/dist/services/learner.js +4 -0
  207. package/dist/services/learner.js.map +1 -0
  208. package/dist/services/scanner.d.ts +3 -0
  209. package/dist/services/scanner.d.ts.map +1 -0
  210. package/dist/services/scanner.js +54 -0
  211. package/dist/services/scanner.js.map +1 -0
  212. package/dist/utils/errors.d.ts +15 -0
  213. package/dist/utils/errors.d.ts.map +1 -0
  214. package/dist/utils/errors.js +27 -0
  215. package/dist/utils/errors.js.map +1 -0
  216. package/dist/utils/file.d.ts +7 -0
  217. package/dist/utils/file.d.ts.map +1 -0
  218. package/dist/utils/file.js +32 -0
  219. package/dist/utils/file.js.map +1 -0
  220. package/dist/utils/logger.d.ts +6 -0
  221. package/dist/utils/logger.d.ts.map +1 -0
  222. package/dist/utils/logger.js +17 -0
  223. package/dist/utils/logger.js.map +1 -0
  224. package/dist/utils/path.d.ts +6 -0
  225. package/dist/utils/path.d.ts.map +1 -0
  226. package/dist/utils/path.js +14 -0
  227. package/dist/utils/path.js.map +1 -0
  228. package/docs/planning/memory-lane.md +83 -0
  229. package/package.json +64 -0
  230. package/packaging/linux/aicgen.spec +23 -0
  231. package/packaging/linux/control +9 -0
  232. package/packaging/macos/scripts/postinstall +12 -0
  233. package/packaging/windows/setup.nsi +92 -0
  234. package/planning/BRANDING-SUMMARY.md +194 -0
  235. package/planning/BRANDING.md +174 -0
  236. package/planning/BUILD.md +186 -0
  237. package/planning/CHUNK-IMPLEMENTATION-PLAN.md +87 -0
  238. package/planning/CHUNK-TAXONOMY.md +375 -0
  239. package/planning/CHUNKS-COMPLETE.md +382 -0
  240. package/planning/DESIGN.md +313 -0
  241. package/planning/DYNAMIC-GUIDELINES-DESIGN.md +265 -0
  242. package/planning/ENTERPRISE-UX-COMPLETE.md +281 -0
  243. package/planning/IMPLEMENTATION-PLAN.md +20 -0
  244. package/planning/PHASE1-COMPLETE.md +211 -0
  245. package/planning/PHASE2-COMPLETE.md +350 -0
  246. package/planning/PHASE3-COMPLETE.md +399 -0
  247. package/planning/PHASE4-COMPLETE.md +361 -0
  248. package/planning/PHASE4.5-CHUNKS.md +462 -0
  249. package/planning/STRUCTURE.md +170 -0
  250. package/scripts/add-categories.ts +87 -0
  251. package/scripts/build-binary.ts +46 -0
  252. package/scripts/embed-data.ts +105 -0
  253. package/scripts/generate-version.ts +150 -0
  254. package/scripts/test-decompress.ts +27 -0
  255. package/scripts/test-extract.ts +31 -0
  256. package/src/__tests__/services/assistant-file-writer.test.ts +400 -0
  257. package/src/__tests__/services/guideline-loader.test.ts +281 -0
  258. package/src/__tests__/services/tarball-extraction.test.ts +125 -0
  259. package/src/commands/add-guideline.ts +296 -0
  260. package/src/commands/clear.ts +61 -0
  261. package/src/commands/guideline-selector.ts +123 -0
  262. package/src/commands/init.ts +645 -0
  263. package/src/commands/quick-add.ts +586 -0
  264. package/src/commands/remove-guideline.ts +152 -0
  265. package/src/commands/stats.ts +49 -0
  266. package/src/commands/update.ts +240 -0
  267. package/src/config.ts +82 -0
  268. package/src/embedded-data.ts +1492 -0
  269. package/src/index.ts +67 -0
  270. package/src/models/profile.ts +24 -0
  271. package/src/models/project.ts +43 -0
  272. package/src/services/assistant-file-writer.ts +612 -0
  273. package/src/services/config-generator.ts +150 -0
  274. package/src/services/config-manager.ts +70 -0
  275. package/src/services/data-source.ts +248 -0
  276. package/src/services/first-run-init.ts +148 -0
  277. package/src/services/guideline-loader.ts +311 -0
  278. package/src/services/hook-generator.ts +178 -0
  279. package/src/services/subagent-generator.ts +310 -0
  280. package/src/utils/banner.ts +66 -0
  281. package/src/utils/errors.ts +27 -0
  282. package/src/utils/file.ts +67 -0
  283. package/src/utils/formatting.ts +172 -0
  284. package/src/utils/logger.ts +89 -0
  285. package/src/utils/path.ts +17 -0
  286. package/src/utils/wizard-state.ts +132 -0
  287. package/tsconfig.json +25 -0
@@ -0,0 +1,260 @@
1
+ # Documentation Organization
2
+
3
+ ## Keep Root Clean
4
+
5
+ **RULE: Documentation must NOT clutter the project root.**
6
+
7
+ ```
8
+ ❌ BAD: Root folder mess
9
+ project/
10
+ ├── README.md
11
+ ├── ARCHITECTURE.md
12
+ ├── API_DOCS.md
13
+ ├── DEPLOYMENT.md
14
+ ├── TROUBLESHOOTING.md
15
+ ├── USER_GUIDE.md
16
+ ├── DATABASE_SCHEMA.md
17
+ ├── TESTING_GUIDE.md
18
+ └── ... (20 more .md files)
19
+
20
+ ✅ GOOD: Organized structure
21
+ project/
22
+ ├── README.md (overview only)
23
+ ├── docs/
24
+ │ ├── architecture/
25
+ │ ├── api/
26
+ │ ├── deployment/
27
+ │ └── guides/
28
+ └── src/
29
+ ```
30
+
31
+ ## Documentation Structure
32
+
33
+ **Standard documentation folder:**
34
+
35
+ ```
36
+ docs/
37
+ ├── architecture/
38
+ │ ├── overview.md
39
+ │ ├── decisions/ # Architecture Decision Records
40
+ │ │ ├── 001-database-choice.md
41
+ │ │ └── 002-api-design.md
42
+ │ └── diagrams/
43
+
44
+ ├── api/
45
+ │ ├── endpoints.md
46
+ │ ├── authentication.md
47
+ │ └── examples/
48
+
49
+ ├── guides/
50
+ │ ├── getting-started.md
51
+ │ ├── development.md
52
+ │ ├── deployment.md
53
+ │ └── troubleshooting.md
54
+
55
+ ├── features/ # Organize by feature
56
+ │ ├── user-auth/
57
+ │ │ ├── overview.md
58
+ │ │ ├── implementation.md
59
+ │ │ └── testing.md
60
+ │ ├── payments/
61
+ │ └── notifications/
62
+
63
+ └── planning/ # Active work planning
64
+ ├── memory-lane.md # Context preservation
65
+ ├── current-phase.md # Active work
66
+ └── next-steps.md # Backlog
67
+ ```
68
+
69
+ ## Memory Lane Document
70
+
71
+ **CRITICAL: Maintain context across sessions**
72
+
73
+ ### Purpose
74
+ When AI context limit is reached, reload from memory lane to restore working context.
75
+
76
+ ### Structure
77
+
78
+ ```markdown
79
+ # Memory Lane - Project Context
80
+
81
+ ## Last Updated
82
+ 2024-12-10 15:30
83
+
84
+ ## Current Objective
85
+ Implementing user authentication system with OAuth2 support
86
+
87
+ ## Recent Progress
88
+ - ✅ Set up database schema (2024-12-08)
89
+ - ✅ Implemented user registration (2024-12-09)
90
+ - 🔄 Working on: OAuth2 integration (2024-12-10)
91
+ - ⏳ Next: Session management
92
+
93
+ ## Key Decisions
94
+ 1. **Database**: PostgreSQL chosen for ACID compliance
95
+ 2. **Auth Strategy**: OAuth2 + JWT tokens
96
+ 3. **Session Store**: Redis for performance
97
+
98
+ ## Important Files
99
+ - `src/auth/oauth.ts` - OAuth2 implementation (IN PROGRESS)
100
+ - `src/models/user.ts` - User model and validation
101
+ - `docs/architecture/decisions/003-auth-system.md` - Full context
102
+
103
+ ## Active Questions
104
+ 1. Should we support refresh tokens? (Pending user decision)
105
+ 2. Token expiry: 1h or 24h? (Pending user decision)
106
+
107
+ ## Technical Context
108
+ - Using Passport.js for OAuth
109
+ - Google and GitHub providers configured
110
+ - Callback URLs: /auth/google/callback, /auth/github/callback
111
+
112
+ ## Known Issues
113
+ - OAuth redirect not working in development (investigating)
114
+ - Need to add rate limiting to prevent abuse
115
+
116
+ ## Next Session
117
+ 1. Fix OAuth redirect issue
118
+ 2. Implement refresh token rotation
119
+ 3. Add comprehensive auth tests
120
+ ```
121
+
122
+ ### Update Frequency
123
+ - Update after each significant milestone
124
+ - Update before context limit is reached
125
+ - Update when switching between features
126
+
127
+ ## Context Reload Strategy
128
+
129
+ **For AI Tools with Hooks:**
130
+
131
+ Create a hook to reload memory lane on startup:
132
+
133
+ ```json
134
+ {
135
+ "hooks": {
136
+ "startup": {
137
+ "command": "cat docs/planning/memory-lane.md"
138
+ }
139
+ }
140
+ }
141
+ ```
142
+
143
+ **For AI Tools with Agents:**
144
+
145
+ Create a context restoration agent:
146
+
147
+ ```markdown
148
+ # Context Restoration Agent
149
+
150
+ Task: Read and summarize current project state
151
+
152
+ Sources:
153
+ 1. docs/planning/memory-lane.md
154
+ 2. docs/architecture/decisions/ (recent ADRs)
155
+ 3. git log --oneline -10 (recent commits)
156
+
157
+ Output: Concise summary of where we are and what's next
158
+ ```
159
+
160
+ ## Feature Documentation
161
+
162
+ **Organize by feature/scope, not by type:**
163
+
164
+ ```
165
+ ❌ BAD: Organized by document type
166
+ docs/
167
+ ├── specifications/
168
+ │ ├── auth.md
169
+ │ ├── payments.md
170
+ │ └── notifications.md
171
+ ├── implementations/
172
+ │ ├── auth.md
173
+ │ ├── payments.md
174
+ │ └── notifications.md
175
+ └── tests/
176
+ ├── auth.md
177
+ └── payments.md
178
+
179
+ ✅ GOOD: Organized by feature
180
+ docs/features/
181
+ ├── auth/
182
+ │ ├── specification.md
183
+ │ ├── implementation.md
184
+ │ ├── api.md
185
+ │ └── testing.md
186
+ ├── payments/
187
+ │ ├── specification.md
188
+ │ ├── implementation.md
189
+ │ └── providers.md
190
+ └── notifications/
191
+ ├── specification.md
192
+ └── channels.md
193
+ ```
194
+
195
+ **Benefits:**
196
+ - All related docs in one place
197
+ - Easy to find feature-specific information
198
+ - Natural scope boundaries
199
+ - Easier to maintain
200
+
201
+ ## Planning Documents
202
+
203
+ **Active planning should be in docs/planning/:**
204
+
205
+ ```
206
+ docs/planning/
207
+ ├── memory-lane.md # Context preservation
208
+ ├── current-sprint.md # Active work
209
+ ├── backlog.md # Future work
210
+ └── spike-results/ # Research findings
211
+ ├── database-options.md
212
+ └── auth-libraries.md
213
+ ```
214
+
215
+ ## Documentation Principles
216
+
217
+ 1. **Separate folder**: All docs in `docs/` directory
218
+ 2. **Organize by scope**: Group by feature, not document type
219
+ 3. **Keep root clean**: Only README.md in project root
220
+ 4. **Maintain memory lane**: Update regularly for context preservation
221
+ 5. **Link related docs**: Use relative links between related documents
222
+
223
+ ## README Guidelines
224
+
225
+ **Root README should be concise:**
226
+
227
+ ```markdown
228
+ # Project Name
229
+
230
+ Brief description
231
+
232
+ ## Quick Start
233
+ [Link to docs/guides/getting-started.md]
234
+
235
+ ## Documentation
236
+ - [Architecture](docs/architecture/overview.md)
237
+ - [API Docs](docs/api/endpoints.md)
238
+ - [Development Guide](docs/guides/development.md)
239
+
240
+ ## Contributing
241
+ [Link to CONTRIBUTING.md or docs/guides/contributing.md]
242
+ ```
243
+
244
+ **Keep it short, link to detailed docs.**
245
+
246
+ ## Anti-Patterns
247
+
248
+ ❌ **Don't:**
249
+ - Put 10+ markdown files in project root
250
+ - Mix documentation types in same folder
251
+ - Forget to update memory lane before context expires
252
+ - Create documentation without clear organization
253
+ - Duplicate information across multiple docs
254
+
255
+ ✅ **Do:**
256
+ - Use `docs/` directory for all documentation
257
+ - Organize by feature/scope
258
+ - Maintain memory lane for context preservation
259
+ - Link related documents together
260
+ - Update docs as code evolves
@@ -0,0 +1,11 @@
1
+ # Development Practices
2
+
3
+ This directory contains development best practices.
4
+
5
+ ## Available Chunks
6
+
7
+ - **planning.md** - Planning workflow, phases, asking for clarification, getting approval
8
+ - **documentation.md** - Documentation organization, folder structure, memory lane
9
+ - **code-review.md** - Review guidelines, PR templates, feedback
10
+ - **refactoring.md** - Code smells, refactoring patterns
11
+ - **version-control.md** - Git workflows, branching strategies
@@ -0,0 +1,142 @@
1
+ # Planning Best Practices
2
+
3
+ ## Plan Before Implementation
4
+
5
+ **ALWAYS design and plan before writing code:**
6
+
7
+ 1. **Understand Requirements**
8
+ - Clarify the goal and scope
9
+ - Identify constraints and dependencies
10
+ - Ask questions about ambiguous requirements
11
+
12
+ 2. **Break Down Into Phases**
13
+ - Divide work into logical phases
14
+ - Define deliverables for each phase
15
+ - Prioritize phases by value and dependencies
16
+
17
+ 3. **Design First**
18
+ - Sketch architecture and data flow
19
+ - Identify components and interfaces
20
+ - Consider edge cases and error scenarios
21
+
22
+ 4. **Get User Approval**
23
+ - Present the plan to stakeholders
24
+ - Explain trade-offs and alternatives
25
+ - Wait for approval before implementation
26
+
27
+ ## Never Make Assumptions
28
+
29
+ **CRITICAL: When in doubt, ASK:**
30
+
31
+ ```typescript
32
+ // ❌ BAD: Assuming what user wants
33
+ async function processOrder(orderId: string) {
34
+ // Assuming we should send email, but maybe not?
35
+ await sendConfirmationEmail(orderId);
36
+ // Assuming payment is already captured?
37
+ await fulfillOrder(orderId);
38
+ }
39
+
40
+ // ✅ GOOD: Clarify requirements first
41
+ // Q: Should we send confirmation email at this stage?
42
+ // Q: Is payment already captured or should we capture it here?
43
+ // Q: What happens if fulfillment fails?
44
+ ```
45
+
46
+ **Ask about:**
47
+ - Expected behavior in edge cases
48
+ - Error handling strategy
49
+ - Performance requirements
50
+ - Security considerations
51
+ - User experience preferences
52
+
53
+ ## Plan in Phases
54
+
55
+ **Structure work into clear phases:**
56
+
57
+ ### Phase 1: Foundation
58
+ - Set up project structure
59
+ - Configure tooling and dependencies
60
+ - Create basic types and interfaces
61
+
62
+ ### Phase 2: Core Implementation
63
+ - Implement main business logic
64
+ - Add error handling
65
+ - Write unit tests
66
+
67
+ ### Phase 3: Integration
68
+ - Connect components
69
+ - Add integration tests
70
+ - Handle edge cases
71
+
72
+ ### Phase 4: Polish
73
+ - Performance optimization
74
+ - Documentation
75
+ - Final review
76
+
77
+ **Checkpoint after each phase:**
78
+ - Demo functionality
79
+ - Get feedback
80
+ - Adjust plan if needed
81
+
82
+ ## Planning Template
83
+
84
+ ```markdown
85
+ ## Goal
86
+ [What are we building and why?]
87
+
88
+ ## Requirements
89
+ - [ ] Requirement 1
90
+ - [ ] Requirement 2
91
+ - [ ] Requirement 3
92
+
93
+ ## Questions for Clarification
94
+ 1. [Question about requirement X]
95
+ 2. [Question about edge case Y]
96
+ 3. [Question about preferred approach for Z]
97
+
98
+ ## Proposed Approach
99
+ [Describe the solution]
100
+
101
+ ## Phases
102
+ 1. **Phase 1**: [Description]
103
+ - Task 1
104
+ - Task 2
105
+
106
+ 2. **Phase 2**: [Description]
107
+ - Task 1
108
+ - Task 2
109
+
110
+ ## Risks & Mitigation
111
+ - **Risk**: [Description]
112
+ **Mitigation**: [How to handle]
113
+
114
+ ## Alternatives Considered
115
+ - **Option A**: [Pros/Cons]
116
+ - **Option B**: [Pros/Cons]
117
+ - **Chosen**: Option A because [reason]
118
+ ```
119
+
120
+ ## Communication Principles
121
+
122
+ 1. **Ask Early**: Don't wait until you're stuck
123
+ 2. **Be Specific**: "Should error X retry or fail immediately?"
124
+ 3. **Propose Options**: "Would you prefer A or B?"
125
+ 4. **Explain Trade-offs**: "Fast but risky vs. Slow but safe"
126
+ 5. **Document Decisions**: Record what was decided and why
127
+
128
+ ## Anti-Patterns
129
+
130
+ ❌ **Don't:**
131
+ - Start coding without understanding requirements
132
+ - Assume you know what the user wants
133
+ - Skip the planning phase to "save time"
134
+ - Make architectural decisions without discussion
135
+ - Proceed with unclear requirements
136
+
137
+ ✅ **Do:**
138
+ - Ask questions when requirements are vague
139
+ - Create a plan and get it approved
140
+ - Break work into reviewable phases
141
+ - Document decisions and reasoning
142
+ - Communicate early and often
@@ -0,0 +1,91 @@
1
+ # Refactoring Patterns
2
+
3
+ ## Common Code Smells
4
+
5
+ ### Long Method
6
+ Split into smaller, focused functions.
7
+
8
+ ```typescript
9
+ // Before
10
+ function processOrder(order: Order) {
11
+ // 100 lines of code...
12
+ }
13
+
14
+ // After
15
+ function processOrder(order: Order) {
16
+ validateOrder(order);
17
+ calculateTotals(order);
18
+ applyDiscounts(order);
19
+ saveOrder(order);
20
+ }
21
+ ```
22
+
23
+ ### Duplicate Code
24
+ Extract common logic.
25
+
26
+ ```typescript
27
+ // Before
28
+ function getAdminUsers() {
29
+ return users.filter(u => u.role === 'admin' && u.active);
30
+ }
31
+ function getModeratorUsers() {
32
+ return users.filter(u => u.role === 'moderator' && u.active);
33
+ }
34
+
35
+ // After
36
+ function getActiveUsersByRole(role: string) {
37
+ return users.filter(u => u.role === role && u.active);
38
+ }
39
+ ```
40
+
41
+ ### Primitive Obsession
42
+ Use value objects.
43
+
44
+ ```typescript
45
+ // Before
46
+ function sendEmail(email: string) { /* ... */ }
47
+
48
+ // After
49
+ class Email {
50
+ constructor(private value: string) {
51
+ if (!this.isValid(value)) throw new Error('Invalid email');
52
+ }
53
+ }
54
+ function sendEmail(email: Email) { /* ... */ }
55
+ ```
56
+
57
+ ### Feature Envy
58
+ Move method to class it uses most.
59
+
60
+ ```typescript
61
+ // Before - Order is accessing customer too much
62
+ class Order {
63
+ getDiscount() {
64
+ return this.customer.isPremium() ?
65
+ this.customer.premiumDiscount :
66
+ this.customer.regularDiscount;
67
+ }
68
+ }
69
+
70
+ // After
71
+ class Customer {
72
+ getDiscount(): number {
73
+ return this.isPremium() ? this.premiumDiscount : this.regularDiscount;
74
+ }
75
+ }
76
+ ```
77
+
78
+ ## Safe Refactoring Steps
79
+
80
+ 1. Ensure tests pass before refactoring
81
+ 2. Make one small change at a time
82
+ 3. Run tests after each change
83
+ 4. Commit frequently
84
+ 5. Refactor in separate commits from feature work
85
+
86
+ ## Best Practices
87
+
88
+ - Refactor when adding features, not separately
89
+ - Keep refactoring commits separate
90
+ - Use IDE refactoring tools when available
91
+ - Write tests before refactoring if missing
@@ -0,0 +1,55 @@
1
+ # Version Control Patterns
2
+
3
+ ## Branching Strategies
4
+
5
+ ### GitHub Flow
6
+ Simple: main + feature branches.
7
+
8
+ ```
9
+ main ─────●─────●─────●─────●─────
10
+ \ /
11
+ feature ●───●───●
12
+ ```
13
+
14
+ ### Git Flow
15
+ For scheduled releases: main, develop, feature, release, hotfix.
16
+
17
+ ```
18
+ main ─────●─────────────●─────
19
+ \ /
20
+ release ●─────────●
21
+ \ /
22
+ develop ●───●───●───●───●───●───
23
+ \ /
24
+ feature ●───●
25
+ ```
26
+
27
+ ## Commit Messages
28
+
29
+ ```
30
+ feat: add user authentication
31
+
32
+ - Implement JWT-based auth
33
+ - Add login/logout endpoints
34
+ - Include password hashing
35
+
36
+ Closes #123
37
+ ```
38
+
39
+ **Prefixes:**
40
+ - `feat:` - New feature
41
+ - `fix:` - Bug fix
42
+ - `refactor:` - Code change that doesn't fix bug or add feature
43
+ - `docs:` - Documentation only
44
+ - `test:` - Adding tests
45
+ - `chore:` - Maintenance tasks
46
+
47
+ ## Best Practices
48
+
49
+ - Keep commits atomic and focused
50
+ - Write descriptive commit messages
51
+ - Pull/rebase before pushing
52
+ - Never force push to shared branches
53
+ - Use pull requests for code review
54
+ - Delete merged branches
55
+ - Tag releases with semantic versions
@@ -0,0 +1,159 @@
1
+ # Authentication & JWT Security
2
+
3
+ ## Password Storage
4
+
5
+ ```typescript
6
+ import bcrypt from 'bcrypt';
7
+
8
+ const SALT_ROUNDS = 12; // Work factor
9
+
10
+ // ✅ Hash password with bcrypt
11
+ async function hashPassword(password: string): Promise<string> {
12
+ return bcrypt.hash(password, SALT_ROUNDS);
13
+ }
14
+
15
+ async function verifyPassword(password: string, hash: string): Promise<boolean> {
16
+ return bcrypt.compare(password, hash);
17
+ }
18
+
19
+ // ✅ Validate password strength
20
+ function validatePassword(password: string): void {
21
+ if (password.length < 12) {
22
+ throw new Error('Password must be at least 12 characters');
23
+ }
24
+ if (password.length > 160) {
25
+ throw new Error('Password too long'); // Prevent DoS via bcrypt
26
+ }
27
+ }
28
+ ```
29
+
30
+ ## JWT Best Practices
31
+
32
+ ```typescript
33
+ import jwt from 'jsonwebtoken';
34
+
35
+ const JWT_SECRET = process.env.JWT_SECRET!;
36
+ const ACCESS_TOKEN_EXPIRY = '15m';
37
+ const REFRESH_TOKEN_EXPIRY = '7d';
38
+
39
+ // ✅ Generate tokens
40
+ function generateTokens(userId: string) {
41
+ const accessToken = jwt.sign(
42
+ { sub: userId, type: 'access' },
43
+ JWT_SECRET,
44
+ { expiresIn: ACCESS_TOKEN_EXPIRY }
45
+ );
46
+
47
+ const refreshToken = jwt.sign(
48
+ { sub: userId, type: 'refresh' },
49
+ JWT_SECRET,
50
+ { expiresIn: REFRESH_TOKEN_EXPIRY }
51
+ );
52
+
53
+ return { accessToken, refreshToken };
54
+ }
55
+
56
+ // ✅ Verify and decode token
57
+ function verifyToken(token: string) {
58
+ try {
59
+ return jwt.verify(token, JWT_SECRET);
60
+ } catch (error) {
61
+ if (error instanceof jwt.TokenExpiredError) {
62
+ throw new UnauthorizedError('Token expired');
63
+ }
64
+ throw new UnauthorizedError('Invalid token');
65
+ }
66
+ }
67
+ ```
68
+
69
+ ## Login Protection
70
+
71
+ ```typescript
72
+ import rateLimit from 'express-rate-limit';
73
+
74
+ // ✅ Rate limit login attempts
75
+ const loginLimiter = rateLimit({
76
+ windowMs: 15 * 60 * 1000, // 15 minutes
77
+ max: 5, // 5 attempts
78
+ message: 'Too many login attempts, please try again later',
79
+ });
80
+
81
+ app.post('/login', loginLimiter, async (req, res) => {
82
+ const { email, password } = req.body;
83
+
84
+ const user = await userService.findByEmail(email);
85
+
86
+ // ✅ Generic error message (don't reveal if user exists)
87
+ if (!user || !await verifyPassword(password, user.passwordHash)) {
88
+ return res.status(401).json({ error: 'Invalid email or password' });
89
+ }
90
+
91
+ const tokens = generateTokens(user.id);
92
+
93
+ // Regenerate session to prevent fixation
94
+ req.session.regenerate(() => {
95
+ res.json({ ...tokens });
96
+ });
97
+ });
98
+ ```
99
+
100
+ ## Session Security
101
+
102
+ ```typescript
103
+ app.use(session({
104
+ secret: process.env.SESSION_SECRET!,
105
+ name: 'sessionId', // Don't use default 'connect.sid'
106
+
107
+ cookie: {
108
+ secure: true, // HTTPS only
109
+ httpOnly: true, // Prevent XSS access
110
+ sameSite: 'strict', // CSRF protection
111
+ maxAge: 30 * 60 * 1000, // 30 minutes
112
+ },
113
+
114
+ resave: false,
115
+ saveUninitialized: false,
116
+ store: new RedisStore({ client: redisClient })
117
+ }));
118
+
119
+ // ✅ Session regeneration after login
120
+ app.post('/login', async (req, res, next) => {
121
+ // ... authenticate user ...
122
+
123
+ req.session.regenerate((err) => {
124
+ req.session.userId = user.id;
125
+ res.json({ success: true });
126
+ });
127
+ });
128
+ ```
129
+
130
+ ## Authorization Middleware
131
+
132
+ ```typescript
133
+ // ✅ Require authentication
134
+ const requireAuth = async (req: Request, res: Response, next: NextFunction) => {
135
+ const token = req.headers.authorization?.replace('Bearer ', '');
136
+
137
+ if (!token) {
138
+ return res.status(401).json({ error: 'Authentication required' });
139
+ }
140
+
141
+ try {
142
+ const payload = verifyToken(token);
143
+ req.user = await userService.findById(payload.sub);
144
+ next();
145
+ } catch (error) {
146
+ res.status(401).json({ error: 'Invalid token' });
147
+ }
148
+ };
149
+
150
+ // ✅ Require specific role
151
+ const requireRole = (...roles: string[]) => {
152
+ return (req: Request, res: Response, next: NextFunction) => {
153
+ if (!roles.includes(req.user.role)) {
154
+ return res.status(403).json({ error: 'Forbidden' });
155
+ }
156
+ next();
157
+ };
158
+ };
159
+ ```