Skip to content

πŸ—οΈ Clean Architecture Migration - Epic: Project Structure ReorganizationΒ #121

@hootanht

Description

@hootanht

πŸ“‹ Epic Overview

This epic tracks the migration from the current N-Layer architecture to Clean Architecture (Onion Architecture) for the Refhub book management system. This will improve maintainability, testability, and separation of concerns.

🎯 Goals

  • Separation of Concerns: Clear boundaries between business logic, data access, and presentation
  • Dependency Inversion: Core business logic independent of external frameworks
  • Testability: Easy unit testing of business logic without external dependencies
  • Maintainability: Modular structure for easier feature development and maintenance
  • Domain-Driven Design: Rich domain models with business logic encapsulation

πŸ“Š Current Architecture Analysis

Current Structure (N-Layer):

Refhub/
β”œβ”€β”€ Controllers/           # Presentation Layer
β”œβ”€β”€ Areas/Admin/          # Admin Presentation
β”œβ”€β”€ Data/
β”‚   β”œβ”€β”€ Context/          # EF DbContext
β”‚   β”œβ”€β”€ Models/           # Data Models (Anemic)
β”‚   └── Configuration/    # EF Configurations
β”œβ”€β”€ Service/
β”‚   β”œβ”€β”€ Interface/        # Service Contracts
β”‚   └── Implement/        # Service Implementations
β”œβ”€β”€ Models/               # ViewModels/DTOs
β”œβ”€β”€ Tools/                # Utilities
└── wwwroot/             # Static Files

Target Structure (Clean Architecture):

Refhub.Domain/            # Core Business Logic
β”œβ”€β”€ Entities/             # Rich Domain Entities
β”œβ”€β”€ ValueObjects/         # Value Objects
β”œβ”€β”€ Interfaces/           # Domain Service Contracts
β”œβ”€β”€ Specifications/       # Business Rules
└── Events/              # Domain Events

Refhub.Application/       # Use Cases & Application Logic
β”œβ”€β”€ Commands/             # CQRS Commands
β”œβ”€β”€ Queries/              # CQRS Queries
β”œβ”€β”€ DTOs/                # Data Transfer Objects
β”œβ”€β”€ Interfaces/           # Application Service Contracts
β”œβ”€β”€ Services/             # Application Services
└── Validators/           # Input Validation

Refhub.Infrastructure/    # External Concerns
β”œβ”€β”€ Data/                 # EF Core Implementation
β”‚   β”œβ”€β”€ Context/          # DbContext
β”‚   β”œβ”€β”€ Configurations/   # EF Configurations
β”‚   └── Repositories/     # Repository Implementations
β”œβ”€β”€ Services/             # External Services (S3, Email, etc.)
└── Migrations/           # Database Migrations

Refhub.Web/              # Presentation Layer
β”œβ”€β”€ Controllers/          # MVC Controllers
β”œβ”€β”€ Areas/               # Admin/User Areas
β”œβ”€β”€ Models/              # ViewModels
└── wwwroot/             # Static Files

Refhub.Tests/            # Test Projects
β”œβ”€β”€ Domain.Tests/         # Domain Unit Tests
β”œβ”€β”€ Application.Tests/    # Application Unit Tests
β”œβ”€β”€ Infrastructure.Tests/ # Infrastructure Tests
└── Web.Tests/           # Integration Tests

πŸ”— Related Issues

This epic is broken down into the following sprint-ready issues:

Sprint 1 (2 weeks) - Foundation

  • #[TBD] - Create Clean Architecture Project Structure
  • #[TBD] - Implement Domain Entities with Rich Business Logic
  • #[TBD] - Setup CQRS Pattern with MediatR

Sprint 2 (2 weeks) - Core Migration

  • #[TBD] - Migrate Repository Pattern to Clean Architecture
  • #[TBD] - Implement Application Services and Use Cases
  • #[TBD] - Setup Domain Events and Event Handlers

Sprint 3 (2 weeks) - Infrastructure & Testing

  • #[TBD] - Migrate Infrastructure Services (S3, Database)
  • #[TBD] - Implement Comprehensive Unit Testing
  • #[TBD] - Update Controllers to Use Application Layer

🏷️ Business Value

  • Reduced Technical Debt: Cleaner, more maintainable codebase
  • Faster Development: Clear separation allows parallel development
  • Better Testing: Improved test coverage and reliability
  • Scalability: Architecture supports future growth and features
  • Team Productivity: Clear guidelines for where code should go

🎯 Success Criteria

  • All business logic moved to Domain layer
  • Complete separation of concerns achieved
  • Controllers only handle HTTP concerns
  • 90%+ unit test coverage for Domain and Application layers
  • Zero circular dependencies
  • All external dependencies abstracted behind interfaces

πŸ“ˆ Estimated Timeline

  • Total Duration: 6 weeks (3 sprints)
  • Team Size: 2-3 developers
  • Risk Level: Medium (well-defined patterns)

πŸ”„ Migration Strategy

  1. Gradual Migration: Implement new structure alongside existing code
  2. Feature Toggles: Use feature flags to switch between old/new implementations
  3. Backward Compatibility: Maintain existing functionality during transition
  4. Testing: Comprehensive testing at each migration step

Epic Owner: @hootanht
Sprint Planning: Ready for breakdown into individual sprint issues

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions