How 200215-moynul-islam/employee-leave-tracker works
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 Dockerfiles 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: Program.cs Program · docker-compose.yml Compose · App.jsx App Shell · UserRepository.cs User Repo
Components 25
Backend API
ASP.NET service for auth, rules, and persistence
- Program · Bootstraps middleware, controllers, and DI
backend/Program.cs - Errors · Central exception handling and API response translation
backend/Middleware/ExceptionHandlingMiddleware.cs - Auth API · Login and authentication endpoints
backend/Controllers/AuthController.cs - User API · Employee profile, account, and password endpoints
backend/Controllers/UserController.cs - Leave API · Leave request lifecycle endpoints
backend/Controllers/LeaveController.cs - Auth Service · Validates credentials and issues JWTs
backend/Services/AuthService.cs - User Service · Admin employee management and password/profile rules
backend/Services/UserService.cs - Leave Service · Leave request creation, approval, rejection, and deletion rules
backend/Services/UserLeaveService.cs - User Repo · User persistence and queries
backend/Repositories/UserRepository.cs - Leave Repo · Leave persistence and queries
backend/Repositories/LeaveRepository.cs - DbContext · SQL Server persistence model and unit of work boundary
backend/Data/EmployeeLeaveTrackerDbContext.cs - Domain Models · User and Leave entities with shared base fields
backend/Models/User.cs - DTOs · API request and response payload shapes
backend/DTOs/ApiResponse.cs - Mapping · Entity-to-DTO translation profile
backend/Mappings/MappingProfile.cs - JWT Helper · Token creation and auth support
backend/Utilities/JwtHelper.cs
Frontend SPA
React/Vite client for role-based workflows
- App Shell · SPA bootstrap and routing surface
frontend/src/App.jsx - Login Page · Authentication entry screen
frontend/src/pages/Login/Login.jsx - Admin Page · Employee management and leave approval dashboard
frontend/src/pages/Admin/Admin.jsx - Employee Page · Leave submission and personal account view
frontend/src/pages/Employee/Employee.jsx - API Client · Shared HTTP wrapper and service modules
frontend/src/api/httpClient.js - UI Components · Reusable forms, tables, modals, and layout pieces
frontend/src/components/Header/Header.jsx - Client Config · Role constants, schemas, messages, and runtime config
frontend/src/config/env.js
Deployment
Containerized runtime and database wiring
- Compose · Container orchestration for frontend, backend, and database
docker-compose.yml - Backend Dockerfile · Builds the ASP.NET API image
backend/Dockerfile - Frontend Dockerfile · Builds the Vite SPA image
frontend/Dockerfile
Connections 34
- 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