@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,106 @@
|
|
|
1
|
+
---
|
|
2
|
+
paths:
|
|
3
|
+
- "**/*.service.ts"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# NestJS Service Standards
|
|
7
|
+
|
|
8
|
+
## Structure
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
import { Injectable, NotFoundException } from '@nestjs/common'
|
|
12
|
+
import { InjectRepository } from '@nestjs/typeorm'
|
|
13
|
+
import { Repository } from 'typeorm'
|
|
14
|
+
import { User } from 'src/users/entities'
|
|
15
|
+
import { CreateUserDto, UpdateUserDto } from 'src/users/dto'
|
|
16
|
+
|
|
17
|
+
@Injectable()
|
|
18
|
+
export class UsersService {
|
|
19
|
+
constructor(
|
|
20
|
+
@InjectRepository(User)
|
|
21
|
+
private readonly usersRepository: Repository<User>,
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
async findAll(): Promise<User[]> {
|
|
25
|
+
return this.usersRepository.find()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async findOne(id: string): Promise<User> {
|
|
29
|
+
const user = await this.usersRepository.findOne({ where: { id } })
|
|
30
|
+
if (!user) {
|
|
31
|
+
throw new NotFoundException(`User with ID ${id} not found`)
|
|
32
|
+
}
|
|
33
|
+
return user
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async create(dto: CreateUserDto): Promise<User> {
|
|
37
|
+
const user = this.usersRepository.create(dto)
|
|
38
|
+
return this.usersRepository.save(user)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async update(id: string, dto: UpdateUserDto): Promise<User> {
|
|
42
|
+
const user = await this.findOne(id)
|
|
43
|
+
Object.assign(user, dto)
|
|
44
|
+
return this.usersRepository.save(user)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async remove(id: string): Promise<void> {
|
|
48
|
+
await this.usersRepository.softDelete(id)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Requirements
|
|
54
|
+
|
|
55
|
+
- @Injectable() decorator
|
|
56
|
+
- Constructor injection for repositories
|
|
57
|
+
- Proper error handling with NestJS exceptions
|
|
58
|
+
- Soft delete using softDelete()
|
|
59
|
+
- Absolute imports from barrel exports
|
|
60
|
+
|
|
61
|
+
## Import Pattern
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
// CORRECT
|
|
65
|
+
import { User } from 'src/users/entities'
|
|
66
|
+
import { CreateUserDto } from 'src/users/dto'
|
|
67
|
+
|
|
68
|
+
// WRONG
|
|
69
|
+
import { User } from './entities/user.entity'
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Transaction Support
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { DataSource } from 'typeorm'
|
|
76
|
+
|
|
77
|
+
@Injectable()
|
|
78
|
+
export class OrdersService {
|
|
79
|
+
constructor(
|
|
80
|
+
private readonly dataSource: DataSource,
|
|
81
|
+
@InjectRepository(Order)
|
|
82
|
+
private readonly ordersRepository: Repository<Order>,
|
|
83
|
+
) {}
|
|
84
|
+
|
|
85
|
+
async createWithItems(dto: CreateOrderDto): Promise<Order> {
|
|
86
|
+
return this.dataSource.transaction(async manager => {
|
|
87
|
+
const order = manager.create(Order, { userId: dto.userId })
|
|
88
|
+
await manager.save(order)
|
|
89
|
+
|
|
90
|
+
for (const item of dto.items) {
|
|
91
|
+
const orderItem = manager.create(OrderItem, { ...item, orderId: order.id })
|
|
92
|
+
await manager.save(orderItem)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return order
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Forbidden Patterns
|
|
102
|
+
|
|
103
|
+
- Missing @Injectable() decorator
|
|
104
|
+
- Direct database operations without repository
|
|
105
|
+
- Catching exceptions without re-throwing
|
|
106
|
+
- Hard deletes (use softDelete)
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: barrel-export-manager
|
|
3
|
+
description: This skill should be used when the user asks to "create barrel exports", "add index.ts", "organize exports", "create entity", "add DTO", "create service", or when adding files to NestJS module directories. Auto-maintains barrel exports.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Barrel Export Manager
|
|
7
|
+
|
|
8
|
+
Auto-creates and maintains `index.ts` barrel export files in NestJS modules for clean, maintainable imports.
|
|
9
|
+
|
|
10
|
+
## Activation Triggers
|
|
11
|
+
|
|
12
|
+
This skill activates when:
|
|
13
|
+
- Creating new entity, DTO, service, controller, guard, decorator
|
|
14
|
+
- Adding files to module directories
|
|
15
|
+
- Organizing NestJS module structure
|
|
16
|
+
- Mentioning "NestJS", "module", "create"
|
|
17
|
+
- Importing from module directories
|
|
18
|
+
|
|
19
|
+
## Required Pattern (MANDATORY)
|
|
20
|
+
|
|
21
|
+
Every NestJS module folder MUST have `index.ts` barrel exports:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
users/
|
|
25
|
+
├── entities/
|
|
26
|
+
│ ├── user.entity.ts
|
|
27
|
+
│ ├── profile.entity.ts
|
|
28
|
+
│ └── index.ts # ✅ Barrel export
|
|
29
|
+
├── dto/
|
|
30
|
+
│ ├── create-user.dto.ts
|
|
31
|
+
│ ├── update-user.dto.ts
|
|
32
|
+
│ └── index.ts # ✅ Barrel export
|
|
33
|
+
├── services/
|
|
34
|
+
│ ├── users.service.ts
|
|
35
|
+
│ └── index.ts # ✅ Barrel export
|
|
36
|
+
└── controllers/
|
|
37
|
+
├── users.controller.ts
|
|
38
|
+
└── index.ts # ✅ Barrel export
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Auto-Management Process
|
|
42
|
+
|
|
43
|
+
### Step 1: Detect New File
|
|
44
|
+
|
|
45
|
+
When user creates:
|
|
46
|
+
```typescript
|
|
47
|
+
// users/entities/user.entity.ts
|
|
48
|
+
@Entity('users')
|
|
49
|
+
export class User {
|
|
50
|
+
@PrimaryGeneratedColumn('uuid')
|
|
51
|
+
id: string
|
|
52
|
+
// ...
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Step 2: Auto-Create/Update index.ts
|
|
57
|
+
|
|
58
|
+
Automatically create or update `users/entities/index.ts`:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
// users/entities/index.ts
|
|
62
|
+
export * from './user.entity'
|
|
63
|
+
export * from './profile.entity'
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Step 3: Verify Imports Use Barrel
|
|
67
|
+
|
|
68
|
+
Ensure other files import from barrel:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
// ✅ CORRECT - Import from barrel
|
|
72
|
+
import { User, Profile } from 'src/users/entities'
|
|
73
|
+
|
|
74
|
+
// ❌ WRONG - Import from specific file
|
|
75
|
+
import { User } from 'src/users/entities/user.entity'
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Step 4: Update on File Changes
|
|
79
|
+
|
|
80
|
+
When files are added/removed/renamed, automatically update the barrel export:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
// User adds: organization.entity.ts
|
|
84
|
+
// Automatically update index.ts:
|
|
85
|
+
export * from './user.entity'
|
|
86
|
+
export * from './profile.entity'
|
|
87
|
+
export * from './organization.entity' // ✅ Added automatically
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Barrel Export Patterns
|
|
91
|
+
|
|
92
|
+
### Entities Directory
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
// users/entities/index.ts
|
|
96
|
+
export * from './user.entity'
|
|
97
|
+
export * from './profile.entity'
|
|
98
|
+
export * from './organization.entity'
|
|
99
|
+
|
|
100
|
+
// Usage
|
|
101
|
+
import { User, Profile, Organization } from 'src/users/entities'
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### DTOs Directory
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
// users/dto/index.ts
|
|
108
|
+
export * from './create-user.dto'
|
|
109
|
+
export * from './update-user.dto'
|
|
110
|
+
export * from './user-response.dto'
|
|
111
|
+
export * from './filter-user.dto'
|
|
112
|
+
|
|
113
|
+
// Usage
|
|
114
|
+
import { CreateUserDto, UpdateUserDto, UserResponseDto } from 'src/users/dto'
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Services Directory
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
// users/services/index.ts
|
|
121
|
+
export * from './users.service'
|
|
122
|
+
export * from './auth.service'
|
|
123
|
+
export * from './email.service'
|
|
124
|
+
|
|
125
|
+
// Usage
|
|
126
|
+
import { UsersService, AuthService } from 'src/users/services'
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Controllers Directory
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
// users/controllers/index.ts
|
|
133
|
+
export * from './users.controller'
|
|
134
|
+
export * from './auth.controller'
|
|
135
|
+
|
|
136
|
+
// Usage
|
|
137
|
+
import { UsersController, AuthController } from 'src/users/controllers'
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Guards Directory
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
// auth/guards/index.ts
|
|
144
|
+
export * from './jwt-auth.guard'
|
|
145
|
+
export * from './roles.guard'
|
|
146
|
+
export * from './api-key.guard'
|
|
147
|
+
|
|
148
|
+
// Usage
|
|
149
|
+
import { JwtAuthGuard, RolesGuard } from 'src/auth/guards'
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Decorators Directory
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
// common/decorators/index.ts
|
|
156
|
+
export * from './current-user.decorator'
|
|
157
|
+
export * from './roles.decorator'
|
|
158
|
+
export * from './api-paginated-response.decorator'
|
|
159
|
+
|
|
160
|
+
// Usage
|
|
161
|
+
import { CurrentUser, Roles } from 'src/common/decorators'
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Complete Module Example
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
users/
|
|
168
|
+
├── users.module.ts
|
|
169
|
+
├── entities/
|
|
170
|
+
│ ├── user.entity.ts
|
|
171
|
+
│ ├── profile.entity.ts
|
|
172
|
+
│ └── index.ts # export * from './user.entity'; export * from './profile.entity'
|
|
173
|
+
├── dto/
|
|
174
|
+
│ ├── create-user.dto.ts
|
|
175
|
+
│ ├── update-user.dto.ts
|
|
176
|
+
│ └── index.ts # export * from './create-user.dto'; ...
|
|
177
|
+
├── services/
|
|
178
|
+
│ ├── users.service.ts
|
|
179
|
+
│ └── index.ts # export * from './users.service'
|
|
180
|
+
├── controllers/
|
|
181
|
+
│ ├── users.controller.ts
|
|
182
|
+
│ └── index.ts # export * from './users.controller'
|
|
183
|
+
└── tests/
|
|
184
|
+
└── users.service.spec.ts
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
**Module file uses barrel exports:**
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
// users/users.module.ts
|
|
191
|
+
import { Module } from '@nestjs/common'
|
|
192
|
+
import { TypeOrmModule } from '@nestjs/typeorm'
|
|
193
|
+
|
|
194
|
+
// ✅ Clean imports from barrels
|
|
195
|
+
import { User, Profile } from './entities'
|
|
196
|
+
import { UsersService } from './services'
|
|
197
|
+
import { UsersController } from './controllers'
|
|
198
|
+
|
|
199
|
+
@Module({
|
|
200
|
+
imports: [TypeOrmModule.forFeature([User, Profile])],
|
|
201
|
+
controllers: [UsersController],
|
|
202
|
+
providers: [UsersService],
|
|
203
|
+
exports: [UsersService],
|
|
204
|
+
})
|
|
205
|
+
export class UsersModule {}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Benefits of Barrel Exports
|
|
209
|
+
|
|
210
|
+
### 1. Clean Imports
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
// ❌ WITHOUT barrels - Verbose
|
|
214
|
+
import { User } from 'src/users/entities/user.entity'
|
|
215
|
+
import { Profile } from 'src/users/entities/profile.entity'
|
|
216
|
+
import { Organization } from 'src/users/entities/organization.entity'
|
|
217
|
+
import { CreateUserDto } from 'src/users/dto/create-user.dto'
|
|
218
|
+
import { UpdateUserDto } from 'src/users/dto/update-user.dto'
|
|
219
|
+
|
|
220
|
+
// ✅ WITH barrels - Clean
|
|
221
|
+
import { User, Profile, Organization } from 'src/users/entities'
|
|
222
|
+
import { CreateUserDto, UpdateUserDto } from 'src/users/dto'
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### 2. Easier Refactoring
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
// Rename user.entity.ts → user-account.entity.ts
|
|
229
|
+
// Only update one file (index.ts):
|
|
230
|
+
export * from './user-account.entity' // Updated filename
|
|
231
|
+
|
|
232
|
+
// All imports still work:
|
|
233
|
+
import { User } from 'src/users/entities' // ✅ No changes needed
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### 3. Encapsulation
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
// Control what's exported
|
|
240
|
+
// users/services/index.ts
|
|
241
|
+
export { UsersService } from './users.service'
|
|
242
|
+
// Don't export internal helpers
|
|
243
|
+
// export { InternalHelper } from './internal-helper' // ❌ Keep private
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Auto-Barrel Creation Rules
|
|
247
|
+
|
|
248
|
+
Automatically create `index.ts` when:
|
|
249
|
+
|
|
250
|
+
1. **2+ files in directory** (avoids unnecessary barrels)
|
|
251
|
+
2. **Files export classes/types** (entities, DTOs, services, etc.)
|
|
252
|
+
3. **Directory is part of module structure** (entities/, dto/, services/, etc.)
|
|
253
|
+
|
|
254
|
+
## Selective Exports
|
|
255
|
+
|
|
256
|
+
For specific exports instead of `export *`:
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
// users/services/index.ts
|
|
260
|
+
|
|
261
|
+
// ✅ Export public API
|
|
262
|
+
export { UsersService } from './users.service'
|
|
263
|
+
export { AuthService } from './auth.service'
|
|
264
|
+
|
|
265
|
+
// ❌ Don't export internal utilities
|
|
266
|
+
// export { InternalHelper } from './internal.helper'
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## Integration with TypeORM
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
// users/entities/index.ts
|
|
273
|
+
export { User } from './user.entity'
|
|
274
|
+
export { Profile } from './profile.entity'
|
|
275
|
+
|
|
276
|
+
// users.module.ts - Clean!
|
|
277
|
+
import { User, Profile } from './entities'
|
|
278
|
+
|
|
279
|
+
@Module({
|
|
280
|
+
imports: [TypeOrmModule.forFeature([User, Profile])],
|
|
281
|
+
// ...
|
|
282
|
+
})
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Module Organization Best Practices
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
// ✅ CORRECT - Organized with barrels
|
|
289
|
+
src/
|
|
290
|
+
├── users/
|
|
291
|
+
│ ├── users.module.ts
|
|
292
|
+
│ ├── entities/
|
|
293
|
+
│ │ ├── user.entity.ts
|
|
294
|
+
│ │ └── index.ts
|
|
295
|
+
│ ├── dto/
|
|
296
|
+
│ │ ├── create-user.dto.ts
|
|
297
|
+
│ │ ├── update-user.dto.ts
|
|
298
|
+
│ │ └── index.ts
|
|
299
|
+
│ ├── services/
|
|
300
|
+
│ │ ├── users.service.ts
|
|
301
|
+
│ │ └── index.ts
|
|
302
|
+
│ └── controllers/
|
|
303
|
+
│ ├── users.controller.ts
|
|
304
|
+
│ └── index.ts
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## Auto-Update Scenarios
|
|
308
|
+
|
|
309
|
+
### Scenario 1: New Entity Added
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
// User creates: payment-method.entity.ts
|
|
313
|
+
|
|
314
|
+
// Automatically update entities/index.ts:
|
|
315
|
+
export * from './user.entity'
|
|
316
|
+
export * from './profile.entity'
|
|
317
|
+
export * from './payment-method.entity' // ✅ Auto-added
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### Scenario 2: DTO Renamed
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
// User renames: update-user.dto.ts → modify-user.dto.ts
|
|
324
|
+
|
|
325
|
+
// Automatically update dto/index.ts:
|
|
326
|
+
export * from './create-user.dto'
|
|
327
|
+
export * from './modify-user.dto' // ✅ Auto-updated
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Scenario 3: File Deleted
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
// User deletes: profile.entity.ts
|
|
334
|
+
|
|
335
|
+
// Automatically update entities/index.ts:
|
|
336
|
+
export * from './user.entity'
|
|
337
|
+
// export * from './profile.entity' // ✅ Auto-removed
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## Cross-Module Imports
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
// orders/services/orders.service.ts
|
|
344
|
+
import { Injectable } from '@nestjs/common'
|
|
345
|
+
|
|
346
|
+
// ✅ Import from other module's barrel
|
|
347
|
+
import { User } from 'src/users/entities'
|
|
348
|
+
import { UsersService } from 'src/users/services'
|
|
349
|
+
|
|
350
|
+
@Injectable()
|
|
351
|
+
export class OrdersService {
|
|
352
|
+
constructor(private usersService: UsersService) {}
|
|
353
|
+
|
|
354
|
+
async createOrder(userId: string) {
|
|
355
|
+
const user = await this.usersService.findOne(userId)
|
|
356
|
+
// ...
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
## Success Criteria
|
|
362
|
+
|
|
363
|
+
✅ Every module directory has barrel exports
|
|
364
|
+
✅ All imports use barrel exports (not specific files)
|
|
365
|
+
✅ Barrels auto-update when files change
|
|
366
|
+
✅ Clean, maintainable import structure
|
|
367
|
+
✅ Easy refactoring (rename/move files)
|
|
368
|
+
|
|
369
|
+
## Behavior
|
|
370
|
+
|
|
371
|
+
**Proactive enforcement:**
|
|
372
|
+
- Create barrels without being asked
|
|
373
|
+
- Update barrels automatically when files change
|
|
374
|
+
- Convert direct imports to barrel imports
|
|
375
|
+
- Explain benefits of barrel exports
|
|
376
|
+
- Maintain consistent structure
|
|
377
|
+
|
|
378
|
+
**Never:**
|
|
379
|
+
- Require explicit "create barrel export" request
|
|
380
|
+
- Allow direct file imports when barrel exists
|
|
381
|
+
- Wait for imports to break
|
|
382
|
+
|
|
383
|
+
**Always:**
|
|
384
|
+
- Create `index.ts` in module directories
|
|
385
|
+
- Keep barrel exports up to date
|
|
386
|
+
- Use `export *` for simplicity (unless selective needed)
|
|
387
|
+
- Ensure imports use barrels
|
|
388
|
+
|
|
389
|
+
This ensures clean, maintainable NestJS module structure from day one.
|