Skip to content

Latest commit

 

History

History
159 lines (130 loc) · 5.35 KB

File metadata and controls

159 lines (130 loc) · 5.35 KB

Taskify Backend - Clean Architecture Refactoring

Overview

This project has been successfully refactored from a monolithic structure to follow Clean Architecture principles with clear separation of concerns and proper dependency direction.

New Project Structure

/Taskify
├── src/
│   ├── Taskify.Domain/           → Core business models and entities
│   ├── Taskify.Application/      → Use cases, commands, queries, and interfaces
│   ├── Taskify.Infrastructure/   → Data access, external services, implementations
│   └── Taskify.Web/              → API controllers and presentation layer
└── tests/
    └── Taskify.Tests/            → Unit and integration tests

Dependency Direction (Clean Architecture Rules)

  • WebApplicationDomain
  • InfrastructureApplication
  • ✅ Domain has no dependencies on other layers
  • ✅ Application depends only on Domain
  • ✅ Infrastructure implements Application interfaces

Key Improvements

1. Domain Layer (Taskify.Domain)

  • Clean domain entities without EF attributes
  • Proper enums with meaningful names
  • Business logic separated from data concerns
  • No external dependencies

2. Application Layer (Taskify.Application)

  • CQRS pattern with MediatR
  • Feature-based folder organization
  • Clear interfaces for external dependencies
  • DTOs for data transfer
  • Vertical slicing by features (Users, Tasks, Projects, etc.)

3. Infrastructure Layer (Taskify.Infrastructure)

  • EF Core DbContext with proper mappings
  • Service implementations (AuthService, EmailService)
  • External API integrations (Google Auth, BCrypt)
  • Dependency injection configuration

4. Web Layer (Taskify.Web)

  • Thin controllers that delegate to Application layer
  • Proper dependency injection setup
  • CORS configuration
  • Swagger/OpenAPI documentation

Technologies & Patterns Used

Core Technologies

  • .NET 9.0 - Latest framework version
  • Entity Framework Core - Data access with PostgreSQL
  • MediatR - CQRS and Mediator pattern implementation
  • BCrypt.Net - Password hashing
  • JWT - Authentication tokens
  • Google APIs - OAuth integration

Architectural Patterns

  • Clean Architecture - Separation of concerns with proper dependencies
  • CQRS - Command Query Responsibility Segregation
  • Mediator Pattern - Decoupled request/response handling
  • Repository Pattern - Data access abstraction
  • Dependency Injection - Loose coupling and testability

Code Quality Improvements

Before (Issues Fixed)

❌ Mixed responsibilities in controllers
❌ EF attributes polluting domain models
❌ Tight coupling between layers
❌ Business logic in infrastructure
❌ Hard to test and maintain

After (Clean Architecture Benefits)

✅ Single Responsibility Principle
✅ Clean domain models
✅ Loose coupling with interfaces
✅ Business logic in Application layer
✅ Easily testable and maintainable
✅ Scalable architecture

Getting Started

1. Prerequisites

  • .NET 9.0 SDK
  • PostgreSQL database
  • Your favorite IDE (Visual Studio, VS Code, Rider)

2. Configuration

Update appsettings.json in the Web project:

{
  "ConnectionStrings": {
    "DefaultConnection": "Host=localhost;Database=taskify_clean;Username=postgres;Password=your_password"
  },
  "Jwt": {
    "Key": "your-secret-key-here-make-it-long-enough-for-security",
    "Issuer": "TaskifyAPI"
  }
}

3. Build and Run

# Build the solution
dotnet build Taskify.sln

# Run the API
cd src/Taskify.Web
dotnet run

# Access Swagger UI
# Navigate to: https://localhost:5001/swagger

What's Next

Immediate Improvements

  1. Add more CQRS features - Complete Commands for Create/Update/Delete operations
  2. Implement validation - FluentValidation for request validation
  3. Add authentication middleware - JWT authentication setup
  4. Create more controllers - Tasks, Projects, Comments, etc.
  5. Add logging - Structured logging with Serilog

Advanced Features

  1. Unit tests - Comprehensive test coverage
  2. Integration tests - API endpoint testing
  3. Event sourcing - For audit trails
  4. Background services - Email notifications, file processing
  5. API versioning - Support multiple API versions
  6. Rate limiting - Protect against abuse
  7. Caching - Redis for performance

Benefits of This Architecture

For Development Team

  • Clear boundaries - Each layer has specific responsibilities
  • Easy testing - Interfaces allow easy mocking
  • Parallel development - Teams can work on different layers independently
  • Code reuse - Business logic is centralized and reusable

For Maintenance

  • Easier debugging - Clear flow of dependencies
  • Flexible technology changes - Swap implementations without affecting business logic
  • Scalability - Easy to add new features following established patterns
  • Documentation - Self-documenting architecture

For Business

  • Faster time to market - Well-structured code means faster development
  • Lower maintenance costs - Clean code is easier to maintain
  • Better quality - Separation of concerns reduces bugs
  • Future-proof - Architecture supports growth and changes

This refactoring sets a solid foundation for building a scalable, maintainable, and testable task management application.