Skip to content

πŸ—οΈ 1. Create Clean Architecture Project StructureΒ #122

@hootanht

Description

@hootanht

🎯 Sprint 1 - Task 1: Create Clean Architecture Project Structure

Epic: #121
Sprint: 1 (2 weeks)
Estimated Effort: 5 days

πŸ“‹ Description

Create the foundational project structure for Clean Architecture migration. This involves setting up separate class library projects for each layer and establishing proper dependency relationships.

πŸ—οΈ Architecture Overview

New Project Structure

Solution: Refhub.sln
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Refhub.Domain/              # Class Library (.NET 9)
β”‚   β”œβ”€β”€ Refhub.Application/         # Class Library (.NET 9)  
β”‚   β”œβ”€β”€ Refhub.Infrastructure/      # Class Library (.NET 9)
β”‚   └── Refhub.Web/                # Web App (.NET 9)
└── tests/
    β”œβ”€β”€ Refhub.Domain.Tests/        # xUnit Test Project
    β”œβ”€β”€ Refhub.Application.Tests/   # xUnit Test Project
    β”œβ”€β”€ Refhub.Infrastructure.Tests/# xUnit Test Project
    └── Refhub.Web.Tests/          # xUnit Test Project

Dependency Flow (Clean Architecture Rules)

Refhub.Web        β†’ Refhub.Application β†’ Refhub.Domain
       ↓                    ↓
Refhub.Infrastructure β”€β”€β”€β”€β”€β”€β”˜

No project should reference projects to its right or below

βœ… Acceptance Criteria

1. Project Structure Setup

  • Create Refhub.Domain class library project
  • Create Refhub.Application class library project
  • Create Refhub.Infrastructure class library project
  • Rename existing Refhub project to Refhub.Web
  • Update solution file with proper project organization

2. Project References Configuration

  • Refhub.Domain: No external dependencies (only .NET 9)
  • Refhub.Application: References only Refhub.Domain
  • Refhub.Infrastructure: References Refhub.Domain and Refhub.Application
  • Refhub.Web: References Refhub.Application and Refhub.Infrastructure

3. Basic Folder Structure

Refhub.Domain/
β”œβ”€β”€ Entities/
β”œβ”€β”€ ValueObjects/
β”œβ”€β”€ Interfaces/
β”œβ”€β”€ Specifications/
β”œβ”€β”€ Events/
└── Common/

Refhub.Application/
β”œβ”€β”€ Commands/
β”œβ”€β”€ Queries/
β”œβ”€β”€ DTOs/
β”œβ”€β”€ Interfaces/
β”œβ”€β”€ Services/
β”œβ”€β”€ Validators/
└── Common/

Refhub.Infrastructure/
β”œβ”€β”€ Data/
β”‚   β”œβ”€β”€ Context/
β”‚   β”œβ”€β”€ Configurations/
β”‚   └── Repositories/
β”œβ”€β”€ Services/
β”œβ”€β”€ Migrations/
└── Common/

Refhub.Web/
β”œβ”€β”€ Controllers/
β”œβ”€β”€ Areas/
β”œβ”€β”€ Models/
β”œβ”€β”€ wwwroot/
└── Configuration/

4. Package Dependencies

  • Install core packages in each project
  • Configure proper package versions
  • Remove unnecessary dependencies

πŸ“¦ Required NuGet Packages

Refhub.Domain

<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.5" />

Refhub.Application

<PackageReference Include="MediatR" Version="12.4.1" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.8.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.5" />

Refhub.Infrastructure

<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.5" />
<PackageReference Include="AWSSDK.S3" Version="4.0.4.2" />

Refhub.Web (Existing packages + new ones)

<PackageReference Include="MediatR" Version="12.4.1" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />

πŸ”§ Implementation Steps

Day 1-2: Project Creation and Structure

  1. Create new class library projects

    # Navigate to solution root
    cd c:\Users\Hootan\source\repos\Refhub
    
    # Create new projects
    dotnet new classlib -n Refhub.Domain -o src/Refhub.Domain
    dotnet new classlib -n Refhub.Application -o src/Refhub.Application  
    dotnet new classlib -n Refhub.Infrastructure -o src/Refhub.Infrastructure
    
    # Create test projects
    dotnet new xunit -n Refhub.Domain.Tests -o tests/Refhub.Domain.Tests
    dotnet new xunit -n Refhub.Application.Tests -o tests/Refhub.Application.Tests
    dotnet new xunit -n Refhub.Infrastructure.Tests -o tests/Refhub.Infrastructure.Tests
    dotnet new xunit -n Refhub.Web.Tests -o tests/Refhub.Web.Tests
  2. Update solution file

    # Add projects to solution
    dotnet sln add src/Refhub.Domain/Refhub.Domain.csproj
    dotnet sln add src/Refhub.Application/Refhub.Application.csproj
    dotnet sln add src/Refhub.Infrastructure/Refhub.Infrastructure.csproj
    dotnet sln add tests/Refhub.Domain.Tests/Refhub.Domain.Tests.csproj
    dotnet sln add tests/Refhub.Application.Tests/Refhub.Application.Tests.csproj
    dotnet sln add tests/Refhub.Infrastructure.Tests/Refhub.Infrastructure.Tests.csproj
    dotnet sln add tests/Refhub.Web.Tests/Refhub.Web.Tests.csproj

Day 3: Configure Project References

# Application references Domain
dotnet add src/Refhub.Application/Refhub.Application.csproj reference src/Refhub.Domain/Refhub.Domain.csproj

# Infrastructure references Domain and Application
dotnet add src/Refhub.Infrastructure/Refhub.Infrastructure.csproj reference src/Refhub.Domain/Refhub.Domain.csproj
dotnet add src/Refhub.Infrastructure/Refhub.Infrastructure.csproj reference src/Refhub.Application/Refhub.Application.csproj

# Web references Application and Infrastructure
dotnet add Refhub/Refhub.csproj reference src/Refhub.Application/Refhub.Application.csproj
dotnet add Refhub/Refhub.csproj reference src/Refhub.Infrastructure/Refhub.Infrastructure.csproj

Day 4-5: Package Installation and Folder Creation

  1. Install required packages in each project
  2. Create folder structures
  3. Add placeholder classes with proper namespaces
  4. Update existing project structure

πŸ“ Example Files to Create

Refhub.Domain/Common/BaseEntity.cs

namespace Refhub.Domain.Common;

public abstract class BaseEntity
{
    public long Id { get; set; }
    public DateTime CreatedAt { get; set; }
    public DateTime? UpdatedAt { get; set; }
    public string? CreatedBy { get; set; }
    public string? UpdatedBy { get; set; }
}

Refhub.Application/Common/IRepository.cs

namespace Refhub.Application.Common;

public interface IRepository<T> where T : class
{
    Task<T?> GetByIdAsync(long id, CancellationToken cancellationToken = default);
    Task<IEnumerable<T>> GetAllAsync(CancellationToken cancellationToken = default);
    Task<T> AddAsync(T entity, CancellationToken cancellationToken = default);
    Task UpdateAsync(T entity, CancellationToken cancellationToken = default);
    Task DeleteAsync(T entity, CancellationToken cancellationToken = default);
}

🎯 Testing Criteria

  • Solution builds successfully
  • All project references work correctly
  • No circular dependencies
  • Test projects run (even with placeholder tests)
  • Existing functionality still works

πŸ”— Related Tasks

πŸ“š Resources


Sprint: 1 | Assignee: @hootanht | Priority: High | Size: Large

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions