specialist-agent 2.12.0 → 3.2.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.
- package/LICENSE +1 -1
- package/README.md +33 -207
- package/dist/catalog.json +15529 -0
- package/dist/hw-worker.mjs +254 -0
- package/dist/icones/icone.ico +0 -0
- package/dist/icones/icone.png +0 -0
- package/dist/interface/assets/figtree-latin-400-normal-g7Dtegnw.woff2 +0 -0
- package/dist/interface/assets/figtree-latin-500-normal-BWnGEVsr.woff2 +0 -0
- package/dist/interface/assets/figtree-latin-600-normal-Cv_xCTDl.woff2 +0 -0
- package/dist/interface/assets/figtree-latin-700-normal-th6qEP7c.woff2 +0 -0
- package/dist/interface/assets/figtree-latin-ext-400-normal-CXAzuTZb.woff2 +0 -0
- package/dist/interface/assets/figtree-latin-ext-500-normal-Du0rIuHj.woff2 +0 -0
- package/dist/interface/assets/figtree-latin-ext-600-normal-DJlfifZj.woff2 +0 -0
- package/dist/interface/assets/figtree-latin-ext-700-normal-CS4sQkGV.woff2 +0 -0
- package/dist/interface/assets/index-BIyqZkro.css +1 -0
- package/dist/interface/assets/index-zAegy908.js +13 -0
- package/dist/interface/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/interface/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
- package/dist/interface/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/interface/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/interface/assets/jetbrains-mono-latin-ext-500-normal-Cut-4mMH.woff2 +0 -0
- package/dist/interface/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/dist/interface/assets/unbounded-latin-500-normal-4slEIF53.woff2 +0 -0
- package/dist/interface/assets/unbounded-latin-700-normal-CaoNriVp.woff2 +0 -0
- package/dist/interface/assets/unbounded-latin-ext-500-normal-BTIpesyw.woff2 +0 -0
- package/dist/interface/assets/unbounded-latin-ext-700-normal-BLzWLLjG.woff2 +0 -0
- package/dist/interface/icones/apple-touch-icon.png +0 -0
- package/dist/interface/icones/favicon-32.png +0 -0
- package/dist/interface/icones/icone-192.png +0 -0
- package/dist/interface/icones/icone-512.png +0 -0
- package/dist/interface/icones/icone-mascara-512.png +0 -0
- package/dist/interface/index.html +19 -0
- package/dist/interface/manifest.webmanifest +19 -0
- package/dist/interface/sw.js +63 -0
- package/dist/specialist-agent.mjs +6919 -0
- package/dist/usage-worker.mjs +174 -0
- package/package.json +32 -57
- package/.claude-plugin/marketplace.json +0 -52
- package/.claude-plugin/plugin.json +0 -37
- package/.codex/INSTALL.md +0 -145
- package/.cursor-plugin/marketplace.json +0 -52
- package/.cursor-plugin/plugin.json +0 -37
- package/.opencode/INSTALL.md +0 -127
- package/.opencode/opencode.json +0 -186
- package/agents/analyst-lite.md +0 -48
- package/agents/analyst.md +0 -396
- package/agents/api-lite.md +0 -43
- package/agents/api.md +0 -427
- package/agents/architect-lite.md +0 -104
- package/agents/architect.md +0 -571
- package/agents/autopilot-lite.md +0 -46
- package/agents/autopilot.md +0 -196
- package/agents/cloud-lite.md +0 -75
- package/agents/cloud.md +0 -213
- package/agents/data-lite.md +0 -67
- package/agents/data.md +0 -306
- package/agents/debugger-lite.md +0 -46
- package/agents/debugger.md +0 -410
- package/agents/deps-lite.md +0 -41
- package/agents/deps.md +0 -363
- package/agents/designer-lite.md +0 -67
- package/agents/designer.md +0 -195
- package/agents/devops-lite.md +0 -67
- package/agents/devops.md +0 -205
- package/agents/docs-lite.md +0 -42
- package/agents/docs.md +0 -454
- package/agents/executor-lite.md +0 -61
- package/agents/executor.md +0 -695
- package/agents/explorer-lite.md +0 -55
- package/agents/explorer.md +0 -152
- package/agents/finance-lite.md +0 -66
- package/agents/finance.md +0 -255
- package/agents/i18n-lite.md +0 -44
- package/agents/i18n.md +0 -594
- package/agents/legal-lite.md +0 -113
- package/agents/legal.md +0 -302
- package/agents/marketing-lite.md +0 -25
- package/agents/marketing.md +0 -188
- package/agents/memory.md +0 -166
- package/agents/orchestrator-lite.md +0 -40
- package/agents/orchestrator.md +0 -512
- package/agents/pair-lite.md +0 -38
- package/agents/pair.md +0 -310
- package/agents/perf-lite.md +0 -42
- package/agents/perf.md +0 -320
- package/agents/planner-lite.md +0 -59
- package/agents/planner.md +0 -272
- package/agents/product-lite.md +0 -25
- package/agents/product.md +0 -195
- package/agents/refactor-lite.md +0 -42
- package/agents/refactor.md +0 -467
- package/agents/ripple-lite.md +0 -106
- package/agents/ripple.md +0 -166
- package/agents/scout-lite.md +0 -37
- package/agents/scout.md +0 -224
- package/agents/security-lite.md +0 -66
- package/agents/security.md +0 -252
- package/agents/sentry-triage-lite.md +0 -54
- package/agents/sentry-triage.md +0 -217
- package/agents/starter-lite.md +0 -80
- package/agents/starter.md +0 -300
- package/agents/support-lite.md +0 -24
- package/agents/support.md +0 -191
- package/agents/tdd-lite.md +0 -43
- package/agents/tdd.md +0 -329
- package/agents/tester-lite.md +0 -71
- package/agents/tester.md +0 -237
- package/cli/architectures.mjs +0 -713
- package/cli/detect-architecture.mjs +0 -752
- package/cli/generate-architecture.mjs +0 -1096
- package/cli/index.mjs +0 -1217
- package/cli/recommend-architecture.mjs +0 -870
- package/hooks/after-review.mjs +0 -130
- package/hooks/after-task.mjs +0 -117
- package/hooks/before-plan.mjs +0 -155
- package/hooks/before-review.mjs +0 -139
- package/hooks/hooks.json +0 -66
- package/hooks/lifecycle.json +0 -91
- package/hooks/native/auto-dispatch.mjs +0 -207
- package/hooks/native/auto-format.mjs +0 -176
- package/hooks/native/mcp-discovery.mjs +0 -168
- package/hooks/native/security-config.json +0 -38
- package/hooks/native/security-guard.mjs +0 -323
- package/hooks/native/session-context.mjs +0 -179
- package/hooks/native/session-end.mjs +0 -42
- package/hooks/native/utils.mjs +0 -62
- package/hooks/on-error.mjs +0 -129
- package/hooks/session-end.mjs +0 -185
- package/hooks/session-start.mjs +0 -154
- package/packs/angular/ARCHITECTURE.md +0 -814
- package/packs/angular/CLAUDE.md +0 -105
- package/packs/angular/agents/builder.md +0 -113
- package/packs/angular/agents/doctor.md +0 -187
- package/packs/angular/agents/migrator.md +0 -101
- package/packs/angular/agents/reviewer.md +0 -252
- package/packs/angular/agents-lite/builder.md +0 -65
- package/packs/angular/agents-lite/doctor.md +0 -64
- package/packs/angular/agents-lite/migrator.md +0 -75
- package/packs/angular/agents-lite/reviewer.md +0 -69
- package/packs/angular/skills/dev-create-component/SKILL.md +0 -56
- package/packs/angular/skills/dev-create-injectable/SKILL.md +0 -60
- package/packs/angular/skills/dev-create-module/SKILL.md +0 -49
- package/packs/angular/skills/dev-create-service/SKILL.md +0 -34
- package/packs/angular/skills/dev-create-test/SKILL.md +0 -78
- package/packs/angular/skills/dev-generate-types/SKILL.md +0 -37
- package/packs/angular/skills/docs-onboard/SKILL.md +0 -42
- package/packs/angular/skills/migration-migrate-component/SKILL.md +0 -42
- package/packs/angular/skills/migration-migrate-module/SKILL.md +0 -25
- package/packs/angular/skills/review-check-architecture/SKILL.md +0 -67
- package/packs/angular/skills/review-fix-violations/SKILL.md +0 -43
- package/packs/angular/skills/review-review/SKILL.md +0 -43
- package/packs/astro/ARCHITECTURE.md +0 -718
- package/packs/astro/CLAUDE.md +0 -106
- package/packs/astro/agents/builder.md +0 -123
- package/packs/astro/agents/doctor.md +0 -200
- package/packs/astro/agents/migrator.md +0 -105
- package/packs/astro/agents/reviewer.md +0 -253
- package/packs/astro/agents-lite/builder.md +0 -71
- package/packs/astro/agents-lite/doctor.md +0 -66
- package/packs/astro/agents-lite/migrator.md +0 -71
- package/packs/astro/agents-lite/reviewer.md +0 -70
- package/packs/astro/skills/dev-create-component/SKILL.md +0 -50
- package/packs/astro/skills/dev-create-island/SKILL.md +0 -63
- package/packs/astro/skills/dev-create-module/SKILL.md +0 -49
- package/packs/astro/skills/dev-create-service/SKILL.md +0 -34
- package/packs/astro/skills/dev-create-test/SKILL.md +0 -76
- package/packs/astro/skills/dev-generate-types/SKILL.md +0 -37
- package/packs/astro/skills/docs-onboard/SKILL.md +0 -51
- package/packs/astro/skills/migration-migrate-component/SKILL.md +0 -48
- package/packs/astro/skills/migration-migrate-module/SKILL.md +0 -25
- package/packs/astro/skills/review-check-architecture/SKILL.md +0 -72
- package/packs/astro/skills/review-fix-violations/SKILL.md +0 -43
- package/packs/astro/skills/review-review/SKILL.md +0 -45
- package/packs/nextjs/ARCHITECTURE.md +0 -1033
- package/packs/nextjs/CLAUDE.md +0 -106
- package/packs/nextjs/agents/builder.md +0 -132
- package/packs/nextjs/agents/doctor.md +0 -226
- package/packs/nextjs/agents/migrator.md +0 -101
- package/packs/nextjs/agents/reviewer.md +0 -243
- package/packs/nextjs/agents-lite/builder.md +0 -74
- package/packs/nextjs/agents-lite/doctor.md +0 -74
- package/packs/nextjs/agents-lite/migrator.md +0 -75
- package/packs/nextjs/agents-lite/reviewer.md +0 -73
- package/packs/nextjs/skills/dev-create-component/SKILL.md +0 -82
- package/packs/nextjs/skills/dev-create-hook/SKILL.md +0 -90
- package/packs/nextjs/skills/dev-create-module/SKILL.md +0 -63
- package/packs/nextjs/skills/dev-create-service/SKILL.md +0 -35
- package/packs/nextjs/skills/dev-create-test/SKILL.md +0 -106
- package/packs/nextjs/skills/dev-generate-types/SKILL.md +0 -37
- package/packs/nextjs/skills/docs-onboard/SKILL.md +0 -55
- package/packs/nextjs/skills/migration-migrate-component/SKILL.md +0 -58
- package/packs/nextjs/skills/migration-migrate-module/SKILL.md +0 -25
- package/packs/nextjs/skills/review-check-architecture/SKILL.md +0 -101
- package/packs/nextjs/skills/review-fix-violations/SKILL.md +0 -48
- package/packs/nextjs/skills/review-review/SKILL.md +0 -47
- package/packs/nuxt/ARCHITECTURE.md +0 -831
- package/packs/nuxt/CLAUDE.md +0 -111
- package/packs/nuxt/agents/builder.md +0 -120
- package/packs/nuxt/agents/doctor.md +0 -198
- package/packs/nuxt/agents/migrator.md +0 -101
- package/packs/nuxt/agents/reviewer.md +0 -255
- package/packs/nuxt/agents-lite/builder.md +0 -67
- package/packs/nuxt/agents-lite/doctor.md +0 -67
- package/packs/nuxt/agents-lite/migrator.md +0 -80
- package/packs/nuxt/agents-lite/reviewer.md +0 -71
- package/packs/nuxt/skills/dev-create-component/SKILL.md +0 -60
- package/packs/nuxt/skills/dev-create-composable/SKILL.md +0 -33
- package/packs/nuxt/skills/dev-create-module/SKILL.md +0 -49
- package/packs/nuxt/skills/dev-create-service/SKILL.md +0 -34
- package/packs/nuxt/skills/dev-create-test/SKILL.md +0 -61
- package/packs/nuxt/skills/dev-generate-types/SKILL.md +0 -37
- package/packs/nuxt/skills/docs-onboard/SKILL.md +0 -49
- package/packs/nuxt/skills/migration-migrate-component/SKILL.md +0 -48
- package/packs/nuxt/skills/migration-migrate-module/SKILL.md +0 -25
- package/packs/nuxt/skills/review-check-architecture/SKILL.md +0 -71
- package/packs/nuxt/skills/review-fix-violations/SKILL.md +0 -43
- package/packs/nuxt/skills/review-review/SKILL.md +0 -45
- package/packs/react/ARCHITECTURE.md +0 -991
- package/packs/react/CLAUDE.md +0 -102
- package/packs/react/agents/builder.md +0 -113
- package/packs/react/agents/doctor.md +0 -203
- package/packs/react/agents/migrator.md +0 -101
- package/packs/react/agents/reviewer.md +0 -252
- package/packs/react/agents-lite/builder.md +0 -65
- package/packs/react/agents-lite/doctor.md +0 -64
- package/packs/react/agents-lite/migrator.md +0 -74
- package/packs/react/agents-lite/reviewer.md +0 -69
- package/packs/react/skills/dev-create-component/SKILL.md +0 -53
- package/packs/react/skills/dev-create-hook/SKILL.md +0 -78
- package/packs/react/skills/dev-create-module/SKILL.md +0 -51
- package/packs/react/skills/dev-create-service/SKILL.md +0 -34
- package/packs/react/skills/dev-create-test/SKILL.md +0 -92
- package/packs/react/skills/dev-generate-types/SKILL.md +0 -37
- package/packs/react/skills/docs-onboard/SKILL.md +0 -42
- package/packs/react/skills/migration-migrate-component/SKILL.md +0 -44
- package/packs/react/skills/migration-migrate-module/SKILL.md +0 -25
- package/packs/react/skills/review-check-architecture/SKILL.md +0 -73
- package/packs/react/skills/review-fix-violations/SKILL.md +0 -45
- package/packs/react/skills/review-review/SKILL.md +0 -44
- package/packs/svelte/ARCHITECTURE.md +0 -975
- package/packs/svelte/CLAUDE.md +0 -102
- package/packs/svelte/agents/builder.md +0 -114
- package/packs/svelte/agents/doctor.md +0 -174
- package/packs/svelte/agents/migrator.md +0 -101
- package/packs/svelte/agents/reviewer.md +0 -238
- package/packs/svelte/agents-lite/builder.md +0 -66
- package/packs/svelte/agents-lite/doctor.md +0 -67
- package/packs/svelte/agents-lite/migrator.md +0 -82
- package/packs/svelte/agents-lite/reviewer.md +0 -70
- package/packs/svelte/skills/dev-create-component/SKILL.md +0 -77
- package/packs/svelte/skills/dev-create-module/SKILL.md +0 -59
- package/packs/svelte/skills/dev-create-service/SKILL.md +0 -35
- package/packs/svelte/skills/dev-create-store/SKILL.md +0 -94
- package/packs/svelte/skills/dev-create-test/SKILL.md +0 -98
- package/packs/svelte/skills/dev-generate-types/SKILL.md +0 -37
- package/packs/svelte/skills/docs-onboard/SKILL.md +0 -47
- package/packs/svelte/skills/migration-migrate-component/SKILL.md +0 -51
- package/packs/svelte/skills/migration-migrate-module/SKILL.md +0 -25
- package/packs/svelte/skills/review-check-architecture/SKILL.md +0 -79
- package/packs/svelte/skills/review-fix-violations/SKILL.md +0 -47
- package/packs/svelte/skills/review-review/SKILL.md +0 -45
- package/packs/vue/ARCHITECTURE.md +0 -798
- package/packs/vue/CLAUDE.md +0 -102
- package/packs/vue/agents/builder.md +0 -112
- package/packs/vue/agents/doctor.md +0 -185
- package/packs/vue/agents/migrator.md +0 -101
- package/packs/vue/agents/reviewer.md +0 -249
- package/packs/vue/agents-lite/builder.md +0 -65
- package/packs/vue/agents-lite/doctor.md +0 -63
- package/packs/vue/agents-lite/migrator.md +0 -73
- package/packs/vue/agents-lite/reviewer.md +0 -68
- package/packs/vue/skills/dev-create-component/SKILL.md +0 -58
- package/packs/vue/skills/dev-create-composable/SKILL.md +0 -31
- package/packs/vue/skills/dev-create-module/SKILL.md +0 -50
- package/packs/vue/skills/dev-create-service/SKILL.md +0 -34
- package/packs/vue/skills/dev-create-test/SKILL.md +0 -62
- package/packs/vue/skills/dev-generate-types/SKILL.md +0 -37
- package/packs/vue/skills/docs-onboard/SKILL.md +0 -42
- package/packs/vue/skills/migration-migrate-component/SKILL.md +0 -41
- package/packs/vue/skills/migration-migrate-module/SKILL.md +0 -25
- package/packs/vue/skills/review-check-architecture/SKILL.md +0 -73
- package/packs/vue/skills/review-fix-violations/SKILL.md +0 -42
- package/packs/vue/skills/review-review/SKILL.md +0 -43
- package/skills/audit/SKILL.md +0 -231
- package/skills/autofix/SKILL.md +0 -166
- package/skills/autopilot/SKILL.md +0 -286
- package/skills/brainstorm/SKILL.md +0 -298
- package/skills/checkpoint/SKILL.md +0 -217
- package/skills/codereview/SKILL.md +0 -268
- package/skills/commit/SKILL.md +0 -150
- package/skills/copywriting/SKILL.md +0 -218
- package/skills/cro/SKILL.md +0 -234
- package/skills/debug/SKILL.md +0 -210
- package/skills/design-review/SKILL.md +0 -217
- package/skills/discovery/SKILL.md +0 -218
- package/skills/estimate/SKILL.md +0 -154
- package/skills/finish/SKILL.md +0 -220
- package/skills/grill/SKILL.md +0 -270
- package/skills/health/SKILL.md +0 -251
- package/skills/improve-architecture/SKILL.md +0 -205
- package/skills/learn/SKILL.md +0 -260
- package/skills/lint/SKILL.md +0 -126
- package/skills/migrate-architecture/SKILL.md +0 -242
- package/skills/migrate-framework/SKILL.md +0 -172
- package/skills/onboard/SKILL.md +0 -168
- package/skills/plan/SKILL.md +0 -141
- package/skills/prd/SKILL.md +0 -241
- package/skills/recall/SKILL.md +0 -112
- package/skills/remember/SKILL.md +0 -108
- package/skills/seo-audit/SKILL.md +0 -240
- package/skills/tdd/SKILL.md +0 -201
- package/skills/tutorial/SKILL.md +0 -346
- package/skills/verify/SKILL.md +0 -168
- package/skills/worktree/SKILL.md +0 -168
- package/skills/write-skill/SKILL.md +0 -225
- package/templates/autopilot/PROMPT.md +0 -39
- package/templates/autopilot/README.md +0 -122
- package/templates/autopilot/devcontainer.json +0 -21
- package/templates/industry/ecommerce.md +0 -127
- package/templates/industry/fintech.md +0 -161
- package/templates/industry/saas.md +0 -134
- package/templates/session-memory.json +0 -48
- package/templates/skill-template/SKILL.md +0 -90
|
@@ -1,718 +0,0 @@
|
|
|
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`
|