Skip to content

PXL Node.js Framework ​

Modular TypeScript framework unifying HTTP, WebSocket, Queue, Database, Cache, Auth, and Observability under a single lifecycle.

PXL sits between "roll everything yourself" and heavyweight monolith frameworks. It keeps you close to Fastify, BullMQ, MikroORM, Redis, and native primitives while providing structured lifecycle control, consistent patterns, and instrumentation.

Core Value Proposition ​

ChallengeWithout PXLWith PXL
Multi-subsystem startupAd-hoc ordering & race conditionsDeterministic lifecycle phases
Resource shutdownForgotten timers / connectionsTracked disposables & graceful timeout
Cross-cutting instrumentationCopy/paste wrappersBuilt-in performance monitor
Queue + HTTP cohesionSeparate bootstrap scriptsUnified Application context
Config sprawlManual mergingDeclarative module config
Logging consistencyMixed formatsStructured logger integration

Features At a Glance ​

  • πŸš€ Unified Application bootstrap (HTTP, WebSocket, Queue, DB, Cache, Auth)
  • βš™οΈ Deterministic lifecycle + hooks (onInit, onStart, onReady, onBeforeShutdown, onShutdown)
  • πŸ§ͺ First-class testing patterns (fast unit + integration)
  • πŸ“Š Performance monitoring spans (HTTP, DB, cache, queue, websocket, custom)
  • πŸ—ƒ MikroORM integration & optional migrations/seeding workflow
  • πŸ“¨ Queue workers with BullMQ (isolated or in-process)
  • πŸ”Œ Structured services pattern for business logic
  • πŸ•Έ WebSocket client + room management
  • 🧡 Request context & utilities
  • πŸ” JWT utilities for auth flows

Architecture (High-Level) ​

          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚      Application     β”‚
          β”‚  (orchestrator)      β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     init/start/stop β”‚ lifecycle events
                     β”‚
 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚ WebServerβ”‚ WebSockβ”‚  Queue    β”‚ Database  β”‚  Cache   β”‚ ...
 β”‚ (Fastify)β”‚ (WS)   β”‚ (BullMQ)  β”‚ (MikroORM)β”‚ (Redis)  β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚            β”‚            β”‚             β”‚
        └─────── Shared Logger / Performance Monitor / Request Context β”€β”€β”€β”€β”€β”€β”€β”˜

Each module is optionalβ€”omit it from config and it won't be initialized.

Install ​

bash
npm install @scpxl/nodejs-framework
# or
pnpm add @scpxl/nodejs-framework
# or
yarn add @scpxl/nodejs-framework

Minimal App (HTTP Only) ​

ts
// app.ts
import { Application } from '@scpxl/nodejs-framework';

const app = new Application({
  webserver: { port: 3000 },
  logger: { level: 'info' },
});

app.webserver.route({ method: 'GET', url: '/health', handler: async () => ({ ok: true }) });

await app.start();
console.log('App running on :3000');

Run (TypeScript ESM loader):

bash
node --loader ts-node/esm app.ts

Add WebSocket ​

ts
const wss = app.websocket; // if enabled in config
wss.onConnection(client => {
  client.sendJSON({ welcome: true });
});

Add Queue Worker ​

ts
app.queue.process('email:send', async job => {
  // send email
});

Graceful Shutdown Example ​

ts
['SIGINT', 'SIGTERM'].forEach(sig => process.on(sig as NodeJS.Signals, () => app.stop()));

Suggested Project Layout ​

src/
  app.ts
  services/
    user.service.ts
  routes/
    user.routes.ts
  queue/
    email.worker.ts
  websocket/
    gateway.ts
  database/
    entities/
    migrations/

Production Notes ​

  • Prefer explicit ports via PORT env.
  • Separate queue-only worker processes if throughput differs from HTTP traffic.
  • Feed performance metrics into your APM via periodic perf.generateReport().
  • Keep migrations versioned & run pre-boot.

Next Steps ​

GoalWhere to Go
Understand lifecycle hooksLifecycle
Configure modulesConfiguration
Add commands / CLI tasks(Soon) Commands & CLI
Instrument performancePerformance & Monitoring
Deploy & scaleDeployment / Scaling
Explore API shapesAPI Reference (TypeDoc)

Missing something? Open an issue or PR on GitHub.

Released under the ISC License.