servcraft 0.1.0 → 0.1.1
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/settings.local.json +29 -0
- package/.github/CODEOWNERS +18 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +46 -0
- package/.github/dependabot.yml +59 -0
- package/.github/workflows/ci.yml +188 -0
- package/.github/workflows/release.yml +195 -0
- package/AUDIT.md +602 -0
- package/README.md +1070 -1
- package/dist/cli/index.cjs +2026 -2168
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +2026 -2168
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +595 -616
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +114 -52
- package/dist/index.d.ts +114 -52
- package/dist/index.js +595 -616
- package/dist/index.js.map +1 -1
- package/docs/CLI-001_MULTI_DB_PLAN.md +546 -0
- package/docs/DATABASE_MULTI_ORM.md +399 -0
- package/docs/PHASE1_BREAKDOWN.md +346 -0
- package/docs/PROGRESS.md +550 -0
- package/docs/modules/ANALYTICS.md +226 -0
- package/docs/modules/API-VERSIONING.md +252 -0
- package/docs/modules/AUDIT.md +192 -0
- package/docs/modules/AUTH.md +431 -0
- package/docs/modules/CACHE.md +346 -0
- package/docs/modules/EMAIL.md +254 -0
- package/docs/modules/FEATURE-FLAG.md +291 -0
- package/docs/modules/I18N.md +294 -0
- package/docs/modules/MEDIA-PROCESSING.md +281 -0
- package/docs/modules/MFA.md +266 -0
- package/docs/modules/NOTIFICATION.md +311 -0
- package/docs/modules/OAUTH.md +237 -0
- package/docs/modules/PAYMENT.md +804 -0
- package/docs/modules/QUEUE.md +540 -0
- package/docs/modules/RATE-LIMIT.md +339 -0
- package/docs/modules/SEARCH.md +288 -0
- package/docs/modules/SECURITY.md +327 -0
- package/docs/modules/SESSION.md +382 -0
- package/docs/modules/SWAGGER.md +305 -0
- package/docs/modules/UPLOAD.md +296 -0
- package/docs/modules/USER.md +505 -0
- package/docs/modules/VALIDATION.md +294 -0
- package/docs/modules/WEBHOOK.md +270 -0
- package/docs/modules/WEBSOCKET.md +691 -0
- package/package.json +53 -38
- package/prisma/schema.prisma +395 -1
- package/src/cli/commands/add-module.ts +520 -87
- package/src/cli/commands/db.ts +3 -4
- package/src/cli/commands/docs.ts +256 -6
- package/src/cli/commands/generate.ts +12 -19
- package/src/cli/commands/init.ts +384 -214
- package/src/cli/index.ts +0 -4
- package/src/cli/templates/repository.ts +6 -1
- package/src/cli/templates/routes.ts +6 -21
- package/src/cli/utils/docs-generator.ts +6 -7
- package/src/cli/utils/env-manager.ts +717 -0
- package/src/cli/utils/field-parser.ts +16 -7
- package/src/cli/utils/interactive-prompt.ts +223 -0
- package/src/cli/utils/template-manager.ts +346 -0
- package/src/config/database.config.ts +183 -0
- package/src/config/env.ts +0 -10
- package/src/config/index.ts +0 -14
- package/src/core/server.ts +1 -1
- package/src/database/adapters/mongoose.adapter.ts +132 -0
- package/src/database/adapters/prisma.adapter.ts +118 -0
- package/src/database/connection.ts +190 -0
- package/src/database/interfaces/database.interface.ts +85 -0
- package/src/database/interfaces/index.ts +7 -0
- package/src/database/interfaces/repository.interface.ts +129 -0
- package/src/database/models/mongoose/index.ts +7 -0
- package/src/database/models/mongoose/payment.schema.ts +347 -0
- package/src/database/models/mongoose/user.schema.ts +154 -0
- package/src/database/prisma.ts +1 -4
- package/src/database/redis.ts +101 -0
- package/src/database/repositories/mongoose/index.ts +7 -0
- package/src/database/repositories/mongoose/payment.repository.ts +380 -0
- package/src/database/repositories/mongoose/user.repository.ts +255 -0
- package/src/database/seed.ts +6 -1
- package/src/index.ts +9 -20
- package/src/middleware/security.ts +2 -6
- package/src/modules/analytics/analytics.routes.ts +80 -0
- package/src/modules/analytics/analytics.service.ts +364 -0
- package/src/modules/analytics/index.ts +18 -0
- package/src/modules/analytics/types.ts +180 -0
- package/src/modules/api-versioning/index.ts +15 -0
- package/src/modules/api-versioning/types.ts +86 -0
- package/src/modules/api-versioning/versioning.middleware.ts +120 -0
- package/src/modules/api-versioning/versioning.routes.ts +54 -0
- package/src/modules/api-versioning/versioning.service.ts +189 -0
- package/src/modules/audit/audit.repository.ts +206 -0
- package/src/modules/audit/audit.service.ts +27 -59
- package/src/modules/auth/auth.controller.ts +2 -2
- package/src/modules/auth/auth.middleware.ts +3 -9
- package/src/modules/auth/auth.routes.ts +10 -107
- package/src/modules/auth/auth.service.ts +126 -23
- package/src/modules/auth/index.ts +3 -4
- package/src/modules/cache/cache.service.ts +367 -0
- package/src/modules/cache/index.ts +10 -0
- package/src/modules/cache/types.ts +44 -0
- package/src/modules/email/email.service.ts +3 -10
- package/src/modules/email/templates.ts +2 -8
- package/src/modules/feature-flag/feature-flag.repository.ts +303 -0
- package/src/modules/feature-flag/feature-flag.routes.ts +247 -0
- package/src/modules/feature-flag/feature-flag.service.ts +566 -0
- package/src/modules/feature-flag/index.ts +20 -0
- package/src/modules/feature-flag/types.ts +192 -0
- package/src/modules/i18n/i18n.middleware.ts +186 -0
- package/src/modules/i18n/i18n.routes.ts +191 -0
- package/src/modules/i18n/i18n.service.ts +456 -0
- package/src/modules/i18n/index.ts +18 -0
- package/src/modules/i18n/types.ts +118 -0
- package/src/modules/media-processing/index.ts +17 -0
- package/src/modules/media-processing/media-processing.routes.ts +111 -0
- package/src/modules/media-processing/media-processing.service.ts +245 -0
- package/src/modules/media-processing/types.ts +156 -0
- package/src/modules/mfa/index.ts +20 -0
- package/src/modules/mfa/mfa.repository.ts +206 -0
- package/src/modules/mfa/mfa.routes.ts +595 -0
- package/src/modules/mfa/mfa.service.ts +572 -0
- package/src/modules/mfa/totp.ts +150 -0
- package/src/modules/mfa/types.ts +57 -0
- package/src/modules/notification/index.ts +20 -0
- package/src/modules/notification/notification.repository.ts +356 -0
- package/src/modules/notification/notification.service.ts +483 -0
- package/src/modules/notification/types.ts +119 -0
- package/src/modules/oauth/index.ts +20 -0
- package/src/modules/oauth/oauth.repository.ts +219 -0
- package/src/modules/oauth/oauth.routes.ts +446 -0
- package/src/modules/oauth/oauth.service.ts +293 -0
- package/src/modules/oauth/providers/apple.provider.ts +250 -0
- package/src/modules/oauth/providers/facebook.provider.ts +181 -0
- package/src/modules/oauth/providers/github.provider.ts +248 -0
- package/src/modules/oauth/providers/google.provider.ts +189 -0
- package/src/modules/oauth/providers/twitter.provider.ts +214 -0
- package/src/modules/oauth/types.ts +94 -0
- package/src/modules/payment/index.ts +19 -0
- package/src/modules/payment/payment.repository.ts +733 -0
- package/src/modules/payment/payment.routes.ts +390 -0
- package/src/modules/payment/payment.service.ts +354 -0
- package/src/modules/payment/providers/mobile-money.provider.ts +274 -0
- package/src/modules/payment/providers/paypal.provider.ts +190 -0
- package/src/modules/payment/providers/stripe.provider.ts +215 -0
- package/src/modules/payment/types.ts +140 -0
- package/src/modules/queue/cron.ts +438 -0
- package/src/modules/queue/index.ts +87 -0
- package/src/modules/queue/queue.routes.ts +600 -0
- package/src/modules/queue/queue.service.ts +842 -0
- package/src/modules/queue/types.ts +222 -0
- package/src/modules/queue/workers.ts +366 -0
- package/src/modules/rate-limit/index.ts +59 -0
- package/src/modules/rate-limit/rate-limit.middleware.ts +134 -0
- package/src/modules/rate-limit/rate-limit.routes.ts +269 -0
- package/src/modules/rate-limit/rate-limit.service.ts +348 -0
- package/src/modules/rate-limit/stores/memory.store.ts +165 -0
- package/src/modules/rate-limit/stores/redis.store.ts +322 -0
- package/src/modules/rate-limit/types.ts +153 -0
- package/src/modules/search/adapters/elasticsearch.adapter.ts +326 -0
- package/src/modules/search/adapters/meilisearch.adapter.ts +261 -0
- package/src/modules/search/adapters/memory.adapter.ts +278 -0
- package/src/modules/search/index.ts +21 -0
- package/src/modules/search/search.service.ts +234 -0
- package/src/modules/search/types.ts +214 -0
- package/src/modules/security/index.ts +40 -0
- package/src/modules/security/sanitize.ts +223 -0
- package/src/modules/security/security-audit.service.ts +388 -0
- package/src/modules/security/security.middleware.ts +398 -0
- package/src/modules/session/index.ts +3 -0
- package/src/modules/session/session.repository.ts +159 -0
- package/src/modules/session/session.service.ts +340 -0
- package/src/modules/session/types.ts +38 -0
- package/src/modules/swagger/index.ts +7 -1
- package/src/modules/swagger/schema-builder.ts +16 -4
- package/src/modules/swagger/swagger.service.ts +9 -10
- package/src/modules/swagger/types.ts +0 -2
- package/src/modules/upload/index.ts +14 -0
- package/src/modules/upload/types.ts +83 -0
- package/src/modules/upload/upload.repository.ts +199 -0
- package/src/modules/upload/upload.routes.ts +311 -0
- package/src/modules/upload/upload.service.ts +448 -0
- package/src/modules/user/index.ts +3 -3
- package/src/modules/user/user.controller.ts +15 -9
- package/src/modules/user/user.repository.ts +237 -113
- package/src/modules/user/user.routes.ts +39 -164
- package/src/modules/user/user.service.ts +4 -3
- package/src/modules/validation/validator.ts +12 -17
- package/src/modules/webhook/index.ts +91 -0
- package/src/modules/webhook/retry.ts +196 -0
- package/src/modules/webhook/signature.ts +135 -0
- package/src/modules/webhook/types.ts +181 -0
- package/src/modules/webhook/webhook.repository.ts +358 -0
- package/src/modules/webhook/webhook.routes.ts +442 -0
- package/src/modules/webhook/webhook.service.ts +457 -0
- package/src/modules/websocket/features.ts +504 -0
- package/src/modules/websocket/index.ts +106 -0
- package/src/modules/websocket/middlewares.ts +298 -0
- package/src/modules/websocket/types.ts +181 -0
- package/src/modules/websocket/websocket.service.ts +692 -0
- package/src/utils/errors.ts +7 -0
- package/src/utils/pagination.ts +4 -1
- package/tests/helpers/db-check.ts +79 -0
- package/tests/integration/auth-redis.test.ts +94 -0
- package/tests/integration/cache-redis.test.ts +387 -0
- package/tests/integration/mongoose-repositories.test.ts +410 -0
- package/tests/integration/payment-prisma.test.ts +637 -0
- package/tests/integration/queue-bullmq.test.ts +417 -0
- package/tests/integration/user-prisma.test.ts +441 -0
- package/tests/integration/websocket-socketio.test.ts +552 -0
- package/tests/setup.ts +11 -9
- package/vitest.config.ts +3 -8
- package/npm-cache/_cacache/content-v2/sha512/1c/d0/03440d500a0487621aad1d6402978340698976602046db8e24fa03c01ee6c022c69b0582f969042d9442ee876ac35c038e960dd427d1e622fa24b8eb7dba +0 -0
- package/npm-cache/_cacache/content-v2/sha512/42/55/28b493ca491833e5aab0e9c3108d29ab3f36c248ca88f45d4630674fce9130959e56ae308797ac2b6328fa7f09a610b9550ed09cb971d039876d293fc69d +0 -0
- package/npm-cache/_cacache/content-v2/sha512/e0/12/f360dc9315ee5f17844a0c8c233ee6bf7c30837c4a02ea0d56c61c7f7ab21c0e958e50ed2c57c59f983c762b93056778c9009b2398ffc26def0183999b13 +0 -0
- package/npm-cache/_cacache/content-v2/sha512/ed/b0/fae1161902898f4c913c67d7f6cdf6be0665aec3b389b9c4f4f0a101ca1da59badf1b59c4e0030f5223023b8d63cfe501c46a32c20c895d4fb3f11ca2232 +0 -0
- package/npm-cache/_cacache/index-v5/58/94/c2cba79e0f16b4c10e95a87e32255741149e8222cc314a476aab67c39cc0 +0 -5
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
# 🗄️ CLI-001 REVISÉ : IMPLÉMENTATION MULTI-DATABASE & MULTI-ORM
|
|
2
|
+
|
|
3
|
+
**Créé le :** 2025-12-19
|
|
4
|
+
**Type :** Feature majeure (était "fix false promise", devient "real implementation")
|
|
5
|
+
**Estimation révisée :** 20-30 heures (au lieu de 2h)
|
|
6
|
+
**Impact :** Framework production-ready avec choix réels de DB/ORM
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 🎯 Vision
|
|
11
|
+
|
|
12
|
+
Transformer ServCraft en un vrai framework **database-agnostic** avec support de:
|
|
13
|
+
- **4 ORMs** : Prisma, Mongoose, Sequelize, TypeORM
|
|
14
|
+
- **5 Databases** : PostgreSQL, MySQL, SQLite, MongoDB, MariaDB
|
|
15
|
+
- **Architecture unifiée** avec adapters et interfaces communes
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 📊 Matrice de Support
|
|
20
|
+
|
|
21
|
+
| ORM | PostgreSQL | MySQL | SQLite | MongoDB | MariaDB |
|
|
22
|
+
|-----|------------|-------|--------|---------|---------|
|
|
23
|
+
| **Prisma** | ✅ | ✅ | ✅ | ✅ (expérimental) | ✅ |
|
|
24
|
+
| **Mongoose** | ❌ | ❌ | ❌ | ✅ | ❌ |
|
|
25
|
+
| **Sequelize** | ✅ | ✅ | ✅ | ❌ | ✅ |
|
|
26
|
+
| **TypeORM** | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
27
|
+
|
|
28
|
+
**Total combinaisons possibles :** ~15 configurations valides
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 🏗️ Architecture Proposée
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
src/database/
|
|
36
|
+
├── adapters/
|
|
37
|
+
│ ├── prisma.adapter.ts # Prisma universal adapter
|
|
38
|
+
│ ├── mongoose.adapter.ts # MongoDB with Mongoose
|
|
39
|
+
│ ├── sequelize.adapter.ts # SQL with Sequelize
|
|
40
|
+
│ └── typeorm.adapter.ts # TypeORM universal adapter
|
|
41
|
+
├── interfaces/
|
|
42
|
+
│ ├── database.interface.ts # Common DB operations
|
|
43
|
+
│ ├── repository.interface.ts # Repository pattern
|
|
44
|
+
│ └── transaction.interface.ts # Transaction support
|
|
45
|
+
├── models/ # Shared model definitions
|
|
46
|
+
│ ├── user.model.ts
|
|
47
|
+
│ ├── payment.model.ts
|
|
48
|
+
│ └── ...
|
|
49
|
+
├── migrations/ # Migration handlers per ORM
|
|
50
|
+
│ ├── prisma/
|
|
51
|
+
│ ├── sequelize/
|
|
52
|
+
│ └── typeorm/
|
|
53
|
+
└── connection.ts # Universal connection factory
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 📝 PLAN DE DÉVELOPPEMENT DÉTAILLÉ
|
|
59
|
+
|
|
60
|
+
### **PHASE 1 : Architecture & Interfaces** (4-6h)
|
|
61
|
+
|
|
62
|
+
#### **CLI-001.1 : Définir interfaces communes** (2h)
|
|
63
|
+
Créer les interfaces TypeScript que TOUS les ORMs doivent implémenter:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// src/database/interfaces/database.interface.ts
|
|
67
|
+
export interface IDatabaseAdapter {
|
|
68
|
+
connect(): Promise<void>;
|
|
69
|
+
disconnect(): Promise<void>;
|
|
70
|
+
healthCheck(): Promise<boolean>;
|
|
71
|
+
migrate(direction?: 'up' | 'down'): Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/database/interfaces/repository.interface.ts
|
|
75
|
+
export interface IRepository<T> {
|
|
76
|
+
findById(id: string): Promise<T | null>;
|
|
77
|
+
findMany(filter?: any, options?: PaginationOptions): Promise<PaginatedResult<T>>;
|
|
78
|
+
create(data: Partial<T>): Promise<T>;
|
|
79
|
+
update(id: string, data: Partial<T>): Promise<T | null>;
|
|
80
|
+
delete(id: string): Promise<boolean>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/database/interfaces/transaction.interface.ts
|
|
84
|
+
export interface ITransactionManager {
|
|
85
|
+
begin(): Promise<ITransaction>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ITransaction {
|
|
89
|
+
commit(): Promise<void>;
|
|
90
|
+
rollback(): Promise<void>;
|
|
91
|
+
execute<T>(operation: () => Promise<T>): Promise<T>;
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Livrable :** Interfaces complètes et documentées
|
|
96
|
+
|
|
97
|
+
#### **CLI-001.2 : Créer factory pattern** (1h)
|
|
98
|
+
```typescript
|
|
99
|
+
// src/database/connection.ts
|
|
100
|
+
export class DatabaseFactory {
|
|
101
|
+
static createAdapter(
|
|
102
|
+
orm: 'prisma' | 'mongoose' | 'sequelize' | 'typeorm',
|
|
103
|
+
database: 'postgresql' | 'mysql' | 'sqlite' | 'mongodb'
|
|
104
|
+
): IDatabaseAdapter {
|
|
105
|
+
// Logic to instantiate correct adapter
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Livrable :** Factory testable et extensible
|
|
111
|
+
|
|
112
|
+
#### **CLI-001.3 : Design système de configuration** (1h)
|
|
113
|
+
```typescript
|
|
114
|
+
// src/config/database.config.ts
|
|
115
|
+
export interface DatabaseConfig {
|
|
116
|
+
orm: string;
|
|
117
|
+
database: string;
|
|
118
|
+
host?: string;
|
|
119
|
+
port?: number;
|
|
120
|
+
username?: string;
|
|
121
|
+
password?: string;
|
|
122
|
+
database_name?: string;
|
|
123
|
+
url?: string;
|
|
124
|
+
// ... other options
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**Livrable :** Configuration unifiée
|
|
129
|
+
|
|
130
|
+
**Checkpoint 1 :** Commit "feat(database): add multi-orm architecture interfaces"
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
### **PHASE 2 : Implémentation Prisma** (3-4h)
|
|
135
|
+
|
|
136
|
+
#### **CLI-001.4 : Adapter Prisma** (2h)
|
|
137
|
+
Refactoriser le code Prisma existant en adapter:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// src/database/adapters/prisma.adapter.ts
|
|
141
|
+
export class PrismaAdapter implements IDatabaseAdapter {
|
|
142
|
+
private prisma: PrismaClient;
|
|
143
|
+
|
|
144
|
+
async connect(): Promise<void> {
|
|
145
|
+
this.prisma = new PrismaClient();
|
|
146
|
+
await this.prisma.$connect();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async disconnect(): Promise<void> {
|
|
150
|
+
await this.prisma.$disconnect();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ... implement all interface methods
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/database/repositories/prisma/
|
|
157
|
+
// - user.repository.ts (refactor existing)
|
|
158
|
+
// - payment.repository.ts (refactor existing)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Livrable :** Prisma adapter fonctionnel
|
|
162
|
+
|
|
163
|
+
#### **CLI-001.5 : Tests Prisma adapter** (1-2h)
|
|
164
|
+
- Test connection avec PostgreSQL
|
|
165
|
+
- Test avec MySQL
|
|
166
|
+
- Test avec SQLite
|
|
167
|
+
- Valider tous les repositories existants
|
|
168
|
+
|
|
169
|
+
**Livrable :** Tests passants pour Prisma
|
|
170
|
+
|
|
171
|
+
**Checkpoint 2 :** Commit "feat(database): implement prisma adapter"
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
### **PHASE 3 : Implémentation Mongoose** (4-5h)
|
|
176
|
+
|
|
177
|
+
#### **CLI-001.6 : Adapter Mongoose** (2h)
|
|
178
|
+
```typescript
|
|
179
|
+
// src/database/adapters/mongoose.adapter.ts
|
|
180
|
+
import mongoose from 'mongoose';
|
|
181
|
+
|
|
182
|
+
export class MongooseAdapter implements IDatabaseAdapter {
|
|
183
|
+
private connection: typeof mongoose | null = null;
|
|
184
|
+
|
|
185
|
+
async connect(): Promise<void> {
|
|
186
|
+
this.connection = await mongoose.connect(config.url);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async disconnect(): Promise<void> {
|
|
190
|
+
await mongoose.disconnect();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ... implement interface
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**Livrable :** Mongoose adapter fonctionnel
|
|
198
|
+
|
|
199
|
+
#### **CLI-001.7 : Créer schemas Mongoose** (1.5h)
|
|
200
|
+
```typescript
|
|
201
|
+
// src/database/models/mongoose/user.schema.ts
|
|
202
|
+
import { Schema, model } from 'mongoose';
|
|
203
|
+
|
|
204
|
+
const userSchema = new Schema({
|
|
205
|
+
email: { type: String, required: true, unique: true },
|
|
206
|
+
password: { type: String, required: true },
|
|
207
|
+
name: { type: String, required: true },
|
|
208
|
+
role: { type: String, enum: ['user', 'admin'], default: 'user' },
|
|
209
|
+
// ... other fields
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
export const UserModel = model('User', userSchema);
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**Livrable :** Schemas pour User, Payment, etc.
|
|
216
|
+
|
|
217
|
+
#### **CLI-001.8 : Repository Mongoose** (1h)
|
|
218
|
+
```typescript
|
|
219
|
+
// src/database/repositories/mongoose/user.repository.ts
|
|
220
|
+
export class MongooseUserRepository implements IRepository<User> {
|
|
221
|
+
async findById(id: string): Promise<User | null> {
|
|
222
|
+
return UserModel.findById(id);
|
|
223
|
+
}
|
|
224
|
+
// ... implement all methods
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Livrable :** Repositories Mongoose
|
|
229
|
+
|
|
230
|
+
#### **CLI-001.9 : Tests Mongoose** (0.5h)
|
|
231
|
+
- Test connection MongoDB
|
|
232
|
+
- Test CRUD operations
|
|
233
|
+
- Validate schemas
|
|
234
|
+
|
|
235
|
+
**Livrable :** Tests Mongoose passants
|
|
236
|
+
|
|
237
|
+
**Checkpoint 3 :** Commit "feat(database): implement mongoose adapter"
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
### **PHASE 4 : Implémentation Sequelize** (4-5h)
|
|
242
|
+
|
|
243
|
+
#### **CLI-001.10 : Adapter Sequelize** (2h)
|
|
244
|
+
```typescript
|
|
245
|
+
// src/database/adapters/sequelize.adapter.ts
|
|
246
|
+
import { Sequelize } from 'sequelize';
|
|
247
|
+
|
|
248
|
+
export class SequelizeAdapter implements IDatabaseAdapter {
|
|
249
|
+
private sequelize: Sequelize;
|
|
250
|
+
|
|
251
|
+
async connect(): Promise<void> {
|
|
252
|
+
this.sequelize = new Sequelize({
|
|
253
|
+
dialect: config.database, // 'postgres' | 'mysql' | 'sqlite'
|
|
254
|
+
host: config.host,
|
|
255
|
+
// ... config
|
|
256
|
+
});
|
|
257
|
+
await this.sequelize.authenticate();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// ... implement interface
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
**Livrable :** Sequelize adapter
|
|
265
|
+
|
|
266
|
+
#### **CLI-001.11 : Modèles Sequelize** (1.5h)
|
|
267
|
+
```typescript
|
|
268
|
+
// src/database/models/sequelize/user.model.ts
|
|
269
|
+
import { DataTypes, Model } from 'sequelize';
|
|
270
|
+
|
|
271
|
+
export class UserModel extends Model {
|
|
272
|
+
declare id: string;
|
|
273
|
+
declare email: string;
|
|
274
|
+
declare password: string;
|
|
275
|
+
// ...
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export function defineUserModel(sequelize: Sequelize) {
|
|
279
|
+
UserModel.init({
|
|
280
|
+
id: { type: DataTypes.UUID, primaryKey: true },
|
|
281
|
+
email: { type: DataTypes.STRING, unique: true },
|
|
282
|
+
// ...
|
|
283
|
+
}, { sequelize });
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
**Livrable :** Modèles Sequelize
|
|
288
|
+
|
|
289
|
+
#### **CLI-001.12 : Repository Sequelize** (1h)
|
|
290
|
+
**Livrable :** Repositories Sequelize
|
|
291
|
+
|
|
292
|
+
#### **CLI-001.13 : Tests Sequelize** (0.5h)
|
|
293
|
+
**Livrable :** Tests pour PostgreSQL, MySQL, SQLite
|
|
294
|
+
|
|
295
|
+
**Checkpoint 4 :** Commit "feat(database): implement sequelize adapter"
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
### **PHASE 5 : Implémentation TypeORM** (4-5h)
|
|
300
|
+
|
|
301
|
+
#### **CLI-001.14 : Adapter TypeORM** (2h)
|
|
302
|
+
```typescript
|
|
303
|
+
// src/database/adapters/typeorm.adapter.ts
|
|
304
|
+
import { DataSource } from 'typeorm';
|
|
305
|
+
|
|
306
|
+
export class TypeORMAdapter implements IDatabaseAdapter {
|
|
307
|
+
private dataSource: DataSource;
|
|
308
|
+
|
|
309
|
+
async connect(): Promise<void> {
|
|
310
|
+
this.dataSource = new DataSource({
|
|
311
|
+
type: config.database, // 'postgres' | 'mysql' | 'mongodb' | 'sqlite'
|
|
312
|
+
// ... config
|
|
313
|
+
});
|
|
314
|
+
await this.dataSource.initialize();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// ... implement interface
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
**Livrable :** TypeORM adapter
|
|
322
|
+
|
|
323
|
+
#### **CLI-001.15 : Entities TypeORM** (1.5h)
|
|
324
|
+
```typescript
|
|
325
|
+
// src/database/models/typeorm/user.entity.ts
|
|
326
|
+
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
|
|
327
|
+
|
|
328
|
+
@Entity('users')
|
|
329
|
+
export class UserEntity {
|
|
330
|
+
@PrimaryGeneratedColumn('uuid')
|
|
331
|
+
id: string;
|
|
332
|
+
|
|
333
|
+
@Column({ unique: true })
|
|
334
|
+
email: string;
|
|
335
|
+
|
|
336
|
+
// ... other fields with decorators
|
|
337
|
+
}
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
**Livrable :** Entities TypeORM
|
|
341
|
+
|
|
342
|
+
#### **CLI-001.16 : Repository TypeORM** (1h)
|
|
343
|
+
**Livrable :** Repositories TypeORM
|
|
344
|
+
|
|
345
|
+
#### **CLI-001.17 : Tests TypeORM** (0.5h)
|
|
346
|
+
**Livrable :** Tests multi-DB
|
|
347
|
+
|
|
348
|
+
**Checkpoint 5 :** Commit "feat(database): implement typeorm adapter"
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
### **PHASE 6 : Intégration CLI** (3-4h)
|
|
353
|
+
|
|
354
|
+
#### **CLI-001.18 : Update CLI prompts** (1h)
|
|
355
|
+
```typescript
|
|
356
|
+
// Enhanced prompts in init.ts
|
|
357
|
+
{
|
|
358
|
+
type: 'list',
|
|
359
|
+
name: 'orm',
|
|
360
|
+
message: 'Select ORM:',
|
|
361
|
+
choices: [
|
|
362
|
+
{ name: 'Prisma (Type-safe, Modern)', value: 'prisma' },
|
|
363
|
+
{ name: 'Mongoose (MongoDB specialist)', value: 'mongoose' },
|
|
364
|
+
{ name: 'Sequelize (SQL veteran)', value: 'sequelize' },
|
|
365
|
+
{ name: 'TypeORM (Decorator-based)', value: 'typeorm' },
|
|
366
|
+
],
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
type: 'list',
|
|
370
|
+
name: 'database',
|
|
371
|
+
message: 'Select database:',
|
|
372
|
+
choices: (answers) => {
|
|
373
|
+
// Dynamic choices based on ORM selection
|
|
374
|
+
return getCompatibleDatabases(answers.orm);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
**Livrable :** CLI intelligent avec validation
|
|
380
|
+
|
|
381
|
+
#### **CLI-001.19 : Générateurs de code** (1.5h)
|
|
382
|
+
Créer fonctions pour générer:
|
|
383
|
+
- Connection files pour chaque ORM
|
|
384
|
+
- Model/Schema/Entity files
|
|
385
|
+
- Repository files
|
|
386
|
+
- Migration setup
|
|
387
|
+
- Config files (.env, database.config.ts)
|
|
388
|
+
|
|
389
|
+
**Livrable :** Générateurs complets
|
|
390
|
+
|
|
391
|
+
#### **CLI-001.20 : Templates validation** (0.5h)
|
|
392
|
+
Tester la génération pour chaque combo ORM/DB
|
|
393
|
+
|
|
394
|
+
**Livrable :** Templates validés
|
|
395
|
+
|
|
396
|
+
**Checkpoint 6 :** Commit "feat(cli): add multi-orm/db support"
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
### **PHASE 7 : Migration des modules existants** (4-6h)
|
|
401
|
+
|
|
402
|
+
#### **CLI-001.21 : Adapter Auth module** (1.5h)
|
|
403
|
+
Faire fonctionner l'authentification avec tous les ORMs
|
|
404
|
+
|
|
405
|
+
**Livrable :** Auth universal
|
|
406
|
+
|
|
407
|
+
#### **CLI-001.22 : Adapter User module** (1.5h)
|
|
408
|
+
**Livrable :** User universal
|
|
409
|
+
|
|
410
|
+
#### **CLI-001.23 : Adapter Payment module** (1.5h)
|
|
411
|
+
**Livrable :** Payment universal
|
|
412
|
+
|
|
413
|
+
#### **CLI-001.24 : Tests cross-ORM** (1.5h)
|
|
414
|
+
Vérifier que tous les modules fonctionnent avec tous les ORMs
|
|
415
|
+
|
|
416
|
+
**Livrable :** Tests intégration complets
|
|
417
|
+
|
|
418
|
+
**Checkpoint 7 :** Commit "feat(modules): add universal orm support"
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
### **PHASE 8 : Documentation** (2-3h)
|
|
423
|
+
|
|
424
|
+
#### **CLI-001.25 : Guide de choix ORM/DB** (1h)
|
|
425
|
+
```markdown
|
|
426
|
+
# Choosing Database & ORM
|
|
427
|
+
|
|
428
|
+
## When to use Prisma
|
|
429
|
+
- Modern TypeScript projects
|
|
430
|
+
- Strong type safety needed
|
|
431
|
+
- Auto-generated types
|
|
432
|
+
- Good DX with migrations
|
|
433
|
+
- Best for: PostgreSQL, MySQL
|
|
434
|
+
|
|
435
|
+
## When to use Mongoose
|
|
436
|
+
- MongoDB projects
|
|
437
|
+
- Schema validation needed
|
|
438
|
+
- Document-oriented data
|
|
439
|
+
- Best for: MongoDB
|
|
440
|
+
|
|
441
|
+
## When to use Sequelize
|
|
442
|
+
- Legacy SQL projects
|
|
443
|
+
- Wide DB support needed
|
|
444
|
+
- Mature ecosystem
|
|
445
|
+
- Best for: PostgreSQL, MySQL, MariaDB
|
|
446
|
+
|
|
447
|
+
## When to use TypeORM
|
|
448
|
+
- Decorator fans
|
|
449
|
+
- Multi-DB projects
|
|
450
|
+
- Active Record or Data Mapper pattern
|
|
451
|
+
- Best for: All databases
|
|
452
|
+
|
|
453
|
+
## Performance Comparison
|
|
454
|
+
[Benchmarks here]
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
**Livrable :** Guide complet
|
|
458
|
+
|
|
459
|
+
#### **CLI-001.26 : Documentation technique** (1h)
|
|
460
|
+
- Architecture multi-ORM
|
|
461
|
+
- Création de nouveaux adapters
|
|
462
|
+
- Extension du système
|
|
463
|
+
- Best practices
|
|
464
|
+
|
|
465
|
+
**Livrable :** Docs techniques
|
|
466
|
+
|
|
467
|
+
#### **CLI-001.27 : Migration guides** (1h)
|
|
468
|
+
- Prisma → Sequelize
|
|
469
|
+
- Mongoose → TypeORM
|
|
470
|
+
- Etc.
|
|
471
|
+
|
|
472
|
+
**Livrable :** Migration guides
|
|
473
|
+
|
|
474
|
+
**Checkpoint 8 :** Commit "docs: add comprehensive multi-orm documentation"
|
|
475
|
+
|
|
476
|
+
---
|
|
477
|
+
|
|
478
|
+
## 📊 Récapitulatif
|
|
479
|
+
|
|
480
|
+
| Phase | Tâches | Temps | Complexité |
|
|
481
|
+
|-------|--------|-------|------------|
|
|
482
|
+
| 1. Architecture | 3 | 4-6h | ⭐⭐⭐ |
|
|
483
|
+
| 2. Prisma | 2 | 3-4h | ⭐⭐ |
|
|
484
|
+
| 3. Mongoose | 4 | 4-5h | ⭐⭐⭐ |
|
|
485
|
+
| 4. Sequelize | 4 | 4-5h | ⭐⭐⭐ |
|
|
486
|
+
| 5. TypeORM | 4 | 4-5h | ⭐⭐⭐ |
|
|
487
|
+
| 6. CLI Integration | 3 | 3-4h | ⭐⭐⭐ |
|
|
488
|
+
| 7. Module Migration | 4 | 4-6h | ⭐⭐⭐⭐ |
|
|
489
|
+
| 8. Documentation | 3 | 2-3h | ⭐⭐ |
|
|
490
|
+
| **TOTAL** | **27** | **28-38h** | - |
|
|
491
|
+
|
|
492
|
+
---
|
|
493
|
+
|
|
494
|
+
## 🎯 Valeur Ajoutée
|
|
495
|
+
|
|
496
|
+
### Pour les développeurs
|
|
497
|
+
✅ Vrai choix de DB/ORM (pas de vendor lock-in)
|
|
498
|
+
✅ Migration facile entre ORMs
|
|
499
|
+
✅ Pattern unifié quel que soit le choix
|
|
500
|
+
✅ Type safety partout
|
|
501
|
+
|
|
502
|
+
### Pour le projet ServCraft
|
|
503
|
+
✅ Feature unique dans l'écosystème Node.js
|
|
504
|
+
✅ Flexibilité maximale
|
|
505
|
+
✅ Production-ready pour tous usages
|
|
506
|
+
✅ Différenciation compétitive majeure
|
|
507
|
+
|
|
508
|
+
---
|
|
509
|
+
|
|
510
|
+
## 🚀 Approche Progressive
|
|
511
|
+
|
|
512
|
+
### MVP (Phase 1-2-3) : 11-15h
|
|
513
|
+
- Architecture + Prisma + Mongoose
|
|
514
|
+
- Couvre 80% des use cases
|
|
515
|
+
- PostgreSQL + MongoDB support
|
|
516
|
+
|
|
517
|
+
### Version complète (Phases 4-8) : +17-23h
|
|
518
|
+
- Sequelize + TypeORM
|
|
519
|
+
- Documentation complète
|
|
520
|
+
- Migration de tous les modules
|
|
521
|
+
|
|
522
|
+
---
|
|
523
|
+
|
|
524
|
+
## ❓ Décision à Prendre
|
|
525
|
+
|
|
526
|
+
**Option A :** MVP d'abord (Prisma + Mongoose, 11-15h)
|
|
527
|
+
- Livre rapidement de la valeur
|
|
528
|
+
- Teste l'architecture
|
|
529
|
+
- Complète Phase 1 partiellement
|
|
530
|
+
|
|
531
|
+
**Option B :** Implémentation complète (28-38h)
|
|
532
|
+
- Feature complète et différenciante
|
|
533
|
+
- Mais retarde QUEUE-001
|
|
534
|
+
|
|
535
|
+
**Option C :** Garder plan initial (retirer MongoDB, 2h)
|
|
536
|
+
- Termine Phase 1 rapidement
|
|
537
|
+
- Repousse multi-ORM à Phase 2
|
|
538
|
+
|
|
539
|
+
---
|
|
540
|
+
|
|
541
|
+
**Quelle option préférez-vous ?**
|
|
542
|
+
1. MVP (Prisma + Mongoose)
|
|
543
|
+
2. Implémentation complète
|
|
544
|
+
3. Plan original (retirer MongoDB)
|
|
545
|
+
|
|
546
|
+
Ou une autre approche ?
|