specialist-agent 2.0.0 → 2.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 (94) hide show
  1. package/README.md +17 -7
  2. package/agents/api.md +374 -93
  3. package/agents/architect.md +553 -0
  4. package/agents/data.md +108 -0
  5. package/agents/deps.md +323 -167
  6. package/agents/devops.md +12 -0
  7. package/agents/docs.md +381 -134
  8. package/agents/executor.md +117 -0
  9. package/agents/finance.md +85 -0
  10. package/agents/i18n.md +512 -117
  11. package/agents/perf.md +287 -109
  12. package/agents/refactor.md +380 -92
  13. package/agents/ripple-lite.md +106 -0
  14. package/agents/ripple.md +162 -0
  15. package/agents/security.md +65 -0
  16. package/agents/tdd.md +11 -3
  17. package/cli/index.mjs +40 -29
  18. package/hooks/native/auto-dispatch.mjs +6 -0
  19. package/hooks/native/settings-template.json +4 -4
  20. package/package.json +15 -2
  21. package/packs/angular/ARCHITECTURE.md +814 -0
  22. package/packs/angular/CLAUDE.md +105 -0
  23. package/packs/angular/agents/builder.md +157 -0
  24. package/packs/angular/agents/doctor.md +241 -0
  25. package/packs/angular/agents/migrator.md +195 -0
  26. package/packs/angular/agents/reviewer.md +263 -0
  27. package/packs/angular/agents-lite/builder.md +65 -0
  28. package/packs/angular/agents-lite/doctor.md +64 -0
  29. package/packs/angular/agents-lite/migrator.md +75 -0
  30. package/packs/angular/agents-lite/reviewer.md +69 -0
  31. package/packs/angular/skills/dev-create-component/SKILL.md +56 -0
  32. package/packs/angular/skills/dev-create-injectable/SKILL.md +60 -0
  33. package/packs/angular/skills/dev-create-module/SKILL.md +49 -0
  34. package/packs/angular/skills/dev-create-service/SKILL.md +34 -0
  35. package/packs/angular/skills/dev-create-test/SKILL.md +78 -0
  36. package/packs/angular/skills/dev-generate-types/SKILL.md +37 -0
  37. package/packs/angular/skills/docs-onboard/SKILL.md +42 -0
  38. package/packs/angular/skills/migration-migrate-component/SKILL.md +42 -0
  39. package/packs/angular/skills/migration-migrate-module/SKILL.md +25 -0
  40. package/packs/angular/skills/review-check-architecture/SKILL.md +67 -0
  41. package/packs/angular/skills/review-fix-violations/SKILL.md +43 -0
  42. package/packs/angular/skills/review-review/SKILL.md +42 -0
  43. package/packs/astro/ARCHITECTURE.md +718 -0
  44. package/packs/astro/CLAUDE.md +106 -0
  45. package/packs/astro/agents/builder.md +192 -0
  46. package/packs/astro/agents/doctor.md +254 -0
  47. package/packs/astro/agents/migrator.md +209 -0
  48. package/packs/astro/agents/reviewer.md +263 -0
  49. package/packs/astro/agents-lite/builder.md +71 -0
  50. package/packs/astro/agents-lite/doctor.md +66 -0
  51. package/packs/astro/agents-lite/migrator.md +71 -0
  52. package/packs/astro/agents-lite/reviewer.md +70 -0
  53. package/packs/astro/skills/dev-create-component/SKILL.md +50 -0
  54. package/packs/astro/skills/dev-create-island/SKILL.md +63 -0
  55. package/packs/astro/skills/dev-create-module/SKILL.md +49 -0
  56. package/packs/astro/skills/dev-create-service/SKILL.md +34 -0
  57. package/packs/astro/skills/dev-create-test/SKILL.md +76 -0
  58. package/packs/astro/skills/dev-generate-types/SKILL.md +37 -0
  59. package/packs/astro/skills/docs-onboard/SKILL.md +51 -0
  60. package/packs/astro/skills/migration-migrate-component/SKILL.md +48 -0
  61. package/packs/astro/skills/migration-migrate-module/SKILL.md +25 -0
  62. package/packs/astro/skills/review-check-architecture/SKILL.md +72 -0
  63. package/packs/astro/skills/review-fix-violations/SKILL.md +43 -0
  64. package/packs/astro/skills/review-review/SKILL.md +44 -0
  65. package/packs/nuxt/ARCHITECTURE.md +831 -0
  66. package/packs/nuxt/CLAUDE.md +111 -0
  67. package/packs/nuxt/agents/builder.md +165 -0
  68. package/packs/nuxt/agents/doctor.md +252 -0
  69. package/packs/nuxt/agents/migrator.md +203 -0
  70. package/packs/nuxt/agents/reviewer.md +275 -0
  71. package/packs/nuxt/agents-lite/builder.md +67 -0
  72. package/packs/nuxt/agents-lite/doctor.md +67 -0
  73. package/packs/nuxt/agents-lite/migrator.md +80 -0
  74. package/packs/nuxt/agents-lite/reviewer.md +71 -0
  75. package/packs/nuxt/skills/dev-create-component/SKILL.md +60 -0
  76. package/packs/nuxt/skills/dev-create-composable/SKILL.md +33 -0
  77. package/packs/nuxt/skills/dev-create-module/SKILL.md +49 -0
  78. package/packs/nuxt/skills/dev-create-service/SKILL.md +34 -0
  79. package/packs/nuxt/skills/dev-create-test/SKILL.md +61 -0
  80. package/packs/nuxt/skills/dev-generate-types/SKILL.md +37 -0
  81. package/packs/nuxt/skills/docs-onboard/SKILL.md +49 -0
  82. package/packs/nuxt/skills/migration-migrate-component/SKILL.md +48 -0
  83. package/packs/nuxt/skills/migration-migrate-module/SKILL.md +25 -0
  84. package/packs/nuxt/skills/review-check-architecture/SKILL.md +71 -0
  85. package/packs/nuxt/skills/review-fix-violations/SKILL.md +43 -0
  86. package/packs/nuxt/skills/review-review/SKILL.md +44 -0
  87. package/skills/checkpoint/SKILL.md +8 -0
  88. package/skills/codereview/SKILL.md +255 -0
  89. package/skills/commit/SKILL.md +150 -0
  90. package/skills/estimate/SKILL.md +9 -0
  91. package/skills/finish/SKILL.md +9 -0
  92. package/skills/health/SKILL.md +9 -0
  93. package/skills/lint/SKILL.md +126 -0
  94. package/skills/plan/SKILL.md +9 -0
@@ -0,0 +1,718 @@
1
+ # ARCHITECTURE.md — Architecture Guide & Patterns
2
+
3
+ > This document is the **source of truth** for all agents and skills.
4
+ > Any architectural decision must be documented here.
5
+
6
+ ---
7
+
8
+ ## 1. Overview — Islands Architecture
9
+
10
+ Astro is a **server-first** web framework designed for content-driven websites. Key principles:
11
+
12
+ | Principle | Description |
13
+ |-----------|-------------|
14
+ | Server-first | Components render on the server — zero JS shipped by default |
15
+ | Islands Architecture | Interactive UI is opt-in via `client:*` directives |
16
+ | Content Collections | Type-safe content management with Zod schemas |
17
+ | Multi-framework | Use React, Vue, Svelte, or Solid components as islands |
18
+ | Hybrid rendering | SSG (static) + SSR (on-demand) per page |
19
+ | File-based routing | `src/pages/` maps directly to URLs |
20
+
21
+ **Zero JS by default**: An `.astro` component ships no JavaScript to the browser. Only framework components with a `client:*` directive become interactive "islands" that hydrate on the client.
22
+
23
+ ---
24
+
25
+ ## 2. Directory Structure
26
+
27
+ ```
28
+ src/
29
+ ├── pages/ # File-based routing (SSG/SSR pages + API endpoints)
30
+ │ ├── index.astro
31
+ │ ├── about.astro
32
+ │ ├── blog/
33
+ │ │ ├── index.astro
34
+ │ │ └── [slug].astro
35
+ │ └── api/
36
+ │ └── posts.ts # Server endpoint (GET, POST, etc.)
37
+ │
38
+ ├── layouts/ # Reusable page templates
39
+ │ ├── BaseLayout.astro
40
+ │ └── BlogLayout.astro
41
+ │
42
+ ├── components/ # .astro server components (zero JS)
43
+ │ ├── Header.astro
44
+ │ ├── Footer.astro
45
+ │ └── PostCard.astro
46
+ │
47
+ ├── islands/ # Interactive framework components (React/Vue/Svelte)
48
+ │ ├── SearchBar.tsx # React island
49
+ │ ├── ThemeToggle.vue # Vue island
50
+ │ └── Counter.svelte # Svelte island
51
+ │
52
+ ├── content/ # Content collections (MDX, Markdown, JSON, YAML)
53
+ │ ├── config.ts # Collection schemas (Zod)
54
+ │ ├── blog/
55
+ │ │ ├── first-post.mdx
56
+ │ │ └── second-post.mdx
57
+ │ └── authors/
58
+ │ └── john.json
59
+ │
60
+ ├── modules/ # Feature modules (business logic)
61
+ │ ├── newsletter/
62
+ │ │ ├── services/
63
+ │ │ │ └── newsletter-service.ts
64
+ │ │ ├── adapters/
65
+ │ │ │ └── newsletter-adapter.ts
66
+ │ │ ├── types/
67
+ │ │ │ ├── newsletter.types.ts
68
+ │ │ │ └── newsletter.contracts.ts
69
+ │ │ ├── __tests__/
70
+ │ │ └── index.ts
71
+ │ │
72
+ │ └── [other-module]/
73
+ │
74
+ ├── shared/ # Shared across modules
75
+ │ ├── components/ # Shared .astro components
76
+ │ ├── islands/ # Shared interactive islands
77
+ │ ├── services/ # API client base, fetch helpers
78
+ │ ├── adapters/ # Shared adapters
79
+ │ ├── types/ # Global types
80
+ │ ├── utils/ # Pure functions (no side effects)
81
+ │ ├── helpers/ # Functions with side effects or DOM
82
+ │ └── constants/ # Static values
83
+ │
84
+ ├── styles/ # Global styles (CSS, SCSS)
85
+ │ └── global.css
86
+ │
87
+ └── assets/ # Static assets processed by Astro (images, fonts)
88
+ ```
89
+
90
+ ### Import Rules Between Layers
91
+ ```
92
+ modules/newsletter <-> shared/ OK — Module imports from shared
93
+ modules/newsletter -> modules/commerce FORBIDDEN — Module does NOT import from another module
94
+ shared/ -> modules/newsletter FORBIDDEN — Shared does NOT import from modules
95
+ pages/ -> modules/* OK — Pages import modules
96
+ pages/ -> components/* OK — Pages import components
97
+ pages/ -> islands/* OK — Pages import islands
98
+ ```
99
+
100
+ If two modules need to share something, move it to `shared/`.
101
+
102
+ ---
103
+
104
+ ## 3. Naming Conventions
105
+
106
+ ### Files and Directories
107
+
108
+ | Type | Pattern | Example |
109
+ |------|---------|---------|
110
+ | Directories | `kebab-case` | `user-settings/` |
111
+ | Astro components | `PascalCase.astro` | `PostCard.astro` |
112
+ | Pages | `kebab-case.astro` | `about-us.astro` |
113
+ | Dynamic pages | `[param].astro` | `[slug].astro` |
114
+ | Layouts | `PascalCase + Layout.astro` | `BlogLayout.astro` |
115
+ | Islands (React) | `PascalCase.tsx` | `SearchBar.tsx` |
116
+ | Islands (Vue) | `PascalCase.vue` | `ThemeToggle.vue` |
117
+ | Islands (Svelte) | `PascalCase.svelte` | `Counter.svelte` |
118
+ | Services | `kebab-case-service.ts` | `newsletter-service.ts` |
119
+ | Adapters | `kebab-case-adapter.ts` | `newsletter-adapter.ts` |
120
+ | Types | `kebab-case.types.ts` | `newsletter.types.ts` |
121
+ | Contracts/Schemas | `kebab-case.contracts.ts` | `newsletter.contracts.ts` |
122
+ | Content schemas | `config.ts` | `src/content/config.ts` |
123
+ | Utils | `kebab-case.ts` | `format-date.ts` |
124
+ | Helpers | `kebab-case.ts` | `clipboard-helper.ts` |
125
+ | Tests | `OriginalName.spec.ts` | `PostCard.spec.ts` |
126
+ | Constants | `kebab-case.constants.ts` | `api-endpoints.constants.ts` |
127
+ | Server endpoints | `kebab-case.ts` | `src/pages/api/posts.ts` |
128
+
129
+ ### Code
130
+
131
+ | Type | Pattern | Example |
132
+ |------|---------|---------|
133
+ | Variables / functions | `camelCase` | `getUserById`, `isLoading` |
134
+ | Types / Interfaces | `PascalCase` | `BlogPost`, `NewsletterItem` |
135
+ | Enums | `PascalCase` | `PostStatus.Published` |
136
+ | Constants | `UPPER_SNAKE_CASE` | `API_BASE_URL`, `MAX_RETRIES` |
137
+ | Collection names | `kebab-case` string | `defineCollection({ ... })` |
138
+ | Event handlers | `handle` + action | `handleSubmit`, `handleDelete` |
139
+ | Boolean | `is`/`has`/`can`/`should` | `isLoading`, `hasPermission` |
140
+
141
+ ---
142
+
143
+ ## 4. Responsibility Layers
144
+
145
+ ### 4.1 Services — Pure Requests
146
+
147
+ Services make **only** the HTTP request. No try/catch, no transformation, no business logic.
148
+
149
+ ```typescript
150
+ // modules/newsletter/services/newsletter-service.ts
151
+
152
+ export const newsletterService = {
153
+ list(params: { page: number; pageSize: number }) {
154
+ return fetch(`${import.meta.env.API_BASE_URL}/newsletter?page=${params.page}&pageSize=${params.pageSize}`)
155
+ .then(res => res.json())
156
+ },
157
+
158
+ getById(id: string) {
159
+ return fetch(`${import.meta.env.API_BASE_URL}/newsletter/${id}`)
160
+ .then(res => res.json())
161
+ },
162
+
163
+ subscribe(payload: { email: string; name: string }) {
164
+ return fetch(`${import.meta.env.API_BASE_URL}/newsletter/subscribe`, {
165
+ method: 'POST',
166
+ headers: { 'Content-Type': 'application/json' },
167
+ body: JSON.stringify(payload),
168
+ }).then(res => res.json())
169
+ },
170
+ }
171
+ ```
172
+
173
+ **Service Rules:**
174
+ - No try/catch (caller handles errors)
175
+ - No data transformation (adapter does that)
176
+ - No business logic
177
+ - No DOM or browser API access
178
+ - One file per resource
179
+ - Export as object with methods
180
+
181
+ ### 4.2 Adapters — Contract Parsers
182
+
183
+ Adapters transform data from the API to the TypeScript app contract (and vice-versa). **Pure functions** with no side effects.
184
+
185
+ ```typescript
186
+ // modules/newsletter/adapters/newsletter-adapter.ts
187
+ import type { NewsletterItemResponse, NewsletterListResponse } from '../types/newsletter.types'
188
+ import type { NewsletterItem, NewsletterList } from '../types/newsletter.contracts'
189
+
190
+ export const newsletterAdapter = {
191
+ toNewsletterItem(response: NewsletterItemResponse): NewsletterItem {
192
+ return {
193
+ id: response.uuid,
194
+ title: response.title,
195
+ author: response.author_name,
196
+ category: response.category_slug,
197
+ isPublished: response.status === 'published',
198
+ publishedAt: new Date(response.published_at),
199
+ updatedAt: new Date(response.updated_at),
200
+ }
201
+ },
202
+
203
+ toNewsletterList(response: NewsletterListResponse): NewsletterList {
204
+ return {
205
+ items: response.results.map(newsletterAdapter.toNewsletterItem),
206
+ totalItems: response.count,
207
+ totalPages: Math.ceil(response.count / response.page_size),
208
+ currentPage: response.page,
209
+ }
210
+ },
211
+
212
+ toSubscribePayload(input: { email: string; name: string }) {
213
+ return {
214
+ email_address: input.email,
215
+ full_name: input.name,
216
+ }
217
+ },
218
+ }
219
+ ```
220
+
221
+ **Adapter Rules:**
222
+ - Pure functions (input -> output, no side effects)
223
+ - Two directions: API->App (inbound) and App->API (outbound)
224
+ - Rename fields (snake_case API -> camelCase App)
225
+ - Convert types (string->Date, cents->decimal, status->boolean)
226
+ - No HTTP calls
227
+ - No try/catch (wrong type = bug to fix)
228
+
229
+ ### 4.3 Types & Contracts
230
+
231
+ ```typescript
232
+ // types/newsletter.types.ts
233
+ // Types that mirror the API exactly as it returns (snake_case)
234
+
235
+ export interface NewsletterItemResponse {
236
+ uuid: string
237
+ title: string
238
+ author_name: string
239
+ category_slug: string
240
+ status: 'published' | 'draft' | 'archived'
241
+ published_at: string
242
+ updated_at: string
243
+ }
244
+
245
+ export interface NewsletterListResponse {
246
+ count: number
247
+ page: number
248
+ page_size: number
249
+ results: NewsletterItemResponse[]
250
+ }
251
+
252
+ // types/newsletter.contracts.ts
253
+ // App contracts (camelCase, correct types)
254
+
255
+ export interface NewsletterItem {
256
+ id: string
257
+ title: string
258
+ author: string
259
+ category: string
260
+ isPublished: boolean
261
+ publishedAt: Date
262
+ updatedAt: Date
263
+ }
264
+
265
+ export interface NewsletterList {
266
+ items: NewsletterItem[]
267
+ totalItems: number
268
+ totalPages: number
269
+ currentPage: number
270
+ }
271
+ ```
272
+
273
+ ### 4.4 Data Fetching — Frontmatter & Endpoints
274
+
275
+ In Astro, data is fetched **at build time (SSG) or request time (SSR)** in the component frontmatter or in server endpoints. There are no client-side composables or Vue Query — data flows server-side.
276
+
277
+ ```astro
278
+ ---
279
+ // src/pages/newsletter/index.astro
280
+ import BaseLayout from '../../layouts/BaseLayout.astro'
281
+ import PostCard from '../../components/PostCard.astro'
282
+ import { newsletterService } from '../../modules/newsletter/services/newsletter-service'
283
+ import { newsletterAdapter } from '../../modules/newsletter/adapters/newsletter-adapter'
284
+
285
+ const response = await newsletterService.list({ page: 1, pageSize: 20 })
286
+ const { items, totalPages } = newsletterAdapter.toNewsletterList(response)
287
+ ---
288
+
289
+ <BaseLayout title="Newsletter">
290
+ <h1>Newsletter</h1>
291
+ <div class="grid">
292
+ {items.map(item => <PostCard item={item} />)}
293
+ </div>
294
+ </BaseLayout>
295
+ ```
296
+
297
+ **Server Endpoint:**
298
+
299
+ ```typescript
300
+ // src/pages/api/newsletter/subscribe.ts
301
+ import type { APIRoute } from 'astro'
302
+ import { newsletterService } from '../../../modules/newsletter/services/newsletter-service'
303
+ import { newsletterAdapter } from '../../../modules/newsletter/adapters/newsletter-adapter'
304
+
305
+ export const POST: APIRoute = async ({ request }) => {
306
+ const body = await request.json()
307
+ const payload = newsletterAdapter.toSubscribePayload(body)
308
+ const result = await newsletterService.subscribe(payload)
309
+
310
+ return new Response(JSON.stringify(result), {
311
+ status: 200,
312
+ headers: { 'Content-Type': 'application/json' },
313
+ })
314
+ }
315
+ ```
316
+
317
+ **Data Fetching Rules:**
318
+ - SSG pages: data fetched at build time in frontmatter
319
+ - SSR pages: data fetched on each request in frontmatter (requires adapter: `output: 'server'`)
320
+ - API endpoints: `src/pages/api/` with exported HTTP method functions
321
+ - Service -> Adapter -> Template (no client-side state management)
322
+ - Error handling: try/catch in frontmatter or endpoint, not in service
323
+
324
+ ---
325
+
326
+ ## 5. Component Patterns
327
+
328
+ ### 5.1 Astro Components (Server, Zero JS)
329
+
330
+ ```astro
331
+ ---
332
+ // components/PostCard.astro
333
+ import type { NewsletterItem } from '../modules/newsletter/types/newsletter.contracts'
334
+ import { formatDate } from '../shared/utils/format-date'
335
+
336
+ interface Props {
337
+ item: NewsletterItem
338
+ }
339
+
340
+ const { item } = Astro.props
341
+ ---
342
+
343
+ <article class="post-card">
344
+ <h2>{item.title}</h2>
345
+ <p class="meta">
346
+ <span>{item.author}</span>
347
+ <time datetime={item.publishedAt.toISOString()}>
348
+ {formatDate(item.publishedAt)}
349
+ </time>
350
+ </p>
351
+ <span class:list={['badge', { published: item.isPublished }]}>
352
+ {item.isPublished ? 'Published' : 'Draft'}
353
+ </span>
354
+ </article>
355
+
356
+ <style>
357
+ .post-card {
358
+ padding: 1rem;
359
+ border: 1px solid var(--border-color);
360
+ border-radius: 0.5rem;
361
+ }
362
+ </style>
363
+ ```
364
+
365
+ **Astro Component Rules:**
366
+ - Server-rendered, zero JS shipped to browser
367
+ - Props via `Astro.props` with typed `Props` interface
368
+ - No event handlers (use islands for interactivity)
369
+ - Scoped styles with `<style>` tag
370
+ - Template uses JSX-like expressions `{}`
371
+ - Class toggling with `class:list`
372
+
373
+ ### 5.2 Islands (Interactive Components)
374
+
375
+ Islands are framework components (React, Vue, Svelte) that hydrate on the client. Use the appropriate `client:*` directive:
376
+
377
+ | Directive | When to Use |
378
+ |-----------|-------------|
379
+ | `client:load` | Immediately visible + interactive (nav, hero CTAs) |
380
+ | `client:idle` | Lower priority, hydrate when browser is idle (sidebar widgets) |
381
+ | `client:visible` | Below the fold, hydrate when scrolled into view (comments, carousels) |
382
+ | `client:media="(max-width: 768px)"` | Only on specific viewports (mobile menus) |
383
+ | `client:only="react"` | Client-only, skip SSR (auth-dependent, browser API) |
384
+
385
+ ```tsx
386
+ // islands/SearchBar.tsx
387
+ import { useState, useEffect } from 'react'
388
+
389
+ interface Props {
390
+ placeholder?: string
391
+ apiUrl: string
392
+ }
393
+
394
+ export default function SearchBar({ placeholder = 'Search...', apiUrl }: Props) {
395
+ const [query, setQuery] = useState('')
396
+ const [results, setResults] = useState([])
397
+
398
+ useEffect(() => {
399
+ if (query.length < 3) return
400
+ const controller = new AbortController()
401
+
402
+ fetch(`${apiUrl}?q=${encodeURIComponent(query)}`, { signal: controller.signal })
403
+ .then(res => res.json())
404
+ .then(data => setResults(data.items))
405
+ .catch(() => {})
406
+
407
+ return () => controller.abort()
408
+ }, [query, apiUrl])
409
+
410
+ return (
411
+ <div className="search">
412
+ <input
413
+ type="search"
414
+ value={query}
415
+ onChange={e => setQuery(e.target.value)}
416
+ placeholder={placeholder}
417
+ />
418
+ {results.length > 0 && (
419
+ <ul className="results">
420
+ {results.map((item: any) => (
421
+ <li key={item.id}>{item.title}</li>
422
+ ))}
423
+ </ul>
424
+ )}
425
+ </div>
426
+ )
427
+ }
428
+ ```
429
+
430
+ **Using an Island in an Astro page:**
431
+
432
+ ```astro
433
+ ---
434
+ import SearchBar from '../islands/SearchBar'
435
+ ---
436
+
437
+ <SearchBar client:idle placeholder="Search posts..." apiUrl="/api/search" />
438
+ ```
439
+
440
+ **Island Rules:**
441
+ - Place in `src/islands/` (or `src/shared/islands/` for shared)
442
+ - ALWAYS specify a `client:*` directive when using in `.astro` files
443
+ - Choose the LEAST aggressive hydration strategy (prefer `client:visible` or `client:idle` over `client:load`)
444
+ - Props must be serializable (no functions, no complex objects with methods)
445
+ - Keep islands small — extract non-interactive parts to `.astro` components
446
+ - Each island is an independent hydration boundary
447
+
448
+ ### 5.3 Component Hierarchy
449
+
450
+ ```
451
+ Pages (src/pages/) -> Data fetching, compose layouts + components
452
+ └── Layouts -> Page structure (header, footer, slots)
453
+ └── Astro Components -> Server-rendered UI (zero JS)
454
+ └── Islands -> Interactive UI (hydrated, framework-specific)
455
+ ```
456
+
457
+ | Type | Responsibility | JavaScript shipped? |
458
+ |------|---------------|---------------------|
459
+ | **Pages** | Route, data fetching (frontmatter), compose layout | No |
460
+ | **Layouts** | Page structure, slots for content | No |
461
+ | **Astro Components** | Server-rendered UI, presentational | No |
462
+ | **Islands** | Client-side interactivity, state, events | Yes (minimal) |
463
+
464
+ ---
465
+
466
+ ## 6. Utils vs Helpers
467
+
468
+ ### Utils — Pure Functions
469
+ - No side effects
470
+ - Input -> Output deterministic
471
+ - Testable without mocks
472
+ - No DOM, browser API, or framework dependency
473
+
474
+ ```typescript
475
+ // shared/utils/format-date.ts
476
+ export function formatDate(date: Date, locale = 'en-US'): string {
477
+ return new Intl.DateTimeFormat(locale).format(date)
478
+ }
479
+
480
+ // shared/utils/slugify.ts
481
+ export function slugify(text: string): string {
482
+ return text.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]/g, '')
483
+ }
484
+ ```
485
+
486
+ ### Helpers — Functions with Side Effects or DOM
487
+ - Interact with browser APIs (clipboard, localStorage, DOM)
488
+ - May have side effects
489
+ - May need mocks in tests
490
+
491
+ ```typescript
492
+ // shared/helpers/clipboard-helper.ts
493
+ export async function copyToClipboard(text: string): Promise<boolean> {
494
+ try {
495
+ await navigator.clipboard.writeText(text)
496
+ return true
497
+ } catch {
498
+ return false
499
+ }
500
+ }
501
+ ```
502
+
503
+ ---
504
+
505
+ ## 7. Error Handling
506
+
507
+ ### In Frontmatter (Pages)
508
+ ```astro
509
+ ---
510
+ import BaseLayout from '../layouts/BaseLayout.astro'
511
+ import { newsletterService } from '../modules/newsletter/services/newsletter-service'
512
+ import { newsletterAdapter } from '../modules/newsletter/adapters/newsletter-adapter'
513
+
514
+ let items = []
515
+ let error = null
516
+
517
+ try {
518
+ const response = await newsletterService.list({ page: 1, pageSize: 20 })
519
+ items = newsletterAdapter.toNewsletterList(response).items
520
+ } catch (e) {
521
+ error = 'Failed to load newsletter items.'
522
+ }
523
+ ---
524
+
525
+ <BaseLayout title="Newsletter">
526
+ {error ? (
527
+ <p class="error">{error}</p>
528
+ ) : items.length === 0 ? (
529
+ <p class="empty">No items found.</p>
530
+ ) : (
531
+ <div class="grid">
532
+ {items.map(item => <PostCard item={item} />)}
533
+ </div>
534
+ )}
535
+ </BaseLayout>
536
+ ```
537
+
538
+ ### In Server Endpoints
539
+ ```typescript
540
+ // src/pages/api/newsletter/subscribe.ts
541
+ import type { APIRoute } from 'astro'
542
+
543
+ export const POST: APIRoute = async ({ request }) => {
544
+ try {
545
+ const body = await request.json()
546
+ // ... process
547
+ return new Response(JSON.stringify({ success: true }), { status: 200 })
548
+ } catch (error) {
549
+ return new Response(JSON.stringify({ error: 'Internal server error' }), { status: 500 })
550
+ }
551
+ }
552
+ ```
553
+
554
+ ### Custom Error Pages
555
+ ```astro
556
+ <!-- src/pages/404.astro -->
557
+ ---
558
+ import BaseLayout from '../layouts/BaseLayout.astro'
559
+ ---
560
+
561
+ <BaseLayout title="Not Found">
562
+ <h1>404 — Page Not Found</h1>
563
+ <p>The page you are looking for does not exist.</p>
564
+ <a href="/">Go home</a>
565
+ </BaseLayout>
566
+ ```
567
+
568
+ ---
569
+
570
+ ## 8. Content Collections
571
+
572
+ ### Schema Definition
573
+ ```typescript
574
+ // src/content/config.ts
575
+ import { defineCollection, z } from 'astro:content'
576
+
577
+ const blog = defineCollection({
578
+ type: 'content',
579
+ schema: z.object({
580
+ title: z.string(),
581
+ description: z.string(),
582
+ author: z.string(),
583
+ publishedAt: z.coerce.date(),
584
+ updatedAt: z.coerce.date().optional(),
585
+ tags: z.array(z.string()).default([]),
586
+ draft: z.boolean().default(false),
587
+ image: z.string().optional(),
588
+ }),
589
+ })
590
+
591
+ const authors = defineCollection({
592
+ type: 'data',
593
+ schema: z.object({
594
+ name: z.string(),
595
+ bio: z.string(),
596
+ avatar: z.string(),
597
+ social: z.object({
598
+ twitter: z.string().optional(),
599
+ github: z.string().optional(),
600
+ }).optional(),
601
+ }),
602
+ })
603
+
604
+ export const collections = { blog, authors }
605
+ ```
606
+
607
+ ### Querying Content
608
+ ```astro
609
+ ---
610
+ // src/pages/blog/index.astro
611
+ import { getCollection } from 'astro:content'
612
+ import BaseLayout from '../../layouts/BaseLayout.astro'
613
+ import PostCard from '../../components/PostCard.astro'
614
+
615
+ const posts = await getCollection('blog', ({ data }) => !data.draft)
616
+ const sortedPosts = posts.sort((a, b) =>
617
+ b.data.publishedAt.getTime() - a.data.publishedAt.getTime()
618
+ )
619
+ ---
620
+
621
+ <BaseLayout title="Blog">
622
+ <h1>Blog</h1>
623
+ {sortedPosts.map(post => (
624
+ <PostCard
625
+ title={post.data.title}
626
+ description={post.data.description}
627
+ slug={post.slug}
628
+ date={post.data.publishedAt}
629
+ />
630
+ ))}
631
+ </BaseLayout>
632
+ ```
633
+
634
+ ### Rendering Content
635
+ ```astro
636
+ ---
637
+ // src/pages/blog/[slug].astro
638
+ import { getCollection, type CollectionEntry } from 'astro:content'
639
+ import BlogLayout from '../../layouts/BlogLayout.astro'
640
+
641
+ export async function getStaticPaths() {
642
+ const posts = await getCollection('blog')
643
+ return posts.map(post => ({
644
+ params: { slug: post.slug },
645
+ props: { post },
646
+ }))
647
+ }
648
+
649
+ interface Props {
650
+ post: CollectionEntry<'blog'>
651
+ }
652
+
653
+ const { post } = Astro.props
654
+ const { Content } = await post.render()
655
+ ---
656
+
657
+ <BlogLayout title={post.data.title}>
658
+ <article>
659
+ <h1>{post.data.title}</h1>
660
+ <Content />
661
+ </article>
662
+ </BlogLayout>
663
+ ```
664
+
665
+ **Content Collection Rules:**
666
+ - All schemas defined in `src/content/config.ts`
667
+ - Use Zod for schema validation
668
+ - `type: 'content'` for Markdown/MDX, `type: 'data'` for JSON/YAML
669
+ - Query with `getCollection()` and `getEntry()`
670
+ - Filter at query time (e.g., exclude drafts)
671
+ - Generate static paths with `getStaticPaths()`
672
+
673
+ ---
674
+
675
+ ## 9. SOLID Applied to Astro
676
+
677
+ | Principle | Astro Application |
678
+ |-----------|------------------|
679
+ | **S**ingle Responsibility | 1 page = 1 route. 1 component = 1 UI piece. 1 service = 1 resource. 1 island = 1 interactive feature. |
680
+ | **O**pen/Closed | Components extensible via slots and props, not by internal modification. Layouts compose via `<slot />`. |
681
+ | **L**iskov Substitution | Shared components work in any page/layout context without breaking. |
682
+ | **I**nterface Segregation | Specific props per component, not generic objects. `<PostCard title description date>` not `<PostCard post>`. |
683
+ | **D**ependency Inversion | Pages depend on service interfaces (types), not implementations. Services injected via imports in frontmatter. |
684
+
685
+ ---
686
+
687
+ ## 10. Migration Checklist (SPA to Astro)
688
+
689
+ ### Page Migration
690
+ - [ ] SPA route -> `src/pages/[route].astro`
691
+ - [ ] Client-side data fetching -> frontmatter `await` calls
692
+ - [ ] React/Vue page component -> `.astro` page with layout
693
+ - [ ] Client-side router -> file-based routing
694
+ - [ ] Loading spinners -> server-rendered content (no loading states for SSG)
695
+
696
+ ### Component Migration
697
+ - [ ] Interactive components -> `src/islands/` with `client:*` directive
698
+ - [ ] Static/presentational components -> `src/components/` as `.astro`
699
+ - [ ] CSS-in-JS -> scoped `<style>` or CSS modules
700
+ - [ ] `useState`/`ref()` (for UI only) -> keep in island
701
+ - [ ] `useEffect`/`onMounted` (data fetching) -> move to frontmatter
702
+
703
+ ### State Management
704
+ - [ ] Global state (Redux/Pinia) -> server-side data + minimal island state
705
+ - [ ] Server state (React Query/Vue Query) -> frontmatter fetch + adapter
706
+ - [ ] Client state -> keep minimal in islands, pass via props
707
+ - [ ] Shared island state -> use `nanostores` or custom events
708
+
709
+ ### Content
710
+ - [ ] CMS API calls -> Content Collections (if static content)
711
+ - [ ] Dynamic content -> SSR with adapter pattern
712
+ - [ ] Markdown rendering -> MDX with Content Collections
713
+
714
+ ### Performance
715
+ - [ ] SPA bundle -> zero JS by default
716
+ - [ ] Code splitting -> automatic per-island
717
+ - [ ] Lazy loading -> `client:visible` / `client:idle`
718
+ - [ ] Image optimization -> `<Image />` from `astro:assets`