This project is a backend API for tracking employees and their assigned project hours using FastAPI and PostgreSQL. It allows you to manage employees, projects, assignments, and quickly identify which employees are available for new projects. The API demonstrates practical CRUD operations, relational schema design, and can be expanded to support advanced features like authentication and reporting.
- Employee, Project, and Assignment CRUD endpoints
- Track total project hours per employee
- Query employees who are currently free (unassigned) for new projects
- Relational database design linking employees, projects, and assignments
- Automatic API documentation via Swagger UI (
/docs) - Pydantic validation for request/response schemas
- FastAPI
- SQLAlchemy ORM
- Pydantic
- PostgreSQL Database
- Uvicorn ASGI Server
git clone https://github.com/yourusername/employee-portfolio-api.git cd employee-portfolio-api
text
- Install PostgreSQL and start the service.
- Create the database and user: CREATE DATABASE employee_portfolio; CREATE USER your_user WITH PASSWORD 'your_password'; GRANT ALL PRIVILEGES ON DATABASE employee_portfolio TO your_user;
text
- Edit
db.py: DATABASE_URL = "postgresql://your_user:your_password@localhost:5432/employee_portfolio"
text
pip install fastapi sqlalchemy psycopg2 pydantic uvicorn
text
uvicorn main:app --reload
text
- After starting the server, go to http://127.0.0.1:8000/docs in your browser to view and test endpoints.
project_dir/ ├─ db.py ├─ models.py ├─ schemas.py └─ main.py
text
POST /employees/— Create a new employeePOST /projects/— Create a new projectPOST /assignments/— Assign employee to a projectGET /employees/free/— List employees who are free for new projects
- Add OAuth2/JWT authentication for secure access
- Implement role-based admin endpoints
- Add reporting endpoints for total project hours
- Enable file/image upload support (e.g., for project documentation)
- Expand unit and integration testing