A lightweight, event-driven, layer-stack framework for building modular Node.js applications with TypeScript.
npm install @prism-dev/nexusLayers. An event or update tick flows through the stack, allowing each layer to inspect, handle, or pass on the data.
UserRegisterEvent) onto a central EventBus.
EmailService listens for UserRegisterEvent) and react accordingly.
ServiceLocator provides easy Dependency Injection for your services (like ConfigService or DatabaseService) without any "prop drilling."
@prism-dev/nexus-cli
bash
npm install -g @prism-dev/nexus-cli
`
$3
The CLI allows you to instantly generate:
Projects: nexus create:project (Sets up TS, directory structure, and config)*
* Layers: nexus create:layer
* Events: nexus create:event
* Services: nexus create:service
Ideal For
Nexus is perfect for any application that benefits from a clear separation of concerns:
* Event-driven Microservices
* Backend APIs (REST, GraphQL)
* Real-time applications (WebSockets)
* Chat Bots (Discord, Slack, etc.)
* Game server backends
Basic Usage
Here is what a minimal app-api application looks like using Nexus. (Note: You can generate a full project structure automatically using the CLI).
main.ts
`typescript
import {
Application,
ApplicationSpecification,
Event,
Layer,
Log,
ServiceLocator
} from "@prism-dev/nexus";
// 1. Define a simple Layer.
class MyLayer extends Layer {
OnAttach(): void {
Log.Info("MyLayer Attached!");
// You can get services anywhere.
// const config = ServiceLocator.Get(ConfigService);
}
OnDetach(): void {}
OnUpdate(ts: number): void {}
OnEvent(event: Event): void {
Log.Info(MyLayer saw event: ${event.Name});
}
}
// 2. Create the Application.
(async () => {
const spec: ApplicationSpecification = { Name: "MyApp" };
const app: Application = new Application(spec);
try {
// 3. Register & Initialize Services.
// app.RegisterService(ConfigService, new ConfigService());
await app.InitializeServices();
} catch (error: any) {
Log.Error(Failed to initialize services!: ${error.message});
process.exit(1);
}
// 4. Push Layers.
app.PushLayer(new MyLayer());
// 5. Run the Application.
app.Run();
// 6. Handle shutdown.
process.on('SIGINT', () => app.Close());
})();
``