This is a FastAPI-based Leave Management System designed to help employees apply for leave, view leave balances, and enable managers to approve or reject leave requests.
- Clone the repository.
- Create a Python virtual environment:
python -m venv venv source venv/bin/activate # Linux/macOS venv\Scripts\activate # Windows 3. Install dependencies: pip install -r requirements.txt
-
Initialize the database (example with SQLite): alembic upgrade head # if using Alembic migrations, or python backend/database_setup.py # custom setup script if any
-
Run the FastAPI app: uvicorn backend.app:app --reload
-
Access the app at
http://localhost:8000
- Each employee is uniquely identified by employee ID.
- Leave requests must be non-overlapping (checks for pending or approved leaves).
- Employees have a fixed total leave balance starting at 20 days.
- Leave balance reduces only after managerial approval.
- Invalid employee IDs return 404 errors.
- Leaves cannot be applied before the employee's joining date.
- Leaves cannot have end dates before start dates.
- Leaves cannot be applied for past dates.
- Overlapping leaves (pending or approved) are disallowed.
- Rejecting leaves does not reduce leave balance.
- Leave balance queries filter by employee correctly.
- Implementing asynchronous endpoints for improved scalability.
- Adding Redis caching for frequently requested data such as leave balances.
- Adding user authentication and role-based access controls (employee, manager).
- Pagination on employees and leave request listings for large datasets.
- Containerize the application with Docker for easier deployment and scaling.
- Adding unit and integration tests.
| Endpoint | Method | Description | Sample Input | Sample Output |
|---|---|---|---|---|
| /apply-leave | POST | Apply for leave | { "employee_id": 1, "start_date": "2025-08-25", "end_date": "2025-08-27", "reason": "Vacation" } |
{ "id": 123, "status": "Pending" } |
| /approve-leave/{leave_id} | POST | Approve leave request | N/A | { "message": "Leave approved." } |
| /reject-leave/{leave_id} | POST | Reject leave request | N/A | { "message": "Leave rejected." } |
| /leave-balance | GET | Get leave balance by employee query param | /leave-balance?employee_id=1 |
{ "employee_id": 1, "leave_balance": 17 } |
The system consists of a browser-based frontend rendering Jinja2 templates served by the FastAPI backend, which manages business logic and communicates with a SQL database via SQLAlchemy ORM. The application supports scalability through load balancing, connection pooling, and caching.)*
For questions or contributions, contact: your.email@example.com

