How edreyer/modulith works
Main Components
• Bounded Contexts: At least three core bounded contexts are present—Booking, Payment, and User. Each context follows the hexagonal layout with sub-components for domain, application (ports and workflows), and adapters (inbound for web APIs and outbound for persistence).
• Common Module: Contains shared configurations, utilities (logging, security, extension functions, etc.), and cross-cutting concerns. This module is used by all bounded contexts.
• Server Module: Acts as the compositional layer that bootstraps the application (entry point: ModulithApplication) and provides global configurations (like MongoDB, Jackson, and security configurations).
• External Dependencies: Include external services like the MongoDB database (as configured in the server’s MongoConfig) and potentially other external systems.
Relationships and Interactions
– Domain (core business logic using ADTs and DDD concepts)
– Application layer (ports for inbound commands and outbound events, including workflows)
– Adapters:
• Inbound (REST controllers, web configurations that drive the workflows)
• Outbound (persistence adapters, external service calls, event publishing adapters)
• Communications between the components:
– REST API calls hitting the input adapters in each module.
– Workflows orchestrated by the application layer processing Commands/Queries via CQRS.
– Outbound adapters interacting with persistence layers (using repositories and persistence configurations) and external systems.
– The server (or orchestrator) bringing together the various bounded contexts.
Important Architectural Patterns and Design Principles
• Hexagonal Architecture (Ports and Adapters): Emphasize the separation between the external world (adapters) and the inner domain logic. Show “port” interfaces that are implemented by inbound and outbound adapters.
• Domain-Driven Design: Identify that each bounded context (User, Booking, Payment) encapsulates its own domain model and that cross-cutting shared utilities live in the Common module.
• CQRS: Demonstrate that incoming commands and queries are handled by specific workflow objects that never throw exceptions but return results (discriminated unions representing success or error states).
• Event-Driven Messaging: Make clear where events are generated (as a result of workflows) and published via Spring’s event system to decouple persistence actions or inter-module communications.
Relevant Technologies, Frameworks, and Libraries
• Kotlin & Spring Boot: The core language and framework utilized.
• Maven Structure: Multi-module arrangement (each bounded context is a separate module).
• Coroutine Support: Indicate that non-blocking and asynchronous operations are achieved via Kotlin coroutines.
• MongoDB: As the persistence layer (see server’s MongoConfig and the persistence adapter configuration).
• Testing Frameworks: ArchUnit (for enforcing architectural constraints) as well as integration tests found under the test directories of each module.
Details and Essential Architectural Elements
• Don’t shy away from including every identifiable module based on the file tree: booking-api, booking, payment-api, payment, user-api, user, common, and server. This level of detail is essential to grasp how the modulith architecture isolates, yet interconnects, each bounded context.
• Both runtime interactions (via Spring’s application contexts and event-driven communication) and compile-time/module isolation (Maven artifacts and package design).