s42-core
v3.0.11
Published
S42-Core v3 is a Bun-first, 100% module-oriented backend framework where each module encapsulates everything needed to work autonomously in production systems.
Maintainers
Readme

S42-Core
Español · Documentation · Website
S42-Core 3.0.11 is a Bun-first TypeScript backend framework for HTTP APIs,
module-oriented services, distributed domain events, and common persistence
workloads.
It is developed by Cesar Casas and Stock42 LLC with AI-assisted engineering workflows.
Requirements
- Bun
>=1.3.0 - TypeScript/ESM projects
- Redis/Valkey, MongoDB, PostgreSQL, MySQL, SQLite, or SQS only when the corresponding component is used
Install the public package:
bun add s42-coreWhat It Provides
- HTTP bootstrap over
Bun.servewith native route maps and a fallback matcher. - Convention-based module discovery with
Bun.Glob. - Three module types:
mws,share, andfull. - Controller-level middleware selection.
- Distributed events through Redis or SQS adapters.
- MongoDB, Redis/Valkey, multi-engine SQL, and direct SQLite helpers.
- SSE, worker clustering, runtime statistics, dependency injection, and leveled logging.
Quick Start
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(),
})
console.info(server.getURL())The repository includes a module demo entrypoint:
bun run modules/server.tsIn the current checkout, that demo and bun run typecheck:modules stop on a
known fixture issue: modules/operators/controllers/operatorList.ts imports the
missing ../events/emit file. The package bootstrap above is unaffected.
Module Model
S42-Core discovers **/__module__.ts files and loads enabled modules in this
order:
mws: on-demand request middleware frommws/index.ts.share: reusable code and contracts; no automatic controller/event loading.full: controllers and optional events.
Minimal manifest:
export default {
name: 'operators',
version: '1.0.0',
type: 'full',
enabled: true,
initialize: async () => {
// Runs after this module has loaded.
},
}Typical layout:
modules/
auth/
__module__.ts
mws/index.ts
share/
__module__.ts
services/
types/
operators/
__module__.ts
controllers/
events/dependencies in a manifest is metadata; the current loader does not resolve
or enforce dependency versions. See MODULES for
the complete runtime contract.
Public Package API
Only exports from src/index.ts are supported package imports.
| Area | Public exports |
| --------------- | --------------------------------------------------------------------------------------- |
| HTTP | Server, RouteControllers, Controller, Res, getControllersStats |
| Modules | Modules, Module, Model, Service, Controllers, getModulesStats |
| Events | EventsDomain, RedisEventsAdapter, SQSEventsAdapter |
| Data | MongoClient, RedisClient, SQL, SQLite, SQLError, isSQLError, Dependencies |
| Runtime | Cluster, SSE, CoreStats |
| Logging/testing | logger, setLogLevel, getLogLevel, setLogSink, Test |
The package also exports the TypeScript types declared by the root entrypoint, including module, event, SQL, logger, SSE, CoreStats, and statistics contracts.
MongoDBStorage, sendEmail (src/Mailgun), and ViewTemplates exist in the
repository but are internal utilities. They are not exported by the package,
and imports such as s42-core/dist/... are unsupported.
Documentation
Start with the consolidated, source-aligned guide:
Component references:
- Runtime: SERVER, ROUTECONTROLLERS, CONTROLLER, RESPONSE, MODULES, and CLUSTER
- Events: EVENTSDOMAIN
- Data: REDISDB, MONGODB, SQL, and SQLITE
- Utilities: SSE, CORESTATS, DEPENDENCIES, LOGGER, and TEST
- Internal reference only: MAILGUN and VIEWTEMPLATE
Spanish component references use the .es.md suffix, beginning with
SERVER.es and
MODULES.es.
Operational Notes
CoreStatsis disabled by default. When enabled, it exposes host and process information and does not add authentication; protect the route before using it outside a trusted network.RouteControllerscurrently emits permissive, fixed CORS headers. Review the routing security notes before production exposure.SSErequires the raw WebRequest; the normalized controller request does not currently preserve its abort signal.- MongoDB, Redis, and EventsDomain use process-wide singletons: the first
configuration passed to
getInstance()wins.
Development
bun run typecheck
bun run typecheck:modules
bun run lint
bun testAll gates except typecheck:modules pass in the current checkout; its known
fixture failure is described above.
See CHANGELOG.md for shipped changes and ROADMAP.md for planned features.
