trinity-method-sdk 2.0.9 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +702 -267
- package/README.md +550 -540
- package/dist/cli/commands/deploy/agents.js +1 -1
- package/dist/cli/commands/deploy/ci-cd.d.ts +4 -3
- package/dist/cli/commands/deploy/ci-cd.js +10 -9
- package/dist/cli/commands/deploy/claude-setup.js +28 -35
- package/dist/cli/commands/deploy/configuration.js +10 -11
- package/dist/cli/commands/deploy/directories.js +13 -14
- package/dist/cli/commands/deploy/gitignore.js +3 -5
- package/dist/cli/commands/deploy/index.d.ts +1 -1
- package/dist/cli/commands/deploy/index.js +7 -3
- package/dist/cli/commands/deploy/knowledge-base.js +3 -3
- package/dist/cli/commands/deploy/pre-flight.js +1 -1
- package/dist/cli/commands/deploy/root-files.js +3 -18
- package/dist/cli/commands/deploy/sdk-install.js +1 -1
- package/dist/cli/commands/deploy/summary.js +3 -3
- package/dist/cli/commands/deploy/templates.js +33 -20
- package/dist/cli/commands/update/agents.js +1 -1
- package/dist/cli/commands/update/backup.js +6 -12
- package/dist/cli/commands/update/commands.d.ts +1 -0
- package/dist/cli/commands/update/commands.js +18 -45
- package/dist/cli/commands/update/knowledge-base.js +2 -2
- package/dist/cli/commands/update/pre-flight.js +11 -11
- package/dist/cli/commands/update/summary.js +5 -5
- package/dist/cli/commands/update/templates.js +35 -13
- package/dist/cli/commands/update/verification.js +5 -5
- package/dist/cli/commands/update/version.js +1 -1
- package/dist/cli/utils/deploy-ci.d.ts +3 -2
- package/dist/cli/utils/deploy-ci.js +24 -24
- package/dist/cli/utils/deploy-linting.js +101 -6
- package/dist/cli/utils/error-classes.d.ts +2 -2
- package/dist/cli/utils/linting-tools.js +14 -6
- package/dist/cli/utils/template-processor.js +2 -4
- package/dist/templates/{claude → .claude}/EMPLOYEE-DIRECTORY.md.template +16 -22
- package/dist/templates/{agents → .claude/agents}/aj-team/apo-documentation-specialist.md.template +10 -10
- package/dist/templates/{agents → .claude/agents}/aj-team/bas-quality-gate.md.template +13 -15
- package/dist/templates/{agents → .claude/agents}/aj-team/bon-dependency-manager.md.template +4 -4
- package/dist/templates/{agents → .claude/agents}/aj-team/cap-configuration-specialist.md.template +3 -3
- package/dist/templates/{agents → .claude/agents}/aj-team/dra-code-reviewer.md.template +8 -10
- package/dist/templates/{agents → .claude/agents}/aj-team/kil-task-executor.md.template +11 -13
- package/dist/templates/{agents → .claude/agents}/aj-team/uro-refactoring-specialist.md.template +3 -3
- package/dist/templates/{agents → .claude/agents}/audit/juno-auditor.md.template +46 -42
- package/dist/templates/{agents → .claude/agents}/deployment/ein-cicd.md.template +59 -164
- package/dist/templates/{agents → .claude/agents}/deployment/ino-context.md.template +25 -22
- package/dist/templates/{agents → .claude/agents}/deployment/tan-structure.md.template +32 -30
- package/dist/templates/{agents → .claude/agents}/deployment/zen-knowledge.md.template +28 -23
- package/dist/templates/{agents → .claude/agents}/leadership/aj-maestro.md.template +10 -6
- package/dist/templates/{agents → .claude/agents}/leadership/aly-cto.md.template +22 -19
- package/dist/templates/{agents → .claude/agents}/planning/eus-decomposer.md.template +8 -4
- package/dist/templates/{agents → .claude/agents}/planning/mon-requirements.md.template +8 -4
- package/dist/templates/{agents → .claude/agents}/planning/ror-design.md.template +8 -4
- package/dist/templates/{agents → .claude/agents}/planning/tra-planner.md.template +10 -4
- package/dist/templates/{shared/claude-commands → .claude/commands/execution}/trinity-audit.md.template +15 -15
- package/dist/templates/.claude/commands/execution/trinity-breakdown.md.template +535 -0
- package/dist/templates/{shared/claude-commands → .claude/commands/execution}/trinity-orchestrate.md.template +48 -48
- package/dist/templates/{shared/claude-commands → .claude/commands/infrastructure}/trinity-init.md.template +32 -54
- package/dist/templates/{shared/claude-commands → .claude/commands/investigation}/trinity-create-investigation.md.template +13 -7
- package/dist/templates/{shared/claude-commands → .claude/commands/investigation}/trinity-investigate-templates.md.template +19 -15
- package/dist/templates/{shared/claude-commands → .claude/commands/investigation}/trinity-plan-investigation.md.template +12 -6
- package/dist/templates/{shared/claude-commands → .claude/commands/maintenance}/trinity-changelog.md.template +9 -8
- package/dist/templates/.claude/commands/maintenance/trinity-docs-update.md.template +279 -0
- package/dist/templates/.claude/commands/maintenance/trinity-docs.md.template +2828 -0
- package/dist/templates/{shared/claude-commands → .claude/commands/maintenance}/trinity-readme.md.template +21 -20
- package/dist/templates/{shared/claude-commands → .claude/commands/planning}/trinity-decompose.md.template +6 -4
- package/dist/templates/{shared/claude-commands → .claude/commands/planning}/trinity-design.md.template +6 -4
- package/dist/templates/{shared/claude-commands → .claude/commands/planning}/trinity-plan.md.template +7 -5
- package/dist/templates/{shared/claude-commands → .claude/commands/planning}/trinity-requirements.md.template +6 -4
- package/dist/templates/{shared/claude-commands → .claude/commands/session}/trinity-continue.md.template +30 -24
- package/dist/templates/{shared/claude-commands → .claude/commands/session}/trinity-end.md.template +403 -397
- package/dist/templates/{shared/claude-commands → .claude/commands/session}/trinity-start.md.template +9 -4
- package/dist/templates/{shared/claude-commands → .claude/commands/utility}/trinity-agents.md.template +11 -8
- package/dist/templates/{shared/claude-commands → .claude/commands/utility}/trinity-verify.md.template +56 -57
- package/dist/templates/{shared/claude-commands → .claude/commands/utility}/trinity-workorder.md.template +13 -9
- package/dist/templates/ci/ci.yml.template +2 -2
- package/dist/templates/root/CLAUDE.md.template +9 -9
- package/dist/templates/root/linting/nodejs/.husky-pre-commit.template +5 -0
- package/dist/templates/source/base-CLAUDE.md.template +310 -310
- package/dist/templates/source/flutter-CLAUDE.md.template +593 -593
- package/dist/templates/source/nodejs-CLAUDE.md.template +531 -531
- package/dist/templates/source/python-CLAUDE.md.template +510 -510
- package/dist/templates/source/react-CLAUDE.md.template +513 -513
- package/dist/templates/source/rust-CLAUDE.md.template +653 -653
- package/dist/templates/trinity/CLAUDE.md.template +14 -14
- package/dist/templates/{knowledge-base → trinity/knowledge-base}/AI-DEVELOPMENT-GUIDE.md.template +1 -1
- package/dist/templates/{knowledge-base → trinity/knowledge-base}/ARCHITECTURE.md.template +5 -5
- package/dist/templates/{knowledge-base → trinity/knowledge-base}/CODING-PRINCIPLES.md.template +1 -1
- package/dist/templates/{knowledge-base → trinity/knowledge-base}/DOCUMENTATION-CRITERIA.md.template +1 -1
- package/dist/templates/{knowledge-base → trinity/knowledge-base}/ISSUES.md.template +9 -9
- package/dist/templates/{knowledge-base → trinity/knowledge-base}/TESTING-PRINCIPLES.md.template +1 -1
- package/dist/templates/{knowledge-base → trinity/knowledge-base}/Technical-Debt.md.template +2 -4
- package/dist/templates/{knowledge-base → trinity/knowledge-base}/To-do.md.template +2 -2
- package/dist/templates/{knowledge-base → trinity/knowledge-base}/Trinity.md.template +6 -6
- package/dist/templates/trinity/templates/documentation/api-docs/README.md.template +218 -0
- package/dist/templates/trinity/templates/documentation/configuration/documentation-structure.md.template +71 -0
- package/dist/templates/trinity/templates/documentation/configuration/env-example-generator.md.template +387 -0
- package/dist/templates/trinity/templates/documentation/discovery/api-endpoint-scanner.md.template +343 -0
- package/dist/templates/trinity/templates/documentation/discovery/component-discovery.md.template +254 -0
- package/dist/templates/trinity/templates/documentation/discovery/env-variable-extraction.md.template +316 -0
- package/dist/templates/trinity/templates/documentation/discovery/framework-detection.md.template +205 -0
- package/dist/templates/trinity/templates/documentation/guides/api-development.md.template +375 -0
- package/dist/templates/trinity/templates/documentation/guides/contributing.md.template +488 -0
- package/dist/templates/trinity/templates/documentation/guides/deployment.md.template +565 -0
- package/dist/templates/trinity/templates/documentation/guides/getting-started.md.template +118 -0
- package/dist/templates/trinity/templates/documentation/mermaid-diagrams/api-endpoint-map.md.template +56 -0
- package/dist/templates/trinity/templates/documentation/mermaid-diagrams/component-hierarchy.md.template +60 -0
- package/dist/templates/trinity/templates/documentation/mermaid-diagrams/database-er.md.template +49 -0
- package/dist/templates/trinity/templates/documentation/mermaid-diagrams/mvc-flow.md.template +41 -0
- package/dist/templates/trinity/templates/documentation/processes/error-handling-protocol.md.template +166 -0
- package/dist/templates/trinity/templates/documentation/processes/fallback-mechanism.md.template +88 -0
- package/dist/templates/trinity/templates/documentation/reports/apo-docs-update-checklist.md.template +343 -0
- package/dist/templates/trinity/templates/documentation/reports/juno-docs-update-checklist.md.template +1337 -0
- package/dist/templates/trinity/templates/documentation/reports/juno-final-report.md.template +237 -0
- package/dist/templates/trinity/templates/documentation/reports/juno-internal-report.md.template +461 -0
- package/dist/templates/trinity/templates/documentation/validation/documentation-verification-rules.md.template +379 -0
- package/dist/templates/trinity/templates/documentation/validation/juno-quality-gates.md.template +282 -0
- package/dist/templates/{investigations → trinity/templates/investigations}/bug.md.template +14 -14
- package/dist/templates/{investigations → trinity/templates/investigations}/feature.md.template +14 -14
- package/dist/templates/{investigations → trinity/templates/investigations}/performance.md.template +14 -14
- package/dist/templates/{investigations → trinity/templates/investigations}/security.md.template +14 -14
- package/dist/templates/{investigations → trinity/templates/investigations}/technical.md.template +14 -14
- package/dist/templates/{work-orders → trinity/templates/work-orders}/ANALYSIS-TEMPLATE.md.template +10 -13
- package/dist/templates/{work-orders → trinity/templates/work-orders}/AUDIT-TEMPLATE.md.template +10 -26
- package/dist/templates/{work-orders → trinity/templates/work-orders}/IMPLEMENTATION-TEMPLATE.md.template +10 -26
- package/dist/templates/{work-orders → trinity/templates/work-orders}/INVESTIGATION-TEMPLATE.md.template +10 -25
- package/dist/templates/{work-orders → trinity/templates/work-orders}/PATTERN-TEMPLATE.md.template +10 -26
- package/dist/templates/{work-orders → trinity/templates/work-orders}/VERIFICATION-TEMPLATE.md.template +10 -26
- package/package.json +99 -94
- package/dist/templates/agents/leadership/aj-cc.md.template +0 -462
- package/dist/templates/ci/cd.yml.template +0 -175
- package/dist/templates/ci/github-actions.yml +0 -86
- package/dist/templates/root/TRINITY.md.template +0 -52
- package/dist/templates/shared/claude-commands/trinity-docs.md.template +0 -2577
- /package/dist/templates/{linting → root/linting}/flutter/.pre-commit-config.yaml.template +0 -0
- /package/dist/templates/{linting → root/linting}/flutter/analysis_options.yaml.template +0 -0
- /package/dist/templates/{linting → root/linting}/nodejs/.eslintrc-commonjs.json.template +0 -0
- /package/dist/templates/{linting → root/linting}/nodejs/.eslintrc-esm.json.template +0 -0
- /package/dist/templates/{linting → root/linting}/nodejs/.eslintrc-typescript.json.template +0 -0
- /package/dist/templates/{linting → root/linting}/nodejs/.pre-commit-config.yaml.template +0 -0
- /package/dist/templates/{linting → root/linting}/nodejs/.prettierrc.json.template +0 -0
- /package/dist/templates/{linting → root/linting}/python/.flake8.template +0 -0
- /package/dist/templates/{linting → root/linting}/python/.pre-commit-config.yaml.template +0 -0
- /package/dist/templates/{linting → root/linting}/python/pyproject.toml.template +0 -0
- /package/dist/templates/{linting → root/linting}/rust/.pre-commit-config.yaml.template +0 -0
- /package/dist/templates/{linting → root/linting}/rust/clippy.toml.template +0 -0
- /package/dist/templates/{linting → root/linting}/rust/rustfmt.toml.template +0 -0
- /package/dist/templates/{documentation → trinity/templates/documentation}/ROOT-README.md.template +0 -0
- /package/dist/templates/{documentation → trinity/templates/documentation}/SUBDIRECTORY-README.md.template +0 -0
package/dist/templates/trinity/templates/documentation/discovery/framework-detection.md.template
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# Framework Detection Patterns
|
|
2
|
+
**Category:** Discovery
|
|
3
|
+
**Purpose:** Detect backend frameworks, frontend frameworks, databases, ORMs, and testing frameworks from package.json
|
|
4
|
+
**Used By:** JUNO (Phase 1), APO-1, APO-2, APO-3 (Fallback Mode)
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
This template provides patterns for detecting technologies used in a codebase by analyzing `package.json` dependencies.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## How to Use
|
|
15
|
+
|
|
16
|
+
1. Read and parse the project's `package.json` file
|
|
17
|
+
2. Check both `dependencies` and `devDependencies` for framework matches
|
|
18
|
+
3. Identify frameworks by package name patterns
|
|
19
|
+
4. Store detected frameworks for template variable substitution
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Framework Detection Logic
|
|
24
|
+
|
|
25
|
+
### Package Analysis Pattern
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
const pkg_json = Read("package.json");
|
|
29
|
+
const pkg = JSON.parse(pkg_json);
|
|
30
|
+
|
|
31
|
+
// Combine all dependencies
|
|
32
|
+
const all_deps = {
|
|
33
|
+
...pkg.dependencies,
|
|
34
|
+
...pkg.devDependencies
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Detect frameworks by package name
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Detection Categories
|
|
43
|
+
|
|
44
|
+
### 1. Backend Frameworks
|
|
45
|
+
|
|
46
|
+
**Patterns to detect:**
|
|
47
|
+
- `express` → Express.js
|
|
48
|
+
- `fastify` → Fastify
|
|
49
|
+
- `koa` → Koa
|
|
50
|
+
- `hapi` → Hapi
|
|
51
|
+
- `@nestjs/core` or `@nestjs/common` → NestJS
|
|
52
|
+
- `next` → Next.js (full-stack)
|
|
53
|
+
|
|
54
|
+
**Example:**
|
|
55
|
+
```javascript
|
|
56
|
+
if (all_deps['express']) backend_framework = 'Express.js';
|
|
57
|
+
if (all_deps['@nestjs/core']) backend_framework = 'NestJS';
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### 2. Frontend Frameworks
|
|
63
|
+
|
|
64
|
+
**Patterns to detect:**
|
|
65
|
+
- `react` → React
|
|
66
|
+
- `vue` → Vue.js
|
|
67
|
+
- `@angular/core` → Angular
|
|
68
|
+
- `svelte` → Svelte
|
|
69
|
+
- `solid-js` → SolidJS
|
|
70
|
+
- `preact` → Preact
|
|
71
|
+
|
|
72
|
+
**Example:**
|
|
73
|
+
```javascript
|
|
74
|
+
if (all_deps['react']) frontend_framework = 'React';
|
|
75
|
+
if (all_deps['vue']) frontend_framework = 'Vue.js';
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
### 3. Database & ORM
|
|
81
|
+
|
|
82
|
+
**Patterns to detect:**
|
|
83
|
+
- `prisma` or `@prisma/client` → Prisma
|
|
84
|
+
- `typeorm` → TypeORM
|
|
85
|
+
- `sequelize` → Sequelize
|
|
86
|
+
- `mongoose` → Mongoose (MongoDB)
|
|
87
|
+
- `knex` → Knex.js
|
|
88
|
+
- `pg` → PostgreSQL (direct driver)
|
|
89
|
+
- `mysql` or `mysql2` → MySQL (direct driver)
|
|
90
|
+
- `mongodb` → MongoDB (direct driver)
|
|
91
|
+
|
|
92
|
+
**Example:**
|
|
93
|
+
```javascript
|
|
94
|
+
if (all_deps['@prisma/client']) orm = 'Prisma';
|
|
95
|
+
if (all_deps['typeorm']) orm = 'TypeORM';
|
|
96
|
+
if (all_deps['pg']) database = 'PostgreSQL';
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
### 4. Testing Frameworks
|
|
102
|
+
|
|
103
|
+
**Patterns to detect:**
|
|
104
|
+
- `jest` → Jest
|
|
105
|
+
- `vitest` → Vitest
|
|
106
|
+
- `mocha` → Mocha
|
|
107
|
+
- `jasmine` → Jasmine
|
|
108
|
+
- `cypress` → Cypress (E2E)
|
|
109
|
+
- `playwright` or `@playwright/test` → Playwright (E2E)
|
|
110
|
+
- `@testing-library/react` → React Testing Library
|
|
111
|
+
|
|
112
|
+
**Example:**
|
|
113
|
+
```javascript
|
|
114
|
+
if (all_deps['jest']) test_framework = 'Jest';
|
|
115
|
+
if (all_deps['vitest']) test_framework = 'Vitest';
|
|
116
|
+
if (all_deps['cypress']) e2e_framework = 'Cypress';
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Fallback Detection
|
|
122
|
+
|
|
123
|
+
If `package.json` is missing or cannot be parsed:
|
|
124
|
+
1. **Backend:** Search for `server.js`, `app.js`, `index.ts` in `src/`, `server/` directories
|
|
125
|
+
2. **Frontend:** Check for `index.html`, `App.tsx`, `App.vue` in `src/`, `client/` directories
|
|
126
|
+
3. **Database:** Look for `prisma/schema.prisma`, TypeORM entity files with `@Entity` decorator
|
|
127
|
+
4. **Testing:** Check for `jest.config.js`, `vitest.config.ts`, `cypress.config.js`
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Template Variable Mapping
|
|
132
|
+
|
|
133
|
+
**Variables to populate:**
|
|
134
|
+
- `{{BACKEND_FRAMEWORK}}` → Backend framework name (e.g., "Express.js", "NestJS")
|
|
135
|
+
- `{{FRONTEND_FRAMEWORK}}` → Frontend framework name (e.g., "React", "Vue.js")
|
|
136
|
+
- `{{DATABASE}}` → Database system (e.g., "PostgreSQL", "MongoDB")
|
|
137
|
+
- `{{ORM}}` → ORM/Query builder (e.g., "Prisma", "TypeORM")
|
|
138
|
+
- `{{TEST_FRAMEWORK}}` → Testing framework (e.g., "Jest", "Vitest")
|
|
139
|
+
- `{{E2E_FRAMEWORK}}` → E2E testing framework (e.g., "Cypress", "Playwright")
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Error Handling
|
|
144
|
+
|
|
145
|
+
**If no frameworks detected:**
|
|
146
|
+
- Log warning: "⚠️ FALLBACK: No frameworks detected in package.json - manual detection required"
|
|
147
|
+
- Use fallback detection methods (file system scanning)
|
|
148
|
+
- If still unsuccessful, mark as "Unknown" but continue processing
|
|
149
|
+
|
|
150
|
+
**If multiple frameworks detected (uncommon but possible):**
|
|
151
|
+
- Select primary framework (most commonly used)
|
|
152
|
+
- Log info: "ℹ️ Multiple frameworks detected: [list] - using [primary]"
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Examples
|
|
157
|
+
|
|
158
|
+
### Example 1: Express + React + Prisma Stack
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
// package.json dependencies:
|
|
162
|
+
{
|
|
163
|
+
"express": "^4.18.2",
|
|
164
|
+
"react": "^18.2.0",
|
|
165
|
+
"@prisma/client": "^5.0.0",
|
|
166
|
+
"jest": "^29.5.0"
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Detection result:
|
|
170
|
+
BACKEND_FRAMEWORK = "Express.js"
|
|
171
|
+
FRONTEND_FRAMEWORK = "React"
|
|
172
|
+
ORM = "Prisma"
|
|
173
|
+
TEST_FRAMEWORK = "Jest"
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Example 2: NestJS + Angular + TypeORM Stack
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
// package.json dependencies:
|
|
180
|
+
{
|
|
181
|
+
"@nestjs/core": "^10.0.0",
|
|
182
|
+
"@angular/core": "^16.0.0",
|
|
183
|
+
"typeorm": "^0.3.17",
|
|
184
|
+
"pg": "^8.11.0",
|
|
185
|
+
"jest": "^29.5.0"
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Detection result:
|
|
189
|
+
BACKEND_FRAMEWORK = "NestJS"
|
|
190
|
+
FRONTEND_FRAMEWORK = "Angular"
|
|
191
|
+
ORM = "TypeORM"
|
|
192
|
+
DATABASE = "PostgreSQL"
|
|
193
|
+
TEST_FRAMEWORK = "Jest"
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Best Practices
|
|
199
|
+
|
|
200
|
+
1. **Always check both `dependencies` and `devDependencies`** - Testing frameworks are often in `devDependencies`
|
|
201
|
+
2. **Use specific package names** - Don't use fuzzy matching to avoid false positives
|
|
202
|
+
3. **Log all detections** - Help debugging if detection fails
|
|
203
|
+
4. **Graceful degradation** - If detection fails, continue with "Unknown" rather than aborting
|
|
204
|
+
|
|
205
|
+
---
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
# API Development Guide
|
|
2
|
+
|
|
3
|
+
This guide covers best practices for developing REST API endpoints in {{PROJECT_NAME}}.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Architecture Overview
|
|
8
|
+
|
|
9
|
+
{{PROJECT_NAME}} follows a **{{ARCHITECTURE_PATTERN}}** architecture:
|
|
10
|
+
|
|
11
|
+
- **Framework:** {{FRAMEWORK}} {{FRAMEWORK_VERSION}}
|
|
12
|
+
- **Database:** {{DATABASE_TYPE}}
|
|
13
|
+
- **ORM:** {{DATABASE_ORM}}
|
|
14
|
+
- **Authentication:** {{AUTH_METHOD}}
|
|
15
|
+
- **Validation:** {{VALIDATION_LIBRARY}}
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Project Structure
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
{{API_DIRECTORY}}/
|
|
23
|
+
├── routes/ # API route definitions
|
|
24
|
+
├── controllers/ # Request handlers
|
|
25
|
+
├── models/ # Data models ({{DATABASE_ORM}})
|
|
26
|
+
├── middleware/ # Custom middleware
|
|
27
|
+
├── validators/ # Request validation schemas
|
|
28
|
+
└── services/ # Business logic
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Creating a New Endpoint
|
|
34
|
+
|
|
35
|
+
### Step 1: Define the Route
|
|
36
|
+
|
|
37
|
+
**File:** `{{ROUTES_DIRECTORY}}/{{EXAMPLE_RESOURCE}}.routes.ts`
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import express from 'express';
|
|
41
|
+
import { {{EXAMPLE_CONTROLLER}} } from '../controllers/{{EXAMPLE_RESOURCE}}.controller';
|
|
42
|
+
{{AUTH_IMPORT}}
|
|
43
|
+
|
|
44
|
+
const router = express.Router();
|
|
45
|
+
|
|
46
|
+
// GET /api/{{EXAMPLE_RESOURCE}}
|
|
47
|
+
router.get('/', {{EXAMPLE_CONTROLLER}}.getAll);
|
|
48
|
+
|
|
49
|
+
// GET /api/{{EXAMPLE_RESOURCE}}/:id
|
|
50
|
+
router.get('/:id', {{EXAMPLE_CONTROLLER}}.getById);
|
|
51
|
+
|
|
52
|
+
// POST /api/{{EXAMPLE_RESOURCE}}
|
|
53
|
+
router.post('/', {{AUTH_MIDDLEWARE}}, {{EXAMPLE_CONTROLLER}}.create);
|
|
54
|
+
|
|
55
|
+
// PUT /api/{{EXAMPLE_RESOURCE}}/:id
|
|
56
|
+
router.put('/:id', {{AUTH_MIDDLEWARE}}, {{EXAMPLE_CONTROLLER}}.update);
|
|
57
|
+
|
|
58
|
+
// DELETE /api/{{EXAMPLE_RESOURCE}}/:id
|
|
59
|
+
router.delete('/:id', {{AUTH_MIDDLEWARE}}, {{EXAMPLE_CONTROLLER}}.delete);
|
|
60
|
+
|
|
61
|
+
export default router;
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Step 2: Create the Controller
|
|
65
|
+
|
|
66
|
+
**File:** `{{CONTROLLERS_DIRECTORY}}/{{EXAMPLE_RESOURCE}}.controller.ts`
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { Request, Response } from 'express';
|
|
70
|
+
import { {{EXAMPLE_SERVICE}} } from '../services/{{EXAMPLE_RESOURCE}}.service';
|
|
71
|
+
|
|
72
|
+
export const {{EXAMPLE_CONTROLLER}} = {
|
|
73
|
+
async getAll(req: Request, res: Response) {
|
|
74
|
+
try {
|
|
75
|
+
const items = await {{EXAMPLE_SERVICE}}.findAll();
|
|
76
|
+
res.json(items);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
res.status(500).json({ error: error.message });
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
async getById(req: Request, res: Response) {
|
|
83
|
+
try {
|
|
84
|
+
const item = await {{EXAMPLE_SERVICE}}.findById(req.params.id);
|
|
85
|
+
if (!item) {
|
|
86
|
+
return res.status(404).json({ error: 'Not found' });
|
|
87
|
+
}
|
|
88
|
+
res.json(item);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
res.status(500).json({ error: error.message });
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
async create(req: Request, res: Response) {
|
|
95
|
+
try {
|
|
96
|
+
const item = await {{EXAMPLE_SERVICE}}.create(req.body);
|
|
97
|
+
res.status(201).json(item);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
res.status(400).json({ error: error.message });
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
async update(req: Request, res: Response) {
|
|
104
|
+
try {
|
|
105
|
+
const item = await {{EXAMPLE_SERVICE}}.update(req.params.id, req.body);
|
|
106
|
+
if (!item) {
|
|
107
|
+
return res.status(404).json({ error: 'Not found' });
|
|
108
|
+
}
|
|
109
|
+
res.json(item);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
res.status(400).json({ error: error.message });
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
async delete(req: Request, res: Response) {
|
|
116
|
+
try {
|
|
117
|
+
await {{EXAMPLE_SERVICE}}.delete(req.params.id);
|
|
118
|
+
res.status(204).send();
|
|
119
|
+
} catch (error) {
|
|
120
|
+
res.status(500).json({ error: error.message });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Step 3: Implement the Service
|
|
127
|
+
|
|
128
|
+
**File:** `{{SERVICES_DIRECTORY}}/{{EXAMPLE_RESOURCE}}.service.ts`
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { {{ORM_CLIENT}} } from '../db';
|
|
132
|
+
|
|
133
|
+
export const {{EXAMPLE_SERVICE}} = {
|
|
134
|
+
async findAll() {
|
|
135
|
+
return {{ORM_CLIENT}}.{{EXAMPLE_MODEL}}.findMany();
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
async findById(id: string) {
|
|
139
|
+
return {{ORM_CLIENT}}.{{EXAMPLE_MODEL}}.findUnique({ where: { id } });
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
async create(data: any) {
|
|
143
|
+
return {{ORM_CLIENT}}.{{EXAMPLE_MODEL}}.create({ data });
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
async update(id: string, data: any) {
|
|
147
|
+
return {{ORM_CLIENT}}.{{EXAMPLE_MODEL}}.update({ where: { id }, data });
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
async delete(id: string) {
|
|
151
|
+
return {{ORM_CLIENT}}.{{EXAMPLE_MODEL}}.delete({ where: { id } });
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Step 4: Register the Route
|
|
157
|
+
|
|
158
|
+
**File:** `{{MAIN_SERVER_FILE}}`
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import {{EXAMPLE_RESOURCE}}Routes from './routes/{{EXAMPLE_RESOURCE}}.routes';
|
|
162
|
+
|
|
163
|
+
app.use('/api/{{EXAMPLE_RESOURCE}}', {{EXAMPLE_RESOURCE}}Routes);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Request Validation
|
|
169
|
+
|
|
170
|
+
{{VALIDATION_SECTION}}
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Authentication & Authorization
|
|
175
|
+
|
|
176
|
+
{{AUTHENTICATION_SECTION}}
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Error Handling
|
|
181
|
+
|
|
182
|
+
### Standard Error Response Format
|
|
183
|
+
|
|
184
|
+
```json
|
|
185
|
+
{
|
|
186
|
+
"error": "Error message",
|
|
187
|
+
"statusCode": 400,
|
|
188
|
+
"timestamp": "2026-01-15T12:00:00Z",
|
|
189
|
+
"path": "/api/{{EXAMPLE_RESOURCE}}"
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Error Handler Middleware
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
app.use((error: Error, req: Request, res: Response, next: NextFunction) => {
|
|
197
|
+
const statusCode = error.statusCode || 500;
|
|
198
|
+
res.status(statusCode).json({
|
|
199
|
+
error: error.message,
|
|
200
|
+
statusCode,
|
|
201
|
+
timestamp: new Date().toISOString(),
|
|
202
|
+
path: req.path
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## Testing API Endpoints
|
|
210
|
+
|
|
211
|
+
### Unit Tests
|
|
212
|
+
|
|
213
|
+
**File:** `{{TEST_DIRECTORY}}/{{EXAMPLE_RESOURCE}}.test.ts`
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
import { {{EXAMPLE_SERVICE}} } from '../services/{{EXAMPLE_RESOURCE}}.service';
|
|
217
|
+
|
|
218
|
+
describe('{{EXAMPLE_SERVICE}}', () => {
|
|
219
|
+
it('should create a new item', async () => {
|
|
220
|
+
const data = { name: 'Test Item' };
|
|
221
|
+
const result = await {{EXAMPLE_SERVICE}}.create(data);
|
|
222
|
+
expect(result.name).toBe('Test Item');
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('should find item by id', async () => {
|
|
226
|
+
const item = await {{EXAMPLE_SERVICE}}.findById('123');
|
|
227
|
+
expect(item).toBeDefined();
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Integration Tests
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import request from 'supertest';
|
|
236
|
+
import app from '../app';
|
|
237
|
+
|
|
238
|
+
describe('{{EXAMPLE_RESOURCE}} API', () => {
|
|
239
|
+
it('GET /api/{{EXAMPLE_RESOURCE}} should return all items', async () => {
|
|
240
|
+
const response = await request(app).get('/api/{{EXAMPLE_RESOURCE}}');
|
|
241
|
+
expect(response.status).toBe(200);
|
|
242
|
+
expect(Array.isArray(response.body)).toBe(true);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('POST /api/{{EXAMPLE_RESOURCE}} should create item', async () => {
|
|
246
|
+
const data = { name: 'New Item' };
|
|
247
|
+
const response = await request(app)
|
|
248
|
+
.post('/api/{{EXAMPLE_RESOURCE}}')
|
|
249
|
+
.send(data);
|
|
250
|
+
expect(response.status).toBe(201);
|
|
251
|
+
expect(response.body.name).toBe('New Item');
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## Best Practices
|
|
259
|
+
|
|
260
|
+
### 1. Use Async/Await
|
|
261
|
+
|
|
262
|
+
Always use async/await for database operations and external API calls.
|
|
263
|
+
|
|
264
|
+
### 2. Validate Input
|
|
265
|
+
|
|
266
|
+
Use {{VALIDATION_LIBRARY}} to validate request data before processing.
|
|
267
|
+
|
|
268
|
+
### 3. Handle Errors Properly
|
|
269
|
+
|
|
270
|
+
Catch all errors and return appropriate HTTP status codes.
|
|
271
|
+
|
|
272
|
+
### 4. Implement Authentication
|
|
273
|
+
|
|
274
|
+
Protect sensitive endpoints with authentication middleware.
|
|
275
|
+
|
|
276
|
+
### 5. Write Tests
|
|
277
|
+
|
|
278
|
+
Aim for 80%+ test coverage on API endpoints.
|
|
279
|
+
|
|
280
|
+
### 6. Document Endpoints
|
|
281
|
+
|
|
282
|
+
Update API documentation when adding or modifying endpoints.
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Database Migrations
|
|
287
|
+
|
|
288
|
+
{{DATABASE_MIGRATION_SECTION}}
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## API Versioning
|
|
293
|
+
|
|
294
|
+
{{API_VERSIONING_SECTION}}
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## Performance Optimization
|
|
299
|
+
|
|
300
|
+
### Database Query Optimization
|
|
301
|
+
|
|
302
|
+
- Use indexes on frequently queried fields
|
|
303
|
+
- Implement pagination for large datasets
|
|
304
|
+
- Use eager loading to avoid N+1 queries
|
|
305
|
+
- Cache frequently accessed data
|
|
306
|
+
|
|
307
|
+
### Example: Pagination
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
async findAll(page: number = 1, limit: number = 20) {
|
|
311
|
+
const skip = (page - 1) * limit;
|
|
312
|
+
return {{ORM_CLIENT}}.{{EXAMPLE_MODEL}}.findMany({
|
|
313
|
+
skip,
|
|
314
|
+
take: limit,
|
|
315
|
+
orderBy: { createdAt: 'desc' }
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
## Common Patterns
|
|
323
|
+
|
|
324
|
+
### Pattern: Resource CRUD
|
|
325
|
+
|
|
326
|
+
All resources follow the same CRUD pattern:
|
|
327
|
+
- GET /api/{resource} - List all
|
|
328
|
+
- GET /api/{resource}/:id - Get by ID
|
|
329
|
+
- POST /api/{resource} - Create
|
|
330
|
+
- PUT /api/{resource}/:id - Update
|
|
331
|
+
- DELETE /api/{resource}/:id - Delete
|
|
332
|
+
|
|
333
|
+
### Pattern: Nested Resources
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
// GET /api/users/:userId/posts
|
|
337
|
+
router.get('/users/:userId/posts', postsController.getByUserId);
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Pattern: Query Parameters
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
// GET /api/{{EXAMPLE_RESOURCE}}?search=term&limit=10&page=2
|
|
344
|
+
router.get('/', async (req: Request, res: Response) => {
|
|
345
|
+
const { search, limit = 20, page = 1 } = req.query;
|
|
346
|
+
// Implementation
|
|
347
|
+
});
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## Debugging
|
|
353
|
+
|
|
354
|
+
### Enable Debug Logging
|
|
355
|
+
|
|
356
|
+
{{DEBUG_LOGGING_SECTION}}
|
|
357
|
+
|
|
358
|
+
### API Testing Tools
|
|
359
|
+
|
|
360
|
+
- **Postman:** GUI for testing API endpoints
|
|
361
|
+
- **cURL:** Command-line API testing
|
|
362
|
+
- **Thunder Client:** VS Code extension for API testing
|
|
363
|
+
|
|
364
|
+
---
|
|
365
|
+
|
|
366
|
+
## Related Documentation
|
|
367
|
+
|
|
368
|
+
- [API Reference](../api/README.md) - Complete endpoint documentation
|
|
369
|
+
- [Getting Started](./getting-started.md) - Project setup guide
|
|
370
|
+
- [Deployment Guide](./deployment.md) - Production deployment
|
|
371
|
+
- [Contributing Guidelines](../CONTRIBUTING.md) - Code standards
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
*Last updated: {{GENERATION_DATE}}*
|