@domusjs/infrastructure - Introduction
The Infrastructure Module is a key part of DomusJS, providing all the essential wiring, adapters, and low-level integrations that power your application.
✅ It connects the core domain layer to the outside world (databases, loggers, message brokers, etc.).
✅ It offers ready-to-use implementations for buses, loggers, error handling, and more.
✅ It ensures your domain layer stays clean and free from infrastructure-specific concerns.
What Does It Provide?
Section titled “What Does It Provide?”The module includes:
- Command Bus, Query Bus, Event Bus → In-memory default implementations, extensible with custom or distributed buses.
- Logger System → Abstraction + implementations like ConsoleLogger, PinoLogger, OpenTelemetryLogger.
- Error Classes → Structured errors with HTTP-friendly status codes.
- Dependency Injection Setup → Centralized setup using
registerDomusCore()
andtsyringe
. - Middlewares → Helpers like tracing middleware for Express.
- Utilities → Helpers like UUIDProvider for unique IDs.
✅ You can plug in your own implementations for any part, thanks to the modular architecture.
Why Keep Infrastructure Separate?
Section titled “Why Keep Infrastructure Separate?”Separating infrastructure helps you:
- Maintain a clean architecture where domain logic is isolated.
- Replace or upgrade technical components (e.g., switch loggers, change bus backend) without touching core business code.
- Improve testability by mocking infrastructure in tests.
✅ This keeps your system flexible, scalable, and easier to maintain.
Where Does It Fit?
Section titled “Where Does It Fit?”The Infrastructure Module acts as a bridge between:
[ External Systems ] ←→ [ Infrastructure Layer ] ←→ [ Domain + Application Layers ]
Examples of external systems:
- Databases (e.g., PostgreSQL, MongoDB)
- Messaging systems (e.g., RabbitMQ, Kafka)
- Logging + observability tools (e.g., Datadog, Signoz)
- Third-party APIs