# inglepriyanshu/neobrain architecture

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

- Interactive diagram: https://gitdiagram.com/inglepriyanshu/neobrain
- Repository: https://github.com/inglepriyanshu/neobrain

## Overview

##### Project type and purpose
- This is a full-stack web application called “NeoBrain” that lets authenticated users upload documents (PDF/DOCX/TXT), process YouTube videos, chat with an AI (Google Gemini 2.5 Flash), store and search citations (RAG/vector search), and manage notebooks.
- Key features: user auth, file upload, video processing, AI chat, citation system, vector search.

##### File structure
- Top-level directories:
- client/ – React frontend
- server/ – Node.js/Express backend
- client/src/components/Auth & Dashboard – MVC‐style React component grouping
- client/src/contexts/AuthContext.js – global auth state via React Context
- server/routes/*.js – Express route handlers (auth, chat, notebooks, sources)
- server/middleware/auth.js – JWT/session authentication guard
- server/models/*.js – Mongoose schemas: User, Chat, Notebook, Source
- server/services/*.js – business logic modules: documentProcessor, geminiService, youtubeService
- server/uploads/ – local storage for uploaded files

##### README for additional insights
- Tech stack: React + Tailwind CSS + Framer Motion on the front end; Node.js/Express and MongoDB Atlas on the back end; Google Gemini AI API for chat.
- Local dev: front end on 3000, back end on 5000.
- Features call out vector search (implying an embedding store or MongoDB Atlas vector index).

a. Main components
- Frontend (React/Tailwind/Framer Motion)
- Backend API (Express)
- Authentication middleware
- Service modules: Document Processor, YouTube Service, Gemini AI Service
- Database: MongoDB Atlas (collections: users, chats, notebooks, sources)
- File storage (server/uploads or cloud bucket)
- External APIs: Google Gemini AI, YouTube Data API

b. Relationships & data flow
1. User → Frontend UI (HTTP/HTTPS)
2. Frontend → Backend (REST API calls)
3. Backend auth middleware verifies token/session
4. Routes delegate to controllers → services:
– documentProcessor reads uploaded files → extracts text/embeddings → persists to DB
– youtubeService fetches video data → transcripts → embeddings → DB
– geminiService calls Google Gemini for chat queries
5. Backend interacts with MongoDB (CRUD for users, chats, notebooks, sources)
6. Backend stores files locally (server/uploads) or could be extended to S3

c. Architectural patterns & principles
- Separation of concerns: UI vs API vs services vs persistence
- MVC‐inspired: routes/controllers vs services vs models
- Token‐based auth middleware
- Service‐oriented modules for each external integration
- Vector search/RAG pattern for AI retrieval

d. Key technologies & frameworks
- Frontend: React, Tailwind CSS, Framer Motion, React Context
- Backend: Node.js, Express, JWT or session middleware
- DB: MongoDB Atlas via mongoose
- AI: Google Gemini 2.5 Flash API
- File parsing: documentProcessor (pdf/text/docx libraries)
- External APIs: YouTube Data API

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (React)" 
        direction TB
        FE_Index["src/index.js"]:::frontend
        FE_App["src/App.js"]:::frontend
        FE_Login["Login.js"]:::frontend
        FE_Register["Register.js"]:::frontend
        FE_Dashboard["Dashboard.js"]:::frontend
        FE_AuthContext["AuthContext.js"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express)" 
        direction TB
        BE_Index["server/index.js"]:::backend
        BE_AuthMW["auth.js"]:::backend
        subgraph "Routes"
            direction TB
            BE_AuthRoutes["auth.js"]:::backend
            BE_ChatRoutes["chat.js"]:::backend
            BE_NotebookRoutes["notebooks.js"]:::backend
            BE_SourceRoutes["sources.js"]:::backend
        end
        subgraph "Services"
            direction TB
            S_DocProc["documentProcessor.js"]:::service
            S_YouTube["youtubeService.js"]:::service
            S_Gemini["geminiService.js"]:::service
        end
        subgraph "Models"
            direction TB
            M_User["User.js"]:::model
            M_Chat["Chat.js"]:::model
            M_Notebook["Notebook.js"]:::model
            M_Source["Source.js"]:::model
        end
        BE_Uploads["uploads/"]:::storage
    end

    %% Database and External
    DB["MongoDB Atlas"]:::db
    EX_Gemini["Google Gemini AI"]:::external
    EX_YouTube["YouTube Data API"]:::external

    %% User Interaction
    User["User"]:::user
    User -->|"uses UI"| FE_Index

    %% Frontend Flow
    FE_Index --> FE_App
    FE_App --> FE_Login
    FE_App --> FE_Register
    FE_App --> FE_Dashboard
    FE_App --> FE_AuthContext
    FE_App -->|"REST API"| BE_Index

    %% Backend Flow
    BE_Index --> BE_AuthMW
    BE_AuthMW --> BE_AuthRoutes
    BE_AuthMW --> BE_ChatRoutes
    BE_AuthMW --> BE_NotebookRoutes
    BE_AuthMW --> BE_SourceRoutes

    %% Routes to Services
    BE_AuthRoutes --> M_User
    BE_ChatRoutes --> S_Gemini
    BE_ChatRoutes --> M_Chat
    BE_NotebookRoutes --> M_Notebook
    BE_NotebookRoutes --> S_DocProc
    BE_SourceRoutes --> S_YouTube
    BE_SourceRoutes --> M_Source

    %% Services Interactions
    S_DocProc --> BE_Uploads
    S_DocProc --> DB
    S_YouTube --> DB
    S_YouTube --> EX_YouTube
    S_Gemini --> EX_Gemini

    %% Models to DB
    M_User --> DB
    M_Chat --> DB
    M_Notebook --> DB
    M_Source --> DB

    %% Click Events
    click FE_Index "https://github.com/inglepriyanshu/neobrain/blob/main/client/src/index.js"
    click FE_App "https://github.com/inglepriyanshu/neobrain/blob/main/client/src/App.js"
    click FE_Login "https://github.com/inglepriyanshu/neobrain/blob/main/client/src/components/Auth/Login.js"
    click FE_Register "https://github.com/inglepriyanshu/neobrain/blob/main/client/src/components/Auth/Register.js"
    click FE_Dashboard "https://github.com/inglepriyanshu/neobrain/blob/main/client/src/components/Dashboard/Dashboard.js"
    click FE_AuthContext "https://github.com/inglepriyanshu/neobrain/blob/main/client/src/contexts/AuthContext.js"
    click BE_Index "https://github.com/inglepriyanshu/neobrain/blob/main/server/index.js"
    click BE_AuthMW "https://github.com/inglepriyanshu/neobrain/blob/main/server/middleware/auth.js"
    click BE_AuthRoutes "https://github.com/inglepriyanshu/neobrain/blob/main/server/routes/auth.js"
    click BE_ChatRoutes "https://github.com/inglepriyanshu/neobrain/blob/main/server/routes/chat.js"
    click BE_NotebookRoutes "https://github.com/inglepriyanshu/neobrain/blob/main/server/routes/notebooks.js"
    click BE_SourceRoutes "https://github.com/inglepriyanshu/neobrain/blob/main/server/routes/sources.js"
    click M_User "https://github.com/inglepriyanshu/neobrain/blob/main/server/models/User.js"
    click M_Chat "https://github.com/inglepriyanshu/neobrain/blob/main/server/models/Chat.js"
    click M_Notebook "https://github.com/inglepriyanshu/neobrain/blob/main/server/models/Notebook.js"
    click M_Source "https://github.com/inglepriyanshu/neobrain/blob/main/server/models/Source.js"
    click S_DocProc "https://github.com/inglepriyanshu/neobrain/blob/main/server/services/documentProcessor.js"
    click S_YouTube "https://github.com/inglepriyanshu/neobrain/blob/main/server/services/youtubeService.js"
    click S_Gemini "https://github.com/inglepriyanshu/neobrain/blob/main/server/services/geminiService.js"
    click BE_Uploads "https://github.com/inglepriyanshu/neobrain/tree/main/server/uploads/"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#90CAF9,color:#0D47A1
    classDef backend fill:#E8F5E9,stroke:#66BB6A,color:#1B5E20
    classDef service fill:#FFF3E0,stroke:#FFA726,color:#E65100
    classDef model fill:#F3E5F5,stroke:#BA68C8,color:#4A148C
    classDef storage fill:#ECEFF1,stroke:#78909C,color:#37474F
    classDef db fill:#EDE7F6,stroke:#7E57C2,color:#4A148C
    classDef external fill:#F1F8E9,stroke:#AED581,color:#33691E
    classDef user fill:#FFEBEE,stroke:#EF5350,color:#B71C1C
```
