Skip to content

stock42/s42-core

Repository files navigation

s42-core

S42-Core

S42-Core is a Bun-first backend framework for building professional APIs, services, and modular cells. It is built around dynamic modules, high-performance HTTP primitives, and event-driven communication.

Developed by Cesar Casas (CEO & Head of Engineering at Stock42 LLC) with AI-assisted engineering workflows (Codex).

What S42-Core Solves

  • Fast HTTP backends on Bun (Bun.serve, Web Request/Response).
  • Modular architecture with convention-based loading.
  • Event-driven communication for distributed cells/services.
  • Built-in utilities for Redis, MongoDB, SQL, SQLite, SSE, and dependency container patterns.
  • Cluster orchestration and IPC for multi-worker runtimes.

Bun-First Architecture

Core runtime choices follow Bun APIs first:

  • HTTP server: Bun.serve
  • Route registration: Bun.serve({ routes }) + fallback matcher for wildcard patterns
  • Process/workers: Bun.spawn + IPC
  • File/module discovery: Bun.Glob
  • SQL/SQLite: Bun.SQL and bun:sqlite
  • Redis: Bun.RedisClient

Module System

S42-Core supports three module types:

  1. full Domain modules with controllers/ and optional events/.
  2. mws Middleware modules with mws/index.ts contract (default, beforeRequest, afterRequest).
  3. share Shared modules for reusable code (services, types, utils, etc.) with no route/event registration.

Load order:

  1. mws
  2. share
  3. full

Middleware execution is on-demand at controller level (requireBefore, requireAfter, beforeRequest, afterRequest).

Quick Start

Install:

bun add s42-core

Minimal bootstrap:

import { Modules, RouteControllers, Server } from 's42-core'

const modules = new Modules('./modules')
await modules.load()

const server = new Server()
await server.start({
  port: 5678,
  RouteControllers: new RouteControllers(modules.getControllers()),
  hooks: modules.getHooks(),
})

Run local module demo in this repo:

bun run modules/server.ts

Module Folder Conventions

modules/
  auth/
    __module__.ts          # type: "mws"
    mws/index.ts
  share/
    __module__.ts          # type: "share"
    services/
    types/
  operators/
    __module__.ts          # type: "full"
    controllers/
    events/

Documentation Index

English:

Spanish:

Current Priorities

See TODO.md for prioritized engineering backlog (P0-P3) based on full src/ analysis and Bun docs alignment.

License

MIT

Credits

S42-Core is developed by Cesar Casas and the engineering team at Stock42 LLC, a company focused on AI solutions, AI agents, and production-grade backend systems.

About

S42-Core – Blazing-fast Bun.js backend framework with zero-config clustering, intuitive SQL abstraction, and high-performance routing. 100% TypeScript · Minimal boilerplate · Built for speed.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors