contextos-agents 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/AGENTS.md +421 -0
- package/.agents/adapters/aider/export.js +137 -0
- package/.agents/adapters/claude/export.js +55 -0
- package/.agents/adapters/copilot/export.js +107 -0
- package/.agents/adapters/cursor/export.js +210 -0
- package/.agents/adapters/gemini/export.js +115 -0
- package/.agents/adapters/shared.js +119 -0
- package/.agents/adapters/zed/export.js +111 -0
- package/.agents/core/profiles/backend.yaml +47 -0
- package/.agents/core/profiles/enterprise.yaml +46 -0
- package/.agents/core/profiles/frontend.yaml +46 -0
- package/.agents/core/profiles/hackathon.yaml +45 -0
- package/.agents/core/profiles/mvp.yaml +43 -0
- package/.agents/core/profiles/startup.yaml +48 -0
- package/.agents/core/skills/adapters/EXAMPLES.md +19 -0
- package/.agents/core/skills/adapters/SKILL.md +105 -0
- package/.agents/core/skills/adapters/TROUBLESHOOTING.md +7 -0
- package/.agents/core/skills/adapters/VALIDATION.json +12 -0
- package/.agents/core/skills/adapters/skill.yaml +10 -0
- package/.agents/core/skills/architecture-diagrams/SKILL.md +108 -0
- package/.agents/core/skills/architecture-diagrams/VALIDATION.json +12 -0
- package/.agents/core/skills/architecture-diagrams/skill.yaml +8 -0
- package/.agents/core/skills/brutalist-design/SKILL.md +150 -0
- package/.agents/core/skills/brutalist-design/VALIDATION.json +12 -0
- package/.agents/core/skills/brutalist-design/skill.yaml +8 -0
- package/.agents/core/skills/context-manager/EXAMPLES.md +19 -0
- package/.agents/core/skills/context-manager/SKILL.md +126 -0
- package/.agents/core/skills/context-manager/TROUBLESHOOTING.md +7 -0
- package/.agents/core/skills/context-manager/VALIDATION.json +12 -0
- package/.agents/core/skills/context-manager/skill.yaml +10 -0
- package/.agents/core/skills/context-os/EXAMPLES.md +21 -0
- package/.agents/core/skills/context-os/SKILL.md +169 -0
- package/.agents/core/skills/context-os/TROUBLESHOOTING.md +7 -0
- package/.agents/core/skills/context-os/VALIDATION.json +12 -0
- package/.agents/core/skills/context-os/packs.yaml +59 -0
- package/.agents/core/skills/context-os/references/context-rules.md +68 -0
- package/.agents/core/skills/context-os/references/pipeline.md +119 -0
- package/.agents/core/skills/context-os/references/project-graph.md +103 -0
- package/.agents/core/skills/context-os/rules.yaml +135 -0
- package/.agents/core/skills/context-os/skill.yaml +10 -0
- package/.agents/core/skills/database/EXAMPLES.md +74 -0
- package/.agents/core/skills/database/SKILL.md +101 -0
- package/.agents/core/skills/database/TROUBLESHOOTING.md +18 -0
- package/.agents/core/skills/database/VALIDATION.json +11 -0
- package/.agents/core/skills/database/skill.yaml +25 -0
- package/.agents/core/skills/ddd/EXAMPLES.md +42 -0
- package/.agents/core/skills/ddd/SKILL.md +247 -0
- package/.agents/core/skills/ddd/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ddd/VALIDATION.json +12 -0
- package/.agents/core/skills/ddd/ddd.md +178 -0
- package/.agents/core/skills/ddd/skill.yaml +10 -0
- package/.agents/core/skills/decisions/EXAMPLES.md +35 -0
- package/.agents/core/skills/decisions/SKILL.md +90 -0
- package/.agents/core/skills/decisions/TROUBLESHOOTING.md +13 -0
- package/.agents/core/skills/decisions/VALIDATION.json +12 -0
- package/.agents/core/skills/decisions/skill.yaml +10 -0
- package/.agents/core/skills/docker/EXAMPLES.md +56 -0
- package/.agents/core/skills/docker/SKILL.md +63 -0
- package/.agents/core/skills/docker/TROUBLESHOOTING.md +18 -0
- package/.agents/core/skills/docker/VALIDATION.json +11 -0
- package/.agents/core/skills/docker/skill.yaml +23 -0
- package/.agents/core/skills/engineering-workflow/EXAMPLES.md +57 -0
- package/.agents/core/skills/engineering-workflow/SKILL.md +343 -0
- package/.agents/core/skills/engineering-workflow/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/engineering-workflow/VALIDATION.json +12 -0
- package/.agents/core/skills/engineering-workflow/skill.yaml +13 -0
- package/.agents/core/skills/fastapi/EXAMPLES.md +36 -0
- package/.agents/core/skills/fastapi/SKILL.md +148 -0
- package/.agents/core/skills/fastapi/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/fastapi/VALIDATION.json +12 -0
- package/.agents/core/skills/fastapi/fastapi.md +112 -0
- package/.agents/core/skills/fastapi/skill.yaml +10 -0
- package/.agents/core/skills/gemini-precision/SKILL.md +169 -0
- package/.agents/core/skills/gemini-precision/VALIDATION.json +12 -0
- package/.agents/core/skills/gemini-precision/skill.yaml +9 -0
- package/.agents/core/skills/generators/EXAMPLES.md +19 -0
- package/.agents/core/skills/generators/SKILL.md +112 -0
- package/.agents/core/skills/generators/TROUBLESHOOTING.md +7 -0
- package/.agents/core/skills/generators/VALIDATION.json +12 -0
- package/.agents/core/skills/generators/skill.yaml +10 -0
- package/.agents/core/skills/generators/templates/API.md +77 -0
- package/.agents/core/skills/generators/templates/ARCHITECTURE.md +70 -0
- package/.agents/core/skills/generators/templates/DATABASE.md +42 -0
- package/.agents/core/skills/generators/templates/DECISION.md +46 -0
- package/.agents/core/skills/generators/templates/PRD.md +67 -0
- package/.agents/core/skills/generators/templates/PROJECT_GRAPH.md +56 -0
- package/.agents/core/skills/generators/templates/ROADMAP.md +51 -0
- package/.agents/core/skills/generators/templates/TASKS.md +43 -0
- package/.agents/core/skills/generators/templates/UI.md +73 -0
- package/.agents/core/skills/graphify/EXAMPLES.md +73 -0
- package/.agents/core/skills/graphify/SKILL.md +130 -0
- package/.agents/core/skills/graphify/VALIDATION.json +12 -0
- package/.agents/core/skills/graphify/skill.yaml +13 -0
- package/.agents/core/skills/gstack-roles/EXAMPLES.md +23 -0
- package/.agents/core/skills/gstack-roles/SKILL.md +152 -0
- package/.agents/core/skills/gstack-roles/TROUBLESHOOTING.md +13 -0
- package/.agents/core/skills/gstack-roles/VALIDATION.json +12 -0
- package/.agents/core/skills/gstack-roles/skill.yaml +12 -0
- package/.agents/core/skills/impeccable-design/EXAMPLES.md +26 -0
- package/.agents/core/skills/impeccable-design/SKILL.md +201 -0
- package/.agents/core/skills/impeccable-design/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/impeccable-design/VALIDATION.json +12 -0
- package/.agents/core/skills/impeccable-design/skill.yaml +14 -0
- package/.agents/core/skills/interview-me/SKILL.md +97 -0
- package/.agents/core/skills/interview-me/VALIDATION.json +12 -0
- package/.agents/core/skills/interview-me/skill.yaml +8 -0
- package/.agents/core/skills/microservices/EXAMPLES.md +38 -0
- package/.agents/core/skills/microservices/SKILL.md +164 -0
- package/.agents/core/skills/microservices/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/microservices/VALIDATION.json +12 -0
- package/.agents/core/skills/microservices/microservices.md +119 -0
- package/.agents/core/skills/microservices/skill.yaml +10 -0
- package/.agents/core/skills/minimalist-design/SKILL.md +113 -0
- package/.agents/core/skills/minimalist-design/VALIDATION.json +12 -0
- package/.agents/core/skills/minimalist-design/skill.yaml +8 -0
- package/.agents/core/skills/nestjs/EXAMPLES.md +40 -0
- package/.agents/core/skills/nestjs/SKILL.md +139 -0
- package/.agents/core/skills/nestjs/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/nestjs/VALIDATION.json +12 -0
- package/.agents/core/skills/nestjs/nestjs.md +103 -0
- package/.agents/core/skills/nestjs/skill.yaml +10 -0
- package/.agents/core/skills/nextjs/EXAMPLES.md +40 -0
- package/.agents/core/skills/nextjs/SKILL.md +163 -0
- package/.agents/core/skills/nextjs/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/nextjs/VALIDATION.json +12 -0
- package/.agents/core/skills/nextjs/nextjs.md +67 -0
- package/.agents/core/skills/nextjs/skill.yaml +10 -0
- package/.agents/core/skills/node/EXAMPLES.md +80 -0
- package/.agents/core/skills/node/SKILL.md +128 -0
- package/.agents/core/skills/node/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/node/VALIDATION.json +12 -0
- package/.agents/core/skills/node/node.md +87 -0
- package/.agents/core/skills/node/skill.yaml +10 -0
- package/.agents/core/skills/performance/EXAMPLES.md +30 -0
- package/.agents/core/skills/performance/SKILL.md +75 -0
- package/.agents/core/skills/performance/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/performance/VALIDATION.json +12 -0
- package/.agents/core/skills/performance/performance.md +52 -0
- package/.agents/core/skills/performance/skill.yaml +10 -0
- package/.agents/core/skills/ponytail-mindset/EXAMPLES.md +45 -0
- package/.agents/core/skills/ponytail-mindset/SKILL.md +193 -0
- package/.agents/core/skills/ponytail-mindset/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ponytail-mindset/VALIDATION.json +12 -0
- package/.agents/core/skills/ponytail-mindset/skill.yaml +14 -0
- package/.agents/core/skills/react/EXAMPLES.md +79 -0
- package/.agents/core/skills/react/SKILL.md +132 -0
- package/.agents/core/skills/react/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/react/VALIDATION.json +12 -0
- package/.agents/core/skills/react/react.md +93 -0
- package/.agents/core/skills/react/skill.yaml +10 -0
- package/.agents/core/skills/react-best-practices/SKILL.md +155 -0
- package/.agents/core/skills/react-best-practices/VALIDATION.json +12 -0
- package/.agents/core/skills/react-best-practices/skill.yaml +10 -0
- package/.agents/core/skills/redesign-audit/SKILL.md +117 -0
- package/.agents/core/skills/redesign-audit/VALIDATION.json +12 -0
- package/.agents/core/skills/redesign-audit/skill.yaml +8 -0
- package/.agents/core/skills/security/EXAMPLES.md +64 -0
- package/.agents/core/skills/security/SKILL.md +158 -0
- package/.agents/core/skills/security/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/security/VALIDATION.json +12 -0
- package/.agents/core/skills/security/security.md +106 -0
- package/.agents/core/skills/security/skill.yaml +10 -0
- package/.agents/core/skills/soft-design/SKILL.md +108 -0
- package/.agents/core/skills/soft-design/VALIDATION.json +12 -0
- package/.agents/core/skills/soft-design/skill.yaml +8 -0
- package/.agents/core/skills/state-management/EXAMPLES.md +56 -0
- package/.agents/core/skills/state-management/SKILL.md +48 -0
- package/.agents/core/skills/state-management/TROUBLESHOOTING.md +18 -0
- package/.agents/core/skills/state-management/VALIDATION.json +11 -0
- package/.agents/core/skills/state-management/skill.yaml +22 -0
- package/.agents/core/skills/subagent-orchestrator/SKILL.md +100 -0
- package/.agents/core/skills/subagent-orchestrator/VALIDATION.json +12 -0
- package/.agents/core/skills/subagent-orchestrator/skill.yaml +8 -0
- package/.agents/core/skills/system-design/EXAMPLES.md +75 -0
- package/.agents/core/skills/system-design/SKILL.md +419 -0
- package/.agents/core/skills/system-design/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/system-design/VALIDATION.json +12 -0
- package/.agents/core/skills/system-design/skill.yaml +13 -0
- package/.agents/core/skills/system-design/system-design.md +112 -0
- package/.agents/core/skills/testing/EXAMPLES.md +71 -0
- package/.agents/core/skills/testing/SKILL.md +70 -0
- package/.agents/core/skills/testing/TROUBLESHOOTING.md +18 -0
- package/.agents/core/skills/testing/VALIDATION.json +11 -0
- package/.agents/core/skills/testing/skill.yaml +26 -0
- package/.agents/core/skills/typescript/EXAMPLES.md +64 -0
- package/.agents/core/skills/typescript/SKILL.md +112 -0
- package/.agents/core/skills/typescript/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/typescript/VALIDATION.json +12 -0
- package/.agents/core/skills/typescript/skill.yaml +10 -0
- package/.agents/core/skills/typescript/typescript.md +71 -0
- package/.agents/core/skills/ui-design/EXAMPLES.md +21 -0
- package/.agents/core/skills/ui-design/SKILL.md +124 -0
- package/.agents/core/skills/ui-design/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ui-design/VALIDATION.json +12 -0
- package/.agents/core/skills/ui-design/skill.yaml +10 -0
- package/.agents/core/skills/ui-design/ui.md +88 -0
- package/.agents/core/skills/ui-ux-pro/EXAMPLES.md +62 -0
- package/.agents/core/skills/ui-ux-pro/SKILL.md +375 -0
- package/.agents/core/skills/ui-ux-pro/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ui-ux-pro/VALIDATION.json +12 -0
- package/.agents/core/skills/ui-ux-pro/skill.yaml +13 -0
- package/.agents/core/skills/ux-design/EXAMPLES.md +36 -0
- package/.agents/core/skills/ux-design/SKILL.md +116 -0
- package/.agents/core/skills/ux-design/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/ux-design/VALIDATION.json +12 -0
- package/.agents/core/skills/ux-design/skill.yaml +10 -0
- package/.agents/core/skills/ux-design/ux.md +80 -0
- package/.agents/core/skills/vercel-optimize/SKILL.md +83 -0
- package/.agents/core/skills/vercel-optimize/VALIDATION.json +12 -0
- package/.agents/core/skills/vercel-optimize/skill.yaml +10 -0
- package/.agents/core/skills/web-accessibility/EXAMPLES.md +39 -0
- package/.agents/core/skills/web-accessibility/SKILL.md +170 -0
- package/.agents/core/skills/web-accessibility/TROUBLESHOOTING.md +19 -0
- package/.agents/core/skills/web-accessibility/VALIDATION.json +12 -0
- package/.agents/core/skills/web-accessibility/accessibility.md +63 -0
- package/.agents/core/skills/web-accessibility/skill.yaml +10 -0
- package/.agents/ctx.js +370 -0
- package/.agents/generated/claude/skills/adapters/SKILL.md +126 -0
- package/.agents/generated/claude/skills/architecture-diagrams/SKILL.md +101 -0
- package/.agents/generated/claude/skills/brutalist-design/SKILL.md +145 -0
- package/.agents/generated/claude/skills/context-manager/SKILL.md +147 -0
- package/.agents/generated/claude/skills/context-os/SKILL.md +191 -0
- package/.agents/generated/claude/skills/database/SKILL.md +191 -0
- package/.agents/generated/claude/skills/ddd/SKILL.md +305 -0
- package/.agents/generated/claude/skills/decisions/SKILL.md +134 -0
- package/.agents/generated/claude/skills/docker/SKILL.md +135 -0
- package/.agents/generated/claude/skills/engineering-workflow/SKILL.md +414 -0
- package/.agents/generated/claude/skills/fastapi/SKILL.md +200 -0
- package/.agents/generated/claude/skills/gemini-precision/SKILL.md +161 -0
- package/.agents/generated/claude/skills/generators/SKILL.md +133 -0
- package/.agents/generated/claude/skills/graphify/SKILL.md +198 -0
- package/.agents/generated/claude/skills/gstack-roles/SKILL.md +184 -0
- package/.agents/generated/claude/skills/impeccable-design/SKILL.md +241 -0
- package/.agents/generated/claude/skills/interview-me/SKILL.md +90 -0
- package/.agents/generated/claude/skills/microservices/SKILL.md +218 -0
- package/.agents/generated/claude/skills/minimalist-design/SKILL.md +108 -0
- package/.agents/generated/claude/skills/nestjs/SKILL.md +195 -0
- package/.agents/generated/claude/skills/nextjs/SKILL.md +219 -0
- package/.agents/generated/claude/skills/node/SKILL.md +224 -0
- package/.agents/generated/claude/skills/performance/SKILL.md +121 -0
- package/.agents/generated/claude/skills/ponytail-mindset/SKILL.md +252 -0
- package/.agents/generated/claude/skills/react/SKILL.md +227 -0
- package/.agents/generated/claude/skills/react-best-practices/SKILL.md +146 -0
- package/.agents/generated/claude/skills/redesign-audit/SKILL.md +112 -0
- package/.agents/generated/claude/skills/security/SKILL.md +237 -0
- package/.agents/generated/claude/skills/soft-design/SKILL.md +103 -0
- package/.agents/generated/claude/skills/state-management/SKILL.md +120 -0
- package/.agents/generated/claude/skills/subagent-orchestrator/SKILL.md +93 -0
- package/.agents/generated/claude/skills/system-design/SKILL.md +507 -0
- package/.agents/generated/claude/skills/testing/SKILL.md +157 -0
- package/.agents/generated/claude/skills/typescript/SKILL.md +192 -0
- package/.agents/generated/claude/skills/ui-design/SKILL.md +161 -0
- package/.agents/generated/claude/skills/ui-ux-pro/SKILL.md +451 -0
- package/.agents/generated/claude/skills/ux-design/SKILL.md +168 -0
- package/.agents/generated/claude/skills/vercel-optimize/SKILL.md +76 -0
- package/.agents/generated/claude/skills/web-accessibility/SKILL.md +225 -0
- package/.agents/generated/gemini/skills/adapters/SKILL.md +135 -0
- package/.agents/generated/gemini/skills/architecture-diagrams/SKILL.md +107 -0
- package/.agents/generated/gemini/skills/brutalist-design/SKILL.md +151 -0
- package/.agents/generated/gemini/skills/context-manager/SKILL.md +156 -0
- package/.agents/generated/gemini/skills/context-os/SKILL.md +200 -0
- package/.agents/generated/gemini/skills/database/SKILL.md +200 -0
- package/.agents/generated/gemini/skills/ddd/SKILL.md +314 -0
- package/.agents/generated/gemini/skills/decisions/SKILL.md +143 -0
- package/.agents/generated/gemini/skills/docker/SKILL.md +144 -0
- package/.agents/generated/gemini/skills/engineering-workflow/SKILL.md +423 -0
- package/.agents/generated/gemini/skills/fastapi/SKILL.md +209 -0
- package/.agents/generated/gemini/skills/gemini-precision/SKILL.md +167 -0
- package/.agents/generated/gemini/skills/generators/SKILL.md +142 -0
- package/.agents/generated/gemini/skills/graphify/SKILL.md +205 -0
- package/.agents/generated/gemini/skills/gstack-roles/SKILL.md +193 -0
- package/.agents/generated/gemini/skills/impeccable-design/SKILL.md +250 -0
- package/.agents/generated/gemini/skills/interview-me/SKILL.md +96 -0
- package/.agents/generated/gemini/skills/microservices/SKILL.md +227 -0
- package/.agents/generated/gemini/skills/minimalist-design/SKILL.md +114 -0
- package/.agents/generated/gemini/skills/nestjs/SKILL.md +204 -0
- package/.agents/generated/gemini/skills/nextjs/SKILL.md +298 -0
- package/.agents/generated/gemini/skills/node/SKILL.md +323 -0
- package/.agents/generated/gemini/skills/performance/SKILL.md +185 -0
- package/.agents/generated/gemini/skills/ponytail-mindset/SKILL.md +261 -0
- package/.agents/generated/gemini/skills/react/SKILL.md +332 -0
- package/.agents/generated/gemini/skills/react-best-practices/SKILL.md +152 -0
- package/.agents/generated/gemini/skills/redesign-audit/SKILL.md +118 -0
- package/.agents/generated/gemini/skills/security/SKILL.md +355 -0
- package/.agents/generated/gemini/skills/soft-design/SKILL.md +109 -0
- package/.agents/generated/gemini/skills/state-management/SKILL.md +129 -0
- package/.agents/generated/gemini/skills/subagent-orchestrator/SKILL.md +99 -0
- package/.agents/generated/gemini/skills/system-design/SKILL.md +631 -0
- package/.agents/generated/gemini/skills/testing/SKILL.md +166 -0
- package/.agents/generated/gemini/skills/typescript/SKILL.md +275 -0
- package/.agents/generated/gemini/skills/ui-design/SKILL.md +170 -0
- package/.agents/generated/gemini/skills/ui-ux-pro/SKILL.md +460 -0
- package/.agents/generated/gemini/skills/ux-design/SKILL.md +177 -0
- package/.agents/generated/gemini/skills/vercel-optimize/SKILL.md +82 -0
- package/.agents/generated/gemini/skills/web-accessibility/SKILL.md +300 -0
- package/.agents/mcp/runtime.py +454 -0
- package/.agents/mcp/server.mjs +189373 -0
- package/.agents/plugins.js +574 -0
- package/.agents/profiles.js +267 -0
- package/.agents/resolver.js +336 -0
- package/.agents/skills-index.json +200 -0
- package/.agents/skills.json +6 -0
- package/.agents/validate.js +500 -0
- package/LICENSE +21 -0
- package/README.md +415 -0
- package/benchmarks/gemini-issues.js +533 -0
- package/bin/index.js +458 -0
- package/package.json +70 -0
- package/registry.json +53 -0
- package/registry.schema.json +32 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: NestJS
|
|
3
|
+
description: >
|
|
4
|
+
ContextOS skill for NestJS
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# NestJS
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
Enterprise Node.js architecture standard using NestJS, TypeScript, and RxJS. Enforces strict modularity, dependency injection, repository pattern, DTO validation via class-validator, and clean layered architecture.
|
|
12
|
+
|
|
13
|
+
## When to Use
|
|
14
|
+
|
|
15
|
+
Activate when building enterprise Node.js microservices, complex REST/GraphQL APIs, or scalable backends requiring strict architectural structure.
|
|
16
|
+
|
|
17
|
+
## Rules & Patterns
|
|
18
|
+
<!-- Source: nestjs.md -->
|
|
19
|
+
|
|
20
|
+
## NestJS — Best Practices
|
|
21
|
+
|
|
22
|
+
## Module Architecture
|
|
23
|
+
|
|
24
|
+
- **One module per domain** — `UsersModule`, `AuthModule`, `OrdersModule`
|
|
25
|
+
- **Feature modules** — encapsulate related controllers, services, repositories
|
|
26
|
+
- **Shared module** — for cross-cutting concerns (logging, config, utils)
|
|
27
|
+
- **Core module** — singleton services (database, auth guards)
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
src/
|
|
31
|
+
├── modules/
|
|
32
|
+
│ ├── users/
|
|
33
|
+
│ │ ├── users.module.ts
|
|
34
|
+
│ │ ├── users.controller.ts
|
|
35
|
+
│ │ ├── users.service.ts
|
|
36
|
+
│ │ ├── users.repository.ts
|
|
37
|
+
│ │ ├── dto/
|
|
38
|
+
│ │ │ ├── create-user.dto.ts
|
|
39
|
+
│ │ │ └── update-user.dto.ts
|
|
40
|
+
│ │ ├── entities/
|
|
41
|
+
│ │ │ └── user.entity.ts
|
|
42
|
+
│ │ └── users.spec.ts
|
|
43
|
+
│ └── auth/
|
|
44
|
+
├── shared/
|
|
45
|
+
│ ├── guards/
|
|
46
|
+
│ ├── interceptors/
|
|
47
|
+
│ ├── pipes/
|
|
48
|
+
│ └── filters/
|
|
49
|
+
├── config/
|
|
50
|
+
└── app.module.ts
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Dependency Injection
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
@Injectable()
|
|
57
|
+
export class UsersService {
|
|
58
|
+
constructor(
|
|
59
|
+
@InjectRepository(User) private readonly usersRepo: Repository<User>,
|
|
60
|
+
private readonly configService: ConfigService,
|
|
61
|
+
) {}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
- Prefer constructor injection
|
|
66
|
+
- Use custom providers for complex setup
|
|
67
|
+
- Scope: default is Singleton, use REQUEST scope only when needed
|
|
68
|
+
|
|
69
|
+
## DTOs and Validation
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { IsEmail, IsString, MinLength } from 'class-validator';
|
|
73
|
+
|
|
74
|
+
export class CreateUserDto {
|
|
75
|
+
@IsEmail()
|
|
76
|
+
email: string;
|
|
77
|
+
|
|
78
|
+
@IsString()
|
|
79
|
+
@MinLength(2)
|
|
80
|
+
name: string;
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- Always use DTOs for request validation
|
|
85
|
+
- Use `ValidationPipe` globally
|
|
86
|
+
- Separate Create/Update/Response DTOs
|
|
87
|
+
|
|
88
|
+
## Guards, Interceptors, Pipes
|
|
89
|
+
|
|
90
|
+
| Type | Purpose |
|
|
91
|
+
| --- | --- |
|
|
92
|
+
| **Guards** | Authentication, authorization |
|
|
93
|
+
| **Interceptors** | Logging, transformation, caching |
|
|
94
|
+
| **Pipes** | Validation, transformation |
|
|
95
|
+
| **Filters** | Exception handling |
|
|
96
|
+
|
|
97
|
+
Execution order: Guards → Interceptors → Pipes → Handler → Interceptors → Filters
|
|
98
|
+
|
|
99
|
+
## Error Handling
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
@Catch()
|
|
103
|
+
export class AllExceptionsFilter implements ExceptionFilter {
|
|
104
|
+
catch(exception: unknown, host: ArgumentsHost) {
|
|
105
|
+
// Transform to standard error format
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Testing
|
|
111
|
+
|
|
112
|
+
- **Unit tests** — mock dependencies with `Test.createTestingModule()`
|
|
113
|
+
- **E2E tests** — use `supertest` with a test module
|
|
114
|
+
- **Mock everything** — services should be testable in isolation
|
|
115
|
+
|
|
116
|
+
## Anti-Patterns
|
|
117
|
+
|
|
118
|
+
- [FAIL] Business logic in controllers — use services
|
|
119
|
+
- [FAIL] Direct database access in controllers — use repositories
|
|
120
|
+
- [FAIL] Circular dependencies — refactor module structure
|
|
121
|
+
- [FAIL] God modules — split large modules by domain
|
|
122
|
+
- [FAIL] Not using DTOs — always validate input
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
## Code Examples
|
|
126
|
+
|
|
127
|
+
See `EXAMPLES.md` for detailed code examples.
|
|
128
|
+
|
|
129
|
+
## Validation Checklist
|
|
130
|
+
|
|
131
|
+
What to verify during the review phase before completing the task.
|
|
132
|
+
|
|
133
|
+
## Common Mistakes
|
|
134
|
+
|
|
135
|
+
Anti-patterns and things to explicitly avoid. See `TROUBLESHOOTING.md`.
|
|
136
|
+
|
|
137
|
+
## Integration Notes
|
|
138
|
+
|
|
139
|
+
How this skill interacts with other skills.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# nestjs Troubleshooting & Common Mistakes
|
|
2
|
+
|
|
3
|
+
## 1. Circular Dependency Between Modules
|
|
4
|
+
|
|
5
|
+
- **Symptom**: "Nest cannot create the module instance. Often, this is caused by circular dependencies".
|
|
6
|
+
- **Root Cause**: Module A imports Module B, and Module B imports Module A.
|
|
7
|
+
- **Fix**: Use `forwardRef(() => ModuleB)` in imports and `@Inject(forwardRef(() => ServiceB))` in constructors, or refactor shared logic into a separate CommonModule.
|
|
8
|
+
|
|
9
|
+
## 2. Memory Leaks from REQUEST Scope
|
|
10
|
+
|
|
11
|
+
- **Symptom**: High memory usage and slow performance under load.
|
|
12
|
+
- **Root Cause**: Providers declared with Scope.REQUEST recreate instances on every HTTP request.
|
|
13
|
+
- **Fix**: Keep services as default Singletons whenever possible. Pass request-scoped parameters directly through method arguments.
|
|
14
|
+
|
|
15
|
+
## 3. Uncaught Domain Exceptions
|
|
16
|
+
|
|
17
|
+
- **Symptom**: Custom domain exceptions bypass formatting and return generic 500 errors.
|
|
18
|
+
- **Root Cause**: Missing custom Global Exception Filter.
|
|
19
|
+
- **Fix**: Implement an AllExceptionsFilter implementing ExceptionFilter and bind it globally in main.ts.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# NestJS — Best Practices
|
|
2
|
+
|
|
3
|
+
## Module Architecture
|
|
4
|
+
|
|
5
|
+
- **One module per domain** — `UsersModule`, `AuthModule`, `OrdersModule`
|
|
6
|
+
- **Feature modules** — encapsulate related controllers, services, repositories
|
|
7
|
+
- **Shared module** — for cross-cutting concerns (logging, config, utils)
|
|
8
|
+
- **Core module** — singleton services (database, auth guards)
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
src/
|
|
12
|
+
├── modules/
|
|
13
|
+
│ ├── users/
|
|
14
|
+
│ │ ├── users.module.ts
|
|
15
|
+
│ │ ├── users.controller.ts
|
|
16
|
+
│ │ ├── users.service.ts
|
|
17
|
+
│ │ ├── users.repository.ts
|
|
18
|
+
│ │ ├── dto/
|
|
19
|
+
│ │ │ ├── create-user.dto.ts
|
|
20
|
+
│ │ │ └── update-user.dto.ts
|
|
21
|
+
│ │ ├── entities/
|
|
22
|
+
│ │ │ └── user.entity.ts
|
|
23
|
+
│ │ └── users.spec.ts
|
|
24
|
+
│ └── auth/
|
|
25
|
+
├── shared/
|
|
26
|
+
│ ├── guards/
|
|
27
|
+
│ ├── interceptors/
|
|
28
|
+
│ ├── pipes/
|
|
29
|
+
│ └── filters/
|
|
30
|
+
├── config/
|
|
31
|
+
└── app.module.ts
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Dependency Injection
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
@Injectable()
|
|
38
|
+
export class UsersService {
|
|
39
|
+
constructor(
|
|
40
|
+
@InjectRepository(User) private readonly usersRepo: Repository<User>,
|
|
41
|
+
private readonly configService: ConfigService,
|
|
42
|
+
) {}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- Prefer constructor injection
|
|
47
|
+
- Use custom providers for complex setup
|
|
48
|
+
- Scope: default is Singleton, use REQUEST scope only when needed
|
|
49
|
+
|
|
50
|
+
## DTOs and Validation
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { IsEmail, IsString, MinLength } from 'class-validator';
|
|
54
|
+
|
|
55
|
+
export class CreateUserDto {
|
|
56
|
+
@IsEmail()
|
|
57
|
+
email: string;
|
|
58
|
+
|
|
59
|
+
@IsString()
|
|
60
|
+
@MinLength(2)
|
|
61
|
+
name: string;
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
- Always use DTOs for request validation
|
|
66
|
+
- Use `ValidationPipe` globally
|
|
67
|
+
- Separate Create/Update/Response DTOs
|
|
68
|
+
|
|
69
|
+
## Guards, Interceptors, Pipes
|
|
70
|
+
|
|
71
|
+
| Type | Purpose |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| **Guards** | Authentication, authorization |
|
|
74
|
+
| **Interceptors** | Logging, transformation, caching |
|
|
75
|
+
| **Pipes** | Validation, transformation |
|
|
76
|
+
| **Filters** | Exception handling |
|
|
77
|
+
|
|
78
|
+
Execution order: Guards → Interceptors → Pipes → Handler → Interceptors → Filters
|
|
79
|
+
|
|
80
|
+
## Error Handling
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
@Catch()
|
|
84
|
+
export class AllExceptionsFilter implements ExceptionFilter {
|
|
85
|
+
catch(exception: unknown, host: ArgumentsHost) {
|
|
86
|
+
// Transform to standard error format
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Testing
|
|
92
|
+
|
|
93
|
+
- **Unit tests** — mock dependencies with `Test.createTestingModule()`
|
|
94
|
+
- **E2E tests** — use `supertest` with a test module
|
|
95
|
+
- **Mock everything** — services should be testable in isolation
|
|
96
|
+
|
|
97
|
+
## Anti-Patterns
|
|
98
|
+
|
|
99
|
+
- [FAIL] Business logic in controllers — use services
|
|
100
|
+
- [FAIL] Direct database access in controllers — use repositories
|
|
101
|
+
- [FAIL] Circular dependencies — refactor module structure
|
|
102
|
+
- [FAIL] God modules — split large modules by domain
|
|
103
|
+
- [FAIL] Not using DTOs — always validate input
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
id: nestjs
|
|
2
|
+
name: NestJS
|
|
3
|
+
category: backend
|
|
4
|
+
tags: [backend, nodejs, typescript, enterprise, di, decorators]
|
|
5
|
+
requires: [typescript, node]
|
|
6
|
+
optional: [postgres, redis, docker, graphql]
|
|
7
|
+
conflicts: [fastapi, express]
|
|
8
|
+
weight: 8
|
|
9
|
+
documents:
|
|
10
|
+
- nestjs.md
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# nextjs Examples — Anti-patterns vs ContextOS Standard
|
|
2
|
+
|
|
3
|
+
## Example 1: Server Components vs Client Components
|
|
4
|
+
|
|
5
|
+
### Anti-pattern: Marking the Entire Page as Client Component
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
// BAD: app/dashboard/page.tsx with 'use client' at top
|
|
9
|
+
// Bloats client bundle, loses SEO benefits, eliminates direct DB access
|
|
10
|
+
'use client';
|
|
11
|
+
|
|
12
|
+
export default function DashboardPage() {
|
|
13
|
+
const [data, setData] = useState(null);
|
|
14
|
+
useEffect(() => { fetch('/api/dashboard').then(...) }, []);
|
|
15
|
+
return <div>...</div>;
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Best practice: ContextOS Standard (RSC by Default, Client Leaf Nodes)
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
// GOOD: Server Component fetches data directly with zero bundle cost
|
|
23
|
+
// app/dashboard/page.tsx (Server Component)
|
|
24
|
+
import { Suspense } from 'react';
|
|
25
|
+
import { db } from '@/lib/db';
|
|
26
|
+
import { InteractiveChart } from './InteractiveChart'; // 'use client' leaf component
|
|
27
|
+
|
|
28
|
+
export default async function DashboardPage() {
|
|
29
|
+
const stats = await db.analytics.getStats();
|
|
30
|
+
return (
|
|
31
|
+
<main>
|
|
32
|
+
<h1>Dashboard</h1>
|
|
33
|
+
<p>Total Revenue: {stats.revenue}</p>
|
|
34
|
+
<Suspense fallback={<ChartSkeleton />}>
|
|
35
|
+
<InteractiveChart initialData={stats.chartData} />
|
|
36
|
+
</Suspense>
|
|
37
|
+
</main>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Next.js
|
|
3
|
+
description: >
|
|
4
|
+
ContextOS skill for Next.js App Router, Server Components, Server Actions, performance optimization, and Vercel best practices.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Next.js App Router Best Practices
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
Enforces high-performance architectural patterns for Next.js App Router based on Vercel Engineering guidelines: React Server Components (RSC), zero-waterfall async pipelines, request deduplication via `React.cache()`, bundle optimization, and secure Server Actions.
|
|
12
|
+
|
|
13
|
+
## When to Use
|
|
14
|
+
|
|
15
|
+
Activate whenever building, refactoring, or reviewing Next.js pages, layouts, Route Handlers (`app/api`), Server Actions, or components in the `app/` directory.
|
|
16
|
+
|
|
17
|
+
## Negative Constraints (What NOT to Do)
|
|
18
|
+
|
|
19
|
+
1. **NEVER use barrel imports for UI libraries**: Avoid `import { Button, Dialog } from '@/components'`. Import directly from the exact file (`import { Button } from '@/components/ui/button'`) to prevent bundler tree-shaking failures and trace bloat.
|
|
20
|
+
2. **NEVER trust client-provided data or session state in Server Actions**: Always authenticate session and authorize tenant ownership inside the Server Action handler itself before mutating data.
|
|
21
|
+
3. **NEVER introduce sequential `await` waterfalls for independent data**: Always use `Promise.all()` or parallel streaming `<Suspense>` boundaries.
|
|
22
|
+
4. **NEVER pass large unneeded serialized data from Server to Client Components**: Only pass the specific primitive fields required by the client component (`server-dedup-props`).
|
|
23
|
+
5. **NEVER use `useEffect` for data fetching**: Fetch directly in Server Components or use TanStack Query / SWR for client-side queries.
|
|
24
|
+
6. **NEVER import server-only modules in client components**: Use the `server-only` package in data access layers to catch accidental client imports at build time.
|
|
25
|
+
|
|
26
|
+
## Rules & Patterns
|
|
27
|
+
|
|
28
|
+
### 1. Eliminating Async Waterfalls (Critical)
|
|
29
|
+
|
|
30
|
+
- **Parallel Fetching**: Fetch independent data concurrently at the top of the route or component.
|
|
31
|
+
- **Granular Streaming**: Wrap slow, non-critical subtrees in `<Suspense fallback={<Skeleton />}>` so critical above-the-fold content streams immediately.
|
|
32
|
+
- **Defer Awaits**: Check cheap synchronous conditions before awaiting remote resources.
|
|
33
|
+
|
|
34
|
+
### 2. Request Deduplication & Caching (`server-cache-react`)
|
|
35
|
+
|
|
36
|
+
- Use `React.cache()` to deduplicate identical database or service calls across multiple components rendered in the same server request lifecycle.
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { cache } from 'react';
|
|
40
|
+
import { db } from '@/lib/db';
|
|
41
|
+
|
|
42
|
+
export const getCurrentUser = cache(async (userId: string) => {
|
|
43
|
+
return await db.user.findUnique({
|
|
44
|
+
where: { id: userId },
|
|
45
|
+
select: { id: true, name: true, role: true, email: true }
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 3. Secure Server Actions (`server-auth-actions`)
|
|
51
|
+
|
|
52
|
+
- Treat every Server Action as a public HTTP endpoint. Always validate session, authorization, and input schema with Zod.
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
'use server';
|
|
56
|
+
|
|
57
|
+
import { z } from 'zod';
|
|
58
|
+
import { auth } from '@/lib/auth';
|
|
59
|
+
import { db } from '@/lib/db';
|
|
60
|
+
import { revalidatePath } from 'next/cache';
|
|
61
|
+
|
|
62
|
+
const UpdateProfileSchema = z.object({
|
|
63
|
+
name: z.string().min(2).max(50),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export async function updateProfile(formData: FormData) {
|
|
67
|
+
const session = await auth();
|
|
68
|
+
if (!session?.userId) throw new Error('Unauthorized');
|
|
69
|
+
|
|
70
|
+
const result = UpdateProfileSchema.safeParse({ name: formData.get('name') });
|
|
71
|
+
if (!result.success) return { error: 'Invalid input', issues: result.error.flatten() };
|
|
72
|
+
|
|
73
|
+
await db.user.update({
|
|
74
|
+
where: { id: session.userId },
|
|
75
|
+
data: { name: result.data.name },
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
revalidatePath('/settings');
|
|
79
|
+
return { success: true };
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 4. Bundle Optimization & Dynamic Imports (`bundle-dynamic-imports`)
|
|
84
|
+
|
|
85
|
+
- Heavy interactive client components (charts, rich-text editors, video players) must be dynamically loaded with `next/dynamic`.
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
import dynamic from 'next/dynamic';
|
|
89
|
+
|
|
90
|
+
const AnalyticsChart = dynamic(
|
|
91
|
+
() => import('@/components/analytics/chart').then(mod => mod.AnalyticsChart),
|
|
92
|
+
{
|
|
93
|
+
loading: () => <div className="h-64 animate-pulse bg-muted rounded-lg" />,
|
|
94
|
+
ssr: false,
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 5. Next.js 15+ Async Request APIs (`async-params`)
|
|
100
|
+
|
|
101
|
+
In Next.js 15+, `params`, `searchParams`, `cookies()`, and `headers()` are asynchronous and must be awaited:
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
// [GOOD] Next.js 15+ Page Component
|
|
105
|
+
interface PageProps {
|
|
106
|
+
params: Promise<{ id: string }>;
|
|
107
|
+
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default async function UserPage({ params, searchParams }: PageProps) {
|
|
111
|
+
const { id } = await params;
|
|
112
|
+
const { tab } = await searchParams;
|
|
113
|
+
const user = await getUser(id);
|
|
114
|
+
|
|
115
|
+
return <UserProfile user={user} activeTab={tab as string} />;
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 6. Non-Blocking Background Tasks with `after()`
|
|
120
|
+
|
|
121
|
+
To execute logging, analytics, or cache priming without delaying the user's HTTP response:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { after } from 'next/server';
|
|
125
|
+
|
|
126
|
+
export async function POST(request: Request) {
|
|
127
|
+
const data = await request.json();
|
|
128
|
+
const result = await processOrder(data);
|
|
129
|
+
|
|
130
|
+
// Executes asynchronously AFTER the response stream has completed
|
|
131
|
+
after(async () => {
|
|
132
|
+
await sendSlackNotification(result);
|
|
133
|
+
await indexOrderInSearch(result.id);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return Response.json({ success: true, orderId: result.id });
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Code Examples
|
|
143
|
+
|
|
144
|
+
See `EXAMPLES.md` for detailed code examples and component templates.
|
|
145
|
+
|
|
146
|
+
## Validation Checklist
|
|
147
|
+
|
|
148
|
+
- [ ] All database queries in RSC layers use `React.cache()` if called across multiple components.
|
|
149
|
+
- [ ] No barrel imports (`from '@/components'`); all imports point to exact component modules.
|
|
150
|
+
- [ ] Server Actions have explicit auth checks and Zod input validation.
|
|
151
|
+
- [ ] Heavy client widgets (charts, editors) use `next/dynamic`.
|
|
152
|
+
- [ ] Images use `next/image` with explicit `sizes` and `priority` on LCP elements.
|
|
153
|
+
|
|
154
|
+
## Common Mistakes
|
|
155
|
+
|
|
156
|
+
- Using `'use client'` at page level instead of leaf components.
|
|
157
|
+
- Relying on client-side authentication checks for Server Actions without server-side validation.
|
|
158
|
+
- Chaining sequential awaits for independent data models.
|
|
159
|
+
|
|
160
|
+
## Integration Notes
|
|
161
|
+
|
|
162
|
+
- Pairs with `react` and `ui-ux-pro` for component design and state management.
|
|
163
|
+
- Pairs with `security` for session authorization and input sanitization.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# nextjs Troubleshooting & Common Mistakes
|
|
2
|
+
|
|
3
|
+
## 1. Hydration Mismatch Errors
|
|
4
|
+
|
|
5
|
+
- **Symptom**: "Text content does not match server-rendered HTML".
|
|
6
|
+
- **Root Cause**: Rendering dates, window dimensions, or local storage data that differs between server render and client hydration.
|
|
7
|
+
- **Fix**: Use suppressHydrationWarning on localized timestamps or load client-only state inside a useEffect after mount.
|
|
8
|
+
|
|
9
|
+
## 2. Accidental Server Code Bundled to Client
|
|
10
|
+
|
|
11
|
+
- **Symptom**: "Module not found: Can't resolve 'fs' or 'pg' in client bundle".
|
|
12
|
+
- **Root Cause**: Client component importing a utility that transitively imports server-only database code.
|
|
13
|
+
- **Fix**: Separate server utilities into *.server.ts and install import 'server-only'; at the top of server files.
|
|
14
|
+
|
|
15
|
+
## 3. Waterfall Fetches in Server Components
|
|
16
|
+
|
|
17
|
+
- **Symptom**: Page takes 3 seconds to load due to sequential await statements.
|
|
18
|
+
- **Root Cause**: Awaiting independent data sources one after another.
|
|
19
|
+
- **Fix**: Use Promise.all([fetchUsers(), fetchProducts()]) or separate into nested <Suspense> boundaries.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Next.js — Best Practices (App Router)
|
|
2
|
+
|
|
3
|
+
## Routing
|
|
4
|
+
|
|
5
|
+
- Use **App Router** (`app/` directory) — not Pages Router
|
|
6
|
+
- **Layouts** — shared UI in `layout.tsx`, nested layouts for sections
|
|
7
|
+
- **Loading states** — `loading.tsx` for Suspense boundaries
|
|
8
|
+
- **Error handling** — `error.tsx` for error boundaries per route
|
|
9
|
+
- **Not found** — `not-found.tsx` for 404 pages
|
|
10
|
+
|
|
11
|
+
## Server vs Client Components
|
|
12
|
+
|
|
13
|
+
- **Default to Server Components** — they're server by default
|
|
14
|
+
- **Use `'use client'`** only when you need: event handlers, useState, useEffect, browser APIs
|
|
15
|
+
- **Push client boundaries down** — keep as much as possible on the server
|
|
16
|
+
- **Don't pass functions** from Server to Client components
|
|
17
|
+
|
|
18
|
+
## Data Fetching
|
|
19
|
+
|
|
20
|
+
- **Server Components** — fetch directly, no useEffect
|
|
21
|
+
- **Server Actions** — for mutations (`'use server'`)
|
|
22
|
+
- **Route Handlers** — `app/api/` for REST endpoints
|
|
23
|
+
- **Parallel fetching** — use Promise.all for independent requests
|
|
24
|
+
- **Caching** — leverage Next.js cache, revalidate strategically
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
// Server Component — direct fetch
|
|
28
|
+
async function UserProfile({ id }: { id: string }) {
|
|
29
|
+
const user = await getUser(id); // No useEffect needed
|
|
30
|
+
return <div>{user.name}</div>;
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## File Structure
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
app/
|
|
38
|
+
├── layout.tsx # Root layout
|
|
39
|
+
├── page.tsx # Home page
|
|
40
|
+
├── globals.css
|
|
41
|
+
├── (auth)/ # Route group (no URL impact)
|
|
42
|
+
│ ├── login/page.tsx
|
|
43
|
+
│ └── register/page.tsx
|
|
44
|
+
├── dashboard/
|
|
45
|
+
│ ├── layout.tsx # Dashboard layout
|
|
46
|
+
│ ├── page.tsx # Dashboard home
|
|
47
|
+
│ └── settings/page.tsx
|
|
48
|
+
├── api/
|
|
49
|
+
│ └── users/route.ts # API route
|
|
50
|
+
└── components/ # Shared components
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Performance
|
|
54
|
+
|
|
55
|
+
- **Image optimization** — always use `next/image`
|
|
56
|
+
- **Font optimization** — use `next/font`
|
|
57
|
+
- **Metadata** — export metadata object from pages
|
|
58
|
+
- **Static generation** — prefer SSG over SSR when possible
|
|
59
|
+
- **Edge runtime** — for latency-sensitive routes
|
|
60
|
+
|
|
61
|
+
## Anti-Patterns
|
|
62
|
+
|
|
63
|
+
- [FAIL] Using `useEffect` for data fetching in Server Components
|
|
64
|
+
- [FAIL] Making everything a Client Component
|
|
65
|
+
- [FAIL] Not using `loading.tsx` and `error.tsx`
|
|
66
|
+
- [FAIL] Importing server-only code in Client Components
|
|
67
|
+
- [FAIL] Not leveraging caching and revalidation
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
id: nextjs
|
|
2
|
+
name: Next.js
|
|
3
|
+
category: frontend
|
|
4
|
+
tags: [frontend, ssr, ssg, fullstack, react, app-router]
|
|
5
|
+
requires: [react, typescript]
|
|
6
|
+
optional: [tailwind, prisma, next-auth, react-query]
|
|
7
|
+
conflicts: [vue, angular, remix]
|
|
8
|
+
weight: 9
|
|
9
|
+
documents:
|
|
10
|
+
- nextjs.md
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Node.js Examples — Anti-patterns vs ContextOS Standard
|
|
2
|
+
|
|
3
|
+
## Example 1: Graceful Process Shutdown
|
|
4
|
+
|
|
5
|
+
### Anti-pattern: Anti-pattern (Abruptly killing process and dropping in-flight requests)
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
// BAD: drops active database transactions and in-flight HTTP connections
|
|
9
|
+
process.on('SIGTERM', () => {
|
|
10
|
+
process.exit(0);
|
|
11
|
+
});
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### Best practice: ContextOS Standard (Graceful connection draining)
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
// GOOD: drains active requests, closes database connections, and exits safely
|
|
18
|
+
import http from 'http';
|
|
19
|
+
import { prisma } from './db';
|
|
20
|
+
import { logger } from './logger';
|
|
21
|
+
|
|
22
|
+
export function setupGracefulShutdown(server: http.Server) {
|
|
23
|
+
const shutdown = async (signal: string) => {
|
|
24
|
+
logger.info(`Received ${signal}. Starting graceful shutdown...`);
|
|
25
|
+
|
|
26
|
+
server.close(async () => {
|
|
27
|
+
logger.info('HTTP server closed.');
|
|
28
|
+
try {
|
|
29
|
+
await prisma.$disconnect();
|
|
30
|
+
logger.info('Database pool closed.');
|
|
31
|
+
process.exit(0);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
logger.error('Error during database disconnect:', err);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Force shutdown after timeout if connections hang
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
logger.error('Forceful shutdown timeout reached.');
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}, 10_000).unref();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
46
|
+
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Example 2: Stream-based File Processing
|
|
53
|
+
|
|
54
|
+
### Anti-pattern: Anti-pattern (Loading entire 500MB file into buffer)
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
// BAD: easily causes Out Of Memory (OOM) crashes under concurrency
|
|
58
|
+
app.get('/download/:file', async (req, res) => {
|
|
59
|
+
const data = await fs.promises.readFile(`/uploads/${req.params.file}`);
|
|
60
|
+
res.send(data);
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Best practice: ContextOS Standard (Piping read stream with pipeline)
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
// GOOD: constant memory usage (O(1) RAM) regardless of file size
|
|
68
|
+
import fs from 'fs';
|
|
69
|
+
import { pipeline } from 'stream/promises';
|
|
70
|
+
|
|
71
|
+
app.get('/download/:file', async (req, res, next) => {
|
|
72
|
+
try {
|
|
73
|
+
const filePath = `/uploads/${req.params.file}`;
|
|
74
|
+
const readStream = fs.createReadStream(filePath);
|
|
75
|
+
await pipeline(readStream, res);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
next(err);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
```
|