Skip to content

Latest commit

 

History

History
92 lines (67 loc) · 2.82 KB

File metadata and controls

92 lines (67 loc) · 2.82 KB

ADR 008: Comprehensive Modularization Strategy

Status

Accepted~~~~

Context

The application needs a clear structure that promotes maintainability, scalability, and separation of concerns. We need to decide on an approach that will guide the organization of our codebase, from the domain model through the application layer to the data model.

Decision

We will implement a comprehensive modularization strategy that extends from the domain model to the data layer. Each module will encapsulate highly cohesive functionality and will have the ability to communicate with other modules when necessary.

Consequences

Positive

  • Clear boundaries between different parts of the system
  • Improved maintainability and easier to understand codebase
  • Facilitates parallel development by different teams
  • Easier to test individual modules
  • Flexibility to evolve or replace modules independently

Negative

  • Increased initial complexity in setting up module boundaries
  • Potential for overengineering if modularization is taken to extremes
  • Need for careful design of inter-module communication

Implementation Details

  1. Domain Layer: Each module will have its own set of domain entities, value objects, and domain services.

  2. Application Layer: Modules will have their own application services, commands, and queries.

  3. Infrastructure Layer: Each module can have its own repositories and external service integrations.

  4. Presentation Layer: API endpoints will be organized by module.

  5. Data Model: Database schemas will be aligned with modules to maintain separation.

  6. Inter-module Communication: Modules can communicate through well-defined interfaces (ModuleClients) and message-based integration events.

Example

// Catalog Module
namespace BookFiesta.Catalog.Domain
{
    public class Book : AggregateRoot<BookId>
    {
        // Book properties and methods
    }
}

namespace BookFiesta.Catalog.Application
{
    public class CreateBookCommand : IRequest<Result<BookDto>>
    {
        // Command properties
    }
}

// Inventory Module
namespace BookFiesta.Inventory.Domain
{
    public class StockItem : AggregateRoot<StockItemId>
    {
        // StockItem properties and methods
    }
}

// Inter-module communication
namespace BookFiesta.Catalog.Infrastructure
{
    public class CatalogService
    {
        private readonly IInventoryModuleClient _inventoryClient;

        public async Task<bool> IsBookInStock(BookId bookId)
        {
            return await _inventoryClient.CheckStockAvailability(bookId);
        }
    }
}

This structure demonstrates how different modules (Catalog and Inventory) are separated but can still communicate when needed.

References