# sagnikbasak04/neuraldetect architecture

> Architecture diagram of the GitHub repository sagnikbasak04/neuraldetect, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sagnikbasak04/neuraldetect
- Repository: https://github.com/sagnikbasak04/neuraldetect

## Overview

##### Project type and purpose
- Project name: NeuralDetect – a DeepFake Detection System
- Purpose: A full-stack web application that allows users to upload videos, runs them through an AI model to detect deep fakes, and presents results.

##### File structure
– Top-level directories:
· client/       → Production React + TypeScript front end (Vite, Tailwind)
· frontend-test/→ A standalone demo or integration test React app
· server/       → Node.js/Express API server, MongoDB integration, authentication, upload endpoints
· server_ai/    → Python AI microservice for deep-fake detection (Flask or similar), trained Keras models (.h5)
– Key patterns and files:
· client/src         → Components (Feed, Login, VideoInput/Modal), Context (AuthContext), Hooks, Routes
· server/src         → Controllers (auth, admin, upload), Routes, Models (User, Upload), Middlewares, DB connector
· server_ai/         → app.py entrypoint, model artifacts (final_model.h5), Jupyter notebooks
· Config & build     → Vite configs, tsconfig.json, package.json in each module, requirements.txt in server_ai
· External integrations: Cloudinary (uploadToCloudinary util), MongoDB

##### README
– Very brief (“DeepFake Detection System”)

a. Main components:
1. Frontend (client) – React app served via static hosting or CDN
2. API Gateway / Backend (server) – Express endpoints for auth, upload, admin
3. AI Service (server_ai) – Python service exposing a predict endpoint
4. Database – MongoDB cluster for users & upload metadata
5. Cloud Storage – Cloudinary for video storage
6. (Optional) Frontend-test – Separate demo app or staging environment

b. Relationships & data-flow:
- User → Frontend → (via HTTPS REST) → API Server
- API Server:
– Auth endpoints ↔ MongoDB
– Upload endpoint: receives file or file URL, delegates to Cloudinary, stores metadata in MongoDB
– Detection endpoint: forwards video or URL to AI Service, receives prediction
- AI Service ↔ Model artifacts (.h5), returns DeepFake probability
- Cloudinary ↔ Stores raw videos, serves URLs
- Frontend polls or receives callback of detection result

c. Architectural patterns & principles:
– Separation of concerns: UI, API logic, AI logic, data storage are distinct services
– Microservice for AI detection (server_ai) – decoupled from main API
– RESTful API design, token-based auth (JWT via generateTokenAndSetCookie)
– MVC-like structure in server: Controllers → Routes → Models
– Context API + Hooks in client for state management (AuthContext, useLogin)

d. Key technologies/frameworks:
– Frontend: React, Vite, TypeScript, TailwindCSS, Context API
– Backend: Node.js, Express, TypeScript, Mongoose/MongoDB
– AI Service: Python (Flask/FastAPI), TensorFlow/Keras (.h5 models)
– External: Cloudinary for video uploads
– DevOps/build: Vite config, ESLint, tsconfig, requirements.txt

## Diagram (Mermaid)

```mermaid
flowchart TD
  direction TB

  subgraph "Client (React App)"
    direction TB
    ClientApp["React App"]:::frontend
    Feed["Feed Component"]:::frontend
    Login["Login Component"]:::frontend
    VideoInput["VideoInput"]:::frontend
    VideoModal["VideoModal"]:::frontend
    AuthContext["AuthContext"]:::frontend
    useLogin["useLogin Hook"]:::frontend
    AppRoutes["AppRoutes"]:::frontend
    uploadUtil["uploadToCloudinary"]:::frontend
  end

  subgraph "API Server (Express)"
    direction TB
    Server["server.ts"]:::backend
    AuthCtrl["AuthController"]:::backend
    UploadCtrl["UploadController"]:::backend
    AdminCtrl["AdminController"]:::backend
    AuthRoutes["AuthRoutes"]:::backend
    UploadRoutes["UploadRoutes"]:::backend
    AdminRoutes["AdminRoutes"]:::backend
    UserModel["UserModel"]:::backend
    UploadModel["UploadModel"]:::backend
    AdminMiddleware["AdminMiddleware"]:::backend
    DBConnector["connectToMongoDB"]:::backend
    JWTUtil["generateTokenAndSetCookie"]:::backend
  end

  subgraph "AI Service (Python)"
    direction TB
    AIApp["app.py"]:::ai
    FinalNotebook["deep-fake-detection.ipynb"]:::ai
    FinalModel["final_model.h5"]:::ai
    ReqTxt["requirements.txt"]:::ai
    InitialNotebook["Initial Notebook"]:::ai
    InitialModel["Initial Model"]:::ai
  end

  DB["MongoDB"]:::database
  Cloud["Cloudinary"]:::external
  Staging["Demo Client"]:::frontend

  User(("User"))
  User -->|"interacts with"| ClientApp
  Staging -->|"interacts with"| Server

  ClientApp -->|"HTTPS REST"| Server
  ClientApp --> Feed
  ClientApp --> Login
  ClientApp --> VideoInput
  ClientApp --> VideoModal
  ClientApp --> AuthContext
  ClientApp --> useLogin
  ClientApp --> AppRoutes
  ClientApp --> uploadUtil

  Server --> AuthRoutes
  Server --> UploadRoutes
  Server --> AdminRoutes
  AuthRoutes --> AuthCtrl
  UploadRoutes --> UploadCtrl
  AdminRoutes --> AdminCtrl

  AuthCtrl --> UserModel
  UploadCtrl --> UploadModel
  AdminCtrl --> UserModel

  DBConnector --> DB
  AuthCtrl --> DB
  UploadCtrl --> DB
  AdminCtrl --> DB

  UploadCtrl --> Cloud
  Cloud -->|"serves video URLs"| ClientApp

  JWTUtil --> AuthCtrl

  Server -->|"POST /predict"| AIApp
  AIApp --> FinalModel
  AIApp --> FinalNotebook
  AIApp --> ReqTxt
  InitialNotebook --> InitialModel

  classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
  classDef backend fill:#E6FFDF,stroke:#28a745,color:#28a745;
  classDef ai fill:#FFF5CC,stroke:#FFAA00,color:#FFAA00;
  classDef database fill:#F0F0F0,stroke:#999999,color:#333333,stroke-dasharray: 5 5;
  classDef external fill:#F0F0F0,stroke:#999999,color:#333333;

  click ClientApp "https://github.com/sagnikbasak04/neuraldetect/tree/main/client/"
  click Feed "https://github.com/sagnikbasak04/neuraldetect/blob/main/client/src/components/Feed.tsx"
  click Login "https://github.com/sagnikbasak04/neuraldetect/blob/main/client/src/components/Login.tsx"
  click VideoInput "https://github.com/sagnikbasak04/neuraldetect/blob/main/client/src/components/VideoInput.tsx"
  click VideoModal "https://github.com/sagnikbasak04/neuraldetect/blob/main/client/src/components/VideoModal.tsx"
  click AuthContext "https://github.com/sagnikbasak04/neuraldetect/blob/main/client/src/context/AuthContext.tsx"
  click useLogin "https://github.com/sagnikbasak04/neuraldetect/blob/main/client/src/hooks/useLogin.ts"
  click AppRoutes "https://github.com/sagnikbasak04/neuraldetect/blob/main/client/src/routes/AppRoutes.tsx"
  click uploadUtil "https://github.com/sagnikbasak04/neuraldetect/blob/main/client/src/utils/uploadToCloudinary.ts"
  click Staging "https://github.com/sagnikbasak04/neuraldetect/tree/main/frontend-test/"
  click Server "https://github.com/sagnikbasak04/neuraldetect/blob/main/server/src/server.ts"
  click AuthCtrl "https://github.com/sagnikbasak04/neuraldetect/blob/main/server/src/controllers/auth.controller.ts"
  click UploadCtrl "https://github.com/sagnikbasak04/neuraldetect/blob/main/server/src/controllers/upload.controller.ts"
  click AdminCtrl "https://github.com/sagnikbasak04/neuraldetect/blob/main/server/src/controllers/admin.controller.ts"
  click AuthRoutes "https://github.com/sagnikbasak04/neuraldetect/blob/main/server/src/routes/auth.routes.ts"
  click UploadRoutes "https://github.com/sagnikbasak04/neuraldetect/blob/main/server/src/routes/upload.routes.ts"
  click AdminRoutes "https://github.com/sagnikbasak04/neuraldetect/blob/main/server/src/routes/admin.routes.ts"
  click UserModel "https://github.com/sagnikbasak04/neuraldetect/blob/main/server/src/models/user.model.ts"
  click UploadModel "https://github.com/sagnikbasak04/neuraldetect/blob/main/server/src/models/uploads.model.ts"
  click AdminMiddleware "https://github.com/sagnikbasak04/neuraldetect/blob/main/server/src/middlewares/admin.middleware.ts"
  click DBConnector "https://github.com/sagnikbasak04/neuraldetect/blob/main/server/src/db/connectToMongoDB.ts"
  click JWTUtil "https://github.com/sagnikbasak04/neuraldetect/blob/main/server/src/utils/generateTokenAndSetCookie.ts"
  click AIApp "https://github.com/sagnikbasak04/neuraldetect/blob/main/server_ai/Final_Approach/app.py"
  click FinalModel "https://github.com/sagnikbasak04/neuraldetect/blob/main/server_ai/Final_Approach/final_model.h5"
  click FinalNotebook "https://github.com/sagnikbasak04/neuraldetect/blob/main/server_ai/Final_Approach/deep-fake-detection.ipynb"
  click ReqTxt "https://github.com/sagnikbasak04/neuraldetect/blob/main/server_ai/requirements.txt"
  click InitialNotebook "https://github.com/sagnikbasak04/neuraldetect/blob/main/server_ai/Initial_Approach/deepfake-detection.ipynb"
  click InitialModel "https://github.com/sagnikbasak04/neuraldetect/blob/main/server_ai/Initial_Approach/my_model.h5"
```
