Layers - clean architecture
Overview of service layers and their responsibilities.
Four Layers with Dedicated Responsibilities
Each service, following the default template, is structured into four distinct layers, each with specific responsibilities and rules:
- Presentation: Handles user interactions and APIs (sync and async)
- Application: Coordinates business operations and enforces use cases
- Domain: Contains core business logic and entities
- Infrastructure: Manages external systems and dependencies (e.g., database, messaging)
Concept is based on Clean architecture (CA).
References & Inspiration:
- https://github.com/jasontaylordev/CleanArchitecture
- https://www.youtube.com/watch?v=dK4Yb6-LxAk
- https://jasontaylor.dev/clean-architecture-getting-started/
CQRS
The white-label and platform design embraces the CQRS (Command Query Responsibility Segregation) pattern for its numerous benefits:
- Separation of Responsibilities: Divides commands and queries to streamline focus and clarity
- Encapsulation of Business Logic: Keeps business logic contained and cohesive
- Ease of Development and Coordination: Simplifies teamwork and development processes
- Robust Implementations: Ensures a strong, maintainable codebase
- Work Organization: Provides a clear structure for handling tasks
- Pipeline Execution: Allows execution of specific steps or checks within command/query pipelines
- Layer Separation: Enforces a strict separation between the presentation and application layers with defined contract
- Scalability and Performance: Facilitates scaling and performance improvements as/if needed
Layers practical point of view
Domain layer
- Contains a set of entities (to be persisted) along with the core business logic
Application layer
- Comprises queries and commands, as well as their associated contracts
- Authorization: Encapsulated within this layer, ensuring it is applied consistently regardless of usage context (e.g., API, messaging, jobs, command line)
- Must allow adjustments without breaking contracts with the presentation layer.
Infrastructure layer
- Provides specific implementations for application layer dependencies, such as persistence, logging, monitoring, and caching
Presentation layer
- Responsibility of exposing functionality provided by a given service using specific contract
Common exposure methods:
- Synchronous: APIs
- Asynchronous: Messaging
- Defines consumer-facing contracts and handles data transformation between:
- Presentation layer data structures (DTOs) and
- Application layer data structures (commands and queries)
- Can implement contract versioning and client-specific adjustments without impacting other layers. This ensures the application and infrastructure layers remain stable and robust.
Host-base (service envelope)
The host-base (service envelope) provides a standardized foundation for all services, ensuring core functionality like logging, serialization, health checks, and authentication. It follows a two-layer structure - the Platform Host-Base delivers shared platform-wide features, while the Project-Specific Host-Base (Extended) extends it to include project-specific customizations and adjustments. This approach ensures consistency, flexibility, and maintainability across services.
Layers interactions and naming conventions
Overview of class naming conventions and interactions between service layers.