@xeno-js/core 3.0.1 → 3.0.3

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/README.md CHANGED
@@ -1,445 +1,589 @@
1
- <div align="center">
2
- <img src="logo/logo.png" alt="Xeno.JS Logo" width="140" />
3
-
4
- <h1>Xeno.JS</h1>
5
- <p><strong>A Typescript application framework architecture for Node.js, designed for lower technical debt, and faster infrastructure migrations.</strong></p>
6
- <p>Build long-lived applications with explicit dependency injection, DDD, CQRS, and transport-independent business logic.</p>
7
-
8
- <p>
9
- <a href="https://www.npmjs.com/package/@xeno-js/core"><img src="https://img.shields.io/npm/v/@xeno-js/core?style=flat-square" alt="NPM Version" /></a>
10
- <a href="https://github.com/xeno-js/xeno-js"><img src="https://img.shields.io/badge/Powered%20by-Xeno-blueviolet?style=flat-square" alt="Powered by Xeno" /></a>
11
- <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue?style=flat-square" alt="License: MIT" /></a>
12
- <a href="https://buymeacoffee.com/xenojs">
13
- <img src="https://img.shields.io/badge/Buy%20Me%20A%20Coffee-Support-FFdd00?style=flat-square&logo=buy-me-a-coffee&logoColor=black" alt="Buy Me A Coffee" />
14
- </a>
15
- </p>
16
- </div>
17
-
18
- ---
19
-
20
- ## What is Xeno?
21
-
22
- Xeno.JS is a TypeScript application architecture framework for Node.js.
23
-
24
- It provides explicit building blocks for applications organized around:
25
-
26
- - **Dependency Injection** with explicit service registration and lifetimes
27
- - **Domain-Driven Design (DDD)** and domain/application boundaries
28
- - **CQRS** with commands, queries, handlers, and composable pipelines
29
- - **Request context** built around asynchronous execution context
30
- - **Repositories and data sources** that keep persistence behind application
31
- boundaries
32
- - **Infrastructure adapters** for databases, Redis, authentication, logging,
33
- resilience, and other integrations
34
-
35
- The goal is simple: **make application architecture explicit in code.**
36
-
37
- Xeno.JS is not tied to a specific HTTP server. Your application layer can remain
38
- independent from the transport that delivers a request.
39
-
40
- ---
41
-
42
- ## Why Xeno?
43
-
44
- ### 01 — Explicit Architecture
45
-
46
- **Your dependency graph is code.**
47
-
48
- Xeno.JS does not require decorators, runtime scanning, or implicit dependency
49
- discovery. Services are registered explicitly, and their lifetimes are visible
50
- at the composition root.
51
-
52
- ```typescript
53
- services.addScoped('USER_REPOSITORY', (container) => {
54
- return new UserRepository(
55
- container.resolve('USER_DATA_SOURCE'),
56
- container.resolve('USER_MAPPER'),
57
- )
58
- })
59
- ```
60
-
61
- This makes the composition of the application easier to inspect, test, and
62
- reason about.
63
-
64
- ### 02 — Transport Independence
65
-
66
- Business logic should not belong to your HTTP framework.
67
-
68
- Xeno.JS keeps application concerns separate from delivery mechanisms, allowing
69
- the same application architecture to be hosted behind transports such as
70
- Fastify, Hono, Express, or other adapters.
71
-
72
- ```text
73
- HTTP / CLI / Worker / Lambda
74
- |
75
- v
76
- Presentation
77
- |
78
- v
79
- Application
80
- Commands / Queries
81
- |
82
- v
83
- Domain
84
- |
85
- v
86
- Infrastructure
87
- DB / Redis / APIs
88
- ```
89
-
90
- ### 03 — CQRS as an Application Primitive
91
-
92
- Commands and queries are first-class application concepts.
93
-
94
- Pipelines can compose cross-cutting behavior around execution, such as:
95
-
96
- - authorization
97
- - idempotency
98
- - concurrency control
99
- - caching
100
- - resilience policies
101
- - request context
102
-
103
- This keeps cross-cutting concerns out of individual handlers.
104
-
105
- ### 04 — Explicit Lifetimes and Request Boundaries
106
-
107
- Xeno.JS distinguishes service lifetimes such as singleton, scoped, and transient
108
- services.
109
-
110
- Request-scoped dependencies are resolved inside an explicit application scope,
111
- while request metadata can be carried through asynchronous execution using
112
- `AsyncLocalStorage`.
113
-
114
- Database transaction state is scoped to the same application boundary, allowing
115
- `UnitOfWork` and `DbContext` to operate against the transaction associated with
116
- the current scope.
117
-
118
- ### 05 — Infrastructure Stays Outside the Domain
119
-
120
- Database clients, Redis, HTTP clients, authentication providers, loggers, and
121
- other infrastructure integrations are composed at the edge of the application.
122
-
123
- Your domain and application code can depend on contracts instead of concrete
124
- infrastructure.
125
-
126
- ---
127
-
128
- ## Architecture
129
-
130
- A typical Xeno.JS application can be organized like this:
131
-
132
- ```text
133
- +------------------------------------------+
134
- | Presentation |
135
- | HTTP / CLI / Workers / Lambda |
136
- +---------------------+--------------------+
137
- |
138
- v
139
- +------------------------------------------+
140
- | Application |
141
- | Commands / Queries / Handlers / Pipes |
142
- +---------------------+--------------------+
143
- |
144
- v
145
- +------------------------------------------+
146
- | Domain |
147
- | Entities / Policies / Rules |
148
- +---------------------+--------------------+
149
- |
150
- v
151
- +------------------------------------------+
152
- | Infrastructure |
153
- | DB / Redis / APIs / Auth / Logs |
154
- +------------------------------------------+
155
- ```
156
-
157
- Xeno's core is focused on composition and application architecture.
158
- Infrastructure capabilities can be enabled only when they are needed.
159
-
160
- ---
161
-
162
- ## Core Concepts
163
-
164
- | Concept | Purpose |
165
- | ------------------ | --------------------------------------------------------- |
166
- | `AppBuilder` | Composition root for assembling an application |
167
- | `ServiceContainer` | Explicit dependency injection and service lifetimes |
168
- | `CQRS` | Commands, queries, handlers, and mediator-based execution |
169
- | `Pipelines` | Cross-cutting behavior around application execution |
170
- | `Request Context` | Request metadata across asynchronous execution |
171
- | `Repository` | Application-facing persistence abstraction |
172
- | `DataSource` | Infrastructure-facing data access implementation |
173
- | `Module` | Explicit registration of related capabilities |
174
- | `Result` | Typed success/failure flow for application operations |
175
-
176
- ---
177
-
178
- ## Installation
179
-
180
- ```bash
181
- npm install @xeno-js/core
182
- ```
183
-
184
- Install only the integrations your application uses. Xeno.JS exposes optional
185
- infrastructure dependencies for capabilities such as databases, Redis, logging,
186
- resilience, and authentication.
187
-
188
- For example:
189
-
190
- ```bash
191
- npm install zod pino cockatiel drizzle-orm
192
- ```
193
-
194
- ---
195
-
196
- ## A Small Example
197
-
198
- The composition root is explicit:
199
-
200
- ```typescript
201
- // src/bootstrap.ts
202
- import { AppBuilder } from '@xeno-js/core'
203
-
204
- const app = new AppBuilder().addServices((services) => {
205
- services.addScoped('USER_REPOSITORY', (container) => {
206
- return new UserRepository(container.resolve('USER_DATA_SOURCE'))
207
- })
208
-
209
- services.addScoped('FIND_USER_HANDLER', (container) => {
210
- return new FindUserHandler(container.resolve('USER_REPOSITORY'))
211
- })
212
-
213
- services.addTransient('FIND_USER_CONTROLLER', (c) => {
214
- return new FindUserController(
215
- c.resolve(TOKENS.REQUEST_CONTEXT),
216
- c.resolve(TOKENS.MEDIATOR),
217
- )
218
- })
219
- })
220
-
221
- await app.build()
222
- ```
223
-
224
- The transport remains outside the application composition:
225
-
226
- > ⚠️ **Implementation note: Example using Fastify** The following snippet uses
227
- > **Fastify** solely for demonstration purposes to illustrate the transport
228
- > layer. Thanks to the framework's agnostic architecture, the underlying logic
229
- > (`container` and `handler`) remains unchanged regardless of the chosen HTTP
230
- > system (e.g., Express, Koa) or interface (CLI, gRPC).
231
-
232
- ```typescript
233
- import Fastify from 'fastify'
234
- import { app } from './bootstrap'
235
-
236
- const fastify = Fastify({ logger: true })
237
-
238
- fastify.get('/users/:id', async (req, reply) => {
239
- const action = async () => {
240
- const controller = ContainerUtils.resolveServiceScoped(
241
- 'FIND_USER_CONTROLLER',
242
- app,
243
- )
244
- return await controller.handle()
245
- }
246
-
247
- const result = await ContainerUtils.runExecute(req, reply, app, action)
248
-
249
- return reply.send(result)
250
- })
251
- ```
252
-
253
- The HTTP adapter is responsible for HTTP. The application handler is responsible
254
- for the use case.
255
-
256
- ---
257
-
258
- ## CQRS & Pipelines
259
-
260
- Cross-cutting behavior can be composed around commands and queries:
261
-
262
- ```typescript
263
- .addPipeline((config) => {
264
- config.authorization.policies = {
265
- FIND_USER_QUERY_HANDLER: {
266
- roles: ['admin'],
267
- permissions: ['read'],
268
- },
269
- }
270
-
271
- config.commandBus.idempotency = {
272
- lockTtlSeconds: 30,
273
- processedTtlSeconds: 60,
274
- }
275
-
276
- config.commandBus.concurrency = {
277
- delayConfig: {
278
- baseDelayMs: 100,
279
- maxJitterMs: 500,
280
- },
281
- maxRetries: 3,
282
- }
283
-
284
- config.queryBus.isEnabled = true
285
- })
286
- ```
287
-
288
- The exact pipeline configuration depends on the integrations enabled by your
289
- application.
290
-
291
- ---
292
-
293
- ## Infrastructure & Integrations
294
-
295
- Xeno.JS Core can be composed with infrastructure such as:
296
-
297
- - **Database:** Drizzle ORM, PostgreSQL, LibSQL
298
- - **Cache / distributed coordination:** Redis
299
- - **Authentication:** Supabase integrations and custom strategies
300
- - **HTTP clients:** Axios
301
- - **Resilience:** Cockatiel
302
- - **Logging:** Console, Pino, Sentry, or custom loggers
303
- - **Validation:** Zod
304
-
305
- These integrations are opt-in rather than mandatory parts of the application
306
- architecture.
307
-
308
- ---
309
-
310
- ## CLI
311
-
312
- Use the official CLI to scaffold a Xeno.JS application:
313
-
314
- ```bash
315
- npm install @xeno-js/cli
316
- xeno-js new my-xeno-app --core
317
- ```
318
-
319
- See the [CLI documentation](https://www.xeno-js.it/cli/overview).
320
-
321
- ---
322
-
323
- ## Documentation
324
-
325
- The documentation hub contains the architecture and integration guides:
326
-
327
- **[xeno-js.it](https://www.xeno-js.it/docs/introduction)**
328
-
329
- Recommended starting points:
330
-
331
- - [Introduction](https://www.xeno-js.it/docs/introduction)
332
- - [Fundamentals](https://www.xeno-js.it/docs/fundamentals/overview)
333
- - [Dependency Injection](https://www.xeno-js.it/docs/dependency-injection/service-container)
334
- - [CQRS](https://www.xeno-js.it/docs/application/cqrs/overview)
335
- - [Pipelines](https://www.xeno-js.it/docs/application/overview)
336
- - [CLI](https://www.xeno-js.it/docs/cli/overview)
337
-
338
- ---
339
-
340
- ## Ecosystem
341
-
342
- Xeno.JS is designed as an ecosystem rather than a single monolithic package:
343
-
344
- | Package | Role |
345
- | ----------------- | ----------------------------------------- |
346
- | `@xeno-js/core` | Application architecture and backend core |
347
- | `@xeno-js/shared` | Shared contracts and types |
348
- | `@xeno-js/vue` | Vue integration |
349
- | `@xeno-js/cli` | Project scaffolding and developer tooling |
350
-
351
- ---
352
-
353
- ## What Xeno.JS Is Not
354
-
355
- Xeno.JS is not primarily an HTTP framework.
356
-
357
- If you are looking for a framework centered on routing, controllers, middleware,
358
- and server lifecycle, there are excellent options already available in the
359
- Node.js ecosystem.
360
-
361
- Xeno.JS focuses on the layer above transport:
362
-
363
- > **How should a TypeScript application be structured so that its business
364
- > logic, dependencies, and infrastructure boundaries remain explicit as the
365
- > application grows?**
366
-
367
- ---
368
-
369
- ## Production Considerations
370
-
371
- Xeno.JS provides architectural primitives, but application correctness still
372
- depends on how those primitives are composed.
373
-
374
- Before deploying an application, test the behaviors that matter to your
375
- workload, especially:
376
-
377
- - request and transaction isolation
378
- - service lifetime boundaries
379
- - authorization policies
380
- - idempotency semantics
381
- - concurrency behavior
382
- - cache consistency
383
- - failure and retry behavior
384
- - trusted proxy / client IP configuration
385
- - database transaction boundaries
386
-
387
- The framework is designed to make these boundaries explicit rather than hide
388
- them behind conventions.
389
-
390
- ---
391
-
392
- ## Contributing
393
-
394
- Contributions are welcome.
395
-
396
- Development happens from feature branches targeting `develop`.
397
-
398
- ```bash
399
- git checkout develop
400
- git pull origin develop
401
- git checkout -b feat/your-feature
402
-
403
- npm install
404
- npm run check
405
- ```
406
-
407
- We use Conventional Commits:
408
-
409
- ```bash
410
- feat(scope): add new feature
411
- fix(scope): resolve bug
412
- chore(scope): update dependencies
413
- ```
414
-
415
- Before opening a pull request, run:
416
-
417
- ```bash
418
- npm run check
419
- ```
420
-
421
- | Command | Description |
422
- | ----------------------- | ------------------------ |
423
- | `npm run build` | Build the package |
424
- | `npm run typecheck` | TypeScript type checking |
425
- | `npm run lint` | ESLint |
426
- | `npm run format:check` | Prettier validation |
427
- | `npm run test` | Vitest test suite |
428
- | `npm run test:coverage` | Test suite with coverage |
429
-
430
- ---
431
-
432
- ## Support
433
-
434
- If Xeno.JS is useful to you, you can support the project through the community
435
- and sponsorship channels documented on the website:
436
-
437
- **[Support Xeno](https://www.xeno-js.it/support-us)**
438
-
439
- ---
440
-
441
- ## License
442
-
443
- Copyright (c) 2026 Xeno.
444
-
445
- Licensed under the [MIT License](LICENSE).
1
+ <div align="center">
2
+ <img src="logo/logo.png" alt="Xeno.JS Logo" width="140" />
3
+
4
+ <h1>Xeno.JS</h1>
5
+ <p><strong>A Typescript application framework architecture for Node.js, designed for lower technical debt, and faster infrastructure migrations.</strong></p>
6
+ <p>Build long-lived applications with explicit dependency injection, DDD, CQRS, and transport-independent business logic.</p>
7
+
8
+ <p>
9
+ <a href="https://www.npmjs.com/package/@xeno-js/core"><img src="https://img.shields.io/npm/v/@xeno-js/core?style=flat-square" alt="NPM Version" /></a>
10
+ <a href="https://github.com/xeno-js/xeno-js"><img src="https://img.shields.io/badge/Powered%20by-Xeno-blueviolet?style=flat-square" alt="Powered by Xeno" /></a>
11
+ <a href="https://www.npmjs.com/package/@xeno-js/core">
12
+ <img src="https://img.shields.io/npm/dt/@xeno-js/core?style=flat-square" alt="NPM Total Downloads" />
13
+ </a>
14
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue?style=flat-square" alt="License: MIT" /></a>
15
+ <a href="https://buymeacoffee.com/xenojs">
16
+ <img src="https://img.shields.io/badge/Buy%20Me%20A%20Coffee-Support-FFdd00?style=flat-square&logo=buy-me-a-coffee&logoColor=black" alt="Buy Me A Coffee" />
17
+ </a>
18
+ </p>
19
+ </div>
20
+
21
+ ---
22
+
23
+ ## What is Xeno?
24
+
25
+ Xeno.JS is a TypeScript application architecture framework for Node.js.
26
+
27
+ It provides explicit building blocks for applications organized around:
28
+
29
+ - **Dependency Injection** with explicit service registration and lifetimes
30
+ - **Domain-Driven Design (DDD)** and domain/application boundaries
31
+ - **CQRS** with commands, queries, handlers, and composable pipelines
32
+ - **Request context** built around asynchronous execution context
33
+ - **Repositories and data sources** that keep persistence behind application
34
+ boundaries
35
+ - **Infrastructure adapters** for databases, Redis, authentication, logging,
36
+ resilience, and other integrations
37
+
38
+ The goal is simple: **make application architecture explicit in code.**
39
+
40
+ Xeno.JS is not tied to a specific HTTP server. Your application layer can remain
41
+ independent from the transport that delivers a request.
42
+
43
+ ---
44
+
45
+ ## Why Xeno?
46
+
47
+ ### 01 — Explicit Architecture
48
+
49
+ **Your dependency graph is code.**
50
+
51
+ Xeno.JS does not require decorators, runtime scanning, or implicit dependency
52
+ discovery. Services are registered explicitly, and their lifetimes are visible
53
+ at the composition root.
54
+
55
+ ```typescript
56
+ services.addScoped('USER_REPOSITORY', (container) => {
57
+ return new UserRepository(
58
+ container.resolve('USER_DATA_SOURCE'),
59
+ container.resolve('USER_MAPPER'),
60
+ )
61
+ })
62
+ ```
63
+
64
+ This makes the composition of the application easier to inspect, test, and
65
+ reason about.
66
+
67
+ ### 02 — Transport Independence
68
+
69
+ Business logic should not belong to your HTTP framework.
70
+
71
+ Xeno.JS keeps application concerns separate from delivery mechanisms, allowing
72
+ the same application architecture to be hosted behind transports such as
73
+ Fastify, Hono, Express, or other adapters.
74
+
75
+ ```text
76
+ HTTP / CLI / Worker / Lambda
77
+ |
78
+ v
79
+ Presentation
80
+ |
81
+ v
82
+ Application
83
+ Commands / Queries
84
+ |
85
+ v
86
+ Domain
87
+ |
88
+ v
89
+ Infrastructure
90
+ DB / Redis / APIs
91
+ ```
92
+
93
+ ### 03 — CQRS as an Application Primitive
94
+
95
+ Commands and queries are first-class application concepts.
96
+
97
+ Pipelines can compose cross-cutting behavior around execution, such as:
98
+
99
+ - authorization
100
+ - idempotency
101
+ - concurrency control
102
+ - caching
103
+ - resilience policies
104
+ - request context
105
+
106
+ This keeps cross-cutting concerns out of individual handlers.
107
+
108
+ ### 04 — Explicit Lifetimes and Request Boundaries
109
+
110
+ Xeno.JS distinguishes service lifetimes such as singleton, scoped, and transient
111
+ services.
112
+
113
+ Request-scoped dependencies are resolved inside an explicit application scope,
114
+ while request metadata can be carried through asynchronous execution using
115
+ `AsyncLocalStorage`.
116
+
117
+ Database transaction state is scoped to the same application boundary, allowing
118
+ `UnitOfWork` and `DbContext` to operate against the transaction associated with
119
+ the current scope.
120
+
121
+ ### 05 — Infrastructure Stays Outside the Domain
122
+
123
+ Database clients, Redis, HTTP clients, authentication providers, loggers, and
124
+ other infrastructure integrations are composed at the edge of the application.
125
+
126
+ Your domain and application code can depend on contracts instead of concrete
127
+ infrastructure.
128
+
129
+ ---
130
+
131
+ ## Architecture
132
+
133
+ A typical Xeno.JS application can be organized like this:
134
+
135
+ ```text
136
+ +------------------------------------------+
137
+ | Presentation |
138
+ | HTTP / CLI / Workers / Lambda |
139
+ +---------------------+--------------------+
140
+ |
141
+ v
142
+ +------------------------------------------+
143
+ | Application |
144
+ | Commands / Queries / Handlers / Pipes |
145
+ +---------------------+--------------------+
146
+ |
147
+ v
148
+ +------------------------------------------+
149
+ | Domain |
150
+ | Entities / Policies / Rules |
151
+ +---------------------+--------------------+
152
+ |
153
+ v
154
+ +------------------------------------------+
155
+ | Infrastructure |
156
+ | DB / Redis / APIs / Auth / Logs |
157
+ +------------------------------------------+
158
+ ```
159
+
160
+ Xeno's core is focused on composition and application architecture.
161
+ Infrastructure capabilities can be enabled only when they are needed.
162
+
163
+ ---
164
+
165
+ ## Core Concepts
166
+
167
+ | Concept | Purpose |
168
+ | ------------------ | --------------------------------------------------------- |
169
+ | `AppBuilder` | Composition root for assembling an application |
170
+ | `ServiceContainer` | Explicit dependency injection and service lifetimes |
171
+ | `CQRS` | Commands, queries, handlers, and mediator-based execution |
172
+ | `Pipelines` | Cross-cutting behavior around application execution |
173
+ | `Request Context` | Request metadata across asynchronous execution |
174
+ | `Repository` | Application-facing persistence abstraction |
175
+ | `DataSource` | Infrastructure-facing data access implementation |
176
+ | `Module` | Explicit registration of related capabilities |
177
+ | `Result` | Typed success/failure flow for application operations |
178
+
179
+ ---
180
+
181
+ ## Installation
182
+
183
+ ```bash
184
+ npm install @xeno-js/core
185
+ ```
186
+
187
+ Install only the integrations your application uses. Xeno.JS exposes optional
188
+ infrastructure dependencies for capabilities such as databases, Redis, logging,
189
+ resilience, and authentication.
190
+
191
+ For example:
192
+
193
+ ```bash
194
+ npm install zod pino cockatiel drizzle-orm
195
+ ```
196
+
197
+ ---
198
+
199
+ ## A Small Example
200
+
201
+ The composition root is explicit:
202
+
203
+ > For this example we are using the PostgreSql integration. If you want to use
204
+ > it, please install the following packages:
205
+
206
+ ```bash
207
+ npm i @xeno-js/postgresql
208
+ ```
209
+
210
+ > See [xeno-js/xeno-postgresql](https://github.com/xeno-js/xeno-postgresql)
211
+
212
+ ```typescript
213
+ // src/registry.ts
214
+ import type {
215
+ IReadDataSource,
216
+ IReadDao,
217
+ IHandler,
218
+ IController,
219
+ } from '@xeno-js/core'
220
+ import type { XenoDbRegistry } from '@xeno-js/postgresql'
221
+ /** We need to import the databse schema: see @link https://www.xeno-js.it/docs/data/db-schema */
222
+ import { DbSchema } from './schema'
223
+
224
+ export interface AppRegistry extends XenoDbRegistry<DbSchema> {
225
+ USER_DATA_SOURCE: IReadDataSource
226
+ USER_REPOSITORY: IReadDao
227
+ FIND_USER_HANDLER: IHandler<FindUserQuery, void>
228
+ FIND_USER_CONTROLLER: IController<FindUserDto, void>
229
+ }
230
+
231
+ // src/bootstrap.ts
232
+ import { AppBuilder, TOKENS } from '@xeno-js/core'
233
+ import { withPostgresql } from '@xeno-js/postgresql'
234
+ import { AppRegistry } from './registry'
235
+ import {
236
+ UserDataSource,
237
+ UserRepository,
238
+ FindUserHandler,
239
+ FindUserController,
240
+ } from './user'
241
+
242
+ const app = new AppBuilder<AppRegistry>()
243
+ .addServices((services) => {
244
+ services.addScoped('USER_DATA_SOURCE', (c) => {
245
+ return new UserDataSource(c.resolve(TOKENS.DB_CONTEXT))
246
+ })
247
+
248
+ services.addScoped('USER_REPOSITORY', (container) => {
249
+ return new UserRepository(container.resolve('USER_DATA_SOURCE'))
250
+ })
251
+
252
+ services.addScoped('FIND_USER_HANDLER', (container) => {
253
+ return new FindUserHandler(
254
+ container.resolve('USER_REPOSITORY'),
255
+ container.resolve(TOKENS.USER_CONTEXT_FACTORY),
256
+ )
257
+ })
258
+
259
+ services.addTransient('FIND_USER_CONTROLLER', (c) => {
260
+ return new FindUserController(
261
+ c.resolve(TOKENS.REQUEST_CONTEXT),
262
+ c.resolve(TOKENS.MEDIATOR),
263
+ )
264
+ })
265
+ })
266
+ .addLogger()
267
+ .addPipeline()
268
+ .addDb(
269
+ withPostgresql((opts, config) => {
270
+ opts.connectionString = config.getOrThrow('DATABASE_URL')
271
+ }),
272
+ )
273
+
274
+ export const container = await app.build()
275
+
276
+ // src/main.ts
277
+ import { container } from './bootstrap'
278
+
279
+ async function Main(args: string[]) {
280
+ const logger = container.resolve(TOKENS.LOGGER)
281
+ const scope = container.createScope()
282
+ try {
283
+ const controller = scope.resolve('FIND_USER_CONTROLLER')
284
+ const response = await controller.handle(
285
+ { id: args[0] },
286
+ new AbortController().signal,
287
+ )
288
+ return {
289
+ success: response.ok,
290
+ status: response.status,
291
+ data: response.data,
292
+ }
293
+ } catch (err: unknown) {
294
+ logger.error('Error during CLI execution', err)
295
+ return {
296
+ success: false,
297
+ error: { message: 'Internal Server Error' },
298
+ }
299
+ } finally {
300
+ await scope.dispose()
301
+ }
302
+ }
303
+
304
+ Main(process.argv.slice(2))
305
+ .then((res) => console.log(res))
306
+ .catch(console.error)
307
+ ```
308
+
309
+ The transport remains outside the application composition:
310
+
311
+ > ⚠️ **Implementation note: Example using Fastify** The following snippet uses
312
+ > **Fastify** solely for demonstration purposes to illustrate the transport
313
+ > layer. Thanks to the framework's agnostic architecture, the underlying logic
314
+ > (`container` and `handler`) remains unchanged regardless of the chosen HTTP
315
+ > system (e.g., Express, Koa) or interface (CLI, gRPC). Xeno.js offers fastify
316
+ > adapter, if you want to try it install the following package:
317
+
318
+ ```bash
319
+ # Install the package
320
+ npm i @xeno-js/fastify
321
+ # See the source code: https://github.com/xeno-js/xeno-fastify
322
+ ```
323
+
324
+ ```typescript
325
+ // src/bootstrap.ts
326
+ import { FastifyXenoBuilder } from '@xeno-js/fastify'
327
+ import { TOKENS } from '@xeno-js/core'
328
+ import { withPostgresql } from '@xeno-js/postgresql'
329
+ import { AppRegistry } from './registry'
330
+ import {
331
+ UserDataSource,
332
+ UserRepository,
333
+ FindUserHandler,
334
+ FindUserController,
335
+ } from './user'
336
+
337
+ const app = new FastifyXenoBuilder<AppRegistry>()
338
+ .addServices((services) => {
339
+ services.addScoped('USER_DATA_SOURCE', (c) => {
340
+ return new UserDataSource(c.resolve(TOKENS.DB_CONTEXT))
341
+ })
342
+
343
+ services.addScoped('USER_REPOSITORY', (container) => {
344
+ return new UserRepository(container.resolve('USER_DATA_SOURCE'))
345
+ })
346
+
347
+ services.addScoped('FIND_USER_HANDLER', (container) => {
348
+ return new FindUserHandler(
349
+ container.resolve('USER_REPOSITORY'),
350
+ container.resolve(TOKENS.USER_CONTEXT_FACTORY),
351
+ )
352
+ })
353
+
354
+ services.addTransient('FIND_USER_CONTROLLER', (c) => {
355
+ return new FindUserController(
356
+ c.resolve(TOKENS.REQUEST_CONTEXT),
357
+ c.resolve(TOKENS.MEDIATOR),
358
+ )
359
+ })
360
+ })
361
+ .addLogger()
362
+ .addPipeline()
363
+ .addDb(
364
+ withPostgresql((opts, config) => {
365
+ opts.connectionString = config.getOrThrow('DATABASE_URL')
366
+ }),
367
+ )
368
+ .addFastify((opts) => {
369
+ opts.logger = true
370
+ })
371
+
372
+ await app.start((fastify, opts, container, config) => {
373
+ fastify.get('/user/:id', async (req, res) => {
374
+ const scope = container.createScope()
375
+ try {
376
+ const controller = scope.resolve('FIND_USER_CONTROLLER')
377
+ const response = await controller.handle(
378
+ req.params,
379
+ new AbortController().signal,
380
+ )
381
+ return res.status(response.status).send(response.data)
382
+ } catch (err: unknown) {
383
+ req.log.error(err)
384
+ return res.status(500).send({
385
+ success: false,
386
+ error: { message: 'Internal Server Error' },
387
+ })
388
+ } finally {
389
+ await scope.dispose()
390
+ }
391
+ })
392
+
393
+ opts.port = config.getNumber('PORT', 3000)
394
+ })
395
+ ```
396
+
397
+ The HTTP adapter is responsible for HTTP. The application handler is responsible
398
+ for the use case.
399
+
400
+ ---
401
+
402
+ ## CQRS & Pipelines
403
+
404
+ Cross-cutting behavior can be composed around commands and queries:
405
+
406
+ ```typescript
407
+ .addPipeline((config) => {
408
+ config.authorization.policies = {
409
+ FIND_USER_QUERY_HANDLER: {
410
+ roles: ['admin'],
411
+ permissions: ['read'],
412
+ },
413
+ }
414
+
415
+ config.commandBus.idempotency = {
416
+ lockTtlSeconds: 30,
417
+ processedTtlSeconds: 60,
418
+ }
419
+
420
+ config.commandBus.concurrency = {
421
+ delayConfig: {
422
+ baseDelayMs: 100,
423
+ maxJitterMs: 500,
424
+ },
425
+ maxRetries: 3,
426
+ }
427
+
428
+ config.queryBus.isEnabled = true
429
+ })
430
+ ```
431
+
432
+ The exact pipeline configuration depends on the integrations enabled by your
433
+ application.
434
+
435
+ ---
436
+
437
+ ## Infrastructure & Integrations
438
+
439
+ Xeno.JS Core can be composed with infrastructure such as:
440
+
441
+ - **Database:** Drizzle ORM, PostgreSQL, LibSQL
442
+ - **Cache / distributed coordination:** Redis
443
+ - **Authentication:** Supabase integrations and custom strategies
444
+ - **HTTP clients:** Axios
445
+ - **Resilience:** Cockatiel
446
+ - **Logging:** Console, Pino, Sentry, or custom loggers
447
+ - **Validation:** Zod
448
+
449
+ These integrations are opt-in rather than mandatory parts of the application
450
+ architecture.
451
+
452
+ ---
453
+
454
+ ## CLI
455
+
456
+ Use the official CLI to scaffold a Xeno.JS application:
457
+
458
+ ```bash
459
+ npm install @xeno-js/cli
460
+ xeno-js new my-xeno-app --core
461
+ ```
462
+
463
+ See the [CLI documentation](https://www.xeno-js.it/cli/overview).
464
+
465
+ ---
466
+
467
+ ## Documentation
468
+
469
+ The documentation hub contains the architecture and integration guides:
470
+
471
+ **[xeno-js.it](https://www.xeno-js.it/docs/introduction)**
472
+
473
+ Recommended starting points:
474
+
475
+ - [Introduction](https://www.xeno-js.it/docs/introduction)
476
+ - [Fundamentals](https://www.xeno-js.it/docs/fundamentals/overview)
477
+ - [Dependency Injection](https://www.xeno-js.it/docs/dependency-injection/service-container)
478
+ - [CQRS](https://www.xeno-js.it/docs/application/cqrs/overview)
479
+ - [Pipelines](https://www.xeno-js.it/docs/application/overview)
480
+ - [CLI](https://www.xeno-js.it/docs/cli/overview)
481
+
482
+ ---
483
+
484
+ ## Ecosystem
485
+
486
+ Xeno.JS is designed as an ecosystem rather than a single monolithic package:
487
+
488
+ | Package | Role |
489
+ | ----------------- | ----------------------------------------- |
490
+ | `@xeno-js/core` | Application architecture and backend core |
491
+ | `@xeno-js/shared` | Shared contracts and types |
492
+ | `@xeno-js/vue` | Vue integration |
493
+ | `@xeno-js/cli` | Project scaffolding and developer tooling |
494
+
495
+ ---
496
+
497
+ ## What Xeno.JS Is Not
498
+
499
+ Xeno.JS is not primarily an HTTP framework.
500
+
501
+ If you are looking for a framework centered on routing, controllers, middleware,
502
+ and server lifecycle, there are excellent options already available in the
503
+ Node.js ecosystem.
504
+
505
+ Xeno.JS focuses on the layer above transport:
506
+
507
+ > **How should a TypeScript application be structured so that its business
508
+ > logic, dependencies, and infrastructure boundaries remain explicit as the
509
+ > application grows?**
510
+
511
+ ---
512
+
513
+ ## Production Considerations
514
+
515
+ Xeno.JS provides architectural primitives, but application correctness still
516
+ depends on how those primitives are composed.
517
+
518
+ Before deploying an application, test the behaviors that matter to your
519
+ workload, especially:
520
+
521
+ - request and transaction isolation
522
+ - service lifetime boundaries
523
+ - authorization policies
524
+ - idempotency semantics
525
+ - concurrency behavior
526
+ - cache consistency
527
+ - failure and retry behavior
528
+ - trusted proxy / client IP configuration
529
+ - database transaction boundaries
530
+
531
+ The framework is designed to make these boundaries explicit rather than hide
532
+ them behind conventions.
533
+
534
+ ---
535
+
536
+ ## Contributing
537
+
538
+ Contributions are welcome.
539
+
540
+ Development happens from feature branches targeting `develop`.
541
+
542
+ ```bash
543
+ git checkout develop
544
+ git pull origin develop
545
+ git checkout -b feat/your-feature
546
+
547
+ npm install
548
+ npm run check
549
+ ```
550
+
551
+ We use Conventional Commits:
552
+
553
+ ```bash
554
+ feat(scope): add new feature
555
+ fix(scope): resolve bug
556
+ chore(scope): update dependencies
557
+ ```
558
+
559
+ Before opening a pull request, run:
560
+
561
+ ```bash
562
+ npm run check
563
+ ```
564
+
565
+ | Command | Description |
566
+ | ----------------------- | ------------------------ |
567
+ | `npm run build` | Build the package |
568
+ | `npm run typecheck` | TypeScript type checking |
569
+ | `npm run lint` | ESLint |
570
+ | `npm run format:check` | Prettier validation |
571
+ | `npm run test` | Vitest test suite |
572
+ | `npm run test:coverage` | Test suite with coverage |
573
+
574
+ ---
575
+
576
+ ## Support
577
+
578
+ If Xeno.JS is useful to you, you can support the project through the community
579
+ and sponsorship channels documented on the website:
580
+
581
+ **[Support Xeno](https://www.xeno-js.it/support-us)**
582
+
583
+ ---
584
+
585
+ ## License
586
+
587
+ Copyright (c) 2026 Xeno.
588
+
589
+ Licensed under the [MIT License](LICENSE).