@breadstone/archipel-mcp 0.0.37 → 0.0.39
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/data/guides/application-bootstrap.md +181 -0
- package/data/guides/email-templates.md +4 -0
- package/data/guides/index.md +1 -2
- package/data/guides/openapi-and-feature-discovery.md +26 -1
- package/data/packages/platform-bootstrap/api/Class.PlatformApplication.md +41 -0
- package/data/packages/platform-bootstrap/api/Class.PlatformApplicationBuilder.md +164 -0
- package/data/packages/platform-bootstrap/api/Class.PlatformBootstrapContext.md +164 -0
- package/data/packages/platform-bootstrap/api/Class.PlatformBootstrapError.md +130 -0
- package/data/packages/platform-bootstrap/api/Function.createPlatformTestApplication.md +26 -0
- package/data/packages/platform-bootstrap/api/Function.useApi.md +32 -0
- package/data/packages/platform-bootstrap/api/Function.useExpressServer.md +32 -0
- package/data/packages/platform-bootstrap/api/Function.useOpenApi.md +32 -0
- package/data/packages/platform-bootstrap/api/Function.useSecurity.md +32 -0
- package/data/packages/platform-bootstrap/api/Function.useSession.md +32 -0
- package/data/packages/platform-bootstrap/api/Interface.IApiStepOptions.md +58 -0
- package/data/packages/platform-bootstrap/api/Interface.IApiValidationOptions.md +58 -0
- package/data/packages/platform-bootstrap/api/Interface.IExpressServerStepOptions.md +46 -0
- package/data/packages/platform-bootstrap/api/Interface.IOpenApiStepOptions.md +34 -0
- package/data/packages/platform-bootstrap/api/Interface.IPlatformApplicationOptions.md +22 -0
- package/data/packages/platform-bootstrap/api/Interface.IPlatformListenOptions.md +46 -0
- package/data/packages/platform-bootstrap/api/Interface.IPlatformTestApplication.md +211 -0
- package/data/packages/platform-bootstrap/api/Interface.ISecurityStepOptions.md +63 -0
- package/data/packages/platform-bootstrap/api/Interface.ISessionStepOptions.md +118 -0
- package/data/packages/platform-bootstrap/api/TypeAlias.PlatformBootstrapNext.md +18 -0
- package/data/packages/platform-bootstrap/api/TypeAlias.PlatformBootstrapStep.md +31 -0
- package/data/packages/platform-bootstrap/api/TypeAlias.PlatformContentSecurityPolicyMode.md +14 -0
- package/data/packages/platform-bootstrap/api/TypeAlias.PlatformCorsOptions.md +14 -0
- package/data/packages/platform-bootstrap/api/TypeAlias.SecurityRateLimitOptions.md +28 -0
- package/data/packages/platform-bootstrap/api/Variable.APP_CORS_ORIGIN.md +14 -0
- package/data/packages/platform-bootstrap/api/Variable.APP_RATE_LIMIT_MAX_REQUESTS.md +14 -0
- package/data/packages/platform-bootstrap/api/Variable.APP_RATE_LIMIT_WINDOW_MS.md +14 -0
- package/data/packages/platform-bootstrap/api/Variable.AUTH_SESSION_MAX_AGE.md +14 -0
- package/data/packages/platform-bootstrap/api/Variable.AUTH_SESSION_SECRET.md +14 -0
- package/data/packages/platform-bootstrap/api/Variable.AUTH_SESSION_SECURE.md +14 -0
- package/data/packages/platform-bootstrap/api/Variable.PLATFORM_SECURITY_CONFIG_ENTRIES.md +14 -0
- package/data/packages/platform-bootstrap/api/Variable.PLATFORM_SERVER_CONFIG_ENTRIES.md +14 -0
- package/data/packages/platform-bootstrap/api/Variable.PLATFORM_SESSION_CONFIG_ENTRIES.md +14 -0
- package/data/packages/platform-bootstrap/api/Variable.PORT.md +14 -0
- package/data/packages/platform-bootstrap/api/index.md +65 -0
- package/data/packages/platform-bootstrap/index.md +162 -0
- package/data/patterns/bootstrap-pattern.md +145 -0
- package/data/patterns/index.md +21 -0
- package/package.json +2 -2
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: '@breadstone/archipel-platform-bootstrap'
|
|
3
|
+
generated: true
|
|
4
|
+
editUrl: false
|
|
5
|
+
---
|
|
6
|
+
# @breadstone/archipel-platform-bootstrap
|
|
7
|
+
|
|
8
|
+
## Classes
|
|
9
|
+
|
|
10
|
+
| Class | Description |
|
|
11
|
+
| ------ | ------ |
|
|
12
|
+
| [PlatformApplication](Class.PlatformApplication) | Entry point for composing an existing NestJS application with Archipel bootstrap steps. |
|
|
13
|
+
| [PlatformApplicationBuilder](Class.PlatformApplicationBuilder) | Fluent builder that composes NestJS bootstrap steps and executes them once. |
|
|
14
|
+
| [PlatformBootstrapContext](Class.PlatformBootstrapContext) | Runtime context shared by platform bootstrap steps. |
|
|
15
|
+
| [PlatformBootstrapError](Class.PlatformBootstrapError) | Error raised when an Archipel platform bootstrap step fails. |
|
|
16
|
+
|
|
17
|
+
## Interfaces
|
|
18
|
+
|
|
19
|
+
| Interface | Description |
|
|
20
|
+
| ------ | ------ |
|
|
21
|
+
| [IApiStepOptions](Interface.IApiStepOptions) | Options for the generic Archipel API bootstrap step. |
|
|
22
|
+
| [IApiValidationOptions](Interface.IApiValidationOptions) | Validation options used by the generic Archipel API bootstrap step. |
|
|
23
|
+
| [IExpressServerStepOptions](Interface.IExpressServerStepOptions) | Options for the Express-compatible server bootstrap step. |
|
|
24
|
+
| [IOpenApiStepOptions](Interface.IOpenApiStepOptions) | Options for the OpenAPI bootstrap step. |
|
|
25
|
+
| [IPlatformApplicationOptions](Interface.IPlatformApplicationOptions) | Options for wrapping an existing NestJS application with Archipel platform bootstrap support. |
|
|
26
|
+
| [IPlatformListenOptions](Interface.IPlatformListenOptions) | Options for resolving the HTTP listen port from typed configuration keys. |
|
|
27
|
+
| [IPlatformTestApplication](Interface.IPlatformTestApplication) | In-memory application contract used by platform bootstrap tests. |
|
|
28
|
+
| [ISecurityStepOptions](Interface.ISecurityStepOptions) | Options for the generic security bootstrap step. |
|
|
29
|
+
| [ISessionStepOptions](Interface.ISessionStepOptions) | Options for the Express-compatible session bootstrap step. |
|
|
30
|
+
|
|
31
|
+
## Type Aliases
|
|
32
|
+
|
|
33
|
+
| Type Alias | Description |
|
|
34
|
+
| ------ | ------ |
|
|
35
|
+
| [PlatformBootstrapNext](TypeAlias.PlatformBootstrapNext) | Continues execution with the next platform bootstrap step. |
|
|
36
|
+
| [PlatformBootstrapStep](TypeAlias.PlatformBootstrapStep) | A composable bootstrap step in the platform application pipeline. |
|
|
37
|
+
| [PlatformContentSecurityPolicyMode](TypeAlias.PlatformContentSecurityPolicyMode) | Named content-security-policy modes supported by `platform-bootstrap/security`. |
|
|
38
|
+
| [PlatformCorsOptions](TypeAlias.PlatformCorsOptions) | CORS options accepted by the security bootstrap step. |
|
|
39
|
+
| [SecurityRateLimitOptions](TypeAlias.SecurityRateLimitOptions) | Rate-limit options accepted by the security bootstrap step. |
|
|
40
|
+
|
|
41
|
+
## Variables
|
|
42
|
+
|
|
43
|
+
| Variable | Description |
|
|
44
|
+
| ------ | ------ |
|
|
45
|
+
| [APP\_CORS\_ORIGIN](Variable.APP_CORS_ORIGIN) | Comma-separated list of allowed CORS origins. |
|
|
46
|
+
| [APP\_RATE\_LIMIT\_MAX\_REQUESTS](Variable.APP_RATE_LIMIT_MAX_REQUESTS) | Maximum requests accepted within the rate-limit window. |
|
|
47
|
+
| [APP\_RATE\_LIMIT\_WINDOW\_MS](Variable.APP_RATE_LIMIT_WINDOW_MS) | Rate-limit window in milliseconds. |
|
|
48
|
+
| [AUTH\_SESSION\_MAX\_AGE](Variable.AUTH_SESSION_MAX_AGE) | Session cookie lifetime, for example `30d` or `86400000`. |
|
|
49
|
+
| [AUTH\_SESSION\_SECRET](Variable.AUTH_SESSION_SECRET) | Secret used by Express-compatible session middleware. |
|
|
50
|
+
| [AUTH\_SESSION\_SECURE](Variable.AUTH_SESSION_SECURE) | Whether session cookies should be marked secure. |
|
|
51
|
+
| [PLATFORM\_SECURITY\_CONFIG\_ENTRIES](Variable.PLATFORM_SECURITY_CONFIG_ENTRIES) | Security step configuration entries provided by `platform-bootstrap/security`. |
|
|
52
|
+
| [PLATFORM\_SERVER\_CONFIG\_ENTRIES](Variable.PLATFORM_SERVER_CONFIG_ENTRIES) | Server bootstrap configuration entries provided by `platform-bootstrap`. |
|
|
53
|
+
| [PLATFORM\_SESSION\_CONFIG\_ENTRIES](Variable.PLATFORM_SESSION_CONFIG_ENTRIES) | Session step configuration entries provided by `platform-bootstrap/session`. |
|
|
54
|
+
| [PORT](Variable.PORT) | HTTP port exposed by serverless hosts such as Vercel. |
|
|
55
|
+
|
|
56
|
+
## Functions
|
|
57
|
+
|
|
58
|
+
| Function | Description |
|
|
59
|
+
| ------ | ------ |
|
|
60
|
+
| [createPlatformTestApplication](Function.createPlatformTestApplication) | Creates a lightweight in-memory NestJS application double for platform bootstrap tests. |
|
|
61
|
+
| [useApi](Function.useApi) | Creates the generic Archipel API bootstrap step. |
|
|
62
|
+
| [useExpressServer](Function.useExpressServer) | Creates an Express-compatible server bootstrap step. |
|
|
63
|
+
| [useOpenApi](Function.useOpenApi) | Creates the Archipel OpenAPI multi-document bootstrap step. |
|
|
64
|
+
| [useSecurity](Function.useSecurity) | Creates the generic security bootstrap step. |
|
|
65
|
+
| [useSession](Function.useSession) | Creates an Express-compatible session bootstrap step. |
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: platform-bootstrap
|
|
3
|
+
description: Generic NestJS application composition for APIs, Express middleware, security, sessions, and OpenAPI.
|
|
4
|
+
order: 1
|
|
5
|
+
tags: [application, bootstrap, server, security, openapi, nestjs]
|
|
6
|
+
package: '@breadstone/archipel-platform-bootstrap'
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# platform-bootstrap
|
|
10
|
+
|
|
11
|
+
Generic NestJS application composition for Archipel APIs. It replaces repeated app-level bootstrap code with a fluent `PlatformApplication` builder and tree-shakable subpath steps.
|
|
12
|
+
|
|
13
|
+
The package starts from an existing Nest application. Your entrypoint still calls `NestFactory.create()`, selects the HTTP adapter, and keeps the concrete application type visible. `platform-bootstrap` then applies reusable startup steps for API defaults, Express middleware, security, sessions, OpenAPI, and tests.
|
|
14
|
+
|
|
15
|
+
**Package:** `@breadstone/archipel-platform-bootstrap`
|
|
16
|
+
|
|
17
|
+
<InstallTabs />
|
|
18
|
+
|
|
19
|
+
## When to Use
|
|
20
|
+
|
|
21
|
+
Use this package when multiple NestJS apps need the same startup shape but still need explicit control over their adapter and deployment target.
|
|
22
|
+
|
|
23
|
+
| Use Case | Fit |
|
|
24
|
+
| -------- | --- |
|
|
25
|
+
| HTTP APIs on Express | Built-in `server/express`, `security`, `session`, and `openapi` steps. |
|
|
26
|
+
| Vercel-compatible NestJS apps | `NestFactory`, `ExpressAdapter`, and `NestExpressApplication` remain in the app entrypoint. |
|
|
27
|
+
| Shared platform startup defaults | Compose a stable sequence once and reuse it across apps. |
|
|
28
|
+
| Step-order tests | Use the `testing` subpath without starting a real HTTP server. |
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { ConsoleLogger } from '@nestjs/common';
|
|
34
|
+
import { NestFactory } from '@nestjs/core';
|
|
35
|
+
import { ExpressAdapter, NestExpressApplication } from '@nestjs/platform-express';
|
|
36
|
+
import { PlatformApplication, useApi } from '@breadstone/archipel-platform-bootstrap';
|
|
37
|
+
import { useExpressServer } from '@breadstone/archipel-platform-bootstrap/server/express';
|
|
38
|
+
import { useSecurity } from '@breadstone/archipel-platform-bootstrap/security';
|
|
39
|
+
import { useSession } from '@breadstone/archipel-platform-bootstrap/session';
|
|
40
|
+
import { useOpenApi } from '@breadstone/archipel-platform-bootstrap/openapi';
|
|
41
|
+
import { AppModule } from './AppModule';
|
|
42
|
+
|
|
43
|
+
async function main(): Promise<void> {
|
|
44
|
+
const app = await NestFactory.create<NestExpressApplication>(AppModule, new ExpressAdapter(), {
|
|
45
|
+
logger: new ConsoleLogger({ prefix: 'API', colors: true, forceConsole: true, compact: true, sorted: true }),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
await PlatformApplication.from(app)
|
|
49
|
+
.use(useApi({ prefix: 'api' }))
|
|
50
|
+
.use(useExpressServer({ json: { limit: '1mb' }, urlEncoded: { extended: true, limit: '1mb' } }))
|
|
51
|
+
.use(useSecurity({ contentSecurityPolicy: 'swagger-compatible' }))
|
|
52
|
+
.use(useSession())
|
|
53
|
+
.use(useOpenApi())
|
|
54
|
+
.listenFromConfig({ fallbackPort: 3000 });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
void main();
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
For a full application setup, see the [Application Bootstrap](/guides/application-bootstrap) guide.
|
|
61
|
+
|
|
62
|
+
## Entry Points
|
|
63
|
+
|
|
64
|
+
| Import | Purpose |
|
|
65
|
+
| ------ | ------- |
|
|
66
|
+
| `@breadstone/archipel-platform-bootstrap` | `PlatformApplication`, builder types, API step, config keys |
|
|
67
|
+
| `@breadstone/archipel-platform-bootstrap/server/express` | Express body parsers and compression middleware |
|
|
68
|
+
| `@breadstone/archipel-platform-bootstrap/security` | CORS, Helmet, content-security-policy, rate limiting |
|
|
69
|
+
| `@breadstone/archipel-platform-bootstrap/session` | Express-compatible session middleware |
|
|
70
|
+
| `@breadstone/archipel-platform-bootstrap/openapi` | `SwaggerFeatureDiscovery.setupMultiDocumentSwagger()` step |
|
|
71
|
+
| `@breadstone/archipel-platform-bootstrap/testing` | Lightweight bootstrap test application helpers |
|
|
72
|
+
|
|
73
|
+
## Configuration
|
|
74
|
+
|
|
75
|
+
Register the config entries in the root module so startup validation and configuration discovery see the same keys the steps read at runtime.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { Module } from '@nestjs/common';
|
|
79
|
+
import {
|
|
80
|
+
ConfigModule,
|
|
81
|
+
EnvironmentConfigStrategy,
|
|
82
|
+
} from '@breadstone/archipel-platform-configuration';
|
|
83
|
+
import {
|
|
84
|
+
PLATFORM_SECURITY_CONFIG_ENTRIES,
|
|
85
|
+
PLATFORM_SERVER_CONFIG_ENTRIES,
|
|
86
|
+
PLATFORM_SESSION_CONFIG_ENTRIES,
|
|
87
|
+
} from '@breadstone/archipel-platform-bootstrap';
|
|
88
|
+
|
|
89
|
+
@Module({
|
|
90
|
+
imports: [
|
|
91
|
+
ConfigModule.forRoot({
|
|
92
|
+
strategyFactory: () => new EnvironmentConfigStrategy(),
|
|
93
|
+
}),
|
|
94
|
+
ConfigModule.register('platform-bootstrap/server', PLATFORM_SERVER_CONFIG_ENTRIES),
|
|
95
|
+
ConfigModule.register('platform-bootstrap/security', PLATFORM_SECURITY_CONFIG_ENTRIES),
|
|
96
|
+
ConfigModule.register('platform-bootstrap/session', PLATFORM_SESSION_CONFIG_ENTRIES),
|
|
97
|
+
],
|
|
98
|
+
})
|
|
99
|
+
export class AppModule {}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
| Entry | Keys |
|
|
103
|
+
| ----- | ---- |
|
|
104
|
+
| `PLATFORM_SERVER_CONFIG_ENTRIES` | `PORT` |
|
|
105
|
+
| `PLATFORM_SECURITY_CONFIG_ENTRIES` | `APP_CORS_ORIGIN`, `APP_RATE_LIMIT_WINDOW_MS`, `APP_RATE_LIMIT_MAX_REQUESTS` |
|
|
106
|
+
| `PLATFORM_SESSION_CONFIG_ENTRIES` | `AUTH_SESSION_SECRET`, `AUTH_SESSION_SECURE`, `AUTH_SESSION_MAX_AGE` |
|
|
107
|
+
|
|
108
|
+
`listenFromConfig()` resolves the HTTP port from `PORT`, then `APP_PORT`, then the provided fallback.
|
|
109
|
+
|
|
110
|
+
## Built-In Steps
|
|
111
|
+
|
|
112
|
+
| Step | Options | Purpose |
|
|
113
|
+
| ---- | ------- | ------- |
|
|
114
|
+
| `useApi()` | `IApiStepOptions` | Global prefix, validation, and global exception filters. |
|
|
115
|
+
| `useExpressServer()` | `IExpressServerStepOptions` | JSON parser, URL-encoded parser, and compression middleware. |
|
|
116
|
+
| `useSecurity()` | `ISecurityStepOptions` | CORS, Helmet, content security policy, and rate limiting. |
|
|
117
|
+
| `useSession()` | `ISessionStepOptions` | Express-compatible sessions using typed config entries. |
|
|
118
|
+
| `useOpenApi()` | `IOpenApiStepOptions` | Multi-document Swagger UI discovery and setup. |
|
|
119
|
+
|
|
120
|
+
## Composition Model
|
|
121
|
+
|
|
122
|
+
The platform builder uses bootstrap steps that receive a `PlatformBootstrapContext` and call `next()` to continue the pipeline. Built-in `use*` helpers are normal step factories, so application-specific setup can live beside them without introducing a new NestJS module.
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { PlatformBootstrapStep } from '@breadstone/archipel-platform-bootstrap';
|
|
126
|
+
|
|
127
|
+
export const useCustomBootstrap = (): PlatformBootstrapStep => {
|
|
128
|
+
return async function customBootstrapStep(context, next): Promise<void> {
|
|
129
|
+
context.app.enableShutdownHooks();
|
|
130
|
+
await next();
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Step factories should use the `use*` naming convention and option interfaces should end in `StepOptions`. The shared pattern is documented in [Bootstrap Pattern](/patterns/bootstrap-pattern).
|
|
136
|
+
|
|
137
|
+
## Testing
|
|
138
|
+
|
|
139
|
+
Use the `testing` subpath when the behavior under test is bootstrap composition rather than HTTP integration.
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
import { describe, expect, it } from 'vitest';
|
|
143
|
+
import { PlatformApplication, useApi } from '@breadstone/archipel-platform-bootstrap';
|
|
144
|
+
import { createPlatformTestApplication } from '@breadstone/archipel-platform-bootstrap/testing';
|
|
145
|
+
|
|
146
|
+
describe('bootstrap', (): void => {
|
|
147
|
+
it('initializes after applying API defaults', async (): Promise<void> => {
|
|
148
|
+
const app = createPlatformTestApplication();
|
|
149
|
+
|
|
150
|
+
await PlatformApplication.from(app)
|
|
151
|
+
.use(useApi({ prefix: 'api' }))
|
|
152
|
+
.initialize();
|
|
153
|
+
|
|
154
|
+
expect(app.calls).toContain('setGlobalPrefix');
|
|
155
|
+
expect(app.calls.at(-1)).toBe('init');
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Current Scope
|
|
161
|
+
|
|
162
|
+
The first implementation targets Express-compatible NestJS HTTP applications and keeps `NestFactory` in the consuming entrypoint. Fastify, serverless handler exports, and standalone worker bootstrap steps are planned as additive subpaths.
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Bootstrap Pattern
|
|
3
|
+
description: Composable NestJS application startup with PlatformApplication, PlatformBootstrapStep, typed config, and ordered use* helpers.
|
|
4
|
+
order: 10
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Archipel Bootstrap Pattern
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
Application startup is an ordered pipeline. The Nest application is created by the consuming app, then passed into `PlatformApplication.from(app)` so reusable startup concerns can be composed as `PlatformBootstrapStep` functions.
|
|
12
|
+
|
|
13
|
+
This pattern keeps platform defaults reusable without hiding the HTTP adapter, serverless shape, or application type chosen by the consuming app.
|
|
14
|
+
|
|
15
|
+
## Canonical Shape
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { NestFactory } from '@nestjs/core';
|
|
19
|
+
import { ExpressAdapter, NestExpressApplication } from '@nestjs/platform-express';
|
|
20
|
+
import { PlatformApplication, useApi } from '@breadstone/archipel-platform-bootstrap';
|
|
21
|
+
import { useOpenApi } from '@breadstone/archipel-platform-bootstrap/openapi';
|
|
22
|
+
import { useExpressServer } from '@breadstone/archipel-platform-bootstrap/server/express';
|
|
23
|
+
import { useSecurity } from '@breadstone/archipel-platform-bootstrap/security';
|
|
24
|
+
import { AppModule } from './AppModule';
|
|
25
|
+
|
|
26
|
+
async function main(): Promise<void> {
|
|
27
|
+
const app = await NestFactory.create<NestExpressApplication>(AppModule, new ExpressAdapter());
|
|
28
|
+
|
|
29
|
+
await PlatformApplication.from(app)
|
|
30
|
+
.use(useApi({ prefix: 'api' }))
|
|
31
|
+
.use(useExpressServer())
|
|
32
|
+
.use(useSecurity({ contentSecurityPolicy: 'swagger-compatible' }))
|
|
33
|
+
.use(useOpenApi())
|
|
34
|
+
.listenFromConfig({ fallbackPort: 3000 });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
void main();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Step Contract
|
|
41
|
+
|
|
42
|
+
A `PlatformBootstrapStep` receives a `PlatformBootstrapContext` and a `next` callback. The step may configure the app, resolve services from the app container, and then continue the pipeline.
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { PlatformBootstrapStep } from '@breadstone/archipel-platform-bootstrap';
|
|
46
|
+
|
|
47
|
+
export function useRequestLogging(): PlatformBootstrapStep {
|
|
48
|
+
return async function requestLoggingStep(context, next): Promise<void> {
|
|
49
|
+
context.app.use((request, response, nextMiddleware): void => {
|
|
50
|
+
response.setHeader('x-platform', 'archipel');
|
|
51
|
+
nextMiddleware();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await next();
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
A step should call `await next()` exactly once unless it intentionally terminates startup because of a validation or configuration failure.
|
|
60
|
+
|
|
61
|
+
## Naming Rules
|
|
62
|
+
|
|
63
|
+
| Artifact | Rule | Example |
|
|
64
|
+
| -------- | ---- | ------- |
|
|
65
|
+
| Step factory | Starts with `use` and describes the application concern. | `useSecurity()` |
|
|
66
|
+
| Options interface | Uses the same concern name and ends with `StepOptions`. | `ISecurityStepOptions` |
|
|
67
|
+
| Step function name | Describes the runtime work and ends with `Step`. | `securityStep` |
|
|
68
|
+
| Import path | Uses the package root for core types and subpaths for optional concerns. | `@breadstone/archipel-platform-bootstrap/security` |
|
|
69
|
+
|
|
70
|
+
Do not introduce alternative public names for the same concept. The shared vocabulary is `PlatformApplication`, `PlatformApplicationBuilder`, `PlatformBootstrapContext`, `PlatformBootstrapStep`, and `use*` helpers.
|
|
71
|
+
|
|
72
|
+
## Ordering Rules
|
|
73
|
+
|
|
74
|
+
Recommended HTTP API order:
|
|
75
|
+
|
|
76
|
+
1. `useApi()` for prefix, validation, and global filters.
|
|
77
|
+
2. `useExpressServer()` for parsers and compression.
|
|
78
|
+
3. `useSecurity()` for CORS, Helmet, content security policy, and rate limiting.
|
|
79
|
+
4. `useSession()` when route handlers or guards need session state.
|
|
80
|
+
5. `useOpenApi()` after modules and decorators are loaded.
|
|
81
|
+
6. Application-specific steps placed next to the platform step they affect.
|
|
82
|
+
|
|
83
|
+
The builder executes once. Calling `initialize()`, `run()`, `listen()`, or `listenFromConfig()` reuses the same execution promise, which prevents duplicate middleware registration during concurrent startup paths.
|
|
84
|
+
|
|
85
|
+
## Configuration Rules
|
|
86
|
+
|
|
87
|
+
- Define config keys with `createConfigKey<T>()` in `env.ts`.
|
|
88
|
+
- Export grouped config entry arrays, such as `PLATFORM_SERVER_CONFIG_ENTRIES`.
|
|
89
|
+
- Register those entries through `ConfigModule.register()` in the root module.
|
|
90
|
+
- Resolve config through `ConfigService` inside steps, never through direct environment access.
|
|
91
|
+
- Let required entries fail during startup instead of failing on the first request.
|
|
92
|
+
|
|
93
|
+
## Custom Step Template
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { INestApplication } from '@nestjs/common';
|
|
97
|
+
import { PlatformBootstrapStep } from '@breadstone/archipel-platform-bootstrap';
|
|
98
|
+
|
|
99
|
+
export interface IShutdownHooksStepOptions {
|
|
100
|
+
readonly signals?: ReadonlyArray<string>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function useShutdownHooks<TApplication extends INestApplication = INestApplication>(
|
|
104
|
+
options?: IShutdownHooksStepOptions,
|
|
105
|
+
): PlatformBootstrapStep<TApplication> {
|
|
106
|
+
return async function shutdownHooksStep(context, next): Promise<void> {
|
|
107
|
+
context.app.enableShutdownHooks(options?.signals);
|
|
108
|
+
await next();
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Use a generic `TApplication extends INestApplication` when a step needs to preserve the concrete application type. Keep options immutable and optional unless the step cannot operate safely without them.
|
|
114
|
+
|
|
115
|
+
## Testing Rules
|
|
116
|
+
|
|
117
|
+
Use the testing subpath for composition tests:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { expect, it } from 'vitest';
|
|
121
|
+
import { PlatformApplication, useApi } from '@breadstone/archipel-platform-bootstrap';
|
|
122
|
+
import { createPlatformTestApplication } from '@breadstone/archipel-platform-bootstrap/testing';
|
|
123
|
+
|
|
124
|
+
it('initializes after applying bootstrap steps', async (): Promise<void> => {
|
|
125
|
+
const app = createPlatformTestApplication();
|
|
126
|
+
|
|
127
|
+
await PlatformApplication.from(app)
|
|
128
|
+
.use(useApi({ prefix: 'api' }))
|
|
129
|
+
.initialize();
|
|
130
|
+
|
|
131
|
+
expect(app.calls).toEqual(expect.arrayContaining(['setGlobalPrefix', 'useGlobalPipes', 'init']));
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Use a real Nest app with Supertest when validating HTTP middleware behavior, route responses, cookies, or Swagger endpoints.
|
|
136
|
+
|
|
137
|
+
## Checklist
|
|
138
|
+
|
|
139
|
+
- `NestFactory` remains in the consuming entrypoint.
|
|
140
|
+
- Startup concerns are added through `.use(useSomething())`.
|
|
141
|
+
- Step option interfaces are named `I*StepOptions`.
|
|
142
|
+
- Steps call `await next()` once in the normal path.
|
|
143
|
+
- Config entries are registered before the builder reads them.
|
|
144
|
+
- Swagger-compatible content security policy is enabled when OpenAPI UI is served.
|
|
145
|
+
- Tests cover step order and failure behavior for custom steps.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Patterns
|
|
3
|
+
description: Reusable implementation patterns for Archipel platform libraries and applications.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Patterns
|
|
7
|
+
|
|
8
|
+
These patterns document repeatable implementation shapes used across Archipel. Use them when adding platform library code, application integration code, or AI-assisted scaffolding that must follow repository conventions.
|
|
9
|
+
|
|
10
|
+
| Pattern | What it covers |
|
|
11
|
+
| ------- | -------------- |
|
|
12
|
+
| [Configuration Pattern](./config-pattern) | Typed config keys, registry entries, and `ConfigModule` integration. |
|
|
13
|
+
| [DTO & Validation Pattern](./dto-pattern) | Request and response classes, validation decorators, and OpenAPI metadata. |
|
|
14
|
+
| [Error Handling Pattern](./error-handling-pattern) | Domain errors, exception filters, and structured error envelopes. |
|
|
15
|
+
| [Guard & Interceptor Pattern](./guard-pattern) | Metadata decorators, guards, interceptors, and request enforcement. |
|
|
16
|
+
| [Mapping Pattern](./mapping-pattern) | Type-safe mapping keys, profiles, and `MappingService` usage. |
|
|
17
|
+
| [Dynamic Module Pattern](./module-pattern) | NestJS dynamic module registration and dependency wiring. |
|
|
18
|
+
| [Query Pattern](./query-pattern) | Repository query objects and transactional query execution. |
|
|
19
|
+
| [Repository Pattern](./repository-pattern) | `RepositoryBase` subclasses and Prisma delegate isolation. |
|
|
20
|
+
| [Testing Pattern](./testing-pattern) | Vitest structure, mocks, and integration test conventions. |
|
|
21
|
+
| [Bootstrap Pattern](./bootstrap-pattern) | Composable NestJS startup with `PlatformApplication` and `PlatformBootstrapStep`. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@breadstone/archipel-mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.39",
|
|
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",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@modelcontextprotocol/sdk": "1.29.0",
|
|
34
34
|
"gray-matter": "4.0.3",
|
|
35
35
|
"tslib": "2.8.1",
|
|
36
|
-
"zod": "4.3
|
|
36
|
+
"zod": "4.4.3"
|
|
37
37
|
},
|
|
38
38
|
"types": "./src/main.d.ts"
|
|
39
39
|
}
|