@lenne.tech/cli 1.0.1 → 1.1.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/build/commands/claude/install-commands.js +10 -5
- package/build/commands/claude/install-mcps.js +258 -0
- package/build/commands/claude/install-skills.js +90 -23
- package/build/lib/mcp-registry.js +80 -0
- package/build/templates/claude-commands/commit-message.md +21 -0
- package/build/templates/claude-commands/create-story.md +407 -0
- package/build/templates/claude-commands/skill-optimize.md +431 -90
- package/build/templates/claude-skills/building-stories-with-tdd/SKILL.md +265 -0
- package/build/templates/claude-skills/{story-tdd → building-stories-with-tdd}/code-quality.md +10 -0
- package/build/templates/claude-skills/{story-tdd → building-stories-with-tdd}/database-indexes.md +9 -0
- package/build/templates/claude-skills/{story-tdd → building-stories-with-tdd}/examples.md +115 -64
- package/build/templates/claude-skills/building-stories-with-tdd/handling-existing-tests.md +197 -0
- package/build/templates/claude-skills/{story-tdd → building-stories-with-tdd}/reference.md +276 -29
- package/build/templates/claude-skills/{story-tdd → building-stories-with-tdd}/security-review.md +8 -0
- package/build/templates/claude-skills/building-stories-with-tdd/workflow.md +1004 -0
- package/build/templates/claude-skills/generating-nest-servers/SKILL.md +303 -0
- package/build/templates/claude-skills/{nest-server-generator → generating-nest-servers}/configuration.md +6 -0
- package/build/templates/claude-skills/{nest-server-generator → generating-nest-servers}/declare-keyword-warning.md +9 -0
- package/build/templates/claude-skills/{nest-server-generator → generating-nest-servers}/description-management.md +9 -0
- package/build/templates/claude-skills/{nest-server-generator → generating-nest-servers}/examples.md +7 -0
- package/build/templates/claude-skills/generating-nest-servers/framework-guide.md +259 -0
- package/build/templates/claude-skills/{nest-server-generator → generating-nest-servers}/quality-review.md +9 -0
- package/build/templates/claude-skills/{nest-server-generator → generating-nest-servers}/reference.md +16 -0
- package/build/templates/claude-skills/{nest-server-generator → generating-nest-servers}/security-rules.md +13 -0
- package/build/templates/claude-skills/generating-nest-servers/verification-checklist.md +262 -0
- package/build/templates/claude-skills/generating-nest-servers/workflow-process.md +1061 -0
- package/build/templates/claude-skills/{lt-cli → using-lt-cli}/SKILL.md +22 -10
- package/build/templates/claude-skills/{lt-cli → using-lt-cli}/examples.md +7 -3
- package/build/templates/claude-skills/{lt-cli → using-lt-cli}/reference.md +10 -3
- package/package.json +2 -2
- package/build/templates/claude-skills/nest-server-generator/SKILL.md +0 -1891
- package/build/templates/claude-skills/story-tdd/SKILL.md +0 -1173
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: generating-nest-servers
|
|
3
|
+
version: 1.1.0
|
|
4
|
+
description: PRIMARY expert for ALL NestJS and @lenne.tech/nest-server tasks. ALWAYS use this skill when working in projects with @lenne.tech/nest-server in package.json dependencies (supports monorepos with projects/*, packages/*, apps/* structure), or when asked about NestJS modules, services, controllers, resolvers, models, objects, tests, server creation, debugging, or any NestJS/nest-server development task. Handles lt server commands, security analysis, test creation, and all backend development. ALWAYS reads CrudService base class before working with Services.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# NestJS Server Development Expert
|
|
8
|
+
|
|
9
|
+
You are the **PRIMARY expert** for NestJS backend development and the @lenne.tech/nest-server framework. This skill handles **ALL NestJS-related tasks**, from analysis to creation to debugging:
|
|
10
|
+
|
|
11
|
+
## When to Use This Skill
|
|
12
|
+
|
|
13
|
+
**✅ ALWAYS use this skill for:**
|
|
14
|
+
|
|
15
|
+
### Analysis & Understanding
|
|
16
|
+
- 📖 Analyzing existing NestJS code structure
|
|
17
|
+
- 🔍 Understanding how modules, services, controllers work
|
|
18
|
+
- 📊 Reviewing project architecture
|
|
19
|
+
- 🗺️ Mapping relationships between modules
|
|
20
|
+
- 📝 Reading and explaining NestJS code
|
|
21
|
+
- 🔎 Finding specific implementations (controllers, services, etc.)
|
|
22
|
+
|
|
23
|
+
### Running & Debugging
|
|
24
|
+
- 🚀 Starting the NestJS server (`npm start`, `npm run dev`)
|
|
25
|
+
- 🐛 Debugging server issues and errors
|
|
26
|
+
- 🧪 Running tests (`npm test`)
|
|
27
|
+
- 📋 Checking server logs and output
|
|
28
|
+
- ⚙️ Configuring environment variables
|
|
29
|
+
- 🔧 Troubleshooting build/compile errors
|
|
30
|
+
|
|
31
|
+
### Creation & Modification
|
|
32
|
+
- ✨ Creating new modules with `lt server module`
|
|
33
|
+
- 🎨 Creating new objects with `lt server object`
|
|
34
|
+
- ➕ Adding properties with `lt server addProp`
|
|
35
|
+
- 🏗️ Creating a new server with `lt server create`
|
|
36
|
+
- ♻️ Modifying existing code (services, controllers, resolvers)
|
|
37
|
+
- 🔗 Adding relationships between modules
|
|
38
|
+
- 📦 Managing dependencies and imports
|
|
39
|
+
|
|
40
|
+
### Testing & Validation
|
|
41
|
+
- ✅ Creating API tests for controllers/resolvers
|
|
42
|
+
- 🧪 Running and fixing failing tests
|
|
43
|
+
- 🎯 Testing endpoints manually
|
|
44
|
+
- 📊 Validating data models and schemas
|
|
45
|
+
- 🔐 Testing authentication and permissions
|
|
46
|
+
|
|
47
|
+
### General NestJS Tasks
|
|
48
|
+
- 💬 Answering NestJS/nest-server questions
|
|
49
|
+
- 📚 Explaining framework concepts
|
|
50
|
+
- 🏛️ Discussing architecture decisions
|
|
51
|
+
- 🛠️ Recommending best practices
|
|
52
|
+
- 🔄 Refactoring existing code
|
|
53
|
+
|
|
54
|
+
**🎯 Rule: If it involves NestJS or @lenne.tech/nest-server in ANY way, use this skill!**
|
|
55
|
+
|
|
56
|
+
## Related Skills
|
|
57
|
+
|
|
58
|
+
**🔄 Works closely with:**
|
|
59
|
+
- `building-stories-with-tdd` skill - For building user stories with Test-Driven Development
|
|
60
|
+
- `using-lt-cli` skill - For Git operations and Fullstack initialization
|
|
61
|
+
|
|
62
|
+
**When to use which:**
|
|
63
|
+
- Building features with TDD workflow? → Use `building-stories-with-tdd` skill (it will use this skill for implementation)
|
|
64
|
+
- Need Git operations? → Use `using-lt-cli` skill
|
|
65
|
+
- Direct NestJS work? → Use this skill
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## 🚨 CRITICAL SECURITY RULES - READ FIRST
|
|
70
|
+
|
|
71
|
+
**Before you start ANY work, understand these NON-NEGOTIABLE rules:**
|
|
72
|
+
|
|
73
|
+
### ⛔ NEVER Do This:
|
|
74
|
+
1. **NEVER remove or weaken `@Restricted()` decorators**
|
|
75
|
+
2. **NEVER change `@Roles()` decorators** to more permissive roles
|
|
76
|
+
3. **NEVER modify `securityCheck()` logic** to bypass security
|
|
77
|
+
4. **NEVER remove class-level `@Restricted(RoleEnum.ADMIN)`**
|
|
78
|
+
|
|
79
|
+
### ✅ ALWAYS Do This:
|
|
80
|
+
1. **ALWAYS analyze permissions BEFORE writing tests**
|
|
81
|
+
2. **ALWAYS test with the LEAST privileged user** who is authorized
|
|
82
|
+
3. **ALWAYS adapt tests to security requirements**, never vice versa
|
|
83
|
+
4. **ALWAYS ask developer for approval** before changing ANY security decorator
|
|
84
|
+
|
|
85
|
+
**📖 Complete security rules with all details, examples, and testing strategies: `security-rules.md`**
|
|
86
|
+
|
|
87
|
+
## 🚨 CRITICAL: NEVER USE `declare` KEYWORD FOR PROPERTIES
|
|
88
|
+
|
|
89
|
+
**⚠️ DO NOT use the `declare` keyword when defining properties in classes!**
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// ❌ WRONG
|
|
93
|
+
declare name: string; // Decorator won't work!
|
|
94
|
+
|
|
95
|
+
// ✅ CORRECT
|
|
96
|
+
@UnifiedField({ description: 'Product name' })
|
|
97
|
+
name: string; // Decorator works properly
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Why**: `declare` prevents decorators from being applied, breaking the decorator system.
|
|
101
|
+
|
|
102
|
+
**📖 Complete explanation and correct patterns: `declare-keyword-warning.md`**
|
|
103
|
+
|
|
104
|
+
## 🚨 CRITICAL: DESCRIPTION MANAGEMENT
|
|
105
|
+
|
|
106
|
+
**⚠️ Descriptions must be applied consistently to EVERY component.**
|
|
107
|
+
|
|
108
|
+
**Quick 3-Step Process:**
|
|
109
|
+
1. Extract descriptions from user's `// comments`
|
|
110
|
+
2. Format: `'English text'` or `'English (Deutsch)'` for German input
|
|
111
|
+
3. Apply EVERYWHERE: Model, CreateInput, UpdateInput, Objects, Class-level decorators
|
|
112
|
+
|
|
113
|
+
**📖 Complete formatting rules, examples, and verification checklist: `description-management.md`**
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Core Responsibilities
|
|
118
|
+
|
|
119
|
+
This skill handles **ALL** NestJS server development tasks, including:
|
|
120
|
+
|
|
121
|
+
### Simple Tasks (Single Commands)
|
|
122
|
+
- Creating a single module with `lt server module`
|
|
123
|
+
- Creating a single object with `lt server object`
|
|
124
|
+
- Adding properties with `lt server addProp`
|
|
125
|
+
- Creating a new server with `lt server create`
|
|
126
|
+
- Starting the server with `npm start` or `npm run dev`
|
|
127
|
+
- Running tests with `npm test`
|
|
128
|
+
|
|
129
|
+
### Complex Tasks (Multiple Components)
|
|
130
|
+
When you receive a complete structure specification, you will:
|
|
131
|
+
|
|
132
|
+
1. **Parse and analyze** the complete structure (modules, models, objects, properties, relationships)
|
|
133
|
+
2. **Create a comprehensive todo list** breaking down all tasks
|
|
134
|
+
3. **Generate all components** in the correct order (objects first, then modules)
|
|
135
|
+
4. **Handle inheritance** properly (Core and custom parent classes)
|
|
136
|
+
5. **Manage descriptions** (translate German to English, add originals in parentheses)
|
|
137
|
+
6. **Create API tests** for all controllers and resolvers
|
|
138
|
+
7. **Verify functionality** and provide a summary with observations
|
|
139
|
+
|
|
140
|
+
### Analysis Tasks
|
|
141
|
+
When analyzing existing code:
|
|
142
|
+
|
|
143
|
+
1. **Explore the project structure** to understand the architecture
|
|
144
|
+
2. **Read relevant files** (modules, services, controllers, models)
|
|
145
|
+
3. **Identify patterns** and conventions used in the project
|
|
146
|
+
4. **Explain findings** clearly and concisely
|
|
147
|
+
5. **Suggest improvements** when appropriate
|
|
148
|
+
|
|
149
|
+
### Debugging Tasks
|
|
150
|
+
When debugging issues:
|
|
151
|
+
|
|
152
|
+
1. **Read error messages and logs** carefully
|
|
153
|
+
2. **Identify the root cause** by analyzing relevant code
|
|
154
|
+
3. **Check configuration** (environment variables, config files)
|
|
155
|
+
4. **Test hypotheses** by examining related files
|
|
156
|
+
5. **Provide solutions** with code examples
|
|
157
|
+
|
|
158
|
+
**Remember:** For ANY task involving NestJS or @lenne.tech/nest-server, use this skill!
|
|
159
|
+
|
|
160
|
+
## 📚 Understanding the Framework
|
|
161
|
+
|
|
162
|
+
**📖 Complete framework guide: `framework-guide.md`**
|
|
163
|
+
|
|
164
|
+
**Critical Rules:**
|
|
165
|
+
- [ ] Read CrudService before modifying any Service (`node_modules/@lenne.tech/nest-server/src/core/common/services/crud.service.ts`)
|
|
166
|
+
- [ ] NEVER blindly pass all serviceOptions to other Services (only pass `currentUser`)
|
|
167
|
+
- [ ] Check if CrudService already provides needed functionality (create, find, findOne, update, delete, pagination)
|
|
168
|
+
|
|
169
|
+
## Configuration File & Commands
|
|
170
|
+
|
|
171
|
+
**📖 Complete guide: `configuration.md`**
|
|
172
|
+
|
|
173
|
+
**Quick Command Reference:**
|
|
174
|
+
```bash
|
|
175
|
+
# Create complete module
|
|
176
|
+
lt server module --name Product --controller Rest|GraphQL|Both|auto
|
|
177
|
+
|
|
178
|
+
# Create SubObject
|
|
179
|
+
lt server object --name Address
|
|
180
|
+
|
|
181
|
+
# Add properties
|
|
182
|
+
lt server addProp --type Module --element User
|
|
183
|
+
|
|
184
|
+
# New project
|
|
185
|
+
lt server create <server-name>
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**Essential Property Flags:**
|
|
189
|
+
- `--prop-name-X / --prop-type-X` - Name and type (string|number|boolean|ObjectId|Json|Date|bigint)
|
|
190
|
+
- `--prop-nullable-X` / `--prop-array-X` - Modifiers
|
|
191
|
+
- `--prop-enum-X / --prop-schema-X / --prop-reference-X` - Complex types
|
|
192
|
+
|
|
193
|
+
## Prerequisites Check
|
|
194
|
+
|
|
195
|
+
**Setup:**
|
|
196
|
+
```bash
|
|
197
|
+
lt --version # Check CLI installation
|
|
198
|
+
npm install -g @lenne.tech/cli # If needed
|
|
199
|
+
ls src/server/modules # Verify project structure
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Creating New Server:**
|
|
203
|
+
```bash
|
|
204
|
+
lt server create <server-name>
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Post-creation verification:** Check `src/config.env.ts` for replaced secrets and correct database URIs.
|
|
208
|
+
|
|
209
|
+
## Understanding the Specification Format
|
|
210
|
+
|
|
211
|
+
**📖 Complete reference and examples: `reference.md` and `examples.md`**
|
|
212
|
+
|
|
213
|
+
**Quick Type Reference:**
|
|
214
|
+
- Basic: `string`, `number`, `boolean`, `Date`, `bigint`, `Json`
|
|
215
|
+
- Arrays: `type[]` → add `--prop-array-X true`
|
|
216
|
+
- Optional: `property?: type` → add `--prop-nullable-X true`
|
|
217
|
+
- References: `User` → use `--prop-type-X ObjectId --prop-reference-X User`
|
|
218
|
+
- Embedded: `Address` → use `--prop-schema-X Address`
|
|
219
|
+
- Enums: `ENUM (VAL1, VAL2)` → use `--prop-enum-X PropertyNameEnum`
|
|
220
|
+
|
|
221
|
+
## Workflow Process
|
|
222
|
+
|
|
223
|
+
**📖 Complete details: `workflow-process.md`**
|
|
224
|
+
|
|
225
|
+
**7-Phase Workflow:**
|
|
226
|
+
1. Analysis & Planning → Parse spec, create todo list
|
|
227
|
+
2. SubObject Creation → Create in dependency order
|
|
228
|
+
3. Module Creation → Create with all properties
|
|
229
|
+
4. Inheritance Handling → Update extends, CreateInput must include parent fields
|
|
230
|
+
5. **Description Management** ⚠️ **CRITICAL** → Extract from comments, format as "ENGLISH (DEUTSCH)", apply everywhere
|
|
231
|
+
6. Enum File Creation → Manual creation in `src/server/common/enums/`
|
|
232
|
+
7. API Test Creation → **MANDATORY:** Analyze permissions first, use least privileged user, test failures
|
|
233
|
+
|
|
234
|
+
**Critical Testing Rules:**
|
|
235
|
+
- ✅ Test via REST/GraphQL using TestHelper (NEVER direct Service tests)
|
|
236
|
+
- ✅ Analyze @Roles decorators BEFORE writing tests
|
|
237
|
+
- ✅ Use appropriate user role (not admin when S_USER works)
|
|
238
|
+
- ✅ Test unauthorized access failures (401/403)
|
|
239
|
+
|
|
240
|
+
## Property Ordering
|
|
241
|
+
|
|
242
|
+
**ALL properties must be in alphabetical order** in Model, Input, and Output files. Verify and reorder after generating.
|
|
243
|
+
|
|
244
|
+
## Verification Checklist
|
|
245
|
+
|
|
246
|
+
**📖 Complete checklist: `verification-checklist.md`**
|
|
247
|
+
|
|
248
|
+
**Essential Checks:**
|
|
249
|
+
- [ ] All components created with descriptions (Model + CreateInput + UpdateInput)
|
|
250
|
+
- [ ] Properties in alphabetical order
|
|
251
|
+
- [ ] Permission analysis BEFORE writing tests
|
|
252
|
+
- [ ] Least privileged user used in tests
|
|
253
|
+
- [ ] Security validation tests (401/403 failures)
|
|
254
|
+
- [ ] All tests pass
|
|
255
|
+
|
|
256
|
+
## Error Handling
|
|
257
|
+
|
|
258
|
+
**Common Issues:**
|
|
259
|
+
- **TypeScript errors** → Add missing imports manually
|
|
260
|
+
- **CreateInput validation fails** → Check parent's CreateInput for required fields
|
|
261
|
+
- **Tests fail with 403** → Check @Roles decorator, use appropriate user role (not admin when S_USER works)
|
|
262
|
+
- **Security tests not failing** → Verify @Roles and securityCheck() logic, fix model/controller if needed
|
|
263
|
+
|
|
264
|
+
## Phase 8: Pre-Report Quality Review
|
|
265
|
+
|
|
266
|
+
**📖 Complete process: `quality-review.md`**
|
|
267
|
+
|
|
268
|
+
**7 Steps:**
|
|
269
|
+
1. Identify all changes (git)
|
|
270
|
+
2. Test management (analyze existing tests, create new, follow patterns)
|
|
271
|
+
3. Compare with existing code (consistency)
|
|
272
|
+
4. Critical analysis (style, structure, quality)
|
|
273
|
+
5. Automated optimizations (imports, properties, formatting)
|
|
274
|
+
6. Pre-report testing (build, lint, all tests must pass)
|
|
275
|
+
7. Final verification (complete checklist)
|
|
276
|
+
|
|
277
|
+
**Critical:** Understand TestHelper, analyze existing tests first, use appropriate user roles, all tests must pass.
|
|
278
|
+
|
|
279
|
+
## Final Report
|
|
280
|
+
|
|
281
|
+
After completing all tasks, provide:
|
|
282
|
+
1. Summary of created components (SubObjects, Objects, Modules, enums, tests)
|
|
283
|
+
2. Observations about data structure
|
|
284
|
+
3. Test results (all passing)
|
|
285
|
+
4. Next steps
|
|
286
|
+
|
|
287
|
+
## Best Practices
|
|
288
|
+
|
|
289
|
+
1. Create dependencies first (SubObjects before Modules)
|
|
290
|
+
2. Check for circular dependencies
|
|
291
|
+
3. Test incrementally, commit after major components
|
|
292
|
+
4. Use appropriate controller types (Rest/GraphQL/Both)
|
|
293
|
+
5. Validate required fields in tests
|
|
294
|
+
6. Document complex relationships
|
|
295
|
+
|
|
296
|
+
## Working with This Skill
|
|
297
|
+
|
|
298
|
+
When receiving a specification:
|
|
299
|
+
1. Parse completely, ask clarifying questions
|
|
300
|
+
2. Create detailed todo list
|
|
301
|
+
3. Execute systematically following workflow
|
|
302
|
+
4. Verify each step, report progress
|
|
303
|
+
5. Provide comprehensive summary
|
|
@@ -4,6 +4,12 @@ version: 1.0.0
|
|
|
4
4
|
description: Complete guide to lt.config.json configuration file
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
+
# Configuration Guide
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
- [Configuration File (lt.config.json)](#configuration-file-ltconfigjson)
|
|
11
|
+
- [Command Syntax Reference](#command-syntax-reference)
|
|
12
|
+
|
|
7
13
|
## Configuration File (lt.config.json)
|
|
8
14
|
|
|
9
15
|
The lenne.tech CLI supports project-level configuration via `lt.config.json` files. This allows you to set default values for commands, eliminating the need for repeated CLI parameters or interactive prompts.
|
|
@@ -6,6 +6,15 @@ description: Critical warning about using the declare keyword in TypeScript clas
|
|
|
6
6
|
|
|
7
7
|
# 🚨 CRITICAL: NEVER USE `declare` KEYWORD FOR PROPERTIES
|
|
8
8
|
|
|
9
|
+
## Table of Contents
|
|
10
|
+
- [WRONG - Using `declare`](#-wrong---using-declare)
|
|
11
|
+
- [CORRECT - Without `declare`](#-correct---without-declare)
|
|
12
|
+
- [Why This Matters](#why-this-matters)
|
|
13
|
+
- [When You Might Be Tempted to Use `declare`](#when-you-might-be-tempted-to-use-declare)
|
|
14
|
+
- [Correct Approach Instead](#correct-approach-instead)
|
|
15
|
+
- [Examples](#examples)
|
|
16
|
+
- [Remember](#remember)
|
|
17
|
+
|
|
9
18
|
**⚠️ IMPORTANT RULE: DO NOT use the `declare` keyword when defining properties in classes!**
|
|
10
19
|
|
|
11
20
|
The `declare` keyword in TypeScript signals that a property is only a type declaration without a runtime value. This prevents decorators from being properly applied and overridden.
|
|
@@ -6,6 +6,15 @@ description: Guidelines for consistent description management across all generat
|
|
|
6
6
|
|
|
7
7
|
# 🚨 CRITICAL: Description Management
|
|
8
8
|
|
|
9
|
+
## Table of Contents
|
|
10
|
+
- [Step 1: ALWAYS Extract Descriptions from User Input](#-step-1-always-extract-descriptions-from-user-input)
|
|
11
|
+
- [Step 2: Format Descriptions Correctly](#-step-2-format-descriptions-correctly)
|
|
12
|
+
- [Step 3: Apply Descriptions EVERYWHERE (Most Critical!)](#-step-3-apply-descriptions-everywhere-most-critical)
|
|
13
|
+
- [Common Mistakes to AVOID](#-common-mistakes-to-avoid)
|
|
14
|
+
- [Verification Checklist](#-verification-checklist)
|
|
15
|
+
- [If You Forget](#-if-you-forget)
|
|
16
|
+
- [Quick Reference](#quick-reference)
|
|
17
|
+
|
|
9
18
|
**⚠️ COMMON MISTAKE:** Descriptions are often applied inconsistently or only partially. You MUST follow this process for EVERY component.
|
|
10
19
|
|
|
11
20
|
---
|
package/build/templates/claude-skills/{nest-server-generator → generating-nest-servers}/examples.md
RENAMED
|
@@ -6,6 +6,13 @@ description: Complete examples for generating NestJS server structures from spec
|
|
|
6
6
|
|
|
7
7
|
# NestJS Server Generator Examples
|
|
8
8
|
|
|
9
|
+
## Table of Contents
|
|
10
|
+
- [Example 1: Library Management System](#example-1-library-management-system)
|
|
11
|
+
- [Example 2: Hotel Booking System (Minimal)](#example-2-hotel-booking-system-minimal)
|
|
12
|
+
- [Key Patterns Demonstrated](#key-patterns-demonstrated)
|
|
13
|
+
- [Best Practices from Examples](#best-practices-from-examples)
|
|
14
|
+
- [Quality Review Workflow Example](#quality-review-workflow-example)
|
|
15
|
+
|
|
9
16
|
## Example 1: Library Management System
|
|
10
17
|
|
|
11
18
|
This example demonstrates all features:
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: nest-server-generator-framework
|
|
3
|
+
version: 1.0.0
|
|
4
|
+
description: Complete guide to @lenne.tech/nest-server framework - CrudService base class, ServiceOptions handling, patterns for Service inheritance, and best practices for working with the framework
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# 📚 Understanding the @lenne.tech/nest-server Framework
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
- [Core Service Base Class: CrudService](#core-service-base-class-crudservice)
|
|
11
|
+
- [CRITICAL: ServiceOptions When Calling Other Services](#-critical-serviceoptions-when-calling-other-services)
|
|
12
|
+
- [Framework Patterns](#framework-patterns)
|
|
13
|
+
- [Key Takeaways](#key-takeaways)
|
|
14
|
+
|
|
15
|
+
## Core Service Base Class: CrudService
|
|
16
|
+
|
|
17
|
+
**IMPORTANT**: Before working with Services, ALWAYS read this file to understand the base functionality:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
node_modules/@lenne.tech/nest-server/src/core/common/services/crud.service.ts
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Why this is critical:**
|
|
24
|
+
- Almost ALL Services extend `CrudService<Model>`
|
|
25
|
+
- CrudService provides base CRUD operations (create, find, update, delete)
|
|
26
|
+
- Understanding CrudService prevents reinventing the wheel
|
|
27
|
+
- Shows patterns for handling permissions, filtering, and pagination
|
|
28
|
+
|
|
29
|
+
**When to read CrudService:**
|
|
30
|
+
1. ✅ Before creating a new Service
|
|
31
|
+
2. ✅ When implementing custom Service methods
|
|
32
|
+
3. ✅ When debugging Service behavior
|
|
33
|
+
4. ✅ When writing tests for Services
|
|
34
|
+
5. ✅ When questions arise about Service functionality
|
|
35
|
+
|
|
36
|
+
**What CrudService provides:**
|
|
37
|
+
- `create(input, options)` - Create new document
|
|
38
|
+
- `find(filterArgs)` - Find multiple documents
|
|
39
|
+
- `findOne(filterArgs)` - Find single document
|
|
40
|
+
- `findAndCount(filterArgs)` - Find with total count (pagination)
|
|
41
|
+
- `update(id, input, options)` - Update document
|
|
42
|
+
- `delete(id, options)` - Delete document
|
|
43
|
+
- Permission handling via `options.roles`
|
|
44
|
+
- Query filtering and population
|
|
45
|
+
- Pagination support
|
|
46
|
+
|
|
47
|
+
**Example Service that extends CrudService:**
|
|
48
|
+
```typescript
|
|
49
|
+
@Injectable()
|
|
50
|
+
export class ProductService extends CrudService<Product> {
|
|
51
|
+
constructor(
|
|
52
|
+
@InjectModel(Product.name) protected readonly productModel: Model<ProductDocument>,
|
|
53
|
+
protected readonly configService: ConfigService,
|
|
54
|
+
) {
|
|
55
|
+
super({ configService, mainDbModel: productModel, mainModelConstructor: Product });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Custom methods can be added here
|
|
59
|
+
// Base CRUD methods are inherited from CrudService
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Action Items:**
|
|
64
|
+
- [ ] Read CrudService before modifying any Service
|
|
65
|
+
- [ ] Check if CrudService already provides the needed functionality
|
|
66
|
+
- [ ] Only add custom methods if CrudService doesn't cover the use case
|
|
67
|
+
- [ ] Follow CrudService patterns for consistency
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 🚨 CRITICAL: ServiceOptions When Calling Other Services
|
|
72
|
+
|
|
73
|
+
**NEVER blindly pass all ServiceOptions when calling another Service!**
|
|
74
|
+
|
|
75
|
+
When a Service method calls another Service, you must carefully analyze which options to pass:
|
|
76
|
+
|
|
77
|
+
### ❌ WRONG - Blindly passing all options
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
async createOrder(input: CreateOrderInput, serviceOptions: ServiceOptions) {
|
|
81
|
+
// ❌ BAD: Passes ALL serviceOptions without checking
|
|
82
|
+
const product = await this.productService.findOne({ id: input.productId }, serviceOptions);
|
|
83
|
+
|
|
84
|
+
// ❌ BAD: inputType might be wrong for userService
|
|
85
|
+
const user = await this.userService.findOne({ id: input.userId }, serviceOptions);
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### ✅ CORRECT - Selectively passing required options
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
async createOrder(input: CreateOrderInput, serviceOptions: ServiceOptions) {
|
|
93
|
+
// ✅ GOOD: Only pass currentUser (needed for permissions)
|
|
94
|
+
const product = await this.productService.findOne(
|
|
95
|
+
{ id: input.productId },
|
|
96
|
+
{ currentUser: serviceOptions.currentUser }
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// ✅ GOOD: Only set inputType if different Input class is needed
|
|
100
|
+
const user = await this.userService.findOne(
|
|
101
|
+
{ id: input.userId },
|
|
102
|
+
{
|
|
103
|
+
currentUser: serviceOptions.currentUser,
|
|
104
|
+
inputType: UserInput // Only if specific Input class needed (e.g., UserInput, UserInputCreate)
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
// ✅ ALSO GOOD: Don't pass inputType if not needed
|
|
109
|
+
const category = await this.categoryService.findOne(
|
|
110
|
+
{ id: input.categoryId },
|
|
111
|
+
{ currentUser: serviceOptions.currentUser } // No inputType - use default
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Why this is critical
|
|
117
|
+
|
|
118
|
+
- **inputType** specifies which Input class (DTO) to use for validation (e.g., `UserInput`, `UserInputCreate`)
|
|
119
|
+
- The inputType from outer service might be wrong for inner service call
|
|
120
|
+
- **roles** might need to be different for the called service
|
|
121
|
+
- **Other options** (limit, skip, etc.) might not apply to the inner call
|
|
122
|
+
- Blindly passing options can cause **incorrect permission checks** or **wrong validation**
|
|
123
|
+
- Can lead to **unexpected behavior** in nested service calls
|
|
124
|
+
|
|
125
|
+
### Analysis Checklist Before Passing ServiceOptions
|
|
126
|
+
|
|
127
|
+
1. **Analyze current serviceOptions:**
|
|
128
|
+
```typescript
|
|
129
|
+
// What's in serviceOptions right now?
|
|
130
|
+
// - currentUser? (usually needed)
|
|
131
|
+
// - inputType? (which Input class: UserInput, UserInputCreate, etc.?)
|
|
132
|
+
// - roles? (are these the right roles?)
|
|
133
|
+
// - other options? (limit, skip, populate, etc.)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
2. **Check target Service requirements:**
|
|
137
|
+
- What does the target Service method need?
|
|
138
|
+
- Read the target Service method signature
|
|
139
|
+
- Check what permissions/validations it performs
|
|
140
|
+
- Understand which Input class (inputType) is appropriate
|
|
141
|
+
|
|
142
|
+
3. **Pass only required options:**
|
|
143
|
+
```typescript
|
|
144
|
+
// Build options object with only what's needed
|
|
145
|
+
const targetOptions: ServiceOptions = {
|
|
146
|
+
currentUser: serviceOptions.currentUser, // Usually needed
|
|
147
|
+
// inputType: Only set if specific Input class is needed (e.g., UserInput, UserInputCreate)!
|
|
148
|
+
// roles: Only if different roles are needed
|
|
149
|
+
// Don't include: limit, skip, etc. unless specifically needed
|
|
150
|
+
};
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Common Patterns
|
|
154
|
+
|
|
155
|
+
- **Reading data for validation**: Usually only need `currentUser` (no inputType needed)
|
|
156
|
+
- **Creating related entities**: May need different Input class as inputType (e.g., `UserInputCreate` instead of `UserInput`)
|
|
157
|
+
- **Admin operations**: May need to override `roles` or set specific Input class (only if necessary)
|
|
158
|
+
- **Nested CRUD operations**: Carefully consider each option - often only currentUser needed
|
|
159
|
+
|
|
160
|
+
### Action Items
|
|
161
|
+
|
|
162
|
+
- [ ] Before calling another Service, analyze current serviceOptions
|
|
163
|
+
- [ ] Determine which options the target Service actually needs
|
|
164
|
+
- [ ] Only pass required options (usually just currentUser)
|
|
165
|
+
- [ ] Only set inputType if a specific Input class (DTO) is needed (e.g., UserInput, UserInputCreate)
|
|
166
|
+
- [ ] NEVER blindly pass all serviceOptions
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Framework Patterns
|
|
171
|
+
|
|
172
|
+
### Service Inheritance Pattern
|
|
173
|
+
|
|
174
|
+
All Services follow this pattern:
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
@Injectable()
|
|
178
|
+
export class YourService extends CrudService<YourModel> {
|
|
179
|
+
constructor(
|
|
180
|
+
@InjectModel(YourModel.name) protected readonly yourModel: Model<YourModelDocument>,
|
|
181
|
+
protected readonly configService: ConfigService,
|
|
182
|
+
// Inject other services if needed
|
|
183
|
+
private readonly otherService: OtherService,
|
|
184
|
+
) {
|
|
185
|
+
super({
|
|
186
|
+
configService,
|
|
187
|
+
mainDbModel: yourModel,
|
|
188
|
+
mainModelConstructor: YourModel
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Add custom methods here
|
|
193
|
+
async customMethod(input: SomeInput, serviceOptions?: ServiceOptions) {
|
|
194
|
+
// Your custom logic
|
|
195
|
+
// Can call base methods: this.create(), this.find(), etc.
|
|
196
|
+
// Can call other services with proper ServiceOptions handling
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Controller/Resolver Pattern
|
|
202
|
+
|
|
203
|
+
Controllers and Resolvers use Services:
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
@Controller('api/products')
|
|
207
|
+
export class ProductController {
|
|
208
|
+
constructor(private readonly productService: ProductService) {}
|
|
209
|
+
|
|
210
|
+
@Get()
|
|
211
|
+
@Roles(RoleEnum.S_USER)
|
|
212
|
+
async getProducts(@CurrentUser() user: User) {
|
|
213
|
+
return this.productService.find({ currentUser: user });
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
@Post()
|
|
217
|
+
@Roles(RoleEnum.S_USER)
|
|
218
|
+
async createProduct(
|
|
219
|
+
@Body() input: ProductCreateInput,
|
|
220
|
+
@CurrentUser() user: User
|
|
221
|
+
) {
|
|
222
|
+
return this.productService.create(input, { currentUser: user });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Permission Handling Pattern
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
// In Model
|
|
231
|
+
export class Product extends CoreModel {
|
|
232
|
+
securityCheck(user: User, force?: boolean) {
|
|
233
|
+
if (force || user?.hasRole(RoleEnum.ADMIN)) {
|
|
234
|
+
return this; // Admin sees all
|
|
235
|
+
}
|
|
236
|
+
if (!equalIds(user, this.createdBy)) {
|
|
237
|
+
return undefined; // Non-creator gets nothing
|
|
238
|
+
}
|
|
239
|
+
return this; // Creator sees own products
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// In Service
|
|
244
|
+
async customMethod(input: Input, serviceOptions?: ServiceOptions) {
|
|
245
|
+
// CrudService automatically applies securityCheck
|
|
246
|
+
const results = await this.find({ currentUser: serviceOptions.currentUser });
|
|
247
|
+
// Only products passing securityCheck are returned
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## Key Takeaways
|
|
254
|
+
|
|
255
|
+
1. **Always read CrudService first** - Understand what's already provided
|
|
256
|
+
2. **Never blindly pass ServiceOptions** - Analyze and pass only what's needed
|
|
257
|
+
3. **Follow framework patterns** - Inherit from CrudService, use proper decorators
|
|
258
|
+
4. **Understand permission flow** - securityCheck + serviceOptions.currentUser + @Roles
|
|
259
|
+
5. **inputType is the Input CLASS** - Not an enum, but the actual DTO class (e.g., UserInput, UserInputCreate)
|
|
@@ -6,6 +6,15 @@ description: Comprehensive quality review guidelines before creating final repor
|
|
|
6
6
|
|
|
7
7
|
# Phase 8: Pre-Report Quality Review
|
|
8
8
|
|
|
9
|
+
## Table of Contents
|
|
10
|
+
- [Step 1: Identify All Changes](#step-1-identify-all-changes)
|
|
11
|
+
- [Step 2: Test Management](#step-2-test-management)
|
|
12
|
+
- [Step 3: Compare with Existing Code](#step-3-compare-with-existing-code)
|
|
13
|
+
- [Step 4: Critical Analysis](#step-4-critical-analysis)
|
|
14
|
+
- [Step 5: Automated Optimizations](#step-5-automated-optimizations)
|
|
15
|
+
- [Step 6: Pre-Report Testing](#step-6-pre-report-testing)
|
|
16
|
+
- [Step 7: Final Verification](#step-7-final-verification)
|
|
17
|
+
|
|
9
18
|
**CRITICAL**: Before creating the final report, you MUST perform a comprehensive quality review:
|
|
10
19
|
|
|
11
20
|
## Step 1: Identify All Changes
|
package/build/templates/claude-skills/{nest-server-generator → generating-nest-servers}/reference.md
RENAMED
|
@@ -6,6 +6,22 @@ description: Quick reference for ALL NestJS server development - from simple sin
|
|
|
6
6
|
|
|
7
7
|
# NestJS Server Development Quick Reference
|
|
8
8
|
|
|
9
|
+
## Table of Contents
|
|
10
|
+
- [Scope](#scope)
|
|
11
|
+
- [Specification Syntax](#specification-syntax)
|
|
12
|
+
- [Execution Workflow](#execution-workflow)
|
|
13
|
+
- [Command Quick Reference](#command-quick-reference)
|
|
14
|
+
- [Description Format](#description-format)
|
|
15
|
+
- [Inheritance Handling](#inheritance-handling)
|
|
16
|
+
- [Enum File Template](#enum-file-template)
|
|
17
|
+
- [API Test Template](#api-test-template)
|
|
18
|
+
- [Common Patterns](#common-patterns)
|
|
19
|
+
- [Troubleshooting](#troubleshooting)
|
|
20
|
+
- [Verification Checklist](#verification-checklist)
|
|
21
|
+
- [File Structure](#file-structure)
|
|
22
|
+
- [Best Practices Summary](#best-practices-summary)
|
|
23
|
+
- [Quick Start](#quick-start)
|
|
24
|
+
|
|
9
25
|
## Scope
|
|
10
26
|
|
|
11
27
|
**This skill handles ALL NestJS server development tasks:**
|
|
@@ -6,6 +6,19 @@ description: Critical security and test coverage rules for NestJS development
|
|
|
6
6
|
|
|
7
7
|
# 🚨 CRITICAL SECURITY RULES
|
|
8
8
|
|
|
9
|
+
## Table of Contents
|
|
10
|
+
- [NEVER Do This](#-never-do-this)
|
|
11
|
+
- [ALWAYS Do This](#-always-do-this)
|
|
12
|
+
- [Permission Hierarchy (Specific Overrides General)](#-permission-hierarchy-specific-overrides-general)
|
|
13
|
+
- [Rule 1: NEVER Weaken Security for Test Convenience](#rule-1-never-weaken-security-for-test-convenience)
|
|
14
|
+
- [Rule 2: Understanding Permission Hierarchy](#rule-2-understanding-permission-hierarchy)
|
|
15
|
+
- [Rule 3: Adapt Tests to Security, Not Vice Versa](#rule-3-adapt-tests-to-security-not-vice-versa)
|
|
16
|
+
- [Rule 4: Test with Least Privileged User](#rule-4-test-with-least-privileged-user)
|
|
17
|
+
- [Rule 5: Create Appropriate Test Users](#rule-5-create-appropriate-test-users)
|
|
18
|
+
- [Rule 6: Comprehensive Test Coverage](#rule-6-comprehensive-test-coverage)
|
|
19
|
+
- [Quick Security Checklist](#quick-security-checklist)
|
|
20
|
+
- [Security Decision Protocol](#security-decision-protocol)
|
|
21
|
+
|
|
9
22
|
**Before you start ANY work, understand these NON-NEGOTIABLE rules.**
|
|
10
23
|
|
|
11
24
|
---
|