Skip to content

SentinelAIbyCodeNewbies/Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

66 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Sentinel AI – Backend

Backend service for a Deepfake Detection Platform that allows users to analyze images/videos and determine whether they are AI-generated or real.


🧠 Features

  • πŸ” User Authentication (JWT + API Key)
  • πŸ”‘ Per-user API Key system
  • πŸ”„ API Key regeneration
  • πŸ“‘ Deepfake detection (URL & file upload)
  • πŸ“œ Scan history tracking
  • πŸ—„οΈ PostgreSQL (Supabase)
  • ⚑ High-performance APIs with FastAPI

πŸ—οΈ Tech Stack

  • Framework: FastAPI
  • Database: PostgreSQL (Supabase)
  • ORM: SQLAlchemy
  • Auth: JWT (python-jose)
  • Hashing: Passlib (bcrypt)
  • Containerization: Docker

πŸ“ Project Structure

.
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ __pycache__/
β”‚   β”‚
β”‚   β”œβ”€β”€ detectors/
β”‚   β”‚   β”œβ”€β”€ image_model.py
β”‚   β”‚   └── video_detector.py
β”‚   β”‚
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ image_detect/
β”‚   β”‚   β”‚   └── xception_deepfake_base.keras
β”‚   β”‚   └── video-detect/
β”‚   β”‚       β”œβ”€β”€ model.ipynb
β”‚   β”‚       └── video_model.keras
β”‚   β”‚
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ __pycache__/
β”‚   β”‚   β”œβ”€β”€ api.py
β”‚   β”‚   └── auth.py
β”‚   β”‚
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ __pycache__/
β”‚   β”‚   β”œβ”€β”€ image_scraper.py
β”‚   β”‚   └── ytdlp_service.py
β”‚   β”‚
β”‚   β”œβ”€β”€ auth.py
β”‚   β”œβ”€β”€ db.py
β”‚   β”œβ”€β”€ image_model.py
β”‚   β”œβ”€β”€ main.py
β”‚   β”œβ”€β”€ models.py
β”‚   β”œβ”€β”€ schemas.py
β”‚   └── utils.py
β”‚
β”œβ”€β”€ venv/
β”œβ”€β”€ .env
β”œβ”€β”€ .gitignore
β”œβ”€β”€ cookies.txt
β”œβ”€β”€ LICENSE
└── README.md

🐳 Docker Setup (Recommended)

Run the backend without installing Python or dependencies.


βœ… Prerequisites

  • Install Docker Desktop

πŸš€ Getting Started

1️⃣ Clone the repository

git clone <your-repo-url>
cd deepfake-backend

2️⃣ Create .env file

DATABASE_URL=postgresql://username:password@host:port/database
use ipv4 instead of ipv6 in case of supabase

⚠️ Use Supabase Session Pooler if required.


3️⃣ Run the backend

docker compose up --build

4️⃣ Access the API


πŸ›‘ Stop the server

docker compose down

πŸ”„ Rebuild after changes

docker compose up --build

⚠️ Notes

  • First build may take time (Docker image build)
  • Ensure port 8080 is free
  • .env file is required
  • No need to install Python locally

πŸ” Authentication

The API supports two authentication methods:

1️⃣ JWT Token (Recommended)

Use the token received after login:

Authorization: Bearer YOUR_JWT_TOKEN

2️⃣ API Key

Use the API key received during registration/login:

x-api-key: YOUR_API_KEY

βœ… You can use either JWT OR API Key to access protected endpoints.


πŸ”‘ Authentication Flow

Register

  • Creates a new user
  • Returns API key

Login

  • Returns:

    • JWT token
    • API key

Regenerate API Key

  • Generates a new API key
  • Invalidates the old one

πŸ“‘ API Endpoints

Auth

  • POST /auth/register β†’ Register user
  • POST /auth/login β†’ Login & get JWT + API key
  • POST /auth/regenerate-key β†’ Generate new API key

Core API

  • POST /analyse/url β†’ Analyze media from URL
  • POST /analyse/analyse_upload β†’ Analyze uploaded file
  • GET /history β†’ Get user scan history

πŸ§ͺ Example Requests

Using JWT

POST /analyse/url

Headers:
  Authorization: Bearer YOUR_JWT_TOKEN

Body:
{
  "url": "https://example.com/video.mp4"
}

Using API Key

POST /analyse/url

Headers:
  x-api-key: YOUR_API_KEY

Body:
{
  "url": "https://example.com/video.mp4"
}

⚑ Notes on Usage

  • Swagger UI supports authentication via the πŸ”’ button
  • JWT is recommended for frontend apps
  • API keys are useful for scripts and external integrations

🧠 Future Improvements

  • πŸ€– Model improvements
  • ⏱️ Rate limiting (Redis)
  • 🌐 Chrome extension
  • πŸ“Š Dashboard
  • πŸ” Multiple API keys

πŸ’€ Notes

  • bcrypt limit: 72 characters
  • Use URL-safe DB credentials
  • Prefer Supabase Session Pooler for production

πŸ‘¨β€πŸ’» Author

Built as part of a hackathon project β€” Sentinel AI


⭐ Contribute

Pull requests are welcome. Open an issue for major changes.


If you want next-level polish, I can:

  • add badges (Docker, FastAPI, stars, etc.)
  • or make it look like a top-tier GitHub repo (with screenshots + demo GIF)

About

FastAPI/Python-based backend for Sentinel AI. Features automated web scraping, ML-driven video analysis, and containerized deployment with Docker.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors