create-bcp-app 0.2.19 → 0.3.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.
Files changed (3) hide show
  1. package/README.md +110 -129
  2. package/package.json +1 -1
  3. package/template/README.md +118 -98
package/README.md CHANGED
@@ -10,7 +10,7 @@ npm run dev
10
10
 
11
11
  ## Project-local BCP CLI
12
12
 
13
- `create-bcp-app` installs BCP Framework as a project-local dependency. Generated npm scripts use the local CLI:
13
+ Generated npm scripts use the local framework CLI:
14
14
 
15
15
  ```json
16
16
  {
@@ -64,17 +64,17 @@ Select storage provider:
64
64
 
65
65
  New projects include `bcp.project.json`.
66
66
 
67
- Example for the `0.2.19` target:
67
+ Example for the `0.3.1` target:
68
68
 
69
69
  ```json
70
70
  {
71
71
  "schemaVersion": 1,
72
72
  "framework": "bcp",
73
73
  "projectName": "my-app",
74
- "frameworkPackage": "npm:@chidchanun/bcp@0.2.19",
74
+ "frameworkPackage": "npm:@chidchanun/bcp@0.3.1",
75
75
  "createdWith": {
76
76
  "package": "create-bcp-app",
77
- "version": "0.2.19"
77
+ "version": "0.3.1"
78
78
  },
79
79
  "packageManager": "npm",
80
80
  "presets": {
@@ -88,181 +88,164 @@ Example for the `0.2.19` target:
88
88
 
89
89
  This manifest records scaffold identity only. Do not place secrets in it.
90
90
 
91
- ## Database presets
92
-
93
- Database choices add starter configuration and the matching driver:
94
-
95
- - MySQL: `mysql2`
96
- - PostgreSQL: `pg`
97
- - SQLite: `better-sqlite3`
98
- - MongoDB: `mongodb`
99
- - None: no database dependency
91
+ ## Application Platform
100
92
 
101
- For MySQL, PostgreSQL and SQLite, generated `lib/database.ts` exposes BCP database primitives through `bcp/database`.
102
-
103
- ## Authentication and security
104
-
105
- The JWT Cookie preset creates starter authentication code. BCP supports revocable session stores, permission/policy authorization, route guards and same-origin/CSRF helpers.
106
-
107
- ## Background jobs, workflows and events
93
+ Applications can centralize server infrastructure through `bcp/application`:
108
94
 
109
95
  ```ts
110
96
  import {
111
- createJobQueue,
112
- createJobScheduler,
113
- } from "bcp/jobs";
114
- import {
115
- createWorkflow,
116
- } from "bcp/workflow";
97
+ createApp,
98
+ } from "bcp/application";
99
+
100
+ export const app =
101
+ createApp({
102
+ name: "my-app",
103
+ });
117
104
  ```
118
105
 
119
- Durable Redis-compatible queues/schedules, workflow orchestration and transactional outbox/event delivery are available without forcing a Redis client dependency.
106
+ Existing BCP subsystem APIs remain independently usable.
120
107
 
121
- ## Realtime
108
+ ## Dependency Injection & Service Container — 0.3.1+
109
+
110
+ Typed dependencies use `bcp/container`:
122
111
 
123
112
  ```ts
124
113
  import {
125
- createRealtime,
126
- } from "bcp/realtime";
114
+ createServiceToken,
115
+ provideFactory,
116
+ provideValue,
117
+ } from "bcp/container";
118
+
119
+ const configToken =
120
+ createServiceToken<{
121
+ apiUrl: string;
122
+ }>("config");
123
+
124
+ const repositoryToken =
125
+ createServiceToken<UserRepository>(
126
+ "user-repository"
127
+ );
127
128
 
128
- export const realtime =
129
- createRealtime();
129
+ export const app =
130
+ createApp({
131
+ name: "my-app",
132
+ providers: [
133
+ provideValue(
134
+ configToken,
135
+ {
136
+ apiUrl: "https://api.example.com",
137
+ }
138
+ ),
139
+ provideFactory(
140
+ repositoryToken,
141
+ [
142
+ configToken,
143
+ ] as const,
144
+ (_context, [config]) =>
145
+ createRepository(
146
+ config.apiUrl
147
+ )
148
+ ),
149
+ ],
150
+ });
130
151
  ```
131
152
 
132
- BCP does not install a WebSocket server library. Applications adapt their provider to `RealtimeSocket`; SSE is built in.
133
-
134
- ## Testing
135
-
136
- `bcp/testing` provides request/route/page/auth/database/middleware/jobs/workflow/outbox/realtime test harnesses and does not require Jest or Vitest.
137
-
138
- ## Plugins
139
-
140
- `bcp/plugins` provides dependency ordering, module composition, lifecycle hooks, config parsing, shared services and async hooks.
141
-
142
- ## Cache Platform v2
153
+ Resolve from server/application code:
143
154
 
144
155
  ```ts
145
- import {
146
- createCacheStore,
147
- } from "bcp/cache";
148
-
149
- export const cache =
150
- createCacheStore();
156
+ const repository =
157
+ await app.container.resolve(
158
+ repositoryToken
159
+ );
151
160
  ```
152
161
 
153
- Multi-instance applications can use Redis-compatible cache and lock adapters for distributed cache-fill coordination.
162
+ Supported lifetimes:
154
163
 
155
- ## Observability Platform v3
164
+ ```text
165
+ singleton
166
+ scoped
167
+ transient
168
+ ```
156
169
 
157
- ```ts
158
- import {
159
- createTracer,
160
- } from "bcp/observability";
170
+ For request/job/test boundaries:
161
171
 
162
- export const tracer =
163
- createTracer({
164
- serviceName: "my-app",
172
+ ```ts
173
+ const scope =
174
+ app.createScope({
175
+ name: "request:123",
165
176
  });
166
177
  ```
167
178
 
168
- Tracing supports W3C `traceparent`, correlation IDs, request middleware, explicit carriers for jobs/workflows/events/realtime and provider-neutral exporters.
169
-
170
- ## Deployment Platform v2 — 0.2.18+
171
-
172
- Use `bcp/deployment` to coordinate application resources in production:
179
+ Testing overrides:
173
180
 
174
181
  ```ts
175
- import {
176
- createDeploymentRuntime,
177
- } from "bcp/deployment";
178
-
179
- export const deployment =
180
- createDeploymentRuntime({
181
- serviceName: "my-app",
182
+ const testScope =
183
+ app.createScope({
184
+ name: "test",
185
+ overrides: [
186
+ provideValue(
187
+ mailerToken,
188
+ fakeMailer
189
+ ),
190
+ ],
182
191
  });
183
192
  ```
184
193
 
185
- Register shared dependencies before components that use them:
194
+ DI is optional. Existing `app.services` and plugin service registries remain supported.
195
+
196
+ ## Lifecycle resources
197
+
198
+ Long-running infrastructure still uses Deployment Platform resources:
186
199
 
187
200
  ```ts
188
- deployment.addResource({
201
+ app.addResource({
189
202
  name: "database",
190
203
 
191
- async start() {
192
- await db.connect();
204
+ start() {
205
+ return database.connect();
193
206
  },
194
207
 
195
208
  ready() {
196
- return db.status === "ready";
197
- },
198
-
199
- async stop() {
200
- await db.close();
201
- },
202
- });
203
-
204
- deployment.addResource({
205
- name: "workers",
206
-
207
- start() {
208
- worker = jobs.startWorker();
209
+ return database.ready;
209
210
  },
210
211
 
211
- async stop() {
212
- await worker.stop();
212
+ stop() {
213
+ return database.close();
213
214
  },
214
215
  });
215
-
216
- await deployment.start();
217
216
  ```
218
217
 
219
- Startup follows registration order and shutdown reverses it. This naturally stops workers before database/cache/Redis connections.
218
+ In `0.3.1`, the DI container remains active until application resources and plugins have stopped, then disposes injected services in reverse creation order.
220
219
 
221
- Readiness endpoint:
220
+ ## Database presets
222
221
 
223
- ```ts
224
- import {
225
- createDeploymentReadinessResponse,
226
- } from "bcp/deployment";
222
+ - MySQL: `mysql2`
223
+ - PostgreSQL: `pg`
224
+ - SQLite: `better-sqlite3`
225
+ - MongoDB: `mongodb`
226
+ - None: no database dependency
227
227
 
228
- export function GET() {
229
- return createDeploymentReadinessResponse(
230
- deployment
231
- );
232
- }
233
- ```
228
+ For MySQL, PostgreSQL and SQLite, generated `lib/database.ts` exposes BCP database primitives through `bcp/database`.
234
229
 
235
- Runtime identity can use:
230
+ ## Authentication and security
236
231
 
237
- ```text
238
- BCP_DEPLOYMENT_ID
239
- BCP_INSTANCE_ID
240
- BCP_RELEASE
241
- NODE_ENV
242
- BCP_SHUTDOWN_TIMEOUT_MS
243
- ```
232
+ The JWT Cookie preset creates starter authentication code. BCP supports revocable session stores, permission/policy authorization, route guards and same-origin/CSRF helpers.
244
233
 
245
- Install graceful signal handling with:
234
+ ## Jobs, workflows, events and realtime
246
235
 
247
- ```ts
248
- const removeSignals =
249
- deployment.installSignalHandlers();
250
- ```
236
+ Use `bcp/jobs`, `bcp/workflow`, `bcp/events` and `bcp/realtime` directly or register selected instances with the Application Platform/DI container.
251
237
 
252
- Default signals are `SIGTERM` and `SIGINT`.
238
+ ## Testing
253
239
 
254
- ## Stability & API Freeze 0.2.19
240
+ `bcp/testing` provides framework-native request/route/page/auth/database/middleware/jobs/workflow/outbox/realtime helpers. DI scope overrides complement these helpers for application-level dependency replacement.
255
241
 
256
- `0.2.19` keeps the `0.2.x` public package surface stable before the next platform baseline.
242
+ ## Plugins
257
243
 
258
- Framework maintainers can validate the frozen contract with:
244
+ `bcp/plugins` remains available for reusable plugin/module lifecycle composition. Plugin definitions/modules can be passed to `createApp()`.
259
245
 
260
- ```bash
261
- npm run api:check
262
- npm run release:readiness
263
- ```
246
+ ## Observability and deployment
264
247
 
265
- Generated applications do not need to run these framework-repository release commands. Application code should continue importing documented `bcp/*` entrypoints rather than private framework source paths.
248
+ `bcp/observability` provides metrics/tracing. `bcp/deployment` remains available when an application wants to own resource lifecycle directly; `bcp/application` reuses its readiness/diagnostics/shutdown model.
266
249
 
267
250
  ## Application packaging
268
251
 
@@ -271,9 +254,7 @@ npm run build
271
254
  npm run package
272
255
  ```
273
256
 
274
- The deployment package excludes application `devDependencies` and project `.env` values. Supply secrets through the deployment environment.
275
-
276
- BCP `0.2.19` prepared framework packages preserve the compiled ESM runtime map introduced by Deployment Platform v2 for the main server entrypoints including config, auth, observability, deployment, server and middleware.
257
+ BCP `0.3.1` prepared packages include compiled `container.mjs` and `application.mjs` server runtimes. Project `.env` files and application devDependencies are excluded from deployment packages.
277
258
 
278
259
  ## Project generators
279
260
 
@@ -301,5 +282,5 @@ npm run generate -- migration create_users
301
282
  For prerelease/local package verification:
302
283
 
303
284
  ```bash
304
- npx create-bcp-app my-app --bcp file:../chidchanun-bcp-0.2.19.tgz
285
+ npx create-bcp-app my-app --bcp file:../chidchanun-bcp-0.3.1.tgz
305
286
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-bcp-app",
3
- "version": "0.2.19",
3
+ "version": "0.3.1",
4
4
  "description": "Create a new BCP Framework application.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,162 +27,182 @@ npm run update
27
27
 
28
28
  Generated projects include `bcp.project.json` with non-secret scaffold metadata. Commit it with the project, but never put passwords, tokens or access keys in it.
29
29
 
30
- ## Authentication and authorization
31
-
32
- JWT Cookie projects can use `createAuth()` and optional `AuthSessionStore` revocation. Permission guards/resource policies live in `bcp/auth`; same-origin/CSRF helpers live in `bcp/server`.
33
-
34
- ## Database
30
+ ## Application Platform — BCP 0.3.x
35
31
 
36
- MySQL, PostgreSQL and SQLite projects expose the BCP database platform through `bcp/database`.
37
-
38
- ## Jobs, scheduling and workflows
32
+ For applications with several server subsystems, `bcp/application` provides one optional composition root:
39
33
 
40
34
  ```ts
41
35
  import {
42
- createJobQueue,
43
- createJobScheduler,
44
- } from "bcp/jobs";
45
- import {
46
- createWorkflow,
47
- } from "bcp/workflow";
48
- ```
49
-
50
- Durable jobs support leases, heartbeat, stale recovery and DLQ. Workflows support sequential/parallel steps, retries, persisted delays and compensation.
36
+ createApp,
37
+ } from "bcp/application";
51
38
 
52
- ## Transactional events
39
+ export const app =
40
+ createApp({
41
+ name: "bcp-app",
42
+ });
43
+ ```
53
44
 
54
- Use `bcp/events` when business data and an integration event must commit in the same SQL transaction. The outbox dispatcher can deliver through durable jobs or an application publisher after commit.
45
+ ## Dependency Injection BCP 0.3.1+
55
46
 
56
- ## Realtime
47
+ Use `bcp/container` for typed application dependencies:
57
48
 
58
49
  ```ts
59
50
  import {
60
- createRealtime,
61
- } from "bcp/realtime";
51
+ createServiceToken,
52
+ provideFactory,
53
+ provideValue,
54
+ } from "bcp/container";
55
+
56
+ const configToken =
57
+ createServiceToken<{
58
+ apiUrl: string;
59
+ }>("config");
60
+
61
+ const clientToken =
62
+ createServiceToken<ApiClient>(
63
+ "api-client"
64
+ );
62
65
 
63
- export const realtime =
64
- createRealtime();
66
+ export const app =
67
+ createApp({
68
+ name: "bcp-app",
69
+ providers: [
70
+ provideValue(
71
+ configToken,
72
+ {
73
+ apiUrl: "https://api.example.com",
74
+ }
75
+ ),
76
+ provideFactory(
77
+ clientToken,
78
+ [
79
+ configToken,
80
+ ] as const,
81
+ (_context, [config]) =>
82
+ createApiClient(
83
+ config.apiUrl
84
+ )
85
+ ),
86
+ ],
87
+ });
65
88
  ```
66
89
 
67
- BCP does not install a WebSocket server library. Adapt the selected provider through `RealtimeSocket`; SSE is built in.
68
-
69
- ## Testing
70
-
71
- `bcp/testing` provides request/route/page/auth/database/middleware/jobs/workflow/outbox/realtime/SSE test helpers without requiring Jest or Vitest.
72
-
73
- ## Plugins
74
-
75
- `bcp/plugins` provides reusable server-side plugins/modules, dependency ordering, lifecycle hooks, config parsing, shared services and awaited hooks.
76
-
77
- ## Cache Platform v2
90
+ Resolve typed services:
78
91
 
79
92
  ```ts
80
- import {
81
- createCacheStore,
82
- } from "bcp/cache";
83
-
84
- export const cache =
85
- createCacheStore();
93
+ const client =
94
+ await app.container.resolve(
95
+ clientToken
96
+ );
86
97
  ```
87
98
 
88
- Use Redis-compatible cache/lock adapters for multi-instance cache-fill coordination when needed.
99
+ Provider lifetimes are `singleton`, `scoped` and `transient`.
89
100
 
90
- ## Observability Platform v3
101
+ For request/job/test scopes:
91
102
 
92
103
  ```ts
93
- import {
94
- createTracer,
95
- } from "bcp/observability";
96
-
97
- export const tracer =
98
- createTracer({
99
- serviceName: "bcp-app",
104
+ const scope =
105
+ app.createScope({
106
+ name: "request:123",
100
107
  });
101
108
  ```
102
109
 
103
- Tracing supports AsyncLocalStorage context, W3C `traceparent`, correlation IDs, request tracing, trace carriers and provider-neutral exporters.
110
+ Testing overrides can replace selected providers within a child scope without changing the root application container.
104
111
 
105
- ## Deployment Platform v2 BCP 0.2.18+
106
-
107
- Use `bcp/deployment` to manage production resource lifecycle:
112
+ The legacy Plugin Platform registry remains supported:
108
113
 
109
114
  ```ts
110
- import {
111
- createDeploymentRuntime,
112
- } from "bcp/deployment";
113
-
114
- export const deployment =
115
- createDeploymentRuntime({
116
- serviceName: "bcp-app",
117
- });
115
+ app.provide("database", database);
118
116
  ```
119
117
 
120
- Register dependencies first:
118
+ Use typed `ServiceToken<T>` providers for new application dependency injection code.
119
+
120
+ ## Lifecycle resources
121
+
122
+ Long-running infrastructure uses `app.addResource()`:
121
123
 
122
124
  ```ts
123
- deployment.addResource({
125
+ app.addResource({
124
126
  name: "database",
125
127
 
126
- async start() {
127
- await db.connect();
128
+ start() {
129
+ return database.connect();
128
130
  },
129
131
 
130
132
  ready() {
131
- return db.status === "ready";
133
+ return database.ready;
132
134
  },
133
135
 
134
- async stop() {
135
- await db.close();
136
+ stop() {
137
+ return database.close();
136
138
  },
137
139
  });
138
140
  ```
139
141
 
140
- Register workers/realtime services afterward so reverse-order shutdown stops them before their shared database/cache/Redis dependencies.
141
-
142
- Start runtime:
142
+ Then start the application runtime from server/bootstrap code:
143
143
 
144
144
  ```ts
145
- await deployment.start();
145
+ await app.start();
146
146
  ```
147
147
 
148
- Readiness endpoint:
148
+ BCP `0.3.1` keeps the DI container alive until application resources/plugins have stopped, then disposes resolved services in reverse creation order.
149
+
150
+ ## Authentication and authorization
151
+
152
+ JWT Cookie projects can use `createAuth()` and optional `AuthSessionStore` revocation. Permission guards/resource policies live in `bcp/auth`; same-origin/CSRF helpers live in `bcp/server`.
153
+
154
+ ## Database
155
+
156
+ MySQL, PostgreSQL and SQLite projects expose database primitives through `bcp/database`.
157
+
158
+ ## Jobs, workflows and events
159
+
160
+ Use `bcp/jobs`, `bcp/workflow` and `bcp/events` independently or compose instances through the Application Platform.
161
+
162
+ ## Realtime
149
163
 
150
164
  ```ts
151
165
  import {
152
- createDeploymentReadinessResponse,
153
- } from "bcp/deployment";
166
+ createRealtime,
167
+ } from "bcp/realtime";
154
168
 
155
- export function GET() {
156
- return createDeploymentReadinessResponse(
157
- deployment
158
- );
159
- }
169
+ export const realtime =
170
+ createRealtime();
160
171
  ```
161
172
 
162
- Install graceful signal handling when the app owns process signals:
173
+ BCP does not install a WebSocket server library. Adapt the selected provider through `RealtimeSocket`; SSE is built in.
163
174
 
164
- ```ts
165
- const removeSignals =
166
- deployment.installSignalHandlers();
167
- ```
175
+ ## Testing
176
+
177
+ `bcp/testing` provides framework-native server test helpers. `bcp/container` child-scope overrides can replace application dependencies during tests.
178
+
179
+ ## Plugins
180
+
181
+ `bcp/plugins` provides reusable server-side plugins/modules, dependency ordering, lifecycle hooks, config parsing, shared services and awaited hooks.
182
+
183
+ ## Cache and observability
184
+
185
+ `bcp/cache` provides provider-neutral cache/lock primitives. `bcp/observability` provides metrics, health and tracing.
186
+
187
+ ## Deployment lifecycle
168
188
 
169
- Default signals are `SIGTERM` and `SIGINT`.
189
+ `bcp/deployment` remains available for direct lifecycle ownership. `bcp/application` composes the same readiness/diagnostics/shutdown model.
170
190
 
171
- Deployment identity can be supplied through:
191
+ Application startup order in `0.3.1` is:
172
192
 
173
193
  ```text
174
- BCP_DEPLOYMENT_ID
175
- BCP_INSTANCE_ID
176
- BCP_RELEASE
177
- NODE_ENV
178
- BCP_SHUTDOWN_TIMEOUT_MS
194
+ application setup
195
+ container
196
+ plugins
197
+ resources
198
+ application start
179
199
  ```
180
200
 
181
- ## Stability baseline BCP 0.2.19
201
+ Shutdown reverses deployment dependencies, then runs application disposal.
182
202
 
183
- BCP `0.2.19` freezes the documented `0.2.x` public `bcp/*` entrypoints and prepared package-resolution contract before the next `0.3.0` baseline.
203
+ ## API baseline
184
204
 
185
- Application code should import documented public entrypoints and avoid private framework `packages/*` paths. This keeps applications compatible with the frozen `0.2.19` surface.
205
+ BCP `0.3.1` advances `0.3.0` additively with `bcp/container`. Application code should use documented public `bcp/*` entrypoints and avoid private framework `packages/*` paths.
186
206
 
187
207
  ## Production build
188
208
 
@@ -197,9 +217,9 @@ npm start
197
217
  npm run package
198
218
  ```
199
219
 
200
- BCP excludes project `.env` files and application `devDependencies` from the deployment package. Supply secrets through the deployment environment.
220
+ BCP excludes project `.env` files and application `devDependencies` from deployment packages. Supply secrets through the deployment environment.
201
221
 
202
- BCP 0.2.19 preserves compiled `.mjs` runtimes for the main server entrypoints, including config, auth, observability, deployment, server and middleware.
222
+ Prepared `0.3.1` packages include compiled `container.mjs` and `application.mjs` runtimes.
203
223
 
204
224
  ## Direct CLI usage
205
225