@breadstone/archipel-mcp 0.0.11 → 0.0.13

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.
@@ -0,0 +1,546 @@
1
+ ---
2
+ title: Database Setup
3
+ description: Set up PostgreSQL access with Prisma, Prisma Accelerate, repositories, queries, transactions, health checks, and error handling.
4
+ order: 5
5
+ ---
6
+
7
+ # Database Setup
8
+
9
+ This guide covers everything you need to connect a NestJS application to PostgreSQL through `platform-database`: module registration, Prisma Accelerate for connection pooling, writing repositories and queries, transactions, pagination, health checks, and error handling.
10
+
11
+ If you haven't installed `platform-core` and registered `ConfigModule` yet, read the [Getting Started](/guides/getting-started) guide first.
12
+
13
+ ---
14
+
15
+ ## Overview
16
+
17
+ `platform-database` provides:
18
+
19
+ | Capability | What it does |
20
+ | ------------------------- | ---------------------------------------------------------------------------------- |
21
+ | **DatabaseModule** | Registers Prisma-backed services for DI with optional Accelerate support |
22
+ | **DatabaseService** | Extended Prisma client with transaction helpers |
23
+ | **RepositoryBase** | Abstract base class for typed repositories with built-in error handling |
24
+ | **Query pattern** | Reusable, testable query objects executed through repositories |
25
+ | **Transactional queries** | Multi-model writes wrapped in Prisma transactions |
26
+ | **Pagination** | Offset-based pagination with metadata (total, pages, next/prev) |
27
+ | **Health indicator** | Terminus-based database health check, auto-registered with the health orchestrator |
28
+ | **Exception filter** | Maps `RepositoryError` to HTTP 500 responses |
29
+
30
+ ---
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ yarn add @breadstone/archipel-platform-database
36
+ ```
37
+
38
+ `platform-database` depends on `@prisma/client`. Make sure your project has a Prisma schema and a generated client:
39
+
40
+ ```bash
41
+ yarn add prisma @prisma/client
42
+ npx prisma init
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Environment Variables
48
+
49
+ `platform-database` ships its own config keys and a ready-made entries array. Set the relevant variables in your environment:
50
+
51
+ ```env
52
+ DATABASE_URL=postgresql://user:password@localhost:5432/mydb
53
+ ```
54
+
55
+ For Prisma Accelerate (managed connection pooling), add the Accelerate URL from the Prisma Console:
56
+
57
+ ```env
58
+ DB_ACCELERATE_URL=prisma://accelerate.prisma-data.net/?api_key=your-accelerate-api-key
59
+ ```
60
+
61
+ Optional environment variables for Prisma Optimize (query analysis dashboard):
62
+
63
+ ```env
64
+ DB_OPTIMIZE=true
65
+ DB_OPTIMIZE_API_KEY=your-optimize-api-key
66
+ ```
67
+
68
+ All environment variables recognised by `platform-database`:
69
+
70
+ | Variable | Description | Required | Default |
71
+ | --------------------- | ----------------------------------------- | ------------------- | ------- |
72
+ | `DATABASE_URL` | PostgreSQL connection string | Yes | — |
73
+ | `DB_ACCELERATE_URL` | Prisma Accelerate proxy URL | No | `''` |
74
+ | `DB_AUTO_CONNECTION` | Auto-connect on module init | No | `true` |
75
+ | `DB_OPTIMIZE` | Enable Prisma Optimize query analysis | No | `true` |
76
+ | `DB_OPTIMIZE_API_KEY` | API key for the Prisma Optimize dashboard | If optimize enabled | `''` |
77
+
78
+ ### Register Config Entries
79
+
80
+ Use the exported `PLATFORM_DATABASE_CONFIG_ENTRIES` to register all database keys with the `ConfigModule` — no need to define them manually:
81
+
82
+ ```typescript
83
+ // src/app.module.ts
84
+ import { Module } from '@nestjs/common';
85
+ import { ConfigModule } from '@breadstone/archipel-platform-core';
86
+ import { DatabaseModule, PLATFORM_DATABASE_CONFIG_ENTRIES } from '@breadstone/archipel-platform-database';
87
+
88
+ @Module({
89
+ imports: [ConfigModule.register('database', PLATFORM_DATABASE_CONFIG_ENTRIES), DatabaseModule.register()],
90
+ })
91
+ export class AppModule {}
92
+ ```
93
+
94
+ The `ConfigModule` validates all required keys at startup. If `DATABASE_URL` is missing, the application fails immediately with a clear error.
95
+
96
+ ---
97
+
98
+ ## Module Registration
99
+
100
+ ### Basic Setup (No Accelerate)
101
+
102
+ For a direct PostgreSQL connection without Accelerate:
103
+
104
+ ```typescript
105
+ import { Module } from '@nestjs/common';
106
+ import { ConfigModule } from '@breadstone/archipel-platform-core';
107
+ import { DatabaseModule, PLATFORM_DATABASE_CONFIG_ENTRIES } from '@breadstone/archipel-platform-database';
108
+
109
+ @Module({
110
+ imports: [ConfigModule.register('database', PLATFORM_DATABASE_CONFIG_ENTRIES), DatabaseModule.register()],
111
+ })
112
+ export class AppModule {}
113
+ ```
114
+
115
+ ### With Prisma Accelerate
116
+
117
+ Accelerate provides connection pooling, global caching, and query optimization — especially useful in serverless or edge environments where direct database connections are expensive. You can enable it in two ways:
118
+
119
+ **Option A — Environment variable (recommended)**
120
+
121
+ Set `DB_ACCELERATE_URL` in your environment. The module reads it automatically via `ConfigService` — no code changes needed:
122
+
123
+ ```env
124
+ DB_ACCELERATE_URL=prisma://accelerate.prisma-data.net/?api_key=your-accelerate-api-key
125
+ ```
126
+
127
+ ```typescript
128
+ @Module({
129
+ imports: [ConfigModule.register('database', PLATFORM_DATABASE_CONFIG_ENTRIES), DatabaseModule.register()],
130
+ })
131
+ export class AppModule {}
132
+ ```
133
+
134
+ **Option B — Module parameter (takes priority)**
135
+
136
+ Pass `accelerateUrl` explicitly. This overrides the environment variable:
137
+
138
+ ```typescript
139
+ import { Module } from '@nestjs/common';
140
+ import { ConfigModule } from '@breadstone/archipel-platform-core';
141
+ import { DatabaseModule, PLATFORM_DATABASE_CONFIG_ENTRIES } from '@breadstone/archipel-platform-database';
142
+
143
+ @Module({
144
+ imports: [
145
+ ConfigModule.register('database', PLATFORM_DATABASE_CONFIG_ENTRIES),
146
+ DatabaseModule.register({
147
+ accelerateUrl: 'prisma://accelerate.prisma-data.net/?api_key=...',
148
+ }),
149
+ ],
150
+ })
151
+ export class AppModule {}
152
+ ```
153
+
154
+ When an Accelerate URL is present (from either source), the Prisma client connects through the Accelerate proxy instead of directly to PostgreSQL. The `DATABASE_URL` is still required — Prisma uses it for schema generation and migrations. At runtime, all queries go through the Accelerate URL.
155
+
156
+ > **Resolution order:** module parameter → `DB_ACCELERATE_URL` environment variable → no Accelerate.
157
+
158
+ ### Global Registration with `forRoot`
159
+
160
+ Use `forRoot()` to make `DatabaseService` globally available without re-importing the module in every feature module:
161
+
162
+ ```typescript
163
+ @Module({
164
+ imports: [ConfigModule.register('database', PLATFORM_DATABASE_CONFIG_ENTRIES), DatabaseModule.forRoot()],
165
+ })
166
+ export class AppModule {}
167
+ ```
168
+
169
+ With `forRoot()`, any module can inject `DatabaseService` without adding `DatabaseModule` to its own `imports`. Accelerate resolution works the same way — via environment variable or explicit `forRoot({ accelerateUrl: '...' })`.
170
+
171
+ ---
172
+
173
+ ## Defining Entities
174
+
175
+ Define entity interfaces that map to your Prisma models. Entity property names must match your Prisma schema exactly:
176
+
177
+ ```typescript
178
+ // src/users/models/entities/IUserEntity.ts
179
+ export interface IUserEntity {
180
+ readonly id: string;
181
+ readonly userName: string;
182
+ readonly email: string;
183
+ readonly createdAt: Date;
184
+ }
185
+ ```
186
+
187
+ Entities are plain interfaces — no methods, no business logic, no mapping. They are the contract between repositories and services.
188
+
189
+ ---
190
+
191
+ ## Writing Queries
192
+
193
+ Queries are plain objects created with the `query()` factory. Each query receives a Prisma delegate and returns a typed result. This keeps data access logic reusable, testable, and separate from repository class methods.
194
+
195
+ ### Single-Model Query
196
+
197
+ ```typescript
198
+ // src/users/queries/findUserByIdQuery.ts
199
+ import { query, type IRepositoryQuery } from '@breadstone/archipel-platform-database';
200
+ import { type Prisma } from '@prisma/client';
201
+ import { type IUserEntity } from '../models/entities/IUserEntity';
202
+
203
+ type UserDelegate = Prisma.UserDelegate;
204
+
205
+ export const findUserByIdQuery = (id: string): IRepositoryQuery<UserDelegate, IUserEntity | null> =>
206
+ query('findUserById', (model) =>
207
+ model.findUnique({
208
+ where: { id },
209
+ select: { id: true, userName: true, email: true, createdAt: true },
210
+ }),
211
+ );
212
+ ```
213
+
214
+ ### Transactional Query
215
+
216
+ When a write spans multiple models, use `transactionalQuery()`. It receives a Prisma `TransactionClient` instead of a single delegate:
217
+
218
+ ```typescript
219
+ // src/orders/queries/createOrderWithItemsQuery.ts
220
+ import { transactionalQuery } from '@breadstone/archipel-platform-database';
221
+
222
+ export const createOrderWithItemsQuery = (userId: string, items: Array<{ productId: string; quantity: number }>) =>
223
+ transactionalQuery('createOrderWithItems', async (tx) => {
224
+ const order = await tx.order.create({
225
+ data: { userId, status: 'pending' },
226
+ });
227
+
228
+ await tx.orderItem.createMany({
229
+ data: items.map((item) => ({
230
+ orderId: order.id,
231
+ productId: item.productId,
232
+ quantity: item.quantity,
233
+ })),
234
+ });
235
+
236
+ return order;
237
+ });
238
+ ```
239
+
240
+ ---
241
+
242
+ ## Creating Repositories
243
+
244
+ Repositories extend `RepositoryBase` and execute queries. They receive `DatabaseService` and the Prisma delegate via constructor injection.
245
+
246
+ ```typescript
247
+ // src/users/UserRepository.ts
248
+ import { Injectable } from '@nestjs/common';
249
+ import { RepositoryBase, DatabaseService } from '@breadstone/archipel-platform-database';
250
+ import { type Prisma } from '@prisma/client';
251
+ import { findUserByIdQuery } from './queries/findUserByIdQuery';
252
+ import { type IUserEntity } from './models/entities/IUserEntity';
253
+
254
+ @Injectable()
255
+ export class UserRepository extends RepositoryBase<
256
+ Prisma.UserDelegate,
257
+ Prisma.UserArgs,
258
+ Prisma.UserGetPayload<unknown>,
259
+ IUserEntity
260
+ > {
261
+ constructor(db: DatabaseService) {
262
+ super(db, db.user);
263
+ }
264
+
265
+ public async findById(id: string): Promise<IUserEntity | null> {
266
+ return this.execute(findUserByIdQuery(id));
267
+ }
268
+ }
269
+ ```
270
+
271
+ ### Executing Transactional Queries
272
+
273
+ Use `executeTransactional()` for queries that need a transaction client:
274
+
275
+ ```typescript
276
+ import { Injectable } from '@nestjs/common';
277
+ import { RepositoryBase, DatabaseService } from '@breadstone/archipel-platform-database';
278
+ import { type Prisma } from '@prisma/client';
279
+ import { createOrderWithItemsQuery } from './queries/createOrderWithItemsQuery';
280
+
281
+ @Injectable()
282
+ export class OrderRepository extends RepositoryBase<
283
+ Prisma.OrderDelegate,
284
+ Prisma.OrderArgs,
285
+ Prisma.OrderGetPayload<unknown>
286
+ > {
287
+ constructor(db: DatabaseService) {
288
+ super(db, db.order);
289
+ }
290
+
291
+ public async createWithItems(
292
+ userId: string,
293
+ items: Array<{ productId: string; quantity: number }>,
294
+ ): Promise<unknown> {
295
+ return this.executeTransactional(createOrderWithItemsQuery(userId, items));
296
+ }
297
+ }
298
+ ```
299
+
300
+ ---
301
+
302
+ ## Pagination
303
+
304
+ `platform-database` provides offset-based pagination. Pass page options to `findMany()`:
305
+
306
+ ```typescript
307
+ import { type IPaginatedResult } from '@breadstone/archipel-platform-database';
308
+
309
+ public async listUsers(page: number, perPage: number): Promise<IPaginatedResult<IUserEntity>> {
310
+ return this.findMany(
311
+ {
312
+ select: { id: true, userName: true, email: true, createdAt: true },
313
+ orderBy: { createdAt: 'desc' },
314
+ },
315
+ { page, perPage },
316
+ );
317
+ }
318
+ ```
319
+
320
+ The result contains:
321
+
322
+ ```typescript
323
+ {
324
+ data: Array<T>;
325
+ meta: {
326
+ total: number;
327
+ lastPage: number;
328
+ currentPage: number;
329
+ perPage: number;
330
+ prev: number | null;
331
+ next: number | null;
332
+ }
333
+ }
334
+ ```
335
+
336
+ ---
337
+
338
+ ## Transactions via DatabaseService
339
+
340
+ For ad-hoc transactions that don't fit the query pattern, use `DatabaseService` directly:
341
+
342
+ ### Batch Transaction
343
+
344
+ ```typescript
345
+ const [user, profile] = await this._db.transaction([
346
+ this._db.user.create({ data: { userName: 'alice', email: 'alice@example.com' } }),
347
+ this._db.profile.create({ data: { userId: 'some-id', bio: 'Hello' } }),
348
+ ]);
349
+ ```
350
+
351
+ ### Callback Transaction
352
+
353
+ ```typescript
354
+ const result = await this._db.transactionCallback(async (tx) => {
355
+ const user = await tx.user.create({ data: { userName: 'bob', email: 'bob@example.com' } });
356
+ await tx.profile.create({ data: { userId: user.id, bio: 'Hey there' } });
357
+ return user;
358
+ });
359
+ ```
360
+
361
+ ---
362
+
363
+ ## Health Checks
364
+
365
+ `DatabaseModule` automatically registers a `DatabaseHealthIndicator` with the health orchestrator from `platform-core`. Once your application exposes a `/health` endpoint, database connectivity is checked via a `SELECT 1` ping. No additional configuration is needed.
366
+
367
+ If the health check fails, the indicator reports `database: down` with the error details.
368
+
369
+ ---
370
+
371
+ ## Error Handling
372
+
373
+ ### RepositoryError
374
+
375
+ All Prisma errors caught by `RepositoryBase` are wrapped in `RepositoryError`, which includes the original Prisma error code and metadata:
376
+
377
+ ```typescript
378
+ import { RepositoryError } from '@breadstone/archipel-platform-database';
379
+
380
+ try {
381
+ await userRepository.findById('non-existent');
382
+ } catch (error) {
383
+ if (error instanceof RepositoryError) {
384
+ console.log(error.code); // 'REPOSITORY_ERROR'
385
+ console.log(error.originalCode); // e.g. 'P2025' (Prisma error code)
386
+ console.log(error.meta); // additional error metadata
387
+ }
388
+ }
389
+ ```
390
+
391
+ ### RepositoryExceptionFilter
392
+
393
+ Register the global exception filter to automatically map `RepositoryError` to HTTP 500 responses:
394
+
395
+ ```typescript
396
+ import { APP_FILTER } from '@nestjs/core';
397
+ import { RepositoryExceptionFilter } from '@breadstone/archipel-platform-database';
398
+
399
+ @Module({
400
+ providers: [
401
+ {
402
+ provide: APP_FILTER,
403
+ useClass: RepositoryExceptionFilter,
404
+ },
405
+ ],
406
+ })
407
+ export class AppModule {}
408
+ ```
409
+
410
+ The filter returns a consistent error envelope:
411
+
412
+ ```json
413
+ {
414
+ "statusCode": 500,
415
+ "timestamp": "2026-04-18T12:00:00.000Z",
416
+ "error": "Repository Error",
417
+ "path": "/api/v1/users/123"
418
+ }
419
+ ```
420
+
421
+ ---
422
+
423
+ ## Prisma Schema and Migrations
424
+
425
+ Keep your Prisma schema in your project and use migrations for all schema changes:
426
+
427
+ ```bash
428
+ # Create a new migration after changing schema.prisma
429
+ npx prisma migrate dev --name add-users-table
430
+
431
+ # Apply migrations in CI/CD
432
+ npx prisma migrate deploy
433
+
434
+ # Generate the Prisma client after schema changes
435
+ npx prisma generate
436
+ ```
437
+
438
+ > **Important:** Never edit applied migrations. If you need to fix a migration, create a new one.
439
+
440
+ When using Accelerate, migrations still run against the direct `DATABASE_URL`. Only runtime queries go through the Accelerate proxy.
441
+
442
+ ---
443
+
444
+ ## Full Example
445
+
446
+ Putting it all together — a complete feature module with database access:
447
+
448
+ ```typescript
449
+ // src/users/UserModule.ts
450
+ import { Module } from '@nestjs/common';
451
+ import { UserRepository } from './UserRepository';
452
+ import { UserService } from './UserService';
453
+ import { UserController } from './UserController';
454
+
455
+ @Module({
456
+ providers: [UserRepository, UserService],
457
+ controllers: [UserController],
458
+ exports: [UserService],
459
+ })
460
+ export class UserModule {}
461
+ ```
462
+
463
+ ```typescript
464
+ // src/users/UserService.ts
465
+ import { Injectable } from '@nestjs/common';
466
+ import { UserRepository } from './UserRepository';
467
+ import { type IUserEntity } from './models/entities/IUserEntity';
468
+
469
+ @Injectable()
470
+ export class UserService {
471
+ private readonly _userRepository: UserRepository;
472
+
473
+ constructor(userRepository: UserRepository) {
474
+ this._userRepository = userRepository;
475
+ }
476
+
477
+ public async getUserById(id: string): Promise<IUserEntity | null> {
478
+ return this._userRepository.findById(id);
479
+ }
480
+ }
481
+ ```
482
+
483
+ ```typescript
484
+ // src/users/UserController.ts
485
+ import { Controller, Get, Param, NotFoundException } from '@nestjs/common';
486
+ import { UserService } from './UserService';
487
+ import { MappingService } from '@breadstone/archipel-platform-core';
488
+ import { USER_TO_RESPONSE } from './mapping-keys';
489
+
490
+ @Controller('users')
491
+ export class UserController {
492
+ private readonly _userService: UserService;
493
+ private readonly _mappingService: MappingService;
494
+
495
+ constructor(userService: UserService, mappingService: MappingService) {
496
+ this._userService = userService;
497
+ this._mappingService = mappingService;
498
+ }
499
+
500
+ @Get(':id')
501
+ public async getUser(@Param('id') id: string): Promise<unknown> {
502
+ const user = await this._userService.getUserById(id);
503
+ if (!user) {
504
+ throw new NotFoundException(`User ${id} not found`);
505
+ }
506
+
507
+ return this._mappingService.map(USER_TO_RESPONSE, user);
508
+ }
509
+ }
510
+ ```
511
+
512
+ And the root module wiring everything together:
513
+
514
+ ```typescript
515
+ // src/app.module.ts
516
+ import { Module } from '@nestjs/common';
517
+ import { ConfigModule, MappingModule } from '@breadstone/archipel-platform-core';
518
+ import { DatabaseModule, PLATFORM_DATABASE_CONFIG_ENTRIES } from '@breadstone/archipel-platform-database';
519
+ import { UserModule } from './users/UserModule';
520
+
521
+ @Module({
522
+ imports: [
523
+ ConfigModule.register('database', PLATFORM_DATABASE_CONFIG_ENTRIES),
524
+ MappingModule,
525
+ DatabaseModule.forRoot(),
526
+ UserModule,
527
+ ],
528
+ })
529
+ export class AppModule {}
530
+ ```
531
+
532
+ ---
533
+
534
+ ## Summary
535
+
536
+ | Task | How |
537
+ | ----------------------- | ---------------------------------------------------------------------------------- |
538
+ | Register the module | `DatabaseModule.register()` or `DatabaseModule.forRoot()` with optional Accelerate |
539
+ | Define entities | Plain interfaces in `models/entities/` |
540
+ | Write queries | `query()` for single-model, `transactionalQuery()` for multi-model |
541
+ | Create repositories | Extend `RepositoryBase`, inject `DatabaseService` |
542
+ | Paginate results | Pass `{ page, perPage }` to `findMany()` |
543
+ | Run transactions | `executeTransactional()`, `db.transaction()`, or `db.transactionCallback()` |
544
+ | Monitor database health | Automatic via `DatabaseHealthIndicator` |
545
+ | Handle errors | `RepositoryExceptionFilter` for HTTP, `RepositoryError` for programmatic handling |
546
+ | Use Prisma Accelerate | Set `DB_ACCELERATE_URL` env var or pass `accelerateUrl` in module config |
@@ -27,6 +27,7 @@ Practical guides for working with Archipel packages in your NestJS application.
27
27
 
28
28
  | Guide | What you'll learn |
29
29
  | ----------------------------------------------- | ------------------------------------------------------------------------------------- |
30
+ | [Database Setup](./database-setup) | PostgreSQL via Prisma, Accelerate, repositories, queries, transactions, and health. |
30
31
  | [Blob Storage](./blob-storage) | Multi-provider file storage, uploads, signed URLs, and metadata tracking. |
31
32
  | [Document Generation](./document-generation) | Generate PDF and DOCX from templates with variable substitution and image processing. |
32
33
  | [E-Signing Integration](./esigning-integration) | Electronic signature workflows, provider setup, and webhook handling. |
@@ -5,9 +5,7 @@ editUrl: false
5
5
  ---
6
6
  # Class: DatabaseModule
7
7
 
8
- Defined in: [DatabaseModule.ts:48](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/DatabaseModule.ts#L48)
9
-
10
- Represents the database module.
8
+ Defined in: [DatabaseModule.ts:62](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/DatabaseModule.ts#L62)
11
9
 
12
10
  ## Constructors
13
11
 
@@ -29,7 +27,7 @@ new DatabaseModule(): DatabaseModule;
29
27
  static forRoot(config?): DynamicModule;
30
28
  ```
31
29
 
32
- Defined in: [DatabaseModule.ts:57](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/DatabaseModule.ts#L57)
30
+ Defined in: [DatabaseModule.ts:71](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/DatabaseModule.ts#L71)
33
31
 
34
32
  Registers the `DatabaseModule` with global middlewares.
35
33
 
@@ -53,7 +51,7 @@ A `DynamicModule` that can be imported globally
53
51
  static register(config?): DynamicModule;
54
52
  ```
55
53
 
56
- Defined in: [DatabaseModule.ts:77](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/DatabaseModule.ts#L77)
54
+ Defined in: [DatabaseModule.ts:91](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/DatabaseModule.ts#L91)
57
55
 
58
56
  Registers the `DatabaseModule` with dynamic middlewares.
59
57
 
@@ -24,7 +24,7 @@ Represents the database service.
24
24
  ### Constructor
25
25
 
26
26
  ```ts
27
- new DatabaseService(configService): DatabaseService;
27
+ new DatabaseService(configService, options?): DatabaseService;
28
28
  ```
29
29
 
30
30
  Defined in: [services/DatabaseService.ts:24](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/DatabaseService.ts#L24)
@@ -36,6 +36,7 @@ Constructs a new instance of the `DatabaseService` class.
36
36
  | Parameter | Type |
37
37
  | ------ | ------ |
38
38
  | `configService` | `ConfigService` |
39
+ | `options?` | [`IPrismaServiceOptions`](Interface.IPrismaServiceOptions) |
39
40
 
40
41
  #### Returns
41
42
 
@@ -53,7 +54,7 @@ Constructs a new instance of the `DatabaseService` class.
53
54
  onModuleDestroy(): Promise<void>;
54
55
  ```
55
56
 
56
- Defined in: [services/PrismaService.ts:80](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L80)
57
+ Defined in: [services/PrismaService.ts:91](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L91)
57
58
 
58
59
  #### Returns
59
60
 
@@ -71,7 +72,7 @@ Defined in: [services/PrismaService.ts:80](https://github.com/RueDeRennes/archip
71
72
  onModuleInit(): Promise<void>;
72
73
  ```
73
74
 
74
- Defined in: [services/PrismaService.ts:68](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L68)
75
+ Defined in: [services/PrismaService.ts:79](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L79)
75
76
 
76
77
  #### Returns
77
78
 
@@ -149,7 +150,7 @@ Executes a transactional callback (extended overload missing in base typing wrap
149
150
  withExtensions(): PrismaService;
150
151
  ```
151
152
 
152
- Defined in: [services/PrismaService.ts:44](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L44)
153
+ Defined in: [services/PrismaService.ts:55](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L55)
153
154
 
154
155
  #### Returns
155
156
 
@@ -5,7 +5,7 @@ editUrl: false
5
5
  ---
6
6
  # Class: PrismaService
7
7
 
8
- Defined in: [services/PrismaService.ts:20](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L20)
8
+ Defined in: [services/PrismaService.ts:27](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L27)
9
9
 
10
10
  Represents the prisma service.
11
11
 
@@ -33,18 +33,19 @@ Represents the prisma service.
33
33
  ### Constructor
34
34
 
35
35
  ```ts
36
- new PrismaService(configService): PrismaService;
36
+ new PrismaService(configService, options?): PrismaService;
37
37
  ```
38
38
 
39
- Defined in: [services/PrismaService.ts:34](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L34)
39
+ Defined in: [services/PrismaService.ts:41](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L41)
40
40
 
41
- Constructs a new instance of the `DatabaseService` class.
41
+ Constructs a new instance of the `PrismaService` class.
42
42
 
43
43
  #### Parameters
44
44
 
45
45
  | Parameter | Type |
46
46
  | ------ | ------ |
47
47
  | `configService` | `ConfigService` |
48
+ | `options?` | [`IPrismaServiceOptions`](Interface.IPrismaServiceOptions) |
48
49
 
49
50
  #### Returns
50
51
 
@@ -64,7 +65,7 @@ PrismaClient.constructor
64
65
  onModuleDestroy(): Promise<void>;
65
66
  ```
66
67
 
67
- Defined in: [services/PrismaService.ts:80](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L80)
68
+ Defined in: [services/PrismaService.ts:91](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L91)
68
69
 
69
70
  #### Returns
70
71
 
@@ -84,7 +85,7 @@ OnModuleDestroy.onModuleDestroy
84
85
  onModuleInit(): Promise<void>;
85
86
  ```
86
87
 
87
- Defined in: [services/PrismaService.ts:68](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L68)
88
+ Defined in: [services/PrismaService.ts:79](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L79)
88
89
 
89
90
  #### Returns
90
91
 
@@ -104,7 +105,7 @@ OnModuleInit.onModuleInit
104
105
  withExtensions(): PrismaService;
105
106
  ```
106
107
 
107
- Defined in: [services/PrismaService.ts:44](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L44)
108
+ Defined in: [services/PrismaService.ts:55](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L55)
108
109
 
109
110
  #### Returns
110
111
 
@@ -11,12 +11,24 @@ Represents the database module configuration.
11
11
 
12
12
  ## Properties
13
13
 
14
+ ### accelerateUrl?
15
+
16
+ ```ts
17
+ optional accelerateUrl?: string;
18
+ ```
19
+
20
+ Defined in: [DatabaseModule.ts:19](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/DatabaseModule.ts#L19)
21
+
22
+ Prisma Accelerate URL allowing the client to connect through Accelerate.
23
+
24
+ ***
25
+
14
26
  ### middlewares?
15
27
 
16
28
  ```ts
17
29
  optional middlewares?: unknown[];
18
30
  ```
19
31
 
20
- Defined in: [DatabaseModule.ts:19](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/DatabaseModule.ts#L19)
32
+ Defined in: [DatabaseModule.ts:21](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/DatabaseModule.ts#L21)
21
33
 
22
34
  Future extension point for Prisma middlewares
@@ -0,0 +1,22 @@
1
+ ---
2
+ title: 'Interface: IPrismaServiceOptions'
3
+ generated: true
4
+ editUrl: false
5
+ ---
6
+ # Interface: IPrismaServiceOptions
7
+
8
+ Defined in: [services/PrismaService.ts:16](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L16)
9
+
10
+ Represents the options for the PrismaService.
11
+
12
+ ## Properties
13
+
14
+ ### accelerateUrl?
15
+
16
+ ```ts
17
+ optional accelerateUrl?: string;
18
+ ```
19
+
20
+ Defined in: [services/PrismaService.ts:18](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/services/PrismaService.ts#L18)
21
+
22
+ Prisma Accelerate URL allowing the client to connect through Accelerate. Takes priority over the `DB_ACCELERATE_URL` config key.
@@ -0,0 +1,14 @@
1
+ ---
2
+ title: 'Variable: DATABASE\_MODULE\_CONFIG'
3
+ generated: true
4
+ editUrl: false
5
+ ---
6
+ # Variable: DATABASE\_MODULE\_CONFIG
7
+
8
+ ```ts
9
+ const DATABASE_MODULE_CONFIG: "DATABASE_MODULE_CONFIG" = 'DATABASE_MODULE_CONFIG';
10
+ ```
11
+
12
+ Defined in: [DatabaseModule.ts:29](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/DatabaseModule.ts#L29)
13
+
14
+ Represents the database module.
@@ -0,0 +1,14 @@
1
+ ---
2
+ title: 'Variable: DB\_ACCELERATE\_URL'
3
+ generated: true
4
+ editUrl: false
5
+ ---
6
+ # Variable: DB\_ACCELERATE\_URL
7
+
8
+ ```ts
9
+ const DB_ACCELERATE_URL: IConfigKey<string>;
10
+ ```
11
+
12
+ Defined in: [configKeys.ts:11](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/configKeys.ts#L11)
13
+
14
+ Prisma Accelerate URL for managed connection pooling.
@@ -0,0 +1,14 @@
1
+ ---
2
+ title: 'Variable: DB\_AUTO\_CONNECTION'
3
+ generated: true
4
+ editUrl: false
5
+ ---
6
+ # Variable: DB\_AUTO\_CONNECTION
7
+
8
+ ```ts
9
+ const DB_AUTO_CONNECTION: IConfigKey<boolean>;
10
+ ```
11
+
12
+ Defined in: [configKeys.ts:8](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/configKeys.ts#L8)
13
+
14
+ Whether to skip the automatic database connection on module init.
@@ -0,0 +1,14 @@
1
+ ---
2
+ title: 'Variable: DB\_OPTIMIZE'
3
+ generated: true
4
+ editUrl: false
5
+ ---
6
+ # Variable: DB\_OPTIMIZE
7
+
8
+ ```ts
9
+ const DB_OPTIMIZE: IConfigKey<boolean>;
10
+ ```
11
+
12
+ Defined in: [configKeys.ts:14](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/configKeys.ts#L14)
13
+
14
+ Whether Prisma Optimize query analysis is enabled.
@@ -0,0 +1,14 @@
1
+ ---
2
+ title: 'Variable: DB\_OPTIMIZE\_API\_KEY'
3
+ generated: true
4
+ editUrl: false
5
+ ---
6
+ # Variable: DB\_OPTIMIZE\_API\_KEY
7
+
8
+ ```ts
9
+ const DB_OPTIMIZE_API_KEY: IConfigKey<string>;
10
+ ```
11
+
12
+ Defined in: [configKeys.ts:17](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/configKeys.ts#L17)
13
+
14
+ API key for the Prisma Optimize dashboard.
@@ -0,0 +1,14 @@
1
+ ---
2
+ title: 'Variable: PLATFORM\_DATABASE\_CONFIG\_ENTRIES'
3
+ generated: true
4
+ editUrl: false
5
+ ---
6
+ # Variable: PLATFORM\_DATABASE\_CONFIG\_ENTRIES
7
+
8
+ ```ts
9
+ const PLATFORM_DATABASE_CONFIG_ENTRIES: ReadonlyArray<Omit<IConfigRegistryEntry, "module">>;
10
+ ```
11
+
12
+ Defined in: [configKeys.ts:20](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-database/src/configKeys.ts#L20)
13
+
14
+ Core configuration entries required by `platform-database`.
@@ -10,7 +10,7 @@ editUrl: false
10
10
  | Class | Description |
11
11
  | ------ | ------ |
12
12
  | [DatabaseHealthIndicator](Class.DatabaseHealthIndicator) | Health indicator for database connectivity. |
13
- | [DatabaseModule](Class.DatabaseModule) | Represents the database module. |
13
+ | [DatabaseModule](Class.DatabaseModule) | - |
14
14
  | [DatabaseService](Class.DatabaseService) | Represents the database service. |
15
15
  | [PrismaService](Class.PrismaService) | Represents the prisma service. |
16
16
  | [RepositoryBase](Class.RepositoryBase) | The base class for all repositories. |
@@ -23,6 +23,7 @@ editUrl: false
23
23
  | [IDatabaseModuleConfig](Interface.IDatabaseModuleConfig) | Represents the database module configuration. |
24
24
  | [IPaginatedResult](Interface.IPaginatedResult) | - |
25
25
  | [IPaginateOptions](Interface.IPaginateOptions) | - |
26
+ | [IPrismaServiceOptions](Interface.IPrismaServiceOptions) | Represents the options for the PrismaService. |
26
27
  | [IRepositoryQuery](Interface.IRepositoryQuery) | Represents a reusable query definition for repositories. |
27
28
  | [ITransactionalRepositoryQuery](Interface.ITransactionalRepositoryQuery) | Represents a repository query that requires a Prisma TransactionClient to access multiple delegates. |
28
29
 
@@ -36,6 +37,17 @@ editUrl: false
36
37
  | [QueryResultType](TypeAlias.QueryResultType) | Extracts the result type from a repository query. Useful for type-safe mapping without duplicating query result types. |
37
38
  | [TransactionalQueryResultType](TypeAlias.TransactionalQueryResultType) | Extracts the result type from a transactional repository query. |
38
39
 
40
+ ## Variables
41
+
42
+ | Variable | Description |
43
+ | ------ | ------ |
44
+ | [DATABASE\_MODULE\_CONFIG](Variable.DATABASE_MODULE_CONFIG) | Represents the database module. |
45
+ | [DB\_ACCELERATE\_URL](Variable.DB_ACCELERATE_URL) | Prisma Accelerate URL for managed connection pooling. |
46
+ | [DB\_AUTO\_CONNECTION](Variable.DB_AUTO_CONNECTION) | Whether to skip the automatic database connection on module init. |
47
+ | [DB\_OPTIMIZE](Variable.DB_OPTIMIZE) | Whether Prisma Optimize query analysis is enabled. |
48
+ | [DB\_OPTIMIZE\_API\_KEY](Variable.DB_OPTIMIZE_API_KEY) | API key for the Prisma Optimize dashboard. |
49
+ | [PLATFORM\_DATABASE\_CONFIG\_ENTRIES](Variable.PLATFORM_DATABASE_CONFIG_ENTRIES) | Core configuration entries required by `platform-database`. |
50
+
39
51
  ## Functions
40
52
 
41
53
  | Function | Description |
@@ -16,10 +16,13 @@ Prisma ORM integration with PostgreSQL featuring a repository base class, type-s
16
16
 
17
17
  ```typescript
18
18
  import { Module } from '@nestjs/common';
19
- import { DatabaseModule } from '@breadstone/archipel-platform-database';
19
+ import { ConfigModule } from '@breadstone/archipel-platform-core';
20
+ import { DatabaseModule, PLATFORM_DATABASE_CONFIG_ENTRIES } from '@breadstone/archipel-platform-database';
20
21
 
21
22
  @Module({
22
23
  imports: [
24
+ ConfigModule.register('database', PLATFORM_DATABASE_CONFIG_ENTRIES),
25
+
23
26
  // Global registration (recommended)
24
27
  DatabaseModule.forRoot(),
25
28
 
@@ -36,6 +39,7 @@ export class AppModule {}
36
39
 
37
40
  ```typescript
38
41
  interface IDatabaseModuleConfig {
42
+ accelerateUrl?: string; // Prisma Accelerate URL (overrides DB_ACCELERATE_URL env var)
39
43
  middlewares?: Array<unknown>; // Future extension point
40
44
  }
41
45
 
@@ -46,14 +50,28 @@ DatabaseModule.forRoot(config?: IDatabaseModuleConfig): DynamicModule
46
50
  DatabaseModule.register(config?: IDatabaseModuleConfig): DynamicModule
47
51
  ```
48
52
 
53
+ ### Config Keys
54
+
55
+ Register all database config keys with `PLATFORM_DATABASE_CONFIG_ENTRIES`:
56
+
57
+ ```typescript
58
+ import { ConfigModule } from '@breadstone/archipel-platform-core';
59
+ import { PLATFORM_DATABASE_CONFIG_ENTRIES } from '@breadstone/archipel-platform-database';
60
+
61
+ ConfigModule.register('database', PLATFORM_DATABASE_CONFIG_ENTRIES);
62
+ ```
63
+
49
64
  ### Environment Variables
50
65
 
51
- | Variable | Description | Required |
52
- | --------------------- | -------------------------------- | ------------------- |
53
- | `DATABASE_URL` | PostgreSQL connection string | Yes |
54
- | `DB_OPTIMIZE` | Enable Prisma query optimization | No |
55
- | `DB_OPTIMIZE_API_KEY` | Prisma Optimize API key | If optimize enabled |
56
- | `DB_AUTO_CONNECTION` | Auto-connect on module init | No (default: true) |
66
+ | Variable | Description | Required | Default |
67
+ | --------------------- | ----------------------------------------- | ------------------- | ------- |
68
+ | `DATABASE_URL` | PostgreSQL connection string | Yes | — |
69
+ | `DB_ACCELERATE_URL` | Prisma Accelerate proxy URL | No | `''` |
70
+ | `DB_AUTO_CONNECTION` | Auto-connect on module init | No | `true` |
71
+ | `DB_OPTIMIZE` | Enable Prisma Optimize query analysis | No | `true` |
72
+ | `DB_OPTIMIZE_API_KEY` | API key for the Prisma Optimize dashboard | If optimize enabled | `''` |
73
+
74
+ > **Accelerate resolution order:** `accelerateUrl` module parameter → `DB_ACCELERATE_URL` environment variable → no Accelerate.
57
75
 
58
76
  ---
59
77
 
@@ -287,14 +305,19 @@ import { DatabaseHealthIndicator } from '@breadstone/archipel-platform-database'
287
305
 
288
306
  ## Exports Summary
289
307
 
290
- | Export | Type | Description |
291
- | ------------------------- | -------------- | ---------------------------------------- |
292
- | `DatabaseModule` | NestJS Module | `forRoot()` / `register()` |
293
- | `DatabaseService` | Service | Extended Prisma client with transactions |
294
- | `PrismaService` | Service | Prisma client with extensions |
295
- | `RepositoryBase` | Abstract class | Base class for repositories |
296
- | `query()` | Factory | Create typed query objects |
297
- | `transactionalQuery()` | Factory | Create transactional query objects |
298
- | `paginator()` | Factory | Create pagination helper |
299
- | `DatabaseHealthIndicator` | Health | PostgreSQL health check |
300
- | `DB` (Prisma) | Namespace | Re-exported Prisma types |
308
+ | Export | Type | Description |
309
+ | ---------------------------------- | -------------- | ---------------------------------------- |
310
+ | `DatabaseModule` | NestJS Module | `forRoot()` / `register()` |
311
+ | `DatabaseService` | Service | Extended Prisma client with transactions |
312
+ | `PrismaService` | Service | Prisma client with extensions |
313
+ | `RepositoryBase` | Abstract class | Base class for repositories |
314
+ | `query()` | Factory | Create typed query objects |
315
+ | `transactionalQuery()` | Factory | Create transactional query objects |
316
+ | `paginator()` | Factory | Create pagination helper |
317
+ | `DatabaseHealthIndicator` | Health | PostgreSQL health check |
318
+ | `PLATFORM_DATABASE_CONFIG_ENTRIES` | Constant | Config entries for `ConfigModule` |
319
+ | `DB_ACCELERATE_URL` | Config Key | Prisma Accelerate URL |
320
+ | `DB_AUTO_CONNECTION` | Config Key | Auto-connect toggle |
321
+ | `DB_OPTIMIZE` | Config Key | Prisma Optimize toggle |
322
+ | `DB_OPTIMIZE_API_KEY` | Config Key | Prisma Optimize API key |
323
+ | `DB` (Prisma) | Namespace | Re-exported Prisma types |
@@ -5,7 +5,7 @@ editUrl: false
5
5
  ---
6
6
  # Class: NoopTelemetryFacade
7
7
 
8
- Defined in: [core/NoopTelemetryFacade.ts:11](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/core/NoopTelemetryFacade.ts#L11)
8
+ Defined in: [core/NoopTelemetryFacade.ts:7](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/core/NoopTelemetryFacade.ts#L7)
9
9
 
10
10
  ## Implements
11
11
 
@@ -31,7 +31,7 @@ new NoopTelemetryFacade(): NoopTelemetryFacade;
31
31
  optional recordCacheEvent(_): void;
32
32
  ```
33
33
 
34
- Defined in: [core/NoopTelemetryFacade.ts:14](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/core/NoopTelemetryFacade.ts#L14)
34
+ Defined in: [core/NoopTelemetryFacade.ts:11](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/core/NoopTelemetryFacade.ts#L11)
35
35
 
36
36
  #### Parameters
37
37
 
@@ -56,21 +56,21 @@ Defined in: [core/NoopTelemetryFacade.ts:14](https://github.com/RueDeRennes/arch
56
56
 
57
57
  ```ts
58
58
  optional recordClientMetric(
59
- name,
60
- type,
61
- value,
59
+ _name,
60
+ _type,
61
+ _value,
62
62
  _labels?): void;
63
63
  ```
64
64
 
65
- Defined in: [core/NoopTelemetryFacade.ts:19](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/core/NoopTelemetryFacade.ts#L19)
65
+ Defined in: [core/NoopTelemetryFacade.ts:14](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/core/NoopTelemetryFacade.ts#L14)
66
66
 
67
67
  #### Parameters
68
68
 
69
69
  | Parameter | Type |
70
70
  | ------ | ------ |
71
- | `name` | `string` |
72
- | `type` | `string` |
73
- | `value` | `number` |
71
+ | `_name` | `string` |
72
+ | `_type` | `string` |
73
+ | `_value` | `number` |
74
74
  | `_labels?` | `Record`\<`string`, `string`\> |
75
75
 
76
76
  #### Returns
@@ -89,7 +89,7 @@ Defined in: [core/NoopTelemetryFacade.ts:19](https://github.com/RueDeRennes/arch
89
89
  runOperation<T>(_, fn): Promise<T>;
90
90
  ```
91
91
 
92
- Defined in: [core/NoopTelemetryFacade.ts:13](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/core/NoopTelemetryFacade.ts#L13)
92
+ Defined in: [core/NoopTelemetryFacade.ts:8](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/core/NoopTelemetryFacade.ts#L8)
93
93
 
94
94
  #### Type Parameters
95
95
 
@@ -42,7 +42,7 @@ optional recordClientMetric(
42
42
  labels?): void;
43
43
  ```
44
44
 
45
- Defined in: [core/NoopTelemetryFacade.ts:8](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/core/NoopTelemetryFacade.ts#L8)
45
+ Defined in: [core/NoopTelemetryFacade.ts:4](https://github.com/RueDeRennes/archipel/blob/main/libs/platform-telemetry/src/core/NoopTelemetryFacade.ts#L4)
46
46
 
47
47
  #### Parameters
48
48
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@breadstone/archipel-mcp",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "MCP server providing Archipel platform knowledge — documentation, query patterns, and coding conventions — to AI development tools.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/main.js",