# 200215-moynul-islam/employee-leave-tracker architecture

> Architecture diagram of the GitHub repository 200215-moynul-islam/employee-leave-tracker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/200215-moynul-islam/employee-leave-tracker
- Repository: https://github.com/200215-moynul-islam/employee-leave-tracker

## Overview

1. **Top-level architecture**
   - This repository is a full-stack employee leave management system split into two deployable applications: a **backend ASP.NET API** and a **frontend React/Vite SPA**.
   - The backend owns authentication, authorization, business rules, and database access; the frontend handles role-based user interaction and calls the API over HTTP.

2. **Backend request pipeline**
   - The API entry point is `backend/Program.cs`, with an `ExceptionHandlingMiddleware` in the request pipeline.
   - Incoming requests are handled by thin controllers in `backend/Controllers`:
     - `AuthController` for login
     - `UserController` for employee management and password/profile operations
     - `LeaveController` for leave request lifecycle
   - Controllers primarily map HTTP requests to service calls and return standardized API responses.

3. **Backend layered design**
   - The backend follows a classic layered structure:
     - **Controllers** for transport/API concerns
     - **Services** for business logic
     - **Repositories** for data access
     - **Entity Framework Core DbContext** for persistence
   - This boundary separation is important: business rules such as role restrictions, leave status rules, and password changes live in services rather than in controllers.

4. **Domain model and persistence**
   - The core entities are `User` and `Leave`, both derived from `EntityBase`.
   - `EmployeeLeaveTrackerDbContext` is the EF Core context, backed by SQL Server.
   - The `Migrations` folder shows the schema is managed through EF migrations, including an initial migration that seeds an admin account and a later password-related schema change.

5. **Data contracts and mapping**
   - The API does not expose entities directly; it uses DTOs in `backend/DTOs` for create/read/update requests and responses.
   - `Mappings/MappingProfile.cs` indicates AutoMapper-style transformation between entities and DTOs.
   - This is the main boundary between internal persistence models and externally visible API payloads.

6. **Authentication and authorization**
   - Authentication is JWT-based, with helper code in `Utilities/JwtHelper.cs` and abstractions in `IJwtHelper`.
   - Role constants live in `Constants/Roles.cs`, and the system is explicitly split into **Admin** and **Employee** access paths.
   - The repo’s policy is enforced in the backend: only admins can create employee accounts, and employees authenticate with admin-provisioned credentials.

7. **Business rules and leave workflow**
   - `UserService`, `AuthService`, and `UserLeaveService` encapsulate the main rules:
     - admin creates/edits/removes employees
     - employees change only their own password
     - employees create leave requests
     - employees can delete only **Pending** leaves
     - admins can approve/reject pending leaves and view all leave history
   - Leave status constants and business error messages are centralized under `Constants`, which suggests consistent rule enforcement and error reporting.

8. **Repository boundary**
   - Data access is abstracted through `IRepositoryBase`, `IUserRepository`, and `ILeaveRepository`, with concrete implementations in `Repositories`.
   - This keeps EF-specific querying isolated from service logic and makes the backend easier to reason about as a clean service/repository architecture.

9. **Error handling and API response shape**
   - Custom exception types (`BusinessException`, `ConflictException`, `NotFoundException`, `InvalidCredentialsException`) are used to represent expected failure modes.
   - `Middleware/ExceptionHandlingMiddleware.cs` and `DTOs/ApiResponse.cs` indicate a centralized error-to-response translation layer, so the frontend receives consistent success/error envelopes.

10. **Frontend structure**
    - The frontend is a React SPA built with Vite.
    - `src/pages` contains the page-level views for `Login`, `Admin`, and `Employee`; `src/components` contains reusable UI blocks such as tables, modals, headers, and forms.
    - `src/api` contains service wrappers (`auth.service.js`, `user.service.js`, `leave.service.js`) plus a shared `httpClient.js`, which is the frontend’s boundary to the backend API.

11. **Frontend role-based user experience**
    - The UI is split by role after authentication:
      - **Admin pages** focus on employee management, pending approvals, and full leave history.
      - **Employee pages** focus on submitting leaves, viewing personal history, and updating password.
    - Constants and schemas in `src/Constants`, `src/messages`, and `src/schemas` suggest client-side validation and shared role/status handling aligned with backend rules.

12. **Runtime, deployment, and external dependencies**
    - The backend targets **ASP.NET 9** and uses **SQL Server** as the persistent store.
    - The frontend runs as a separate Node/Vite app.
    - `docker-compose.yml` and both `Dockerfile`s show the system is designed for containerized deployment, with the frontend and backend running as separate services and the backend connecting to the database via configuration.

Main entry points: [`backend/Program.cs`](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Program.cs) (Program), [`docker-compose.yml`](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/docker-compose.yml) (Compose), [`frontend/src/App.jsx`](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/App.jsx) (App Shell), [`backend/Repositories/UserRepository.cs`](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Repositories/UserRepository.cs) (User Repo)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend API"]
  node_program["Program<br/>api host<br/>[Program.cs]"]
  node_middleware["Errors<br/>middleware"]
  node_auth_controller["Auth API<br/>controller<br/>[AuthController.cs]"]
  node_user_controller["User API<br/>controller<br/>[UserController.cs]"]
  node_leave_controller["Leave API<br/>controller<br/>[LeaveController.cs]"]
  node_auth_service["Auth Service<br/>business service<br/>[AuthService.cs]"]
  node_user_service["User Service<br/>business service<br/>[UserService.cs]"]
  node_leave_service["Leave Service<br/>business service"]
  node_user_repo["User Repo<br/>[UserRepository.cs]"]
  node_leave_repo["Leave Repo<br/>[LeaveRepository.cs]"]
  node_dbcontext[("DbContext<br/>ef core context")]
  node_models["Domain Models<br/>entities<br/>[User.cs]"]
  node_dtos["DTOs<br/>contracts<br/>[ApiResponse.cs]"]
  node_mapping["Mapping<br/>transform<br/>[MappingProfile.cs]"]
  node_jwt["JWT Helper<br/>auth utility<br/>[JwtHelper.cs]"]
end

subgraph group_frontend["Frontend SPA"]
  node_frontend_app["App Shell<br/>react app<br/>[App.jsx]"]
  node_login_page["Login Page<br/>[Login.jsx]"]
  node_admin_page["Admin Page<br/>[Admin.jsx]"]
  node_employee_page["Employee Page<br/>[Employee.jsx]"]
  node_api_client["API Client<br/>http layer<br/>[httpClient.js]"]
  node_ui_components["UI Components<br/>react components<br/>[Header.jsx]"]
  node_config["Client Config<br/>validation/config<br/>[env.js]"]
end

subgraph group_deployment["Deployment"]
  node_compose["Compose<br/>deployment<br/>[docker-compose.yml]"]
  node_backend_docker["Backend Dockerfile<br/>container build"]
  node_frontend_docker["Frontend Dockerfile<br/>container build"]
end

node_program -->|"uses"| node_middleware
node_program -->|"maps"| node_auth_controller
node_program -->|"maps"| node_user_controller
node_program -->|"maps"| node_leave_controller
node_auth_controller -->|"calls"| node_auth_service
node_user_controller -->|"calls"| node_user_service
node_leave_controller -->|"calls"| node_leave_service
node_auth_service -->|"queries"| node_user_repo
node_auth_service -->|"issues"| node_jwt
node_user_service -->|"persists"| node_user_repo
node_user_service -->|"uses"| node_dbcontext
node_leave_service -->|"persists"| node_leave_repo
node_leave_service -->|"loads"| node_user_repo
node_leave_repo -->|"uses"| node_dbcontext
node_user_repo -->|"uses"| node_dbcontext
node_dbcontext -->|"maps"| node_models
node_mapping -->|"projects"| node_dtos
node_mapping -->|"projects"| node_models
node_auth_controller -->|"accepts/returns"| node_dtos
node_user_controller -->|"accepts/returns"| node_dtos
node_leave_controller -->|"accepts/returns"| node_dtos
node_frontend_app -->|"shows"| node_login_page
node_frontend_app -->|"shows"| node_admin_page
node_frontend_app -->|"shows"| node_employee_page
node_login_page -->|"authenticates via"| node_api_client
node_admin_page -->|"fetches via"| node_api_client
node_employee_page -->|"fetches via"| node_api_client
node_api_client -->|"uses"| node_config
node_ui_components -->|"supports"| node_admin_page
node_ui_components -->|"supports"| node_employee_page
node_compose -->|"builds"| node_backend_docker
node_compose -->|"builds"| node_frontend_docker
node_compose -->|"runs"| node_program
node_compose -->|"runs"| node_frontend_app

click node_program "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Program.cs"
click node_middleware "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Middleware/ExceptionHandlingMiddleware.cs"
click node_auth_controller "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Controllers/AuthController.cs"
click node_user_controller "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Controllers/UserController.cs"
click node_leave_controller "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Controllers/LeaveController.cs"
click node_auth_service "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Services/AuthService.cs"
click node_user_service "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Services/UserService.cs"
click node_leave_service "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Services/UserLeaveService.cs"
click node_user_repo "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Repositories/UserRepository.cs"
click node_leave_repo "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Repositories/LeaveRepository.cs"
click node_dbcontext "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Data/EmployeeLeaveTrackerDbContext.cs"
click node_models "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Models/User.cs"
click node_dtos "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/DTOs/ApiResponse.cs"
click node_mapping "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Mappings/MappingProfile.cs"
click node_jwt "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Utilities/JwtHelper.cs"
click node_frontend_app "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/App.jsx"
click node_login_page "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/pages/Login/Login.jsx"
click node_admin_page "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/pages/Admin/Admin.jsx"
click node_employee_page "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/pages/Employee/Employee.jsx"
click node_api_client "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/api/httpClient.js"
click node_ui_components "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/components/Header/Header.jsx"
click node_config "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/config/env.js"
click node_compose "https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/docker-compose.yml"
click node_backend_docker "https://github.com/200215-moynul-islam/employee-leave-tracker/tree/main/backend/Dockerfile"
click node_frontend_docker "https://github.com/200215-moynul-islam/employee-leave-tracker/tree/main/frontend/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_program,node_middleware,node_auth_controller,node_user_controller,node_leave_controller,node_auth_service,node_user_service,node_leave_service,node_user_repo,node_leave_repo,node_dbcontext,node_models,node_dtos,node_mapping,node_jwt toneBlue
class node_frontend_app,node_login_page,node_admin_page,node_employee_page,node_api_client,node_ui_components,node_config toneAmber
class node_compose,node_backend_docker,node_frontend_docker toneMint
```

## Components

### Backend API

ASP.NET service for auth, rules, and persistence

- [Program](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Program.cs): api host · Bootstraps middleware, controllers, and DI · `backend/Program.cs`
- [Errors](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Middleware/ExceptionHandlingMiddleware.cs): middleware · Central exception handling and API response translation · `backend/Middleware/ExceptionHandlingMiddleware.cs`
- [Auth API](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Controllers/AuthController.cs): controller · Login and authentication endpoints · `backend/Controllers/AuthController.cs`
- [User API](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Controllers/UserController.cs): controller · Employee profile, account, and password endpoints · `backend/Controllers/UserController.cs`
- [Leave API](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Controllers/LeaveController.cs): controller · Leave request lifecycle endpoints · `backend/Controllers/LeaveController.cs`
- [Auth Service](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Services/AuthService.cs): business service · Validates credentials and issues JWTs · `backend/Services/AuthService.cs`
- [User Service](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Services/UserService.cs): business service · Admin employee management and password/profile rules · `backend/Services/UserService.cs`
- [Leave Service](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Services/UserLeaveService.cs): business service · Leave request creation, approval, rejection, and deletion rules · `backend/Services/UserLeaveService.cs`
- [User Repo](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Repositories/UserRepository.cs): repository · User persistence and queries · `backend/Repositories/UserRepository.cs`
- [Leave Repo](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Repositories/LeaveRepository.cs): repository · Leave persistence and queries · `backend/Repositories/LeaveRepository.cs`
- [DbContext](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Data/EmployeeLeaveTrackerDbContext.cs): ef core context · SQL Server persistence model and unit of work boundary · `backend/Data/EmployeeLeaveTrackerDbContext.cs`
- [Domain Models](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Models/User.cs): entities · User and Leave entities with shared base fields · `backend/Models/User.cs`
- [DTOs](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/DTOs/ApiResponse.cs): contracts · API request and response payload shapes · `backend/DTOs/ApiResponse.cs`
- [Mapping](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Mappings/MappingProfile.cs): transform · Entity-to-DTO translation profile · `backend/Mappings/MappingProfile.cs`
- [JWT Helper](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/backend/Utilities/JwtHelper.cs): auth utility · Token creation and auth support · `backend/Utilities/JwtHelper.cs`

### Frontend SPA

React/Vite client for role-based workflows

- [App Shell](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/App.jsx): react app · SPA bootstrap and routing surface · `frontend/src/App.jsx`
- [Login Page](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/pages/Login/Login.jsx): page · Authentication entry screen · `frontend/src/pages/Login/Login.jsx`
- [Admin Page](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/pages/Admin/Admin.jsx): page · Employee management and leave approval dashboard · `frontend/src/pages/Admin/Admin.jsx`
- [Employee Page](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/pages/Employee/Employee.jsx): page · Leave submission and personal account view · `frontend/src/pages/Employee/Employee.jsx`
- [API Client](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/api/httpClient.js): http layer · Shared HTTP wrapper and service modules · `frontend/src/api/httpClient.js`
- [UI Components](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/components/Header/Header.jsx): react components · Reusable forms, tables, modals, and layout pieces · `frontend/src/components/Header/Header.jsx`
- [Client Config](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/frontend/src/config/env.js): validation/config · Role constants, schemas, messages, and runtime config · `frontend/src/config/env.js`

### Deployment

Containerized runtime and database wiring

- [Compose](https://github.com/200215-moynul-islam/employee-leave-tracker/blob/main/docker-compose.yml): deployment · Container orchestration for frontend, backend, and database · `docker-compose.yml`
- [Backend Dockerfile](https://github.com/200215-moynul-islam/employee-leave-tracker/tree/main/backend/Dockerfile): container build · Builds the ASP.NET API image · `backend/Dockerfile`
- [Frontend Dockerfile](https://github.com/200215-moynul-islam/employee-leave-tracker/tree/main/frontend/Dockerfile): container build · Builds the Vite SPA image · `frontend/Dockerfile`

## Connections

- Program → Errors: uses · Registers exception handling in the request pipeline
- Program → Auth API: maps · Exposes authentication endpoints
- Program → User API: maps · Exposes employee endpoints
- Program → Leave API: maps · Exposes leave endpoints
- Auth API → Auth Service: calls · Delegates login logic
- User API → User Service: calls · Delegates user/account operations
- Leave API → Leave Service: calls · Delegates leave workflow operations
- Auth Service → User Repo: queries · Looks up users for credential validation
- Auth Service → JWT Helper: issues · Creates access tokens
- User Service → User Repo: persists · Creates and updates employee records
- User Service → DbContext: uses · Executes database operations through repository boundary
- Leave Service → Leave Repo: persists · Stores and updates leave requests
- Leave Service → User Repo: loads · Resolves user context and ownership checks
- Leave Repo → DbContext: uses · Runs EF Core queries and saves
- User Repo → DbContext: uses · Runs EF Core queries and saves
- DbContext → Domain Models: maps · Persists entity types to SQL Server tables
- Mapping → DTOs: projects · Transforms entities to API payloads
- Mapping → Domain Models: projects · Transforms domain entities
- Auth API → DTOs: accepts/returns · Uses login and response contracts
- User API → DTOs: accepts/returns · Uses user and password contracts
- Leave API → DTOs: accepts/returns · Uses leave request contracts
- App Shell → Login Page: shows · Initial unauthenticated experience
- App Shell → Admin Page: shows · Admin post-login experience
- App Shell → Employee Page: shows · Employee post-login experience
- Login Page → API Client: authenticates via · Submits login requests to the API
- Admin Page → API Client: fetches via · Loads employees and leave queues
- Employee Page → API Client: fetches via · Manages personal leave and profile actions
- API Client → Client Config: uses · Shares environment, role, and validation settings
- UI Components → Admin Page: supports · Reusable admin workflow UI
- UI Components → Employee Page: supports · Reusable employee workflow UI
- Compose → Backend Dockerfile: builds · Builds backend container image
- Compose → Frontend Dockerfile: builds · Builds frontend container image
- Compose → Program: runs · Starts backend service
- Compose → App Shell: runs · Starts frontend service
