This project implements a FastAPI-based image prediction service integrated with a PostgreSQL database, Dockerized microservices, and complete CI-level testing. It provides endpoints for user management, authentication, feedback storage, and image classification through a separate ML service.
✅ All unit and integration tests pass successfully (pytest)
✅ Docker & seed scripts verified
✅ Production-ready modular structure
assignment/
├── app/
│ ├── auth/
│ │ ├── jwt.py
│ │ ├── router.py
│ ├── db.py
│ ├── model/
│ │ ├── router.py
│ │ ├── schema.py
│ │ ├── services.py
│ ├── feedback/
│ │ ├── router.py
│ │ ├── models.py
│ ├── user/
│ │ ├── models.py
│ │ ├── schema.py
│ │ ├── services.py
│ │ ├── validator.py
│ │ ├── router.py
│ ├── utils.py
│ ├── seed.py
│ └── main.py
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
├── Makefile
└── tests/
| Service | Description | Container Name |
|---|---|---|
| FastAPI backend | Main API app | ml_api |
| ML service | Model prediction service | ml_service |
| PostgreSQL | Database | postgres_db |
| Redis | Task/message queue | assignment-redis-1 |
| UI | Optional dashboard | ml_ui |
make rebuild-api # rebuild API container
make up # start all servicesmake down # stop and remove containers
make clean # prune unused images/volumesmake seedCreates or updates an admin user:
email: admin@example.com
password: admin
make test-api-allmake test-api-model # model endpoint tests
make test-api # API layer tests
make test-model # ML service testsmake shot-allRuns full cycle: rebuild → up → seed → test-api → test-model
| Method | Endpoint | Description |
|---|---|---|
POST |
/login |
Obtain JWT token |
GET |
/me |
Get current user |
POST |
/model/predict |
Upload image and get prediction |
GET |
/user/ |
Get all users |
POST |
/user/ |
Create user registration |
GET |
/user/{id} |
Get user by ID |
DELETE |
/user/{id} |
Delete user |
GET |
/feedback/ |
Get all feedback entries |
POST |
/feedback/ |
Create new feedback |
-
OAuth2 Bearer Token (JWT)
-
Use
/loginto obtain token -
Add header to protected requests:
Authorization: Bearer <your_token>
The /model/predict endpoint interacts with a separate ML container.
It:
- Validates image type (PNG/JPG/JPEG/GIF)
- Computes SHA-256 hash for filename
- Stores it under
/tmp(or configuredUPLOAD_FOLDER) - Sends it to the ML service for classification
- Returns:
{
"success": true,
"prediction": "cat",
"score": 0.95,
"image_file_name": "fakehash123"
}- All async endpoints tested using
pytest-asyncio - Follows PEP8 and FastAPI best practices
- Uses SQLAlchemy ORM + Pydantic models
- Consistent hashing and validation logic in
utils.py - Full reproducibility via Docker
- All tests pass (
pytest) - Docker Compose builds without errors
- API routes reachable at
http://localhost:8000/docs - Admin seed created successfully
- Model predictions functional
- User CRUD + Feedback endpoints verified
© 2025 — Developed for the ANYONE AI – MLOps Assignment 3 Author: Jose Daniel Soto