Skip to content

ar-refai/TaskFlow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TaskFlow API

A production-grade REST API for task management built with .NET 8, following Onion Architecture and Domain-Driven Design (DDD) principles.

🎯 Project Purpose

This project demonstrates best practices for building maintainable, testable, and scalable enterprise applications using:

  • Onion Architecture (strict dependency inversion)
  • Domain-Driven Design (rich domain models, value objects, aggregates)
  • CQRS Pattern (manual implementation without MediatR)
  • Result Pattern (explicit error handling)
  • Repository Pattern with Unit of Work
  • EF Core as a state manager (not data access abstraction)
  • RESTful API design with proper HTTP semantics

πŸ—οΈ Architecture

Layer Structure

TaskFlow/
β”œβ”€β”€ TaskFlow.Domain          # Core business logic (zero dependencies)
β”œβ”€β”€ TaskFlow.Application     # Use cases, handlers (depends on Domain only)
β”œβ”€β”€ TaskFlow.Infrastructure  # EF Core, repositories (depends on Domain only)
└── TaskFlow.API             # HTTP layer, controllers (depends on all layers)

Dependency Flow

API β†’ Application β†’ Domain
  β†˜    Infrastructure β†—

Key Rule: Dependencies point inward. Inner layers never reference outer layers.


πŸš€ Features

Domain Model

  • Entities: Task, Project, TeamMember, Comment
  • Value Objects: TaskId, ProjectId, TeamMemberId, CommentId, Priority, TaskStatus, DateRange, Tag
  • Aggregates: Task (root), Comment (child)
  • Domain Events: TaskAssigned, TaskCompleted, TaskStatusChanged
  • Business Rules: State machine for task status transitions, invariant validation

API Endpoints (20 Total)

Projects (5 endpoints)

  • POST /api/projects β€” Create project
  • GET /api/projects β€” List all projects
  • GET /api/projects/{id} β€” Get project by ID
  • PUT /api/projects/{id} β€” Update project
  • DELETE /api/projects/{id} β€” Delete project

Tasks (10 endpoints)

  • POST /api/projects/{projectId}/tasks β€” Create task in project
  • GET /api/projects/{projectId}/tasks β€” Get all tasks in project
  • GET /api/tasks?status=...&assigneeId=... β€” Filter tasks (query parameters)
  • GET /api/tasks/{id} β€” Get task by ID
  • PUT /api/tasks/{id} β€” Update task details
  • DELETE /api/tasks/{id} β€” Delete task
  • PUT /api/tasks/{id}/assign β€” Assign task to team member
  • PUT /api/tasks/{id}/status β€” Change task status
  • POST /api/tasks/{id}/comments β€” Add comment to task
  • PUT /api/tasks/{id}/tags β€” Update task tags

Team Members (5 endpoints)

  • POST /api/team-members β€” Create team member
  • GET /api/team-members β€” List all team members
  • GET /api/team-members/{id} β€” Get team member by ID
  • PUT /api/team-members/{id} β€” Update team member
  • DELETE /api/team-members/{id} β€” Delete team member

πŸ› οΈ Technologies

Layer Technologies
API ASP.NET Core 8, Swagger (OpenAPI)
Application CQRS (manual), Result Pattern
Infrastructure EF Core 8, SQL Server, Fluent API
Domain C# 12, Record types, Value objects
DevOps Docker (SQL Server), Git

πŸ“¦ Getting Started

Prerequisites

Installation

  1. Clone the repository:
   git clone https://github.com/YOUR_USERNAME/TaskFlow.git
   cd TaskFlow
  1. Start SQL Server (Docker):
   docker-compose up -d
  1. Restore dependencies:
   dotnet restore
  1. Run migrations:
   cd src/TaskFlow.Infrastructure
   dotnet ef database update --startup-project ../TaskFlow.API
   cd ../..
  1. Run the API:
   dotnet run --project src/TaskFlow.API
  1. Open Swagger UI:
   http://localhost:5000 (or the port shown in terminal)

πŸ§ͺ Testing

End-to-end testing via Swagger UI:

  1. Create a project
  2. Create a team member
  3. Create a task in the project
  4. Assign the task to the team member
  5. Change task status through valid transitions
  6. Add comments and tags
  7. Test error cases (invalid status transitions, duplicate emails, etc.)

πŸ“š Learning Highlights

Domain-Driven Design Patterns

  • βœ… Entities with identity and lifecycle
  • βœ… Value Objects (immutable, equality by value)
  • βœ… Aggregates (TaskEntity owns Comments)
  • βœ… Domain Events (TaskAssigned, TaskCompleted)
  • βœ… Domain Exceptions (InvalidStatusTransitionException)

Onion Architecture Principles

  • βœ… Dependency Inversion (interfaces in Domain, implementations in Infrastructure)
  • βœ… Separation of Concerns (each layer has single responsibility)
  • βœ… Testability (domain logic has zero dependencies)

CQRS Implementation

  • βœ… Commands (state changes, return Result)
  • βœ… Queries (read-only, return Result)
  • βœ… Handlers (one per use case, explicit dependencies)

EF Core Best Practices

  • βœ… Fluent API (zero data annotations in domain)
  • βœ… Value Conversions (value objects ↔ primitives)
  • βœ… Owned Entities (DateRange, Tags)
  • βœ… Backing Fields (encapsulation, read-only properties)
  • βœ… Interceptors (automatic CreatedAt/UpdatedAt)

πŸ“Š Project Statistics

Metric Count
Total Endpoints 20
Domain Entities 4 (Task, Project, TeamMember, Comment)
Value Objects 9 (IDs, enums, DateRange, Tag)
Handlers 20 (13 commands, 7 queries)
Database Tables 5 (Projects, Tasks, TeamMembers, Comments, TaskTags)
Lines of Code ~3,500

πŸŽ“ Key Concepts Demonstrated

  1. Strict Layering β€” No shortcuts, proper dependency management
  2. Rich Domain Models β€” Business logic lives in entities, not services
  3. Value Objects β€” Type safety, immutability, validation
  4. Result Pattern β€” Explicit success/failure without exceptions
  5. CQRS β€” Separate read and write concerns
  6. Repository Pattern β€” Data access abstraction
  7. Unit of Work β€” Transaction coordination
  8. Global Exception Handling β€” Centralized error mapping
  9. Fluent API β€” Clean domain layer, configuration in Infrastructure
  10. Aggregate Boundaries β€” Comment can only be created through Task

🚧 Roadmap / Future Enhancements

  • JWT Authentication & Authorization
  • Unit Testing (xUnit + FluentAssertions)
  • Integration Testing
  • Soft Delete (IsDeleted flag)
  • Domain Event Dispatching
  • Pagination & Sorting
  • FluentValidation
  • Logging (Serilog)
  • API Versioning
  • Rate Limiting

πŸ“ License

This project is for educational purposes. Feel free to use it as a reference or template for your own projects.


πŸ™ Acknowledgments

Built as a hands-on learning project to master:

  • Onion Architecture
  • Domain-Driven Design
  • CQRS Pattern
  • EF Core as a state manager
  • REST API best practices

About

Production-grade REST API for task management | .NET 8 | Onion Architecture | DDD | CQRS | EF Core | Docker | 20 endpoints with full CRUD operations

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages