Skip to content

ahmadabdelbary2001/HR.LeaveManagement.Clean

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

74 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ› οΈ HR.LeaveManagement.Clean

A clean architecture-based Human Resources Leave Management system, built with .NET 8, MediatR, and AutoMapper, demonstrating best practices in API development and domain-driven design.

πŸ“– Overview

This project implements a comprehensive HR Leave Management system following a Clean Architecture approach. It showcases a well-structured, maintainable, and testable application built with .NET 8. The system handles various aspects of leave management, including leave types, leave requests, and leave allocations, providing a robust foundation for enterprise-level HR solutions.


πŸ“‹ Table of Contents

  1. ✨ Features
  2. πŸš€ Getting Started
  3. πŸ“ Project Structure
  4. βš™οΈ Configuration
  5. πŸ§ͺ Testing
  6. πŸ“– API Documentation
  7. πŸ“Š Performance Optimization
  8. πŸ” Observability
  9. πŸ“¦ Design Patterns
  10. πŸ› οΈ Contributing
  11. πŸ“œ License
  12. πŸ”— Additional Resources

✨ Features

  • Clean Architecture β€” Organized into Domain, Application, Infrastructure, and API layers for clear separation of concerns.
  • MediatR Implementation β€” Utilizes MediatR for handling commands, queries, and events, promoting a decoupled and testable codebase.
  • AutoMapper Integration β€” Seamless object-to-object mapping to reduce boilerplate code and improve maintainability.
  • Centralized Exception Handling β€” Robust error management through custom middleware for consistent API responses.
  • CRUD Operations for Leave Management β€” Comprehensive functionalities for managing Leave Types, Leave Requests, and Leave Allocations.
  • API Development with .NET 8 β€” Modern RESTful API built on .NET 6, leveraging its latest features and performance improvements.
  • Unit and Integration Testing β€” Dedicated test projects ensuring code quality and reliability.
  • Swagger/OpenAPI Documentation β€” Automatically generated API documentation for easy consumption and testing.

πŸš€ Getting Started

Prerequisites

Ensure you have the following installed:

  • .NET 8 SDK
  • SQL Server (or any compatible database) β€” For persistence layer.
  • Visual Studio 2022 (or VS Code with C# extensions) β€” Recommended IDE.

Installation

  1. Clone the repository:

    git clone https://github.com/ahmadabdelbary2001/HR.LeaveManagement.Clean.git
    cd HR.LeaveManagement.Clean
  2. Restore dependencies:

    dotnet restore
  3. Configure Database: Update the connection string in HR.LeaveManagement.Api/appsettings.json and HR.LeaveManagement.Api/appsettings.Development.json to point to your SQL Server instance.

  4. Apply Migrations: Navigate to the HR.LeaveManagement.Persistence project and apply database migrations:

    dotnet ef database update --project HR.LeaveManagement.Persistence
  5. Build and run the API project:

    dotnet run --project HR.LeaveManagement.Api

    The API will typically run on https://localhost:5296 (or a similar port).

πŸ“ Project Structure

HR.LeaveManagement.Clean/
β”œβ”€β”€ HR.LeaveManagement.Api/               # ASP.NET Core Web API project
β”‚   β”œβ”€β”€ Controllers/                      # API Endpoints
β”‚   β”œβ”€β”€ Middleware/                       # Custom Middleware (e.g., Exception Handling)
β”‚   β”œβ”€β”€ Models/                           # API-specific models (e.g., Email settings)
β”‚   β”œβ”€β”€ Program.cs                        # Application startup and service registration
β”‚   └── appsettings.json                  # Configuration files
β”œβ”€β”€ HR.LeaveManagement.Application/       # Application layer (Core business logic)
β”‚   β”œβ”€β”€ Contracts/                        # Interfaces for services and repositories
β”‚   β”œβ”€β”€ Exceptions/                       # Custom exceptions
β”‚   β”œβ”€β”€ Features/                         # MediatR handlers (Commands, Queries, Events)
β”‚   β”œβ”€β”€ MappingProfiles/                  # AutoMapper profiles
β”‚   β”œβ”€β”€ Models/                           # Application-specific models
β”‚   └── ApplicationServiceRegistration.cs # Dependency Injection for Application services
β”œβ”€β”€ HR.LeaveManagement.Domain/            # Domain layer (Enterprise business rules and entities)
β”‚   β”œβ”€β”€ Common/                           # Base entities and common domain logic
β”‚   β”œβ”€β”€ Entities/                         # Core domain entities (LeaveType, LeaveRequest, LeaveAllocation)
β”‚   └── HR.LeaveManagement.Domain.csproj  # Project file
β”œβ”€β”€ HR.LeaveManagement.Infrastructure/    # Infrastructure layer (External services, e.g., Email, Logging)
β”‚   └── EmailService/                     # Email sending implementation
β”œβ”€β”€ HR.LeaveManagement.Persistence/       # Persistence layer (Data access, e.g., Entity Framework Core)
β”‚   β”œβ”€β”€ Configurations/                   # Entity Framework Core configurations
β”‚   β”œβ”€β”€ Repositories/                     # Concrete implementations of domain repositories
β”‚   β”œβ”€β”€ DatabaseContext/                  # DbContext for Entity Framework Core
β”‚   └── PersistenceServiceRegistration.cs # Dependency Injection for Persistence services
β”œβ”€β”€ HR.LeaveManagement.Application.UnitTests/ # Unit tests for the Application layer
β”œβ”€β”€ HR.LeaveManagement.Persistence.IntegrationTests/ # Integration tests for the Persistence layer
└── HR.LeaveManagement.Clean.sln          # Solution file

βš™οΈ Configuration

Environment Variables

Connection strings and other sensitive configurations should be managed securely. For local development, you can use appsettings.Development.json or user secrets.

Settings

  • Connection Strings β€” Located in appsettings.json and appsettings.Development.json for database connectivity.
  • CORS Policy β€” Configured in Program.cs to allow all origins, headers, and methods for development purposes. Adjust as needed for production environments.
  • Swagger/OpenAPI β€” Enabled in Program.cs for API documentation and testing, typically only in development environments.

πŸ§ͺ Testing

Run test suite with:

dotnet test

Test Coverage:

  • Unit Tests: HR.LeaveManagement.Application.UnitTests/ βœ…
  • Integration Tests: HR.LeaveManagement.Persistence.IntegrationTests/ πŸ”—

πŸ“– API Documentation

The API documentation is generated using Swagger/OpenAPI and can be accessed when the application is running (typically at https://localhost:5296/swagger).

Authentication

This project currently does not implement explicit authentication/authorization mechanisms. All API endpoints are publicly accessible. For production use, consider integrating IdentityServer4 or ASP.NET Core Identity.

Example API Endpoint (Conceptual - based on project structure)

  • Endpoint: GET /api/LeaveType
  • Description: Retrieves a list of all leave types.
  • Response Codes:
    • 200 OK β€” Success βœ…
    • 500 Internal Server Error β€” Server error πŸ”₯

πŸ“Š Performance Optimization

  • Asynchronous Processing β€” Utilizes async/await for non-blocking I/O operations, improving responsiveness.
  • Caching β€” While not explicitly implemented in the provided code, a caching mechanism (e.g., Redis, in-memory cache) can be integrated into the Infrastructure layer to reduce database load.
  • Connection Pooling β€” Managed by Entity Framework Core for efficient database connection reuse.
  • Minimal API Surface β€” The API is designed to expose only necessary endpoints, reducing overhead.

πŸ” Observability

  • Centralized Exception Handling β€” Custom middleware (ExceptionMiddleware) in the API layer captures and handles exceptions consistently.
  • Logging β€” Can be integrated using popular logging frameworks like Serilog or NLog for structured logging across different environments.
  • Health Checks β€” ASP.NET Core Health Checks can be added to monitor the health of various components (database, external services).

πŸ“¦ Design Patterns

List of implemented patterns with brief descriptions:

  • Clean Architecture β€” Separates concerns into distinct layers (Domain, Application, Infrastructure, Presentation) to improve maintainability, testability, and scalability.
  • Mediator Pattern (MediatR) β€” Decouples senders from receivers, allowing for a more flexible and testable command/query/event handling system.
  • Repository Pattern β€” Abstracts the data access layer, providing a clean API for interacting with data sources.
  • Unit of Work Pattern β€” Ensures atomicity of transactions by coordinating multiple repository operations within a single transaction.
  • Dependency Injection β€” Manages dependencies between components, promoting loose coupling and testability.
  • AutoMapper β€” Simplifies object-to-object mapping, reducing manual mapping code.

πŸ› οΈ Contributing

  1. Fork the repository 🍴
  2. Create your feature branch: git checkout -b feature/my-feature
  3. Commit changes: git commit -m 'Add my feature'
  4. Push to branch: git push origin feature/my-feature
  5. Open a Pull Request

Please adhere to the existing coding style and run tests before submitting.

πŸ“œ License

License: MIT

This project is licensed under the MIT License. See the LICENSE file for details.

πŸ”— Additional Resources

Made with ❀️ by @Ahmad Abdelbary

About

a Clean Architecture-based Human Resources Leave Management system built with .NET 8, MediatR, and AutoMapper, demonstrating best practices in API development and domain-driven design.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors