@smicolon/ai-kit 0.1.0 → 0.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/.claude-plugin/CLAUDE.md +7 -0
- package/.claude-plugin/marketplace.json +373 -0
- package/README.md +26 -16
- package/dist/index.js +146 -38
- package/package.json +4 -3
- package/packs/architect/CHANGELOG.md +17 -0
- package/packs/architect/README.md +58 -0
- package/packs/architect/agents/system-architect.md +768 -0
- package/packs/architect/commands/diagram-create.md +300 -0
- package/packs/better-auth/.claude-plugin/plugin.json +14 -0
- package/packs/better-auth/.mcp.json +14 -0
- package/packs/better-auth/CHANGELOG.md +26 -0
- package/packs/better-auth/README.md +125 -0
- package/packs/better-auth/agents/auth-architect.md +278 -0
- package/packs/better-auth/commands/auth-provider-add.md +265 -0
- package/packs/better-auth/commands/auth-setup.md +298 -0
- package/packs/better-auth/skills/auth-security/SKILL.md +425 -0
- package/packs/better-auth/skills/better-auth-patterns/SKILL.md +455 -0
- package/packs/dev-loop/.claude-plugin/plugin.json +10 -0
- package/packs/dev-loop/CHANGELOG.md +69 -0
- package/packs/dev-loop/README.md +155 -0
- package/packs/dev-loop/commands/cancel-dev.md +21 -0
- package/packs/dev-loop/commands/dev-loop.md +72 -0
- package/packs/dev-loop/commands/dev-plan.md +351 -0
- package/packs/dev-loop/hooks/hooks.json +15 -0
- package/packs/dev-loop/hooks/stop-hook.sh +178 -0
- package/packs/dev-loop/scripts/setup-dev-loop.sh +194 -0
- package/packs/dev-loop/skills/tdd-planner/SKILL.md +249 -0
- package/packs/dev-loop/skills/tdd-planner/references/framework-patterns.md +874 -0
- package/packs/dev-loop/skills/tdd-planner/references/good-example.md +260 -0
- package/packs/dev-loop/skills/tdd-planner/references/plan-template.md +275 -0
- package/packs/django/CHANGELOG.md +39 -0
- package/packs/django/README.md +92 -0
- package/packs/django/agents/django-architect.md +182 -0
- package/packs/django/agents/django-builder.md +250 -0
- package/packs/django/agents/django-feature-based.md +420 -0
- package/packs/django/agents/django-reviewer.md +253 -0
- package/packs/django/agents/django-tester.md +230 -0
- package/packs/django/commands/api-endpoint.md +285 -0
- package/packs/django/commands/model-create.md +178 -0
- package/packs/django/commands/test-generate.md +325 -0
- package/packs/django/rules/migrations.md +138 -0
- package/packs/django/rules/models.md +167 -0
- package/packs/django/rules/serializers.md +126 -0
- package/packs/django/rules/services.md +131 -0
- package/packs/django/rules/tests.md +140 -0
- package/packs/django/rules/views.md +102 -0
- package/packs/django/skills/import-convention-enforcer/SKILL.md +226 -0
- package/packs/django/skills/import-convention-enforcer/patterns/django-imports.md +343 -0
- package/packs/django/skills/migration-safety-checker/SKILL.md +375 -0
- package/packs/django/skills/model-entity-validator/SKILL.md +298 -0
- package/packs/django/skills/performance-optimizer/SKILL.md +447 -0
- package/packs/django/skills/red-phase-verifier/SKILL.md +180 -0
- package/packs/django/skills/security-first-validator/SKILL.md +435 -0
- package/packs/django/skills/test-coverage-advisor/SKILL.md +394 -0
- package/packs/django/skills/test-validity-checker/SKILL.md +194 -0
- package/packs/failure-log/.claude-plugin/plugin.json +14 -0
- package/packs/failure-log/CHANGELOG.md +20 -0
- package/packs/failure-log/README.md +168 -0
- package/packs/failure-log/commands/failure-add.md +106 -0
- package/packs/failure-log/commands/failure-list.md +89 -0
- package/packs/failure-log/hooks/hooks.json +16 -0
- package/packs/failure-log/hooks/scripts/inject-failures.sh +64 -0
- package/packs/failure-log/skills/failure-log-manager/SKILL.md +164 -0
- package/packs/flutter/.claude-plugin/plugin.json +10 -0
- package/packs/flutter/CHANGELOG.md +19 -0
- package/packs/flutter/README.md +170 -0
- package/packs/flutter/agents/flutter-architect.md +166 -0
- package/packs/flutter/agents/flutter-builder.md +303 -0
- package/packs/flutter/agents/release-manager.md +355 -0
- package/packs/flutter/commands/fastlane-setup.md +188 -0
- package/packs/flutter/commands/flutter-build.md +90 -0
- package/packs/flutter/commands/flutter-deploy.md +133 -0
- package/packs/flutter/commands/flutter-test.md +117 -0
- package/packs/flutter/commands/signing-setup.md +209 -0
- package/packs/flutter/hooks/hooks.json +17 -0
- package/packs/flutter/skills/fastlane-knowledge/SKILL.md +193 -0
- package/packs/flutter/skills/flutter-architecture/SKILL.md +127 -0
- package/packs/flutter/skills/store-publishing/SKILL.md +163 -0
- package/packs/hono/.claude-plugin/plugin.json +19 -0
- package/packs/hono/CHANGELOG.md +19 -0
- package/packs/hono/README.md +143 -0
- package/packs/hono/agents/hono-architect.md +240 -0
- package/packs/hono/agents/hono-builder.md +285 -0
- package/packs/hono/agents/hono-reviewer.md +279 -0
- package/packs/hono/agents/hono-tester.md +346 -0
- package/packs/hono/commands/middleware-create.md +223 -0
- package/packs/hono/commands/project-init.md +306 -0
- package/packs/hono/commands/route-create.md +153 -0
- package/packs/hono/commands/rpc-client.md +263 -0
- package/packs/hono/hooks/hooks.json +4 -0
- package/packs/hono/skills/cloudflare-bindings/SKILL.md +408 -0
- package/packs/hono/skills/hono-patterns/SKILL.md +309 -0
- package/packs/hono/skills/rpc-typesafe/SKILL.md +388 -0
- package/packs/hono/skills/zod-validation/SKILL.md +332 -0
- package/packs/nestjs/CHANGELOG.md +29 -0
- package/packs/nestjs/README.md +75 -0
- package/packs/nestjs/agents/nestjs-architect.md +402 -0
- package/packs/nestjs/agents/nestjs-builder.md +301 -0
- package/packs/nestjs/agents/nestjs-tester.md +437 -0
- package/packs/nestjs/commands/module-create.md +369 -0
- package/packs/nestjs/rules/controllers.md +92 -0
- package/packs/nestjs/rules/dto.md +124 -0
- package/packs/nestjs/rules/entities.md +102 -0
- package/packs/nestjs/rules/services.md +106 -0
- package/packs/nestjs/skills/barrel-export-manager/SKILL.md +389 -0
- package/packs/nestjs/skills/import-convention-enforcer/SKILL.md +365 -0
- package/packs/nextjs/CHANGELOG.md +36 -0
- package/packs/nextjs/README.md +76 -0
- package/packs/nextjs/agents/frontend-tester.md +680 -0
- package/packs/nextjs/agents/frontend-visual.md +820 -0
- package/packs/nextjs/agents/nextjs-architect.md +331 -0
- package/packs/nextjs/agents/nextjs-modular.md +433 -0
- package/packs/nextjs/commands/component-create.md +398 -0
- package/packs/nextjs/rules/api-routes.md +129 -0
- package/packs/nextjs/rules/components.md +106 -0
- package/packs/nextjs/rules/hooks.md +132 -0
- package/packs/nextjs/skills/accessibility-validator/SKILL.md +445 -0
- package/packs/nextjs/skills/import-convention-enforcer/SKILL.md +399 -0
- package/packs/nextjs/skills/react-form-validator/SKILL.md +569 -0
- package/packs/nuxtjs/CHANGELOG.md +30 -0
- package/packs/nuxtjs/README.md +56 -0
- package/packs/nuxtjs/agents/frontend-tester.md +680 -0
- package/packs/nuxtjs/agents/frontend-visual.md +820 -0
- package/packs/nuxtjs/agents/nuxtjs-architect.md +537 -0
- package/packs/nuxtjs/commands/component-create.md +223 -0
- package/packs/nuxtjs/rules/components.md +101 -0
- package/packs/nuxtjs/rules/composables.md +118 -0
- package/packs/nuxtjs/rules/server-routes.md +127 -0
- package/packs/nuxtjs/skills/accessibility-validator/SKILL.md +183 -0
- package/packs/nuxtjs/skills/import-convention-enforcer/SKILL.md +196 -0
- package/packs/nuxtjs/skills/veevalidate-form-validator/SKILL.md +190 -0
- package/packs/onboard/CHANGELOG.md +22 -0
- package/packs/onboard/README.md +103 -0
- package/packs/onboard/agents/onboard-guide.md +118 -0
- package/packs/onboard/commands/onboard.md +313 -0
- package/packs/onboard/skills/onboard-context-provider/SKILL.md +98 -0
- package/packs/tanstack-router/.claude-plugin/plugin.json +14 -0
- package/packs/tanstack-router/CHANGELOG.md +30 -0
- package/packs/tanstack-router/README.md +113 -0
- package/packs/tanstack-router/agents/tanstack-architect.md +173 -0
- package/packs/tanstack-router/agents/tanstack-builder.md +360 -0
- package/packs/tanstack-router/agents/tanstack-tester.md +454 -0
- package/packs/tanstack-router/commands/form-create.md +313 -0
- package/packs/tanstack-router/commands/query-create.md +263 -0
- package/packs/tanstack-router/commands/route-create.md +190 -0
- package/packs/tanstack-router/commands/table-create.md +413 -0
- package/packs/tanstack-router/skills/ai-patterns/SKILL.md +370 -0
- package/packs/tanstack-router/skills/db-patterns/SKILL.md +346 -0
- package/packs/tanstack-router/skills/devtools-patterns/SKILL.md +415 -0
- package/packs/tanstack-router/skills/form-patterns/SKILL.md +425 -0
- package/packs/tanstack-router/skills/pacer-patterns/SKILL.md +341 -0
- package/packs/tanstack-router/skills/query-patterns/SKILL.md +359 -0
- package/packs/tanstack-router/skills/router-patterns/SKILL.md +285 -0
- package/packs/tanstack-router/skills/store-patterns/SKILL.md +351 -0
- package/packs/tanstack-router/skills/table-patterns/SKILL.md +531 -0
- package/packs/tanstack-router/skills/tanstack-conventions/SKILL.md +428 -0
- package/packs/tanstack-router/skills/virtual-patterns/SKILL.md +490 -0
- package/packs/worktree/.claude-plugin/plugin.json +19 -0
- package/packs/worktree/CHANGELOG.md +24 -0
- package/packs/worktree/README.md +110 -0
- package/packs/worktree/commands/wt.md +73 -0
- package/packs/worktree/scripts/wt.sh +396 -0
- package/packs/worktree/skills/worktree-manager/SKILL.md +68 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the smi-nestjs plugin will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
- Renamed from `smi-nestjs` to `nestjs` as part of ai-kit migration
|
|
9
|
+
- Moved from `plugins/smi-nestjs/` to `packs/nestjs/`
|
|
10
|
+
|
|
11
|
+
## [2.1.0] - 2025-01-02
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- 2 auto-enforcing skills
|
|
15
|
+
- `barrel-export-manager` - Auto-creates index.ts exports
|
|
16
|
+
- `import-convention-enforcer` - Absolute imports from barrels
|
|
17
|
+
|
|
18
|
+
## [2.0.0] - 2024-12-01
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
- BREAKING: Updated import conventions to use barrel exports
|
|
22
|
+
- Standardized entity patterns with UUID primary keys
|
|
23
|
+
|
|
24
|
+
## [1.0.0] - 2024-10-01
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
- Initial stable release
|
|
28
|
+
- 3 agents: architect, builder, tester
|
|
29
|
+
- 1 command: module-create
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# NestJS Development Standards Plugin
|
|
2
|
+
|
|
3
|
+
Smicolon company standards for NestJS/TypeScript backend projects.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Add Smicolon marketplace
|
|
9
|
+
/plugin marketplace add https://github.com/smicolon/ai-kit
|
|
10
|
+
|
|
11
|
+
# Install NestJS plugin
|
|
12
|
+
/plugin install nestjs
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## What's Included
|
|
16
|
+
|
|
17
|
+
### 3 Specialized Agents
|
|
18
|
+
|
|
19
|
+
- `@nestjs-architect` - Backend architecture design and planning
|
|
20
|
+
- `@nestjs-builder` - Feature implementation with NestJS best practices
|
|
21
|
+
- `@nestjs-tester` - Test writing for NestJS applications
|
|
22
|
+
|
|
23
|
+
### 2 Auto-Enforcing Skills (NEW!)
|
|
24
|
+
|
|
25
|
+
Skills automatically activate based on context - no manual invocation needed:
|
|
26
|
+
|
|
27
|
+
**Code Organization:**
|
|
28
|
+
- `barrel-export-manager` - Auto-creates/maintains index.ts barrel exports in all module directories
|
|
29
|
+
- `import-convention-enforcer` - Auto-fixes imports to use absolute paths from barrel exports
|
|
30
|
+
|
|
31
|
+
**How Skills Work:**
|
|
32
|
+
- Auto-invoke when creating entities, DTOs, services, or importing modules
|
|
33
|
+
- Automatically create index.ts files with proper exports
|
|
34
|
+
- Convert relative imports to absolute barrel imports
|
|
35
|
+
- Maintain clean, organized module structure
|
|
36
|
+
- Work alongside agents for complete code quality
|
|
37
|
+
|
|
38
|
+
### Automatic Convention Enforcement
|
|
39
|
+
|
|
40
|
+
**Import Pattern:**
|
|
41
|
+
```typescript
|
|
42
|
+
// CORRECT - Absolute imports from barrel exports
|
|
43
|
+
import { User } from 'src/users/entities'
|
|
44
|
+
import { UsersService } from 'src/users/services'
|
|
45
|
+
import { CreateUserDto } from 'src/users/dto'
|
|
46
|
+
|
|
47
|
+
// WRONG - Relative imports
|
|
48
|
+
import { User } from './entities/user.entity'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Entity Standards:**
|
|
52
|
+
- UUID primary keys
|
|
53
|
+
- Timestamps (createdAt, updatedAt)
|
|
54
|
+
- Soft deletes (deletedAt)
|
|
55
|
+
- DTOs with class-validator
|
|
56
|
+
- Dependency injection
|
|
57
|
+
- Guards on protected routes
|
|
58
|
+
- Barrel exports (index.ts) in all folders
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Design architecture
|
|
64
|
+
@nestjs-architect "Design a REST API for inventory management"
|
|
65
|
+
|
|
66
|
+
# Implement features
|
|
67
|
+
@nestjs-builder "Implement inventory API endpoints"
|
|
68
|
+
|
|
69
|
+
# Write tests
|
|
70
|
+
@nestjs-tester "Write tests for inventory module"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Documentation
|
|
74
|
+
|
|
75
|
+
See the main [Smicolon Claude Infra repository](https://github.com/smicolon/ai-kit) for complete documentation.
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: nestjs-architect
|
|
3
|
+
description: Senior NestJS architect for designing TypeScript backend architecture with TypeORM and absolute imports
|
|
4
|
+
model: inherit
|
|
5
|
+
skills:
|
|
6
|
+
- barrel-export-manager
|
|
7
|
+
- import-convention-enforcer
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# NestJS Architect - Smicolon
|
|
11
|
+
|
|
12
|
+
You are a senior NestJS architect specializing in TypeScript backend development.
|
|
13
|
+
|
|
14
|
+
## Current Task
|
|
15
|
+
Provide architectural guidance for NestJS backend development following Smicolon conventions.
|
|
16
|
+
|
|
17
|
+
## Smicolon NestJS Stack
|
|
18
|
+
- **Framework**: NestJS (latest)
|
|
19
|
+
- **Language**: TypeScript (strict mode)
|
|
20
|
+
- **Database**: TypeORM or Prisma
|
|
21
|
+
- **Validation**: class-validator + class-transformer
|
|
22
|
+
- **Authentication**: JWT + Passport
|
|
23
|
+
- **Testing**: Jest
|
|
24
|
+
- **Documentation**: Swagger/OpenAPI
|
|
25
|
+
|
|
26
|
+
## Architecture Principles
|
|
27
|
+
|
|
28
|
+
### 1. Import Pattern (CRITICAL)
|
|
29
|
+
|
|
30
|
+
**ALWAYS use absolute imports from barrel exports:**
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
// ✅ CORRECT - Absolute imports from index files
|
|
34
|
+
import { User } from 'src/users/entities'
|
|
35
|
+
import { UsersService } from 'src/users/services'
|
|
36
|
+
import { CreateUserDto, UpdateUserDto } from 'src/users/dto'
|
|
37
|
+
import { JwtAuthGuard } from 'src/auth/guards'
|
|
38
|
+
|
|
39
|
+
// ❌ WRONG - Never use relative imports
|
|
40
|
+
import { User } from './entities/user.entity'
|
|
41
|
+
import { CreateUserDto } from '../dto/create-user.dto'
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 2. NestJS Module Structure
|
|
45
|
+
|
|
46
|
+
**Standard Module Organization:**
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
src/
|
|
50
|
+
├── main.ts
|
|
51
|
+
├── app.module.ts
|
|
52
|
+
├── users/ # Feature module
|
|
53
|
+
│ ├── users.module.ts
|
|
54
|
+
│ ├── entities/
|
|
55
|
+
│ │ ├── index.ts # Export all entities
|
|
56
|
+
│ │ └── user.entity.ts
|
|
57
|
+
│ ├── dto/
|
|
58
|
+
│ │ ├── index.ts # Export all DTOs
|
|
59
|
+
│ │ ├── create-user.dto.ts
|
|
60
|
+
│ │ └── update-user.dto.ts
|
|
61
|
+
│ ├── services/
|
|
62
|
+
│ │ ├── index.ts # Export all services
|
|
63
|
+
│ │ └── users.service.ts
|
|
64
|
+
│ ├── controllers/
|
|
65
|
+
│ │ ├── index.ts
|
|
66
|
+
│ │ └── users.controller.ts
|
|
67
|
+
│ └── __tests__/
|
|
68
|
+
├── auth/ # Auth module
|
|
69
|
+
│ ├── auth.module.ts
|
|
70
|
+
│ ├── guards/
|
|
71
|
+
│ ├── strategies/
|
|
72
|
+
│ └── services/
|
|
73
|
+
└── common/ # Shared utilities
|
|
74
|
+
├── decorators/
|
|
75
|
+
├── filters/
|
|
76
|
+
├── interceptors/
|
|
77
|
+
└── pipes/
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 3. Entity Pattern (TypeORM)
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
// src/users/entities/user.entity.ts
|
|
84
|
+
import {
|
|
85
|
+
Entity,
|
|
86
|
+
PrimaryGeneratedColumn,
|
|
87
|
+
Column,
|
|
88
|
+
CreateDateColumn,
|
|
89
|
+
UpdateDateColumn,
|
|
90
|
+
DeleteDateColumn,
|
|
91
|
+
} from 'typeorm'
|
|
92
|
+
import { Exclude } from 'class-transformer'
|
|
93
|
+
|
|
94
|
+
@Entity('users')
|
|
95
|
+
export class User {
|
|
96
|
+
@PrimaryGeneratedColumn('uuid')
|
|
97
|
+
id: string
|
|
98
|
+
|
|
99
|
+
@Column({ unique: true })
|
|
100
|
+
email: string
|
|
101
|
+
|
|
102
|
+
@Column()
|
|
103
|
+
@Exclude() // Don't expose in responses
|
|
104
|
+
password: string
|
|
105
|
+
|
|
106
|
+
@Column({ nullable: true })
|
|
107
|
+
firstName: string
|
|
108
|
+
|
|
109
|
+
@Column({ nullable: true })
|
|
110
|
+
lastName: string
|
|
111
|
+
|
|
112
|
+
@CreateDateColumn()
|
|
113
|
+
createdAt: Date
|
|
114
|
+
|
|
115
|
+
@UpdateDateColumn()
|
|
116
|
+
updatedAt: Date
|
|
117
|
+
|
|
118
|
+
@DeleteDateColumn() // Soft delete
|
|
119
|
+
deletedAt?: Date
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/users/entities/index.ts
|
|
123
|
+
export * from './user.entity'
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 4. DTO Pattern (Validation)
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
// src/users/dto/create-user.dto.ts
|
|
130
|
+
import { IsEmail, IsString, MinLength, IsOptional } from 'class-validator'
|
|
131
|
+
import { ApiProperty } from '@nestjs/swagger'
|
|
132
|
+
|
|
133
|
+
export class CreateUserDto {
|
|
134
|
+
@ApiProperty({ example: 'user@example.com' })
|
|
135
|
+
@IsEmail()
|
|
136
|
+
email: string
|
|
137
|
+
|
|
138
|
+
@ApiProperty({ minLength: 8 })
|
|
139
|
+
@IsString()
|
|
140
|
+
@MinLength(8)
|
|
141
|
+
password: string
|
|
142
|
+
|
|
143
|
+
@ApiProperty({ required: false })
|
|
144
|
+
@IsString()
|
|
145
|
+
@IsOptional()
|
|
146
|
+
firstName?: string
|
|
147
|
+
|
|
148
|
+
@ApiProperty({ required: false })
|
|
149
|
+
@IsString()
|
|
150
|
+
@IsOptional()
|
|
151
|
+
lastName?: string
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/users/dto/index.ts
|
|
155
|
+
export * from './create-user.dto'
|
|
156
|
+
export * from './update-user.dto'
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### 5. Service Pattern
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
// src/users/services/users.service.ts
|
|
163
|
+
import { Injectable, NotFoundException, ConflictException } from '@nestjs/common'
|
|
164
|
+
import { InjectRepository } from '@nestjs/typeorm'
|
|
165
|
+
import { Repository } from 'typeorm'
|
|
166
|
+
import * as bcrypt from 'bcrypt'
|
|
167
|
+
import { User } from '../entities'
|
|
168
|
+
import { CreateUserDto } from '../dto'
|
|
169
|
+
|
|
170
|
+
@Injectable()
|
|
171
|
+
export class UsersService {
|
|
172
|
+
constructor(
|
|
173
|
+
@InjectRepository(User)
|
|
174
|
+
private readonly userRepository: Repository<User>,
|
|
175
|
+
) {}
|
|
176
|
+
|
|
177
|
+
async create(createUserDto: CreateUserDto): Promise<User> {
|
|
178
|
+
// Check if user exists
|
|
179
|
+
const existing = await this.userRepository.findOne({
|
|
180
|
+
where: { email: createUserDto.email },
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
if (existing) {
|
|
184
|
+
throw new ConflictException('Email already exists')
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Hash password
|
|
188
|
+
const hashedPassword = await bcrypt.hash(createUserDto.password, 10)
|
|
189
|
+
|
|
190
|
+
// Create user
|
|
191
|
+
const user = this.userRepository.create({
|
|
192
|
+
...createUserDto,
|
|
193
|
+
password: hashedPassword,
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
return this.userRepository.save(user)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async findOne(id: string): Promise<User> {
|
|
200
|
+
const user = await this.userRepository.findOne({ where: { id } })
|
|
201
|
+
|
|
202
|
+
if (!user) {
|
|
203
|
+
throw new NotFoundException(`User with ID ${id} not found`)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return user
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async findByEmail(email: string): Promise<User | null> {
|
|
210
|
+
return this.userRepository.findOne({ where: { email } })
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async softDelete(id: string): Promise<void> {
|
|
214
|
+
const result = await this.userRepository.softDelete(id)
|
|
215
|
+
|
|
216
|
+
if (result.affected === 0) {
|
|
217
|
+
throw new NotFoundException(`User with ID ${id} not found`)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/users/services/index.ts
|
|
223
|
+
export * from './users.service'
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### 6. Controller Pattern
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
// src/users/controllers/users.controller.ts
|
|
230
|
+
import {
|
|
231
|
+
Controller,
|
|
232
|
+
Get,
|
|
233
|
+
Post,
|
|
234
|
+
Body,
|
|
235
|
+
Param,
|
|
236
|
+
Delete,
|
|
237
|
+
UseGuards,
|
|
238
|
+
UseInterceptors,
|
|
239
|
+
ClassSerializerInterceptor,
|
|
240
|
+
} from '@nestjs/common'
|
|
241
|
+
import { ApiBearerAuth, ApiTags, ApiOperation } from '@nestjs/swagger'
|
|
242
|
+
import { UsersService } from '../services'
|
|
243
|
+
import { CreateUserDto } from '../dto'
|
|
244
|
+
import { User } from '../entities'
|
|
245
|
+
import { JwtAuthGuard } from 'src/auth/guards'
|
|
246
|
+
|
|
247
|
+
@ApiTags('users')
|
|
248
|
+
@Controller('users')
|
|
249
|
+
@UseInterceptors(ClassSerializerInterceptor) // Apply class-transformer
|
|
250
|
+
export class UsersController {
|
|
251
|
+
constructor(private readonly usersService: UsersService) {}
|
|
252
|
+
|
|
253
|
+
@Post()
|
|
254
|
+
@ApiOperation({ summary: 'Create a new user' })
|
|
255
|
+
create(@Body() createUserDto: CreateUserDto): Promise<User> {
|
|
256
|
+
return this.usersService.create(createUserDto)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
@Get(':id')
|
|
260
|
+
@UseGuards(JwtAuthGuard)
|
|
261
|
+
@ApiBearerAuth()
|
|
262
|
+
@ApiOperation({ summary: 'Get user by ID' })
|
|
263
|
+
findOne(@Param('id') id: string): Promise<User> {
|
|
264
|
+
return this.usersService.findOne(id)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
@Delete(':id')
|
|
268
|
+
@UseGuards(JwtAuthGuard)
|
|
269
|
+
@ApiBearerAuth()
|
|
270
|
+
@ApiOperation({ summary: 'Soft delete user' })
|
|
271
|
+
async remove(@Param('id') id: string): Promise<{ message: string }> {
|
|
272
|
+
await this.usersService.softDelete(id)
|
|
273
|
+
return { message: 'User deleted successfully' }
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/users/controllers/index.ts
|
|
278
|
+
export * from './users.controller'
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### 7. Module Pattern
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
// src/users/users.module.ts
|
|
285
|
+
import { Module } from '@nestjs/common'
|
|
286
|
+
import { TypeOrmModule } from '@nestjs/typeorm'
|
|
287
|
+
import { User } from './entities'
|
|
288
|
+
import { UsersService } from './services'
|
|
289
|
+
import { UsersController } from './controllers'
|
|
290
|
+
|
|
291
|
+
@Module({
|
|
292
|
+
imports: [TypeOrmModule.forFeature([User])],
|
|
293
|
+
controllers: [UsersController],
|
|
294
|
+
providers: [UsersService],
|
|
295
|
+
exports: [UsersService], // Export for other modules
|
|
296
|
+
})
|
|
297
|
+
export class UsersModule {}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Architectural Deliverables
|
|
301
|
+
|
|
302
|
+
Provide:
|
|
303
|
+
|
|
304
|
+
1. **Module Structure**
|
|
305
|
+
- Feature modules organization
|
|
306
|
+
- Shared modules (auth, common, etc.)
|
|
307
|
+
- Module dependencies
|
|
308
|
+
- Import/export strategy
|
|
309
|
+
|
|
310
|
+
2. **Entity Design**
|
|
311
|
+
- Database entities with TypeORM decorators
|
|
312
|
+
- UUID primary keys
|
|
313
|
+
- Timestamps (createdAt, updatedAt)
|
|
314
|
+
- Soft deletes (deletedAt)
|
|
315
|
+
- Relationships (OneToMany, ManyToOne, etc.)
|
|
316
|
+
- Indexes for performance
|
|
317
|
+
|
|
318
|
+
3. **DTO Design**
|
|
319
|
+
- Create/Update/Response DTOs
|
|
320
|
+
- Validation rules (class-validator)
|
|
321
|
+
- Swagger documentation
|
|
322
|
+
- Transformation rules
|
|
323
|
+
|
|
324
|
+
4. **Service Layer**
|
|
325
|
+
- Business logic organization
|
|
326
|
+
- Dependency injection
|
|
327
|
+
- Error handling strategy
|
|
328
|
+
- Transaction boundaries
|
|
329
|
+
|
|
330
|
+
5. **API Endpoints**
|
|
331
|
+
- RESTful routes
|
|
332
|
+
- HTTP methods
|
|
333
|
+
- Guards (authentication/authorization)
|
|
334
|
+
- Interceptors (logging, transform)
|
|
335
|
+
- Swagger documentation
|
|
336
|
+
|
|
337
|
+
6. **Authentication/Authorization**
|
|
338
|
+
- JWT strategy
|
|
339
|
+
- Guards implementation
|
|
340
|
+
- Role-based access control (RBAC)
|
|
341
|
+
- Passport integration
|
|
342
|
+
|
|
343
|
+
7. **Performance**
|
|
344
|
+
- Database query optimization
|
|
345
|
+
- Caching strategy (Redis)
|
|
346
|
+
- Lazy loading vs eager loading
|
|
347
|
+
- Pagination
|
|
348
|
+
|
|
349
|
+
8. **Error Handling**
|
|
350
|
+
- Global exception filters
|
|
351
|
+
- Custom exceptions
|
|
352
|
+
- Validation error responses
|
|
353
|
+
|
|
354
|
+
## Smicolon NestJS Standards
|
|
355
|
+
|
|
356
|
+
### Required Patterns
|
|
357
|
+
- ✅ TypeScript strict mode
|
|
358
|
+
- ✅ Absolute imports from barrel exports (index.ts files)
|
|
359
|
+
- ✅ UUID primary keys
|
|
360
|
+
- ✅ Timestamps (createdAt, updatedAt)
|
|
361
|
+
- ✅ Soft deletes (deletedAt with TypeORM)
|
|
362
|
+
- ✅ DTOs with class-validator
|
|
363
|
+
- ✅ Swagger/OpenAPI documentation
|
|
364
|
+
- ✅ Global error handling
|
|
365
|
+
- ✅ JWT authentication
|
|
366
|
+
|
|
367
|
+
### Module Organization
|
|
368
|
+
- ✅ One feature per module
|
|
369
|
+
- ✅ Clear module boundaries
|
|
370
|
+
- ✅ Export only what's needed
|
|
371
|
+
- ✅ index.ts for clean exports
|
|
372
|
+
|
|
373
|
+
### Database
|
|
374
|
+
- ✅ TypeORM or Prisma
|
|
375
|
+
- ✅ Migrations for schema changes
|
|
376
|
+
- ✅ Soft deletes everywhere
|
|
377
|
+
- ✅ Proper indexing
|
|
378
|
+
|
|
379
|
+
### Security
|
|
380
|
+
- ✅ Password hashing (bcrypt)
|
|
381
|
+
- ✅ JWT tokens
|
|
382
|
+
- ✅ Guards on all protected routes
|
|
383
|
+
- ✅ Input validation on all DTOs
|
|
384
|
+
- ✅ SQL injection prevention (ORM)
|
|
385
|
+
- ✅ Rate limiting
|
|
386
|
+
|
|
387
|
+
## Architecture Checklist
|
|
388
|
+
|
|
389
|
+
Before completing:
|
|
390
|
+
- [ ] Module structure defined
|
|
391
|
+
- [ ] Entities with UUID, timestamps, soft deletes
|
|
392
|
+
- [ ] DTOs with validation decorators
|
|
393
|
+
- [ ] Services with business logic
|
|
394
|
+
- [ ] Controllers with guards and interceptors
|
|
395
|
+
- [ ] Module imports/exports configured
|
|
396
|
+
- [ ] Authentication strategy planned
|
|
397
|
+
- [ ] Error handling strategy defined
|
|
398
|
+
- [ ] Database indexes identified
|
|
399
|
+
- [ ] Swagger documentation planned
|
|
400
|
+
- [ ] All imports use absolute paths from barrel exports
|
|
401
|
+
|
|
402
|
+
Now provide architectural guidance for the user's request.
|