Deep Guard Backend is a robust RESTful API built with Node.js and Express, serving as the core logic layer for the Deep Guard system. It handles authentication, deepfake analysis workflows, and integration with Supabase and external ML services.
For a detailed technical overview, please refer to the System Architecture.
- Runtime: Node.js
- Framework: Express.js
- Database: Supabase (PostgreSQL)
- Storage: Supabase Storage (
video_analyses,image_analyses,trial_analyses) - Authentication: Custom JWT (Access + Refresh Tokens) with Cookie Rotation & Google OAuth
- ML Integration: FastAPI (Python) for Deepfake Detection
- Utilities:
- Nodemailer: Email services (OTP, Bug Reports)
- Multer: File uploads (Memory Storage)
- AdmZip: ZIP handling for reports
-
Clone the repository:
git clone <repository-url> cd Deep-Guard-Backend
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.envfile in the root directory:PORT=5000 NODE_ENV=development FRONTEND_URL=http://localhost:3000 # Supabase SUPABASE_URL=your_supabase_url SUPABASE_KEY=your_supabase_anon_key SUPABASE_SERVICE_ROLE_KEY=your_service_role_key # Authentication JWT_SECRET=your_jwt_secret JWT_REFRESH_SECRET=your_refresh_secret GOOGLE_CLIENT_ID=your_google_client_id # Email Service EMAIL_USER=your_email@gmail.com EMAIL_PASSWORD=your_email_app_password # ML Service ML_API_URL=http://localhost:8000 ML_IMAGE_URL=http://localhost:8000
- Development:
npm run dev(usesnodemon) - Production:
npm start
If you prefer to run the backend in a container, use the included Dockerfile from the Deep-Guard-Backend directory.
-
Build the image:
docker build -t deep-guard-backend . -
Run the container with your environment file:
docker run --rm -p 5000:5000 --env-file .env deep-guard-backend
-
Make sure
ML_API_URLandML_IMAGE_URLpoint to a reachable ML service from inside the container.
This repository includes:
.github/workflows/keep-alive.ymlto periodically call the Supabase keep-alive endpoint..github/workflows/repository-heartbeat.ymlto create a monthly heartbeat commit on the default branch and help prevent GitHub from marking scheduled workflows as inactive.
If the repository is inactive for 60 days, GitHub automatically disables scheduled workflows in public repositories. The heartbeat workflow helps prevent that inactivity window, but it cannot repair the situation after GitHub has already disabled scheduled workflows, because the scheduler is no longer running.
If that happens, re-enable the workflow manually in GitHub or trigger it from an external scheduler or service.
- JWT-based Auth: Uses
httpOnlycookies foraccessToken(15m) andrefreshToken(30d). - Session Management: Sessions are tracked in Supabase (
sessionstable) with device fingerprinting. Includes token rotation and fraud detection (reuse detection).
- Video Analysis: Uploads video to Supabase -> Sends to ML Service -> Receives Confidence Report -> Stores Results.
- Image Analysis: Supports batch upload (max 10 files).
- Report Generation: Automatically handles ZIP generation containing annotated frames/images.
- Stateless Trial: Allows unauthenticated users to try the service.
- Limits: Restricted to 3 uploads per day per device (fingerprinted by IP + User Agent).
- Storage: Uses a dedicated
trial_analysesbucket with auto-cleanup logic.
- GitHub: Fetches repository stats (contributors, pulls) for the "About" page.
Deep-Guard-Backend/
├── .github/ # GitHub Actions workflows
├── config/ # Supabase client configuration
├── controllers/ # Business logic (Auth, Analysis, Trial, Github)
├── middleware/ # Auth checks, File upload limits, Error handling
├── routes/ # API Endpoints
│ ├── auth.js # Login, Signup, OTP, Refresh
│ ├── analysis.js # Video analysis & CRUD
│ ├── analysis-image-upload.js # Image analysis upload
│ ├── ml-service.js # Core ML integration (Video)
│ ├── ml-service-images.js # Core ML integration (Image)
│ ├── trial.js # Trial session management
│ └── ...
├── services/ # Helper services for storage/DB operations
├── supabase/ # Edge Functions & Setup
├── utils/ # Helpers (Logger, Encryption)
├── server.js # Entry point
└── package.json
POST /signup- Register with OTP verificationPOST /login- Sign inPOST /google- Google OAuth loginPOST /refresh- Refresh access tokenPOST /logout- Sign out
GET /- List user analysesPOST /upload- Upload video for analysisGET /:id- Get analysis resultGET /:id/download- Download report ZIP
POST /upload- Batch upload images
PUT /update-profile- Update name/avatarPUT /change-password- Change password
Contributions are welcome! Please follow the project's coding standards and submit a pull request.