The complete framework for building modern web applications with Actor-based architecture
Zero external dependencies · Enterprise-grade patterns · Type-safe · Production-ready
npm install cortexRequirements: Node.js 18.0.0 or higher
import { EventBus, ActorSystem, CortexHttpServer } from 'cortex';
// Create core components
const eventBus = EventBus.getInstance();
const actorSystem = new ActorSystem(eventBus);
const server = new CortexHttpServer(eventBus, undefined, 3000);
// Create a simple actor
class PingActor {
async receive(message: any) {
console.log('Ping actor received:', message);
return { response: 'pong' };
}
}
// Register and dispatch
await actorSystem.createActor(PingActor, 'ping-actor');
await actorSystem.dispatch('ping-actor', { type: 'ping' });
// Start server
await server.listen();- Full Documentation - Complete guide and API reference
- Getting Started Guide - Step-by-step tutorial
- API Reference - Detailed API documentation
- Examples - Working code examples
- Actor System: Robust actor model for managing concurrent message-driven processes
- Event Bus: Central pub-sub messaging hub for event-driven communication
- HTTP Server: Built-in HTTP/REST server with middleware support
- Configuration Management: Centralized config system with environment support
- Logger: Structured logging with multiple output levels
- Distributed Tracing: OpenTelemetry-compatible trace generation and collection
- Metrics Collection: Prometheus-compatible metrics (counters, gauges, histograms)
- Health Checks: Registry with memory, uptime, CPU, and app-level health checks
- Circuit Breaker: Prevent cascading failures with intelligent request handling
- Retry Executor: Configurable retry logic with exponential backoff and jitter
- Bulkhead Pattern: Isolate resources and limit concurrent operations
- Composite Policy: Combine multiple resilience patterns seamlessly
- HTTP Compression: Support for Brotli, Gzip, and Deflate compression
- HTTP Caching: Client and server-side caching strategies
- Response Streaming: Efficient data transfer for large payloads
- Content Security Policy (CSP): Builder for setting CSP headers
- Rate Limiting: Request throttling with sliding window algorithm
- Request Validation: Input sanitization and validation middleware
- Web3 Integration: Smart contract interaction and IPFS client support
- WebAssembly Support: Memory management and WASM module utilities
- Web Workers: Actor-based worker pool for concurrent processing
- GraphQL API: Zero-dependency GraphQL stub for extensibility
- gRPC Support: gRPC server/client implementations
- Project Generator: Scaffold new Cortex projects with templates
- Interactive Wizard: Terminal-based configuration and setup
- Command Framework: Build custom CLI commands easily
┌─────────────────────────────────────────────────────────────┐
│ Cortex Framework │
├─────────────────────────────────────────────────────────────┤
│ Core Layer │
│ ├─ EventBus (Singleton pub-sub) │
│ ├─ ActorSystem (Actor lifecycle management) │
│ ├─ CortexHttpServer (HTTP/REST interface) │
│ ├─ Logger (Structured logging) │
│ └─ Config (Configuration management) │
├─────────────────────────────────────────────────────────────┤
│ Feature Modules │
│ ├─ Observability (Tracing, Metrics, Health) │
│ ├─ Resilience (Circuit Breaker, Retry, Bulkhead) │
│ ├─ Performance (Compression, Caching) │
│ ├─ Security (CSP, Rate Limiting) │
│ ├─ Workers (WorkerPool, WorkerActor) │
│ └─ Web3 (Smart Contracts, IPFS) │
├─────────────────────────────────────────────────────────────┤
│ API & Integration │
│ ├─ GraphQL (Zero-dependency stub) │
│ ├─ gRPC (Server/Client implementations) │
│ ├─ CLI (Project generation, commands) │
│ └─ WASM (Memory manager, utilities) │
└─────────────────────────────────────────────────────────────┘
EventBus(src/core/eventBus.ts): Singleton pub-sub system providing central event-driven communication. Components subscribe to topics and publish typed messages.ActorSystem(src/core/actorSystem.ts): Manages actor lifecycle, message routing, and dispatch. Actors process messages asynchronously via mailboxes.CortexHttpServer(src/core/httpServer.ts): HTTP server with middleware support and route handling for triggering actor workflows.Logger(src/core/logger.ts): Structured logging with multiple levels and output handlers.Config(src/core/config.ts): Environment-aware configuration management with type safety.
src/observability/: Distributed tracing, metrics collection, and health checkssrc/resilience/: Circuit breaker, retry logic, bulkhead, and composite policiessrc/performance/: Compression middleware, HTTP caching strategiessrc/security/: CSP builder, rate limiting middlewaresrc/workers/: Web worker integration with actor modelsrc/web3/: Smart contract client, IPFS integrationsrc/wasm/: WebAssembly memory management and utilitiessrc/api/: GraphQL and gRPC implementationssrc/cli/: Project generation and CLI frameworksrc/neurons/: Example actors (PingNeuron, PongNeuron)
- Node.js (v18 or higher)
- npm (Node Package Manager)
-
Clone the repository:
git clone https://github.com/your-username/cortex.git cd cortex -
Install dependencies:
npm install
-
Build the project:
npm run build
To start the HTTP server and the integrated neuron system, run:
npm startThe server will listen on http://localhost:3000. You can then access the /ping endpoint:
curl http://localhost:3000/pingimport { ActorSystem, EventBus } from 'cortex';
const eventBus = EventBus.getInstance();
const actorSystem = new ActorSystem(eventBus);
class MyActor extends Actor {
async receive(message: any): Promise<void> {
console.log('Received:', message);
}
}
actorSystem.createActor(MyActor, 'myActor', eventBus);
await actorSystem.dispatch('myActor', { type: 'greeting', text: 'Hello!' });import { ObservabilityFactory } from 'cortex';
const tracer = ObservabilityFactory.createTracer('my-service', 0.1);
const span = tracer.startSpan('important-operation');
// ... do work ...
span.end();import { CircuitBreaker, RetryExecutor } from 'cortex';
const circuitBreaker = new CircuitBreaker({ failureThreshold: 5 });
const retryExecutor = new RetryExecutor({ maxAttempts: 3 });
await circuitBreaker.execute(async () => {
// Protected operation
return await someRiskyOperation();
});To run all unit and integration tests, use:
npm testThis will execute comprehensive tests for all modules including:
- Event Bus and Actor System
- HTTP Server and routing
- Observability stack (tracing, metrics, health)
- Resilience patterns (circuit breaker, retry, bulkhead)
- Performance optimizations (compression, caching)
- Security features (CSP, rate limiting)
- Advanced integrations (Web3, WebAssembly, Workers)
The Cortex Framework is built on several core principles:
- Actor Model: Processes are isolated, concurrent entities that communicate via asynchronous messages
- Event-Driven: Components communicate through a central event bus for loose coupling
- Reactive: Non-blocking, asynchronous processing with proper error handling
- Type-Safe: Strict TypeScript enforcement with no implicit
anytypes - Zero-Dependency Core: Core framework has no external dependencies
- Modular: Features are organized into independently usable modules
- Production-Ready: Includes observability, resilience, and security patterns out-of-the-box
- Use Actors for Concurrent Work: Leverage the actor model for handling multiple operations safely
- Monitor with Observability: Always instrument your actors with tracing and metrics
- Apply Resilience Patterns: Wrap external calls with circuit breakers and retry logic
- Secure Your APIs: Use rate limiting and CSP headers for production deployments
- Test Integration Paths: Use the integration test suite as a reference for multi-module interactions
- Handle Backpressure: Use the bulkhead pattern to control resource consumption
Comprehensive documentation is available in:
ARCHITECTURE_DIAGRAM.md- Visual framework architectureIMPLEMENTATION_SPEC.md- Detailed implementation guideRESEARCH_SUMMARY.md- Design decisions and best practicesQUICK_REFERENCE.md- Code examples and API reference
We welcome contributions to the Cortex Framework! Please refer to the CONTRIBUTING.md file for guidelines on how to contribute, including information on our GitFlow workflow, TDD practices, and coding standards.
This project is licensed under the MIT License. See the LICENSE file for details.
Built with ❤️ using strict TypeScript and modern JavaScript