specialist-agent 2.13.0 → 3.3.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 +36 -206
- package/dist/catalog.json +16677 -0
- package/dist/hw-worker.mjs +288 -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-BltVv7tb.js +24 -0
- package/dist/interface/assets/index-Cpa6kApK.css +1 -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 +64 -0
- package/dist/licencas/BRAND.md +22 -0
- package/dist/licencas/LICENSE-CONTENT.md +44 -0
- package/dist/licencas/OFL-Figtree.txt +93 -0
- package/dist/licencas/OFL-JetBrainsMono.txt +93 -0
- package/dist/licencas/OFL-Unbounded.txt +93 -0
- package/dist/licencas/TERCEIROS.txt +104 -0
- package/dist/specialist-agent.mjs +14515 -0
- package/dist/usage-worker.mjs +1077 -0
- package/package.json +34 -58
- 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,814 +0,0 @@
|
|
|
1
|
-
# ARCHITECTURE.md -- Architecture & Patterns Guide
|
|
2
|
-
|
|
3
|
-
> This document is the **source of truth** for all subagents.
|
|
4
|
-
> Every architectural decision must be documented here.
|
|
5
|
-
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## 1. Overview
|
|
9
|
-
|
|
10
|
-
We are migrating / building an Angular project following a modern, typed, modular architecture:
|
|
11
|
-
|
|
12
|
-
| From | To |
|
|
13
|
-
|------|----|
|
|
14
|
-
| JavaScript | TypeScript (strict) |
|
|
15
|
-
| NgModule-based components | Standalone components |
|
|
16
|
-
| @Input()/@Output() decorators | input()/output() signal-based I/O |
|
|
17
|
-
| Constructor DI | inject() function |
|
|
18
|
-
| RxJS BehaviorSubject stores | Signal-based stores (WritableSignal + computed) |
|
|
19
|
-
| Manual HTTP / inline transforms | Services + Adapters + HttpClient |
|
|
20
|
-
| Scattered try/catch | Centralized error handling via HttpInterceptor |
|
|
21
|
-
| Structure by file type | Modular architecture by feature |
|
|
22
|
-
| Class-heavy patterns | Functional + signal-based patterns |
|
|
23
|
-
| Inconsistent naming | Strict documented conventions |
|
|
24
|
-
|
|
25
|
-
### Core Stack
|
|
26
|
-
|
|
27
|
-
- **Angular 17+** with standalone components
|
|
28
|
-
- **TypeScript** (strict mode)
|
|
29
|
-
- **Angular Signals** for reactive state (signal, computed, effect)
|
|
30
|
-
- **HttpClient** for HTTP calls
|
|
31
|
-
- **Angular Router** with lazy loading
|
|
32
|
-
- **Zod** for runtime validation
|
|
33
|
-
- **Jest/Vitest** + **Angular Testing Library** for tests
|
|
34
|
-
|
|
35
|
-
### Data Flow
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
Service (HttpClient only) --> Adapter (parse) --> Injectable/Component (orchestrate) --> Component (template)
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
## 2. Directory Structure (Modular Architecture)
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
src/
|
|
47
|
-
+-- app/ # Application shell
|
|
48
|
-
| +-- app.component.ts
|
|
49
|
-
| +-- app.config.ts
|
|
50
|
-
| +-- app.routes.ts
|
|
51
|
-
| +-- guards/
|
|
52
|
-
| +-- interceptors/ # HttpInterceptors (auth, error handling)
|
|
53
|
-
|
|
|
54
|
-
+-- modules/ # Feature modules (bounded contexts)
|
|
55
|
-
| +-- auth/
|
|
56
|
-
| | +-- components/
|
|
57
|
-
| | +-- services/
|
|
58
|
-
| | +-- adapters/
|
|
59
|
-
| | +-- stores/
|
|
60
|
-
| | +-- types/
|
|
61
|
-
| | +-- pages/
|
|
62
|
-
| | +-- __tests__/
|
|
63
|
-
| | +-- index.ts # Barrel export (public API)
|
|
64
|
-
| |
|
|
65
|
-
| +-- marketplace/
|
|
66
|
-
| | +-- components/
|
|
67
|
-
| | | +-- marketplace-list.component.ts
|
|
68
|
-
| | | +-- marketplace-card.component.ts
|
|
69
|
-
| | | +-- marketplace-filters.component.ts
|
|
70
|
-
| | | +-- marketplace-card/ # Sub-components if needed
|
|
71
|
-
| | | +-- marketplace-card-header.component.ts
|
|
72
|
-
| | | +-- marketplace-card-actions.component.ts
|
|
73
|
-
| | +-- services/
|
|
74
|
-
| | | +-- marketplace.service.ts
|
|
75
|
-
| | +-- adapters/
|
|
76
|
-
| | | +-- marketplace.adapter.ts
|
|
77
|
-
| | +-- stores/
|
|
78
|
-
| | | +-- marketplace.store.ts # Client state only (filters, UI)
|
|
79
|
-
| | +-- types/
|
|
80
|
-
| | | +-- marketplace.types.ts
|
|
81
|
-
| | | +-- marketplace.contracts.ts # Zod schemas / app contracts
|
|
82
|
-
| | +-- pages/
|
|
83
|
-
| | | +-- marketplace-page.component.ts
|
|
84
|
-
| | +-- __tests__/
|
|
85
|
-
| | +-- index.ts
|
|
86
|
-
| |
|
|
87
|
-
| +-- [other-module]/
|
|
88
|
-
|
|
|
89
|
-
+-- shared/ # Shared across modules
|
|
90
|
-
| +-- components/ # Generic components (Button, Modal, Table)
|
|
91
|
-
| +-- services/ # Base API client, interceptors
|
|
92
|
-
| +-- adapters/ # Shared adapters
|
|
93
|
-
| +-- types/ # Global types
|
|
94
|
-
| +-- utils/ # Pure functions, no side effects
|
|
95
|
-
| +-- helpers/ # Functions with side effects or DOM
|
|
96
|
-
| +-- constants/ # Static values
|
|
97
|
-
| +-- pipes/ # Angular pipes
|
|
98
|
-
| +-- directives/ # Angular directives
|
|
99
|
-
|
|
|
100
|
-
+-- assets/ # Static assets (images, fonts, global CSS)
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### Import Rules Between Layers
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
modules/auth <-> shared/ OK Module imports from shared
|
|
107
|
-
modules/auth --> modules/market NO Module does NOT import from another module
|
|
108
|
-
shared/ --> modules/auth NO Shared does NOT import from modules
|
|
109
|
-
app/ --> modules/* OK App imports modules (routes, providers)
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
If two modules need to share something, move it to `shared/`.
|
|
113
|
-
|
|
114
|
-
---
|
|
115
|
-
|
|
116
|
-
## 3. Naming Conventions
|
|
117
|
-
|
|
118
|
-
### Files and Directories
|
|
119
|
-
|
|
120
|
-
| Type | Pattern | Example |
|
|
121
|
-
|------|---------|---------|
|
|
122
|
-
| Directories | `kebab-case` | `user-settings/` |
|
|
123
|
-
| Components | `kebab-case.component.ts` | `user-settings-form.component.ts` |
|
|
124
|
-
| Pages | `kebab-case-page.component.ts` | `marketplace-page.component.ts` |
|
|
125
|
-
| Services | `kebab-case.service.ts` | `marketplace.service.ts` |
|
|
126
|
-
| Adapters | `kebab-case.adapter.ts` | `marketplace.adapter.ts` |
|
|
127
|
-
| Stores | `kebab-case.store.ts` | `marketplace.store.ts` |
|
|
128
|
-
| Types | `kebab-case.types.ts` | `marketplace.types.ts` |
|
|
129
|
-
| Contracts/Schemas | `kebab-case.contracts.ts` | `marketplace.contracts.ts` |
|
|
130
|
-
| Utils | `kebab-case.ts` | `format-date.ts` |
|
|
131
|
-
| Helpers | `kebab-case.ts` | `clipboard-helper.ts` |
|
|
132
|
-
| Tests | `kebab-case.spec.ts` | `marketplace-list.component.spec.ts` |
|
|
133
|
-
| Constants | `kebab-case.constants.ts` | `api-endpoints.constants.ts` |
|
|
134
|
-
| Pipes | `kebab-case.pipe.ts` | `currency-format.pipe.ts` |
|
|
135
|
-
| Directives | `kebab-case.directive.ts` | `click-outside.directive.ts` |
|
|
136
|
-
| Guards | `kebab-case.guard.ts` | `auth.guard.ts` |
|
|
137
|
-
| Interceptors | `kebab-case.interceptor.ts` | `error-handler.interceptor.ts` |
|
|
138
|
-
|
|
139
|
-
### Code
|
|
140
|
-
|
|
141
|
-
| Type | Pattern | Example |
|
|
142
|
-
|------|---------|---------|
|
|
143
|
-
| Variables / functions | `camelCase` | `getUserById`, `isLoading` |
|
|
144
|
-
| Classes / Components | `PascalCase` | `UserProfile`, `MarketplaceListComponent` |
|
|
145
|
-
| Enums | `PascalCase` | `UserRole.Admin` |
|
|
146
|
-
| Constants | `UPPER_SNAKE_CASE` | `API_BASE_URL`, `MAX_RETRIES` |
|
|
147
|
-
| Services | `PascalCase + Service` | `MarketplaceService` |
|
|
148
|
-
| Stores | `PascalCase + Store` | `MarketplaceStore` |
|
|
149
|
-
| Selectors | `kebab-case` | `'app-marketplace-list'` |
|
|
150
|
-
| Event handlers | `handle` + action | `handleSubmit`, `handleDelete` |
|
|
151
|
-
| Boolean | `is`/`has`/`can`/`should` | `isLoading`, `hasPermission` |
|
|
152
|
-
|
|
153
|
-
---
|
|
154
|
-
|
|
155
|
-
## 4. Responsibility Layers
|
|
156
|
-
|
|
157
|
-
### 4.1 Services -- Pure HTTP Requests
|
|
158
|
-
|
|
159
|
-
Services make **only** the HTTP request via HttpClient. No try/catch, no transformation, no business logic.
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
// services/marketplace.service.ts
|
|
163
|
-
import { Injectable, inject } from '@angular/core'
|
|
164
|
-
import { HttpClient } from '@angular/common/http'
|
|
165
|
-
import type {
|
|
166
|
-
MarketplaceListResponse,
|
|
167
|
-
MarketplaceItemResponse,
|
|
168
|
-
CreateMarketplacePayload,
|
|
169
|
-
} from '../types/marketplace.types'
|
|
170
|
-
|
|
171
|
-
@Injectable({ providedIn: 'root' })
|
|
172
|
-
export class MarketplaceService {
|
|
173
|
-
private readonly http = inject(HttpClient)
|
|
174
|
-
private readonly baseUrl = '/api/marketplace'
|
|
175
|
-
|
|
176
|
-
list(params: { page: number; pageSize: number; search?: string }) {
|
|
177
|
-
return this.http.get<MarketplaceListResponse>(this.baseUrl, { params: { ...params } })
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
getById(id: string) {
|
|
181
|
-
return this.http.get<MarketplaceItemResponse>(`${this.baseUrl}/${id}`)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
create(payload: CreateMarketplacePayload) {
|
|
185
|
-
return this.http.post<MarketplaceItemResponse>(this.baseUrl, payload)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
delete(id: string) {
|
|
189
|
-
return this.http.delete(`${this.baseUrl}/${id}`)
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
**Service Rules:**
|
|
195
|
-
- NO try/catch (caller handles errors)
|
|
196
|
-
- NO data transformation (adapter does that)
|
|
197
|
-
- NO business logic
|
|
198
|
-
- NO store or signal access
|
|
199
|
-
- YES HttpClient calls with typed request/response
|
|
200
|
-
- YES one file per domain/resource
|
|
201
|
-
- YES `@Injectable({ providedIn: 'root' })` with `inject()`
|
|
202
|
-
|
|
203
|
-
### 4.2 Adapters -- Contract Parsers
|
|
204
|
-
|
|
205
|
-
Adapters transform API data to the application's TypeScript contract (and vice-versa). They are **pure functions** with no side effects.
|
|
206
|
-
|
|
207
|
-
```typescript
|
|
208
|
-
// adapters/marketplace.adapter.ts
|
|
209
|
-
import type {
|
|
210
|
-
MarketplaceListResponse,
|
|
211
|
-
MarketplaceItemResponse,
|
|
212
|
-
} from '../types/marketplace.types'
|
|
213
|
-
import type {
|
|
214
|
-
MarketplaceItem,
|
|
215
|
-
MarketplaceList,
|
|
216
|
-
} from '../types/marketplace.contracts'
|
|
217
|
-
|
|
218
|
-
export const marketplaceAdapter = {
|
|
219
|
-
/**
|
|
220
|
-
* API response -> App contract (inbound)
|
|
221
|
-
*/
|
|
222
|
-
toMarketplaceItem(response: MarketplaceItemResponse): MarketplaceItem {
|
|
223
|
-
return {
|
|
224
|
-
id: response.uuid,
|
|
225
|
-
name: response.name,
|
|
226
|
-
vendor: response.vendor_name,
|
|
227
|
-
category: response.category_slug,
|
|
228
|
-
price: response.price_cents / 100,
|
|
229
|
-
isActive: response.status === 'active',
|
|
230
|
-
createdAt: new Date(response.created_at),
|
|
231
|
-
updatedAt: new Date(response.updated_at),
|
|
232
|
-
}
|
|
233
|
-
},
|
|
234
|
-
|
|
235
|
-
toMarketplaceList(response: MarketplaceListResponse): MarketplaceList {
|
|
236
|
-
return {
|
|
237
|
-
items: response.results.map(marketplaceAdapter.toMarketplaceItem),
|
|
238
|
-
totalItems: response.count,
|
|
239
|
-
totalPages: Math.ceil(response.count / response.page_size),
|
|
240
|
-
currentPage: response.page,
|
|
241
|
-
}
|
|
242
|
-
},
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* App contract -> API payload (outbound)
|
|
246
|
-
*/
|
|
247
|
-
toCreatePayload(item: CreateMarketplaceInput): CreateMarketplacePayload {
|
|
248
|
-
return {
|
|
249
|
-
name: item.name,
|
|
250
|
-
vendor_name: item.vendor,
|
|
251
|
-
category_slug: item.category,
|
|
252
|
-
price_cents: Math.round(item.price * 100),
|
|
253
|
-
}
|
|
254
|
-
},
|
|
255
|
-
}
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
**Adapter Rules:**
|
|
259
|
-
- YES pure functions (input -> output, no side effects)
|
|
260
|
-
- YES two directions: API->App (inbound) and App->API (outbound)
|
|
261
|
-
- YES rename fields (snake_case API -> camelCase App)
|
|
262
|
-
- YES convert types (string->Date, cents->decimal, status->boolean)
|
|
263
|
-
- NO HTTP calls
|
|
264
|
-
- NO store/service access
|
|
265
|
-
- NO try/catch (failure = wrong type = bug to fix)
|
|
266
|
-
|
|
267
|
-
### 4.3 Types & Contracts
|
|
268
|
-
|
|
269
|
-
```typescript
|
|
270
|
-
// types/marketplace.types.ts
|
|
271
|
-
// <-- Types that mirror the API exactly as it returns (snake_case)
|
|
272
|
-
|
|
273
|
-
export interface MarketplaceItemResponse {
|
|
274
|
-
uuid: string
|
|
275
|
-
name: string
|
|
276
|
-
vendor_name: string
|
|
277
|
-
category_slug: string
|
|
278
|
-
price_cents: number
|
|
279
|
-
status: 'active' | 'inactive' | 'pending'
|
|
280
|
-
created_at: string
|
|
281
|
-
updated_at: string
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
export interface MarketplaceListResponse {
|
|
285
|
-
count: number
|
|
286
|
-
page: number
|
|
287
|
-
page_size: number
|
|
288
|
-
results: MarketplaceItemResponse[]
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
export interface CreateMarketplacePayload {
|
|
292
|
-
name: string
|
|
293
|
-
vendor_name: string
|
|
294
|
-
category_slug: string
|
|
295
|
-
price_cents: number
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// types/marketplace.contracts.ts
|
|
299
|
-
// <-- Application contracts (camelCase, correct types)
|
|
300
|
-
|
|
301
|
-
export interface MarketplaceItem {
|
|
302
|
-
id: string
|
|
303
|
-
name: string
|
|
304
|
-
vendor: string
|
|
305
|
-
category: string
|
|
306
|
-
price: number // in currency, not cents
|
|
307
|
-
isActive: boolean // derived from status
|
|
308
|
-
createdAt: Date
|
|
309
|
-
updatedAt: Date
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export interface MarketplaceList {
|
|
313
|
-
items: MarketplaceItem[]
|
|
314
|
-
totalItems: number
|
|
315
|
-
totalPages: number
|
|
316
|
-
currentPage: number
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
export interface CreateMarketplaceInput {
|
|
320
|
-
name: string
|
|
321
|
-
vendor: string
|
|
322
|
-
category: string
|
|
323
|
-
price: number
|
|
324
|
-
}
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
### 4.4 Signal Stores -- Client State Only
|
|
328
|
-
|
|
329
|
-
Signal stores manage state that **does not come from the server**: UI state, filters, preferences, auth tokens.
|
|
330
|
-
|
|
331
|
-
```typescript
|
|
332
|
-
// stores/marketplace.store.ts
|
|
333
|
-
import { Injectable, signal, computed } from '@angular/core'
|
|
334
|
-
|
|
335
|
-
@Injectable({ providedIn: 'root' })
|
|
336
|
-
export class MarketplaceStore {
|
|
337
|
-
// State (private writable signals)
|
|
338
|
-
private readonly _selectedCategory = signal<string | null>(null)
|
|
339
|
-
private readonly _viewMode = signal<'grid' | 'list'>('grid')
|
|
340
|
-
private readonly _searchQuery = signal('')
|
|
341
|
-
|
|
342
|
-
// Public read-only signals
|
|
343
|
-
readonly selectedCategory = this._selectedCategory.asReadonly()
|
|
344
|
-
readonly viewMode = this._viewMode.asReadonly()
|
|
345
|
-
readonly searchQuery = this._searchQuery.asReadonly()
|
|
346
|
-
|
|
347
|
-
// Computed
|
|
348
|
-
readonly hasActiveFilters = computed(() =>
|
|
349
|
-
!!this._selectedCategory() || !!this._searchQuery()
|
|
350
|
-
)
|
|
351
|
-
|
|
352
|
-
// Actions
|
|
353
|
-
setCategory(category: string | null) {
|
|
354
|
-
this._selectedCategory.set(category)
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
setViewMode(mode: 'grid' | 'list') {
|
|
358
|
-
this._viewMode.set(mode)
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
setSearchQuery(query: string) {
|
|
362
|
-
this._searchQuery.set(query)
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
clearFilters() {
|
|
366
|
-
this._selectedCategory.set(null)
|
|
367
|
-
this._searchQuery.set('')
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
**Store Rules:**
|
|
373
|
-
- YES client state only (UI, filters, preferences, session)
|
|
374
|
-
- YES `@Injectable({ providedIn: 'root' })` with signals
|
|
375
|
-
- YES private WritableSignal, public asReadonly()
|
|
376
|
-
- YES computed() for derived values
|
|
377
|
-
- NO server state (API data is fetched via services and managed locally)
|
|
378
|
-
- NO HTTP calls inside stores
|
|
379
|
-
- NO complex business logic (services or components handle that)
|
|
380
|
-
|
|
381
|
-
### 4.5 Components -- Standalone with Signals
|
|
382
|
-
|
|
383
|
-
```typescript
|
|
384
|
-
// components/marketplace-list.component.ts
|
|
385
|
-
import { Component, inject, input, output, signal, computed } from '@angular/core'
|
|
386
|
-
import { MarketplaceService } from '../services/marketplace.service'
|
|
387
|
-
import { marketplaceAdapter } from '../adapters/marketplace.adapter'
|
|
388
|
-
import { MarketplaceStore } from '../stores/marketplace.store'
|
|
389
|
-
import { MarketplaceCardComponent } from './marketplace-card.component'
|
|
390
|
-
import type { MarketplaceItem } from '../types/marketplace.contracts'
|
|
391
|
-
|
|
392
|
-
@Component({
|
|
393
|
-
selector: 'app-marketplace-list',
|
|
394
|
-
standalone: true,
|
|
395
|
-
imports: [MarketplaceCardComponent],
|
|
396
|
-
template: `
|
|
397
|
-
@if (isLoading()) {
|
|
398
|
-
<div>Loading...</div>
|
|
399
|
-
} @else if (isEmpty()) {
|
|
400
|
-
<div>No items found</div>
|
|
401
|
-
} @else {
|
|
402
|
-
@for (item of items(); track item.id) {
|
|
403
|
-
<app-marketplace-card
|
|
404
|
-
[item]="item"
|
|
405
|
-
[isSelected]="item.id === selectedId()"
|
|
406
|
-
(select)="handleSelect($event)"
|
|
407
|
-
/>
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
`,
|
|
411
|
-
})
|
|
412
|
-
export class MarketplaceListComponent {
|
|
413
|
-
// Inputs / Outputs (signal-based)
|
|
414
|
-
readonly categoryFilter = input<string>()
|
|
415
|
-
readonly select = output<MarketplaceItem>()
|
|
416
|
-
|
|
417
|
-
// Injected dependencies
|
|
418
|
-
private readonly service = inject(MarketplaceService)
|
|
419
|
-
private readonly store = inject(MarketplaceStore)
|
|
420
|
-
|
|
421
|
-
// Local state
|
|
422
|
-
readonly page = signal(1)
|
|
423
|
-
readonly selectedId = signal<string | null>(null)
|
|
424
|
-
readonly items = signal<MarketplaceItem[]>([])
|
|
425
|
-
readonly isLoading = signal(false)
|
|
426
|
-
|
|
427
|
-
// Computed
|
|
428
|
-
readonly isEmpty = computed(() => !this.isLoading() && this.items().length === 0)
|
|
429
|
-
readonly isFirstPage = computed(() => this.page() === 1)
|
|
430
|
-
|
|
431
|
-
// Handlers
|
|
432
|
-
handleSelect(item: MarketplaceItem) {
|
|
433
|
-
this.selectedId.set(item.id)
|
|
434
|
-
this.select.emit(item)
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
handlePageChange(newPage: number) {
|
|
438
|
-
this.page.set(newPage)
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
```
|
|
442
|
-
|
|
443
|
-
---
|
|
444
|
-
|
|
445
|
-
## 5. Component Patterns
|
|
446
|
-
|
|
447
|
-
### 5.1 Stop Prop Drilling -- Component Composition
|
|
448
|
-
|
|
449
|
-
**BAD -- Prop Drilling:**
|
|
450
|
-
```html
|
|
451
|
-
<!-- GrandParent passes data through 3 levels -->
|
|
452
|
-
<app-parent [user]="user" [theme]="theme" [permissions]="permissions">
|
|
453
|
-
<app-child [user]="user" [theme]="theme" [permissions]="permissions">
|
|
454
|
-
<app-grandchild [user]="user" [permissions]="permissions" />
|
|
455
|
-
</app-child>
|
|
456
|
-
</app-parent>
|
|
457
|
-
```
|
|
458
|
-
|
|
459
|
-
**GOOD -- Composition with content projection:**
|
|
460
|
-
```typescript
|
|
461
|
-
// marketplace-page.component.ts
|
|
462
|
-
@Component({
|
|
463
|
-
selector: 'app-marketplace-page',
|
|
464
|
-
standalone: true,
|
|
465
|
-
imports: [PageLayoutComponent, MarketplaceFiltersComponent, MarketplaceListComponent, MarketplaceDetailsComponent],
|
|
466
|
-
template: `
|
|
467
|
-
<app-page-layout>
|
|
468
|
-
<ng-container header>
|
|
469
|
-
<app-marketplace-filters />
|
|
470
|
-
</ng-container>
|
|
471
|
-
|
|
472
|
-
<app-marketplace-list (select)="handleSelect($event)" />
|
|
473
|
-
|
|
474
|
-
@if (selectedItem()) {
|
|
475
|
-
<ng-container sidebar>
|
|
476
|
-
<app-marketplace-details [item]="selectedItem()!" />
|
|
477
|
-
</ng-container>
|
|
478
|
-
}
|
|
479
|
-
</app-page-layout>
|
|
480
|
-
`,
|
|
481
|
-
})
|
|
482
|
-
export class MarketplacePageComponent {
|
|
483
|
-
readonly selectedItem = signal<MarketplaceItem | null>(null)
|
|
484
|
-
|
|
485
|
-
handleSelect(item: MarketplaceItem) {
|
|
486
|
-
this.selectedItem.set(item)
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
```
|
|
490
|
-
|
|
491
|
-
**GOOD -- Shared injectable for cross-component state:**
|
|
492
|
-
```typescript
|
|
493
|
-
// stores/marketplace-context.store.ts
|
|
494
|
-
import { Injectable, signal, computed } from '@angular/core'
|
|
495
|
-
import type { MarketplaceItem } from '../types/marketplace.contracts'
|
|
496
|
-
|
|
497
|
-
@Injectable()
|
|
498
|
-
export class MarketplaceContextStore {
|
|
499
|
-
private readonly _selectedItem = signal<MarketplaceItem | null>(null)
|
|
500
|
-
|
|
501
|
-
readonly selectedItem = this._selectedItem.asReadonly()
|
|
502
|
-
readonly hasSelection = computed(() => this._selectedItem() !== null)
|
|
503
|
-
|
|
504
|
-
selectItem(item: MarketplaceItem) {
|
|
505
|
-
this._selectedItem.set(item)
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
clearSelection() {
|
|
509
|
-
this._selectedItem.set(null)
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
// Provide in the page component:
|
|
514
|
-
@Component({
|
|
515
|
-
providers: [MarketplaceContextStore],
|
|
516
|
-
// ...
|
|
517
|
-
})
|
|
518
|
-
export class MarketplacePageComponent {
|
|
519
|
-
private readonly context = inject(MarketplaceContextStore)
|
|
520
|
-
}
|
|
521
|
-
```
|
|
522
|
-
|
|
523
|
-
### 5.2 Component Hierarchy
|
|
524
|
-
|
|
525
|
-
```
|
|
526
|
-
Pages --> Composition, orchestration, provide context
|
|
527
|
-
+-- Layout --> Visual structure (content projection)
|
|
528
|
-
+-- Features --> Feature logic (services, stores, signals)
|
|
529
|
-
+-- Shared --> Pure presentation (inputs in, outputs out)
|
|
530
|
-
```
|
|
531
|
-
|
|
532
|
-
| Type | Responsibility | Can have logic? | Can have state? |
|
|
533
|
-
|------|---------------|-----------------|-----------------|
|
|
534
|
-
| **Pages** | Compose components, provide context | Via services/stores | Yes (signals) |
|
|
535
|
-
| **Feature Components** | UI + feature logic | Via services/stores | Yes (signals) |
|
|
536
|
-
| **Shared Components** | Generic, reusable UI | Minimal (UI only) | Minimal (local) |
|
|
537
|
-
|
|
538
|
-
---
|
|
539
|
-
|
|
540
|
-
## 6. Utils vs Helpers
|
|
541
|
-
|
|
542
|
-
### Utils -- Pure Functions
|
|
543
|
-
- No side effects
|
|
544
|
-
- Deterministic input -> output
|
|
545
|
-
- Testable without mocks
|
|
546
|
-
- No dependency on DOM, browser APIs, or Angular
|
|
547
|
-
|
|
548
|
-
```typescript
|
|
549
|
-
// shared/utils/format-date.ts
|
|
550
|
-
export function formatDate(date: Date, locale = 'en-US'): string {
|
|
551
|
-
return new Intl.DateTimeFormat(locale).format(date)
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
// shared/utils/currency.ts
|
|
555
|
-
export function formatCurrency(value: number, currency = 'USD'): string {
|
|
556
|
-
return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(value)
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
// shared/utils/string.ts
|
|
560
|
-
export function slugify(text: string): string {
|
|
561
|
-
return text.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]/g, '')
|
|
562
|
-
}
|
|
563
|
-
```
|
|
564
|
-
|
|
565
|
-
### Helpers -- Functions with Side Effects or DOM
|
|
566
|
-
- Interact with browser APIs (clipboard, localStorage, DOM)
|
|
567
|
-
- May have side effects
|
|
568
|
-
- May need mocks in tests
|
|
569
|
-
|
|
570
|
-
```typescript
|
|
571
|
-
// shared/helpers/clipboard-helper.ts
|
|
572
|
-
export async function copyToClipboard(text: string): Promise<boolean> {
|
|
573
|
-
try {
|
|
574
|
-
await navigator.clipboard.writeText(text)
|
|
575
|
-
return true
|
|
576
|
-
} catch {
|
|
577
|
-
return false
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
// shared/helpers/download-helper.ts
|
|
582
|
-
export function downloadAsFile(content: string, filename: string): void {
|
|
583
|
-
const blob = new Blob([content], { type: 'text/plain' })
|
|
584
|
-
const url = URL.createObjectURL(blob)
|
|
585
|
-
const a = document.createElement('a')
|
|
586
|
-
a.href = url
|
|
587
|
-
a.download = filename
|
|
588
|
-
a.click()
|
|
589
|
-
URL.revokeObjectURL(url)
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
// shared/helpers/storage-helper.ts
|
|
593
|
-
export function getStorageItem<T>(key: string, fallback: T): T {
|
|
594
|
-
try {
|
|
595
|
-
const item = localStorage.getItem(key)
|
|
596
|
-
return item ? (JSON.parse(item) as T) : fallback
|
|
597
|
-
} catch {
|
|
598
|
-
return fallback
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
```
|
|
602
|
-
|
|
603
|
-
---
|
|
604
|
-
|
|
605
|
-
## 7. Error Handling -- Centralized Pattern
|
|
606
|
-
|
|
607
|
-
### Global HttpInterceptor
|
|
608
|
-
|
|
609
|
-
```typescript
|
|
610
|
-
// app/interceptors/error-handler.interceptor.ts
|
|
611
|
-
import { HttpInterceptorFn, HttpErrorResponse } from '@angular/common/http'
|
|
612
|
-
import { inject } from '@angular/core'
|
|
613
|
-
import { Router } from '@angular/router'
|
|
614
|
-
import { catchError, throwError } from 'rxjs'
|
|
615
|
-
|
|
616
|
-
export const errorHandlerInterceptor: HttpInterceptorFn = (req, next) => {
|
|
617
|
-
const router = inject(Router)
|
|
618
|
-
|
|
619
|
-
return next(req).pipe(
|
|
620
|
-
catchError((error: HttpErrorResponse) => {
|
|
621
|
-
// Only redirect on 401 (session expired)
|
|
622
|
-
if (error.status === 401) {
|
|
623
|
-
router.navigate(['/login'])
|
|
624
|
-
}
|
|
625
|
-
// DO NOT handle other errors here -- let the caller handle them
|
|
626
|
-
return throwError(() => error)
|
|
627
|
-
}),
|
|
628
|
-
)
|
|
629
|
-
}
|
|
630
|
-
```
|
|
631
|
-
|
|
632
|
-
### Service-Level Error Handling (in components)
|
|
633
|
-
|
|
634
|
-
```typescript
|
|
635
|
-
// In the component that subscribes:
|
|
636
|
-
this.service.delete(id).subscribe({
|
|
637
|
-
next: () => {
|
|
638
|
-
// success: refresh data, show toast
|
|
639
|
-
},
|
|
640
|
-
error: (error) => {
|
|
641
|
-
// handle error: show toast with parseApiError(error)
|
|
642
|
-
},
|
|
643
|
-
})
|
|
644
|
-
```
|
|
645
|
-
|
|
646
|
-
### Centralized Error Parser
|
|
647
|
-
|
|
648
|
-
```typescript
|
|
649
|
-
// shared/utils/parse-api-error.ts
|
|
650
|
-
import { HttpErrorResponse } from '@angular/common/http'
|
|
651
|
-
|
|
652
|
-
interface ApiErrorResponse {
|
|
653
|
-
message?: string
|
|
654
|
-
detail?: string
|
|
655
|
-
errors?: Record<string, string[]>
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
export function parseApiError(error: unknown): string {
|
|
659
|
-
if (error instanceof HttpErrorResponse) {
|
|
660
|
-
const data = error.error as ApiErrorResponse | undefined
|
|
661
|
-
if (data?.message) return data.message
|
|
662
|
-
if (data?.detail) return data.detail
|
|
663
|
-
if (error.status === 403) return 'Permission denied'
|
|
664
|
-
if (error.status === 404) return 'Resource not found'
|
|
665
|
-
if (error.status === 500) return 'Internal server error'
|
|
666
|
-
}
|
|
667
|
-
return 'Unexpected error. Please try again.'
|
|
668
|
-
}
|
|
669
|
-
```
|
|
670
|
-
|
|
671
|
-
---
|
|
672
|
-
|
|
673
|
-
## 8. Barrel Exports (index.ts)
|
|
674
|
-
|
|
675
|
-
Each module exports only its **public API**:
|
|
676
|
-
|
|
677
|
-
```typescript
|
|
678
|
-
// modules/marketplace/index.ts
|
|
679
|
-
|
|
680
|
-
// Pages (for the router)
|
|
681
|
-
export { MarketplacePageComponent } from './pages/marketplace-page.component'
|
|
682
|
-
|
|
683
|
-
// Components reusable by others (rare, avoid)
|
|
684
|
-
export { MarketplaceCardComponent } from './components/marketplace-card.component'
|
|
685
|
-
|
|
686
|
-
// Types (for consumers that need typing)
|
|
687
|
-
export type { MarketplaceItem, MarketplaceList } from './types/marketplace.contracts'
|
|
688
|
-
|
|
689
|
-
// DO NOT export:
|
|
690
|
-
// - services (internal detail)
|
|
691
|
-
// - adapters (internal detail)
|
|
692
|
-
// - stores (internal detail)
|
|
693
|
-
// - internal components
|
|
694
|
-
```
|
|
695
|
-
|
|
696
|
-
---
|
|
697
|
-
|
|
698
|
-
## 9. SOLID Principles Applied to Angular
|
|
699
|
-
|
|
700
|
-
| Principle | Angular Application |
|
|
701
|
-
|-----------|---------------------|
|
|
702
|
-
| **S**ingle Responsibility | 1 component = 1 responsibility. 1 service = 1 resource. 1 store = 1 domain. |
|
|
703
|
-
| **O**pen/Closed | Components extensible via content projection (ng-content) and inputs -- not by internal modification. |
|
|
704
|
-
| **L**iskov Substitution | Shared components must work in any context without breaking. |
|
|
705
|
-
| **I**nterface Segregation | Specific inputs, not generic objects. `<app-avatar [src]="src" [alt]="alt" />` not `<app-avatar [user]="user" />`. |
|
|
706
|
-
| **D**ependency Inversion | Components depend on abstractions (injection tokens), not concrete implementations. Services injected via inject(), never instantiated directly. |
|
|
707
|
-
|
|
708
|
-
### SOLID Examples
|
|
709
|
-
|
|
710
|
-
**Single Responsibility:**
|
|
711
|
-
```typescript
|
|
712
|
-
// BAD: component doing too much
|
|
713
|
-
@Component({ /* ... */ })
|
|
714
|
-
export class UserDashboardComponent {
|
|
715
|
-
// fetching data, filtering, rendering chart, rendering table, handling forms...
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
// GOOD: composed from focused components
|
|
719
|
-
@Component({
|
|
720
|
-
template: `
|
|
721
|
-
<app-dashboard-layout>
|
|
722
|
-
<app-user-stats />
|
|
723
|
-
<app-user-activity-chart />
|
|
724
|
-
<app-user-table />
|
|
725
|
-
</app-dashboard-layout>
|
|
726
|
-
`,
|
|
727
|
-
})
|
|
728
|
-
export class UserDashboardComponent {}
|
|
729
|
-
```
|
|
730
|
-
|
|
731
|
-
**Open/Closed:**
|
|
732
|
-
```typescript
|
|
733
|
-
// GOOD: extensible via content projection and inputs
|
|
734
|
-
@Component({
|
|
735
|
-
selector: 'app-data-table',
|
|
736
|
-
template: `
|
|
737
|
-
@if (items().length === 0) {
|
|
738
|
-
<ng-content select="[empty]" />
|
|
739
|
-
} @else {
|
|
740
|
-
<table>
|
|
741
|
-
<ng-content select="[header]" />
|
|
742
|
-
<tbody>
|
|
743
|
-
@for (item of items(); track trackFn(item)) {
|
|
744
|
-
<ng-content />
|
|
745
|
-
}
|
|
746
|
-
</tbody>
|
|
747
|
-
</table>
|
|
748
|
-
}
|
|
749
|
-
`,
|
|
750
|
-
})
|
|
751
|
-
export class DataTableComponent<T> {
|
|
752
|
-
readonly items = input.required<T[]>()
|
|
753
|
-
readonly trackFn = input.required<(item: T) => unknown>()
|
|
754
|
-
}
|
|
755
|
-
```
|
|
756
|
-
|
|
757
|
-
**Interface Segregation:**
|
|
758
|
-
```typescript
|
|
759
|
-
// BAD: passing entire object when only a few fields are needed
|
|
760
|
-
@Component({ /* ... */ })
|
|
761
|
-
export class AvatarComponent {
|
|
762
|
-
readonly user = input.required<User>() // component only uses name and avatarUrl
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
// GOOD: specific inputs
|
|
766
|
-
@Component({ /* ... */ })
|
|
767
|
-
export class AvatarComponent {
|
|
768
|
-
readonly src = input.required<string>()
|
|
769
|
-
readonly alt = input.required<string>()
|
|
770
|
-
readonly size = input<'sm' | 'md' | 'lg'>('md')
|
|
771
|
-
}
|
|
772
|
-
```
|
|
773
|
-
|
|
774
|
-
---
|
|
775
|
-
|
|
776
|
-
## 10. Migration Checklist per File
|
|
777
|
-
|
|
778
|
-
### Component (.component.ts)
|
|
779
|
-
- [ ] Standalone component (no NgModule)
|
|
780
|
-
- [ ] input() / output() signal-based I/O
|
|
781
|
-
- [ ] inject() instead of constructor DI
|
|
782
|
-
- [ ] No prop drilling (use content projection / shared injectable)
|
|
783
|
-
- [ ] < 200 lines total
|
|
784
|
-
- [ ] Template < 100 lines
|
|
785
|
-
- [ ] No business logic in template
|
|
786
|
-
- [ ] Loading / error / empty states
|
|
787
|
-
- [ ] OnPush change detection strategy
|
|
788
|
-
- [ ] trackBy function for @for loops
|
|
789
|
-
|
|
790
|
-
### Service (.service.ts)
|
|
791
|
-
- [ ] HttpClient calls only
|
|
792
|
-
- [ ] No try/catch
|
|
793
|
-
- [ ] No data transformation
|
|
794
|
-
- [ ] Typed request and response
|
|
795
|
-
- [ ] inject(HttpClient) instead of constructor
|
|
796
|
-
- [ ] `@Injectable({ providedIn: 'root' })`
|
|
797
|
-
|
|
798
|
-
### Adapter (.adapter.ts)
|
|
799
|
-
- [ ] Pure functions
|
|
800
|
-
- [ ] Inbound (API->App) and Outbound (App->API)
|
|
801
|
-
- [ ] Naming conversion (snake_case -> camelCase)
|
|
802
|
-
- [ ] Type conversion (string->Date, etc.)
|
|
803
|
-
|
|
804
|
-
### Store (.store.ts)
|
|
805
|
-
- [ ] Client state only
|
|
806
|
-
- [ ] Private WritableSignal, public asReadonly()
|
|
807
|
-
- [ ] computed() for derived values
|
|
808
|
-
- [ ] inject() for dependencies
|
|
809
|
-
- [ ] No HTTP calls
|
|
810
|
-
|
|
811
|
-
### Types
|
|
812
|
-
- [ ] `.types.ts` for API types (raw response)
|
|
813
|
-
- [ ] `.contracts.ts` for application contracts
|
|
814
|
-
- [ ] No `any`
|