Welcome to S42- Core
What is s42-core?
Introduction
s42-core is a robust and flexible Bun.js library designed to simplify the development of modern, scalable, and modular applications. Built with performance and developer productivity in mind, s42-core is particularly well-suited for microservices and cell-based architectures. It empowers developers to create high-performance solutions that are easy to maintain, update, and scale.
Key Features
Microservices and Cell-Based Architectures
s42-core provides out-of-the-box support for microservices and cell-based architectures. It enables developers to build modular applications where each microservice or cell can operate independently while communicating seamlessly. This design promotes better scalability and maintainability.
Framework Agnostic
Unlike many libraries, s42-core does not lock you into a specific framework. You can integrate it with any framework or even use it standalone. Whether you are working with Bun.js, Express, Fastify, or Nest.js, s42-core fits seamlessly into your existing tech stack, allowing gradual adoption.
Optimized for Bun.js
As a library built specifically for Bun.js, s42-core takes full advantage of Bun’s performance capabilities. This results in faster application execution, reduced startup times, and lower resource consumption.
High Performance
Applications built with s42-core are optimized for demanding environments. It employs efficient patterns and practices, ensuring smooth and responsive performance even under heavy workloads.
Simplified Monorepo Management
s42-core promotes modularity by facilitating the development of small, reusable software components (atoms). This makes it easier to manage and scale monorepos, as code can be shared and reused across multiple projects within a single repository.
Features Overview
Cluster Management
Easily manage multiple processes with the built-in Cluster module. Whether you’re scaling horizontally or running multiple worker threads, s42-core provides seamless clustering capabilities.
Server-Sent Events (SSE)
s42-core simplifies the implementation of real-time communication with its Server-Sent Events (SSE) support. Push updates from the server to clients effortlessly, enabling real-time functionality in your applications.
Event-Driven Architecture
With the EventsDomain class, s42-core allows you to implement a fully event-driven architecture. Microservices can emit and listen to domain events, fostering a decoupled and resilient system.
SQLite and Redis Support
s42-core includes built-in support for SQLite and Redis, enabling fast and efficient data storage and caching solutions. It also simplifies interactions with these databases, so you can focus on your application’s logic.
Dynamic Routing
The RouteControllers module provides dynamic routing capabilities, allowing you to create flexible and modular route configurations for your application.
Use Cases
Real-Time Applications
Leverage SSE to implement real-time features such as live notifications, dashboards, or chat applications.
Event-Driven Systems
Build event-driven architectures where microservices communicate through domain events. For instance, emit an event when a user registers, and have another microservice listen for this event to send a welcome email.
Modular Monorepos
With s42-core, you can structure your codebase as reusable components, promoting better collaboration and faster development cycles.
Data-Intensive Applications
Effortlessly integrate SQLite and Redis for efficient data management, ensuring optimal performance for data-intensive operations.
Getting Started
Installation
To install s42-core, run:
Usage Examples
Using EventsDomain for Microservices Communication
The EventsDomain
class enables seamless event-based communication between microservices. For example, you can use it to emit an event from a user registration service and listen to it in an email notification service.
Creating Controllers
Controllers handle HTTP requests and middleware. Here’s an example of creating a simple controller:
Integrating Controllers with RouteControllers
RouteControllers organize and manage multiple controllers efficiently:
Server-Sent Events (SSE)
Easily implement real-time communication with the SSE class:
Cluster Management
The Cluster
class simplifies worker process management:
For assistance, you can contact the author via Telegram or email:
- Telegram: Contact
- Email: cesar@stock42.com
Explore the documentation to learn more about leveraging the power of s42-core in your projects.