cc-codeconductor 0.4.3 → 0.5.0

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 (141) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +2642 -226
  3. package/package.json +1 -1
  4. package/presets/agy/skills/evaluation/SKILL.md +6 -0
  5. package/presets/agy/skills/openspec/SKILL.md +32 -0
  6. package/presets/agy/workflows/cc-openspec.md +62 -0
  7. package/presets/agy/workflows/cc-scorecard.md +17 -0
  8. package/presets/claude/commands/cc/openspec.md +144 -0
  9. package/presets/claude/commands/cc/review.md +13 -2
  10. package/presets/claude/commands/cc/scorecard.md +65 -0
  11. package/presets/claude/skills/evaluation/SKILL.md +42 -0
  12. package/presets/claude/skills/openspec/SKILL.md +54 -0
  13. package/presets/codex/AGENTS.md +57 -0
  14. package/presets/cursor/.cursorignore +15 -0
  15. package/presets/cursor/AGENTS.md +504 -0
  16. package/presets/cursor/agents/architect.md +211 -0
  17. package/presets/cursor/agents/complexity-auditor.md +76 -0
  18. package/presets/cursor/agents/contract-builder.md +75 -0
  19. package/presets/cursor/agents/docs.md +180 -0
  20. package/presets/cursor/agents/goal-planner.md +71 -0
  21. package/presets/cursor/agents/implementer.md +161 -0
  22. package/presets/cursor/agents/orchestrator.md +377 -0
  23. package/presets/cursor/agents/repo-explorer.md +100 -0
  24. package/presets/cursor/agents/reviewer.md +237 -0
  25. package/presets/cursor/agents/security-reviewer.md +113 -0
  26. package/presets/cursor/agents/task-coach.md +145 -0
  27. package/presets/cursor/agents/tester.md +241 -0
  28. package/presets/cursor/commands/cc/api-contract.md +58 -0
  29. package/presets/cursor/commands/cc/db-migration.md +58 -0
  30. package/presets/cursor/commands/cc/feature.md +115 -0
  31. package/presets/cursor/commands/cc/fix.md +121 -0
  32. package/presets/cursor/commands/cc/openspec.md +144 -0
  33. package/presets/cursor/commands/cc/pagespeed.md +103 -0
  34. package/presets/cursor/commands/cc/refactor.md +148 -0
  35. package/presets/cursor/commands/cc/review.md +137 -0
  36. package/presets/cursor/commands/cc/scorecard.md +65 -0
  37. package/presets/cursor/commands/cc/tdd-cycle.md +226 -0
  38. package/presets/cursor/commands/cc/test-plan.md +138 -0
  39. package/presets/cursor/rules/behavioral-discipline.mdc +14 -0
  40. package/presets/cursor/rules/context-budget.mdc +12 -0
  41. package/presets/cursor/rules/orchestration.mdc +12 -0
  42. package/presets/cursor/rules/yagni-stdlib.mdc +11 -0
  43. package/presets/cursor/skills/android/SKILL.md +122 -0
  44. package/presets/cursor/skills/api-versioning/SKILL.md +394 -0
  45. package/presets/cursor/skills/astro/SKILL.md +322 -0
  46. package/presets/cursor/skills/auth-token-inspector/SKILL.md +33 -0
  47. package/presets/cursor/skills/code-review/SKILL.md +208 -0
  48. package/presets/cursor/skills/conductor-setup/SKILL.md +127 -0
  49. package/presets/cursor/skills/django-orm/SKILL.md +463 -0
  50. package/presets/cursor/skills/django-testing/SKILL.md +417 -0
  51. package/presets/cursor/skills/django-uv/SKILL.md +409 -0
  52. package/presets/cursor/skills/drizzle-schema-architect/SKILL.md +54 -0
  53. package/presets/cursor/skills/evaluation/SKILL.md +8 -0
  54. package/presets/cursor/skills/fastapi-pydantic-strict/SKILL.md +46 -0
  55. package/presets/cursor/skills/find-skills/SKILL.md +144 -0
  56. package/presets/cursor/skills/jpa-nplusone-detector/SKILL.md +49 -0
  57. package/presets/cursor/skills/jpa-postgres/SKILL.md +626 -0
  58. package/presets/cursor/skills/laravel-specialist/SKILL.md +267 -0
  59. package/presets/cursor/skills/laravel-specialist/references/eloquent.md +351 -0
  60. package/presets/cursor/skills/laravel-specialist/references/livewire.md +512 -0
  61. package/presets/cursor/skills/laravel-specialist/references/queues.md +423 -0
  62. package/presets/cursor/skills/laravel-specialist/references/routing.md +362 -0
  63. package/presets/cursor/skills/laravel-specialist/references/testing.md +522 -0
  64. package/presets/cursor/skills/livewire-alpine-bridge/SKILL.md +39 -0
  65. package/presets/cursor/skills/multi-agent-orchestration/README.md +144 -0
  66. package/presets/cursor/skills/multi-agent-orchestration/SKILL.md +579 -0
  67. package/presets/cursor/skills/multi-agent-orchestration/examples/framework_implementations.py +362 -0
  68. package/presets/cursor/skills/multi-agent-orchestration/examples/orchestration_patterns.py +411 -0
  69. package/presets/cursor/skills/multi-agent-orchestration/scripts/agent_communication.py +334 -0
  70. package/presets/cursor/skills/multi-agent-orchestration/scripts/benchmarking.py +341 -0
  71. package/presets/cursor/skills/multi-agent-orchestration/scripts/workflow_management.py +334 -0
  72. package/presets/cursor/skills/nextjs-typescript/SKILL.md +394 -0
  73. package/presets/cursor/skills/openspec/SKILL.md +52 -0
  74. package/presets/cursor/skills/pagespeed-insights/SKILL.md +445 -0
  75. package/presets/cursor/skills/pagespeed-insights/reference.md +50 -0
  76. package/presets/cursor/skills/pagespeed-perf/SKILL.md +281 -0
  77. package/presets/cursor/skills/php-pro/SKILL.md +210 -0
  78. package/presets/cursor/skills/php-pro/references/async-patterns.md +412 -0
  79. package/presets/cursor/skills/php-pro/references/laravel-patterns.md +377 -0
  80. package/presets/cursor/skills/php-pro/references/modern-php-features.md +323 -0
  81. package/presets/cursor/skills/php-pro/references/symfony-patterns.md +466 -0
  82. package/presets/cursor/skills/php-pro/references/testing-quality.md +466 -0
  83. package/presets/cursor/skills/python/SKILL.md +613 -0
  84. package/presets/cursor/skills/python-django-stack/SKILL.md +500 -0
  85. package/presets/cursor/skills/python-fastapi-stack/SKILL.md +464 -0
  86. package/presets/cursor/skills/security/SKILL.md +384 -0
  87. package/presets/cursor/skills/seo-analytics-injector/SKILL.md +44 -0
  88. package/presets/cursor/skills/spring-auth-auditor/SKILL.md +33 -0
  89. package/presets/cursor/skills/spring-boot-feature/SKILL.md +566 -0
  90. package/presets/cursor/skills/spring-boot-kotlin/SKILL.md +408 -0
  91. package/presets/cursor/skills/spring-boot-testing-strategy/SKILL.md +479 -0
  92. package/presets/cursor/skills/sqlalchemy/SKILL.md +473 -0
  93. package/presets/cursor/skills/tailwind-responsive-auditor/SKILL.md +32 -0
  94. package/presets/cursor/skills/tdd-mutation-tester/SKILL.md +28 -0
  95. package/presets/cursor/skills/testing-tdd/SKILL.md +592 -0
  96. package/presets/cursor/skills/workflow-orchestration-patterns/SKILL.md +98 -0
  97. package/presets/cursor/skills/workflow-orchestration-patterns/references/details.md +223 -0
  98. package/presets/opencode/agents/architect.md +1 -2
  99. package/presets/opencode/agents/complexity-auditor.md +1 -0
  100. package/presets/opencode/agents/contract-builder.md +93 -0
  101. package/presets/opencode/agents/docs.md +1 -2
  102. package/presets/opencode/agents/goal-planner.md +82 -0
  103. package/presets/opencode/agents/implementer.md +9 -2
  104. package/presets/opencode/agents/orchestrator.md +50 -12
  105. package/presets/opencode/agents/repo-explorer.md +0 -1
  106. package/presets/opencode/agents/reviewer.md +23 -2
  107. package/presets/opencode/agents/security-reviewer.md +129 -0
  108. package/presets/opencode/agents/task-coach.md +1 -2
  109. package/presets/opencode/agents/tester.md +1 -2
  110. package/presets/opencode/commands/cc-openspec.md +61 -0
  111. package/presets/opencode/commands/cc-scorecard.md +16 -0
  112. package/presets/opencode/prompts/v0.5.0/architect.md +222 -0
  113. package/presets/opencode/prompts/v0.5.0/complexity-auditor.md +91 -0
  114. package/presets/opencode/prompts/v0.5.0/contract-builder.md +84 -0
  115. package/presets/opencode/prompts/v0.5.0/docs.md +190 -0
  116. package/presets/opencode/prompts/v0.5.0/goal-planner.md +80 -0
  117. package/presets/opencode/prompts/v0.5.0/implementer.md +171 -0
  118. package/presets/opencode/prompts/v0.5.0/orchestrator.md +388 -0
  119. package/presets/opencode/prompts/v0.5.0/repo-explorer.md +111 -0
  120. package/presets/opencode/prompts/v0.5.0/reviewer.md +248 -0
  121. package/presets/opencode/prompts/v0.5.0/security-reviewer.md +123 -0
  122. package/presets/opencode/prompts/v0.5.0/task-coach.md +156 -0
  123. package/presets/opencode/prompts/v0.5.0/tester.md +252 -0
  124. package/presets/opencode/skills/evaluation/SKILL.md +6 -0
  125. package/presets/opencode/skills/openspec/SKILL.md +50 -0
  126. package/presets/templates/BACKLOG.md +33 -0
  127. package/presets/templates/execution-profile.yml +6 -0
  128. package/presets/templates/model-comparison.md +11 -0
  129. package/presets/templates/regression-checklist.yml +10 -0
  130. package/src/presets/manifests/agy.yml +2 -2
  131. package/src/presets/manifests/claude.yml +2 -2
  132. package/src/presets/manifests/codex.yml +2 -2
  133. package/src/presets/manifests/cursor.yml +19 -3
  134. package/src/presets/manifests/gemini.yml +2 -2
  135. package/src/presets/manifests/opencode.yml +2 -2
  136. package/src/presets/models/agy.yml +21 -0
  137. package/src/presets/models/claude.yml +18 -0
  138. package/src/presets/models/codex.yml +18 -0
  139. package/src/presets/models/cursor.yml +39 -9
  140. package/src/presets/models/gemini.yml +18 -0
  141. package/src/presets/models/opencode.yml +18 -0
@@ -0,0 +1,394 @@
1
+ ---
2
+ id: api-versioning
3
+ version: 1.0.0
4
+ name: API Versioning
5
+ description: >
6
+ Provides expert knowledge for designing, implementing, and managing REST API
7
+ versioning strategies with deprecation workflows.
8
+
9
+ user-invokable: true
10
+ license: MIT
11
+ metadata:
12
+ author: lgzarturo
13
+ category: api
14
+
15
+ compatibility:
16
+ tools: [claude, codex, gemini, agy, opencode]
17
+ stacks:
18
+ languages: [kotlin, java, typescript, python, go]
19
+ frameworks: [spring-boot, spring-mvc, express, fastapi]
20
+
21
+ risk:
22
+ level: high
23
+ can_execute_shell: false
24
+ can_modify_files: true
25
+ requires_network: false
26
+
27
+ inputs:
28
+ - source_files
29
+ - openapi spec files
30
+ - existing controller classes
31
+
32
+ outputs:
33
+ - versioned controller classes
34
+ - OpenAPI spec updates
35
+ - deprecation headers
36
+ - changelog entries
37
+ - contract test scaffolding
38
+
39
+ quality:
40
+ reviewed_by: codeconductor-core
41
+ version: 0.1.0
42
+ ---
43
+ # API Versioning
44
+
45
+ ## Versioning Strategies
46
+
47
+ ### URL Path Versioning (recommended for breaking changes)
48
+
49
+ ```text
50
+ GET /api/v1/users
51
+ GET /api/v2/users
52
+ ```
53
+
54
+ Tradeoffs:
55
+
56
+ - Explicit and visible in logs, proxies, and browser history
57
+ - Easy to cache at the CDN level — the URL uniquely identifies the resource
58
+ version
59
+ - Easy to route at the load balancer
60
+ - Results in some duplication of controller code
61
+ - Changing the URL violates REST HATEOAS principles, though in practice this is
62
+ acceptable
63
+
64
+ Use this when: you have breaking changes and need maximum visibility and
65
+ cacheability.
66
+
67
+ ### Header Versioning
68
+
69
+ ```text
70
+ GET /api/users
71
+ Accept: application/vnd.myapp+json;version=1
72
+ ```
73
+
74
+ Tradeoffs:
75
+
76
+ - Cleaner URLs
77
+ - Harder to test manually — browsers and curl require extra flags
78
+ - Cannot be bookmarked or linked directly
79
+ - CDN caching requires `Vary: Accept` header, which reduces cache hit rates
80
+
81
+ Use this when: you need clean URLs and your clients are all programmatic (no
82
+ browsers).
83
+
84
+ ### Query Parameter Versioning (avoid)
85
+
86
+ ```text
87
+ GET /api/users?version=1
88
+ ```
89
+
90
+ This approach contaminates resource URLs with transport concerns. The version is
91
+ not part of the resource identity. Do not use it. The only valid exception is
92
+ temporary backward-compat support during a migration window.
93
+
94
+ ## When to Version
95
+
96
+ Version when the change is breaking. Not every change requires a version bump.
97
+
98
+ **Breaking — requires new version:**
99
+
100
+ - Removing a field from a response
101
+ - Renaming a field
102
+ - Changing a field's type (e.g., `string` to `object`)
103
+ - Changing the meaning of an existing field
104
+ - Removing an endpoint
105
+ - Changing required fields in a request
106
+ - Changing status codes in a non-additive way
107
+
108
+ **Not breaking — no version bump needed:**
109
+
110
+ - Adding an optional field to a response
111
+ - Adding a new endpoint
112
+ - Adding an optional request parameter
113
+ - Deprecating a field (marking it, but still returning it)
114
+ - Performance improvements
115
+ - Bug fixes that restore documented behavior
116
+
117
+ ## Deprecation Process
118
+
119
+ When a version or endpoint is being phased out, follow this process:
120
+
121
+ **Step 1: Mark in OpenAPI.**
122
+
123
+ ```yaml
124
+ paths:
125
+ /api/v1/users/{id}:
126
+ get:
127
+ deprecated: true
128
+ description: |
129
+ Deprecated since 2026-05-07. Use /api/v2/users/{id} instead.
130
+ Sunset date: 2026-11-07.
131
+ summary: Get user by ID (deprecated)
132
+ ```
133
+
134
+ **Step 2: Add deprecation headers to responses.**
135
+
136
+ ```kotlin
137
+ @GetMapping("/{id}")
138
+ fun getUserV1(@PathVariable id: UUID, response: HttpServletResponse): ResponseEntity<UserV1Response> {
139
+ response.addHeader("Deprecation", "date=\"Wed, 07 May 2026 00:00:00 GMT\"")
140
+ response.addHeader("Sunset", "Mon, 07 Nov 2026 00:00:00 GMT")
141
+ response.addHeader("Link", "</api/v2/users/$id>; rel=\"successor-version\"")
142
+ return ResponseEntity.ok(userService.getById(id).toV1Response())
143
+ }
144
+ ```
145
+
146
+ **Step 3: Document in CHANGELOG.**
147
+
148
+ ```markdown
149
+ ## Deprecated
150
+
151
+ - `GET /api/v1/users/{id}` — deprecated in favor of `GET /api/v2/users/{id}`.
152
+ Sunset: 2026-11-07.
153
+ ```
154
+
155
+ **Step 4: Maintain dual support.**
156
+
157
+ Keep at least two active major versions at all times. When v3 ships, v1 can be
158
+ removed (v2 and v3 remain active).
159
+
160
+ **Step 5: Communicate the sunset date.**
161
+
162
+ Notify consumers before the sunset date through:
163
+
164
+ - API changelog
165
+ - Developer portal announcements
166
+ - Deprecation headers (machine-readable)
167
+ - Direct contact if you have consumer registration data
168
+
169
+ Do not remove a version without a minimum 6-month notice period. 3 months is the
170
+ absolute minimum if forced.
171
+
172
+ ## OpenAPI Conventions
173
+
174
+ ### One file per version (simple cases)
175
+
176
+ ```text
177
+ openapi-v1.yaml
178
+ openapi-v2.yaml
179
+ ```
180
+
181
+ Each file is self-contained and independently valid.
182
+
183
+ ### Single file with version in info (evolving APIs)
184
+
185
+ ```yaml
186
+ openapi: '3.1.0'
187
+ info:
188
+ title: Users API
189
+ version: '2.0.0'
190
+ ```
191
+
192
+ Use `$ref` to share schemas across versions without duplication.
193
+
194
+ ### Cross-version schema reuse
195
+
196
+ ```yaml
197
+ # schemas/user-base.yaml
198
+ UserBase:
199
+ type: object
200
+ properties:
201
+ id:
202
+ type: string
203
+ format: uuid
204
+ email:
205
+ type: string
206
+
207
+ # openapi-v1.yaml
208
+ components:
209
+ schemas:
210
+ UserResponse:
211
+ allOf:
212
+ - $ref: './schemas/user-base.yaml#/UserBase'
213
+ - properties:
214
+ full_name:
215
+ type: string
216
+
217
+ # openapi-v2.yaml — splits full_name into first_name + last_name
218
+ components:
219
+ schemas:
220
+ UserResponse:
221
+ allOf:
222
+ - $ref: './schemas/user-base.yaml#/UserBase'
223
+ - properties:
224
+ first_name:
225
+ type: string
226
+ last_name:
227
+ type: string
228
+ ```
229
+
230
+ ### Documenting breaking changes
231
+
232
+ Put the breaking change in the endpoint description, not just in a changelog:
233
+
234
+ ```yaml
235
+ /api/v2/users/{id}:
236
+ get:
237
+ description: |
238
+ Returns user details.
239
+
240
+ Breaking changes from v1:
241
+ - `full_name` has been replaced by `first_name` and `last_name`
242
+ ```
243
+
244
+ ## Spring Boot Implementation
245
+
246
+ ### URL path versioning
247
+
248
+ ```kotlin
249
+ // V1 controller — never modify once published
250
+ @RestController
251
+ @RequestMapping("/api/v1/users")
252
+ class UserV1Controller(private val userService: UserService) {
253
+
254
+ @GetMapping("/{id}")
255
+ @Deprecated("Use /api/v2/users/{id}", ReplaceWith("UserV2Controller.getUser()"))
256
+ fun getUser(
257
+ @PathVariable id: UUID,
258
+ response: HttpServletResponse
259
+ ): ResponseEntity<UserV1Response> {
260
+ response.addHeader("Deprecation", "date=\"Wed, 07 May 2026 00:00:00 GMT\"")
261
+ response.addHeader("Sunset", "Mon, 07 Nov 2026 00:00:00 GMT")
262
+ return when (val result = userService.getById(id)) {
263
+ is UserResult.Found -> ResponseEntity.ok(result.user.toV1Response())
264
+ is UserResult.NotFound -> ResponseEntity.notFound().build()
265
+ }
266
+ }
267
+ }
268
+
269
+ // V2 controller — new version, new controller, shared service
270
+ @RestController
271
+ @RequestMapping("/api/v2/users")
272
+ class UserV2Controller(private val userService: UserService) {
273
+
274
+ @GetMapping("/{id}")
275
+ fun getUser(@PathVariable id: UUID): ResponseEntity<UserV2Response> {
276
+ return when (val result = userService.getById(id)) {
277
+ is UserResult.Found -> ResponseEntity.ok(result.user.toV2Response())
278
+ is UserResult.NotFound -> ResponseEntity.notFound().build()
279
+ }
280
+ }
281
+ }
282
+ ```
283
+
284
+ Rules:
285
+
286
+ - Create a new controller for each new version — do not modify the existing one
287
+ - The service layer is shared across versions — only the controller and DTO
288
+ change
289
+ - DTO mapper functions are version-specific: `toV1Response()`, `toV2Response()`
290
+ - Never delete a versioned controller until after the sunset date
291
+
292
+ ### DTO versioning
293
+
294
+ ```kotlin
295
+ // V1 — original shape
296
+ data class UserV1Response(
297
+ val id: UUID,
298
+ val email: String,
299
+ val full_name: String
300
+ )
301
+
302
+ // V2 — breaking change: split full_name
303
+ data class UserV2Response(
304
+ val id: UUID,
305
+ val email: String,
306
+ val first_name: String,
307
+ val last_name: String
308
+ )
309
+
310
+ // Extension functions for mapping
311
+ fun User.toV1Response(): UserV1Response = UserV1Response(
312
+ id = id,
313
+ email = email,
314
+ full_name = "$firstName $lastName"
315
+ )
316
+
317
+ fun User.toV2Response(): UserV2Response = UserV2Response(
318
+ id = id,
319
+ email = email,
320
+ first_name = firstName,
321
+ last_name = lastName
322
+ )
323
+ ```
324
+
325
+ ## Contract Testing
326
+
327
+ Contract tests verify that your API does not break existing consumers before
328
+ changes reach production.
329
+
330
+ **When to run:** in CI, before merging any change that touches a controller,
331
+ DTO, or OpenAPI spec.
332
+
333
+ **Tool: Pact (consumer-driven contracts)**
334
+
335
+ Consumer writes a pact:
336
+
337
+ ```kotlin
338
+ // In the consumer service test
339
+ @ExtendWith(PactConsumerTestExt::class)
340
+ class UserServiceConsumerTest {
341
+
342
+ @Pact(consumer = "order-service", provider = "user-service")
343
+ fun getUserPact(builder: PactDslWithProvider): RequestResponsePact {
344
+ return builder
345
+ .given("user with id exists")
346
+ .uponReceiving("a request for user by id")
347
+ .path("/api/v1/users/123e4567-e89b-12d3-a456-426614174000")
348
+ .method("GET")
349
+ .willRespondWith()
350
+ .status(200)
351
+ .body(LambdaDsl.newJsonBody { body ->
352
+ body.uuid("id")
353
+ body.stringType("email")
354
+ body.stringType("full_name")
355
+ }.build())
356
+ .toPact()
357
+ }
358
+ }
359
+ ```
360
+
361
+ Provider verifies the pact:
362
+
363
+ ```kotlin
364
+ @Provider("user-service")
365
+ @PactFolder("pacts")
366
+ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
367
+ class UserServiceProviderTest {
368
+
369
+ @TestTarget
370
+ lateinit var target: HttpTestTarget
371
+
372
+ @BeforeEach
373
+ fun setUp(@LocalServerPort port: Int) {
374
+ target = HttpTestTarget("localhost", port)
375
+ }
376
+ }
377
+ ```
378
+
379
+ **Rule:** run contract tests in CI before any merge that touches an API surface.
380
+ A broken contract test means a consumer will break in production.
381
+
382
+ ## Test Structure Per Version
383
+
384
+ Each API version must have its own test class:
385
+
386
+ ```text
387
+ src/test/kotlin/{package}/user/
388
+ controller/
389
+ UserV1ControllerTest.kt # tests for v1 endpoints
390
+ UserV2ControllerTest.kt # tests for v2 endpoints
391
+ ```
392
+
393
+ Do not share test cases across versions. V1 behavior must be tested
394
+ independently from V2 — they can diverge.
@@ -0,0 +1,322 @@
1
+ ---
2
+ id: astro
3
+ version: 1.0.0
4
+ name: Astro
5
+ description: >
6
+ Provides expert knowledge for building Astro 5+ sites with Islands Architecture, Content Collections, TypeScript, and performance-first rendering strategies.
7
+
8
+ user-invokable: true
9
+ license: MIT
10
+ metadata:
11
+ author: lgzarturo
12
+ category: frontend
13
+
14
+ compatibility:
15
+ tools: [claude, codex, gemini, agy, opencode]
16
+ stacks:
17
+ languages: []
18
+ frameworks: []
19
+
20
+ risk:
21
+ level: low
22
+ can_execute_shell: false
23
+ can_modify_files: true
24
+ requires_network: false
25
+
26
+ inputs: []
27
+
28
+ outputs: []
29
+
30
+ quality:
31
+ reviewed_by: codeconductor-core
32
+ version: 0.1.0
33
+ paths:
34
+ - "**/*.astro"
35
+ - "**/astro.config.*"
36
+ ---
37
+
38
+
39
+
40
+ # Astro
41
+
42
+ ## Islands Architecture
43
+
44
+ Astro renders everything to static HTML by default. JavaScript ships only for
45
+ components that explicitly opt in — these are called Islands.
46
+
47
+ ### Hydration Directives
48
+
49
+ | Directive | When JS loads | Use case |
50
+ |-----------|--------------|----------|
51
+ | `client:load` | On page load | Interactive above-the-fold UI |
52
+ | `client:idle` | When browser is idle | Non-critical interactive widgets |
53
+ | `client:visible` | When element enters viewport | Below-the-fold islands |
54
+ | `client:media` | When CSS media query matches | Responsive interactive components |
55
+ | `client:only` | Client-only, no SSR | Components that require the DOM (e.g., charting libs) |
56
+
57
+ ```astro
58
+ ---
59
+ import Counter from '../components/Counter.tsx';
60
+ import HeavyChart from '../components/HeavyChart.tsx';
61
+ import MobileNav from '../components/MobileNav.tsx';
62
+ ---
63
+
64
+ <!-- Hydrates immediately — user interacts right away -->
65
+ <Counter client:load />
66
+
67
+ <!-- Hydrates when scrolled into view — saves initial JS -->
68
+ <HeavyChart client:visible />
69
+
70
+ <!-- Only on mobile, only when query matches -->
71
+ <MobileNav client:media="(max-width: 768px)" />
72
+ ```
73
+
74
+ Rules:
75
+
76
+ - Default to no hydration directive — most UI does not need JavaScript
77
+ - `client:load` is the most expensive directive; use it sparingly
78
+ - `client:only` skips server rendering entirely — the component receives no
79
+ props from the server; pass all data via props or fetch inside the component
80
+ - Do not use `client:load` for components that could use `client:visible`
81
+
82
+ ### Framework Components Inside Astro
83
+
84
+ ```astro
85
+ ---
86
+ import ReactButton from './Button.tsx'; // React island
87
+ import VueWidget from './Widget.vue'; // Vue island
88
+ ---
89
+
90
+ <!-- Both can coexist on the same page -->
91
+ <ReactButton client:idle label="Click me" />
92
+ <VueWidget client:visible />
93
+ ```
94
+
95
+ Each framework ships its own runtime only when at least one island of that
96
+ framework is on the page.
97
+
98
+ ## Content Collections
99
+
100
+ Content Collections provide type-safe access to Markdown, MDX, and data files.
101
+ Define schemas in `src/content/config.ts`.
102
+
103
+ ### Schema Definition
104
+
105
+ ```typescript
106
+ // src/content/config.ts
107
+ import { defineCollection, z } from 'astro:content';
108
+
109
+ const blog = defineCollection({
110
+ type: 'content', // .md or .mdx files
111
+ schema: z.object({
112
+ title: z.string(),
113
+ description: z.string(),
114
+ pubDate: z.coerce.date(),
115
+ updatedDate: z.coerce.date().optional(),
116
+ author: z.string().default('Anonymous'),
117
+ tags: z.array(z.string()).default([]),
118
+ draft: z.boolean().default(false),
119
+ image: z.object({
120
+ src: z.string(),
121
+ alt: z.string(),
122
+ }).optional(),
123
+ }),
124
+ });
125
+
126
+ const docs = defineCollection({
127
+ type: 'content',
128
+ schema: z.object({
129
+ title: z.string(),
130
+ order: z.number(),
131
+ section: z.enum(['guide', 'reference', 'tutorial']),
132
+ }),
133
+ });
134
+
135
+ export const collections = { blog, docs };
136
+ ```
137
+
138
+ ### Querying Collections
139
+
140
+ ```astro
141
+ ---
142
+ import { getCollection, getEntry } from 'astro:content';
143
+
144
+ // All published posts, sorted by date
145
+ const posts = (await getCollection('blog', ({ data }) => !data.draft))
146
+ .sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
147
+
148
+ // Single entry by slug
149
+ const post = await getEntry('blog', 'my-first-post');
150
+ const { Content } = await post.render();
151
+ ---
152
+
153
+ {posts.map(post => (
154
+ <article>
155
+ <h2><a href={`/blog/${post.slug}`}>{post.data.title}</a></h2>
156
+ <time>{post.data.pubDate.toLocaleDateString()}</time>
157
+ </article>
158
+ ))}
159
+ ```
160
+
161
+ ### Dynamic Routes from Collections
162
+
163
+ ```astro
164
+ ---
165
+ // src/pages/blog/[slug].astro
166
+ import { getCollection } from 'astro:content';
167
+
168
+ export async function getStaticPaths() {
169
+ const posts = await getCollection('blog');
170
+ return posts.map(post => ({
171
+ params: { slug: post.slug },
172
+ props: { post },
173
+ }));
174
+ }
175
+
176
+ const { post } = Astro.props;
177
+ const { Content, headings } = await post.render();
178
+ ---
179
+
180
+ <article>
181
+ <h1>{post.data.title}</h1>
182
+ <Content />
183
+ </article>
184
+ ```
185
+
186
+ ## Rendering Strategies
187
+
188
+ ### SSG (Static Site Generation) — default
189
+
190
+ Every page is pre-rendered at build time. Best for content that does not change
191
+ per request.
192
+
193
+ ```javascript
194
+ // astro.config.mjs — no output config needed; SSG is the default
195
+ export default defineConfig({
196
+ site: 'https://example.com',
197
+ });
198
+ ```
199
+
200
+ ### SSR (Server-Side Rendering)
201
+
202
+ Renders pages on each request. Required for: authenticated routes, personalized
203
+ content, live data.
204
+
205
+ ```javascript
206
+ // astro.config.mjs
207
+ import node from '@astrojs/node';
208
+
209
+ export default defineConfig({
210
+ output: 'server',
211
+ adapter: node({ mode: 'standalone' }),
212
+ });
213
+ ```
214
+
215
+ ### Hybrid Mode
216
+
217
+ Mix SSG and SSR on a per-page basis. Most pages are static; specific routes opt
218
+ into server rendering.
219
+
220
+ ```javascript
221
+ // astro.config.mjs
222
+ export default defineConfig({
223
+ output: 'hybrid',
224
+ adapter: node({ mode: 'standalone' }),
225
+ });
226
+ ```
227
+
228
+ ```astro
229
+ ---
230
+ // src/pages/dashboard.astro — this page is server-rendered
231
+ export const prerender = false;
232
+
233
+ // src/pages/about.astro — this page is statically generated (hybrid default)
234
+ export const prerender = true;
235
+ ---
236
+ ```
237
+
238
+ Use hybrid mode when: most content is static but a few routes need auth or
239
+ live data. Do not make everything `output: 'server'` — you lose the performance
240
+ benefits of static generation.
241
+
242
+ ## Image Optimization
243
+
244
+ Use the built-in `<Image>` and `<Picture>` components. Never use raw `<img>`
245
+ for local assets — you lose automatic optimization.
246
+
247
+ ```astro
248
+ ---
249
+ import { Image, Picture } from 'astro:assets';
250
+ import heroImage from '../assets/hero.png';
251
+ ---
252
+
253
+ <!-- Optimized single image -->
254
+ <Image
255
+ src={heroImage}
256
+ alt="Hero illustration"
257
+ width={800}
258
+ height={600}
259
+ format="webp"
260
+ quality={80}
261
+ />
262
+
263
+ <!-- Responsive with multiple formats -->
264
+ <Picture
265
+ src={heroImage}
266
+ formats={['avif', 'webp']}
267
+ alt="Hero illustration"
268
+ widths={[400, 800, 1200]}
269
+ sizes="(max-width: 800px) 100vw, 800px"
270
+ />
271
+ ```
272
+
273
+ Rules:
274
+
275
+ - Always provide `alt` — empty string is acceptable only for decorative images
276
+ - Prefer `avif` + `webp` fallback for best compression
277
+ - Use `widths` + `sizes` on above-the-fold images to serve the right size per
278
+ viewport
279
+ - Remote images require explicit `width` and `height` to prevent layout shift
280
+
281
+ ## Project Structure
282
+
283
+ ```text
284
+ src/
285
+ assets/ — images and static assets processed by Astro
286
+ components/ — .astro components (and framework islands)
287
+ content/
288
+ blog/ — .md and .mdx files
289
+ config.ts — collection schemas
290
+ layouts/ — page shell layouts
291
+ pages/ — file-based routing; every file is a route
292
+ styles/ — global CSS
293
+ astro.config.mjs
294
+ tsconfig.json
295
+ ```
296
+
297
+ Colocation rule: put framework island components (`.tsx`, `.vue`) in
298
+ `src/components/`. Do not scatter them in `src/pages/`.
299
+
300
+ ## TypeScript Conventions
301
+
302
+ ```json
303
+ // tsconfig.json — use the strict Astro preset
304
+ {
305
+ "extends": "astro/tsconfigs/strict"
306
+ }
307
+ ```
308
+
309
+ ```astro
310
+ ---
311
+ // Type props explicitly in the frontmatter
312
+ interface Props {
313
+ title: string;
314
+ description?: string;
315
+ tags: string[];
316
+ }
317
+
318
+ const { title, description = '', tags } = Astro.props;
319
+ ---
320
+ ```
321
+
322
+ Astro infers prop types from `interface Props` automatically. Do not use `any`.