Skip to content

josedaniel-dev/anyone_ai_sprint3_ml_api

Repository files navigation

🧠 Image Prediction API — Technical Documentation

📋 Overview

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 verifiedProduction-ready modular structure


🏗️ Architecture Overview

📂 Directory 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/

🐳 Dockerized Stack

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

⚙️ Setup & Execution

🧩 Build and Run

make rebuild-api   # rebuild API container
make up            # start all services

🧹 Clean up

make down          # stop and remove containers
make clean         # prune unused images/volumes

🌱 Seed Database

make seed

Creates or updates an admin user:

email: admin@example.com
password: admin

🧪 Testing

Run all tests

make test-api-all

Individual tests

make test-api-model     # model endpoint tests
make test-api           # API layer tests
make test-model         # ML service tests

One-shot full verification

make shot-all

Runs full cycle: rebuild → up → seed → test-api → test-model


🧰 Key Endpoints

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

🔑 Authentication

  • OAuth2 Bearer Token (JWT)

  • Use /login to obtain token

  • Add header to protected requests:

    Authorization: Bearer <your_token>
    

🧬 Model Service

The /model/predict endpoint interacts with a separate ML container. It:

  1. Validates image type (PNG/JPG/JPEG/GIF)
  2. Computes SHA-256 hash for filename
  3. Stores it under /tmp (or configured UPLOAD_FOLDER)
  4. Sends it to the ML service for classification
  5. Returns:
{
  "success": true,
  "prediction": "cat",
  "score": 0.95,
  "image_file_name": "fakehash123"
}

🧑‍💻 Development Notes

  • 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

✅ Definition of Done

  • 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

📜 License

© 2025 — Developed for the ANYONE AI – MLOps Assignment 3 Author: Jose Daniel Soto

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published