# drishti2904/talkify-video_calling_chat_app architecture

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

- Interactive diagram: https://gitdiagram.com/drishti2904/talkify-video_calling_chat_app
- Repository: https://github.com/drishti2904/talkify-video_calling_chat_app

## Overview

##### Project type and purpose
- Talkify is a full-stack MERN (MongoDB, Express.js, React, Node.js) real-time chat and one-on-one video call application for language learners.
- Key features: JWT-based authentication, friend management, real-time messaging/video via GetStream.io, efficient client caching with TanStack Query, theming via Tailwind CSS + DaisyUI.

##### File structure
- Top level:
- backend/ (Express server)
- frontend/ (React app)
- package.json (root scripts, if any)
- backend/src:
- controllers (auth, chat, user) – MVC pattern
- models (User, FriendRequest) – Mongoose ODM
- lib (db.js → Mongo connection, stream.js → GetStream server SDK init)
- middleware (auth.middleware.js → JWT validation)
- routes (auth.route.js, chat.route.js, user.route.js)
- server.js (app entry point)
- frontend/src:
- pages (Login, SignUp, Home, Friends, Chat, Call, Notifications, Onboarding)
- components (Navbar, Sidebar, ChatLoader, PageLoader, CallButton, FriendCard, etc.)
- lib (api.js → REST calls wrapper, axios.js, utils.js)
- hooks (useAuthUser, useLogin, useSignup, useLogout)
- store (useThemeStore – Zustand or similar)
- constants, index.css, main.jsx, index.html
- config: Vite, ESLint, PostCSS, Tailwind

##### Extract additional insights from README
- Backend uses JWT for stateless authentication, Bcrypt for hashing, Mongoose for data persistence, GetStream.io server SDK to create/query chat channels and generate video tokens.
- Frontend initializes GetStream Chat client with SDK and API key, uses TanStack Query for data fetching/caching.
- The real-time channel is entirely managed by GetStream; backend’s chat.controller handles backend-only operations (e.g., moderation, server-side channel creation, friend requests).

##### Main components & their relationships
A. Client (Browser)
- React components & pages
- TanStack Query (data layer)
- GetStream Chat client SDK
- Axios calls → REST API
B. API Gateway (Express Server)
- Routes: /auth, /user, /chat
- Controllers → business logic
- Middleware → JWT auth
- stream.js → calls GetStream API
- db.js → connects to MongoDB
C. Data Store
- MongoDB (Collections: users, friend_requests)
D. External Service
- GetStream.io
- Chat & messaging channel management
- Video call signaling/Signaling tokens
E. Optional: Hosting/Env
- Environment variables (.env in backend and frontend)
- Deployed on e.g., Heroku/Vercel, Mongo Atlas

1. User ↔ React UI
2. React UI → REST API (via axios/api.js)
3. REST API → MongoDB (db.js, Mongoose models)
4. REST API → GetStream.io (stream.js)
5. React UI ↔ GetStream Chat SDK (Websocket over Stream’s hosted infra)
6. Data caching flows inside React via TanStack Query

##### Architectural patterns & design principles
- Layered architecture (Presentation / API / Data)
- MVC on the backend (Routes → Controllers → Models)
- Component-based UI on the frontend
- Stateless REST for auth/data, delegated real-time comms to GetStream
- Single responsibility: each controller handles one domain; hooks abstract authentication; lib folders centralize cross-cutting concerns

##### Elements
- Clear labels for each component (e.g., “AuthController”, “ChatPage.jsx”, “GetStream Chat Client SDK”)
- REST calls (Frontend → Backend)
- DB queries (Backend → MongoDB)
- External API calls (Backend → GetStream REST API)
- Websocket streams (Frontend ↔ GetStream Chat)
- Rectangles for code modules (e.g., controllers, pages)

a. Sketch two columns: Frontend (left), Backend (center), External/DB (right).
- UI Pages → Components → Hooks → API client → Stream SDK.
c. In Backend column, list:
- Incoming request → Middleware → Routes → Controllers → Libs → Models
- From API client → Express Route, label “HTTP POST /login” etc.
- From Controllers → MongoDB, label “Mongoose query”
- From Controllers → Stream SDK, label “Stream REST call”
- From React UI → Stream Chat SDK, label “WebSocket chat/video”
f. Authentication flow: annotate JWT generation (AuthController → client), JWT attached in headers (every API call via axios).

##### Detail without over-splitting
- Folder’s role but group leaf files (e.g., group all components under “Components”).
- Precise flows for chat vs REST.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Frontend Layer
    subgraph "Frontend" 
        direction TB
        subgraph "UI Pages"
            direction TB
            LoginPage["LoginPage.jsx"]:::frontend
            SignUpPage["SignUpPage.jsx"]:::frontend
            HomePage["HomePage.jsx"]:::frontend
            FriendsPage["FriendsPage.jsx"]:::frontend
            ChatPage["ChatPage.jsx"]:::frontend
            CallPage["CallPage.jsx"]:::frontend
            NotificationsPage["NotificationsPage.jsx"]:::frontend
            OnboardingPage["OnboardingPage.jsx"]:::frontend
        end
        subgraph "Components"
            direction TB
            Navbar["Navbar.jsx"]:::frontend
            Sidebar["Sidebar.jsx"]:::frontend
            ChatLoader["ChatLoader.jsx"]:::frontend
            CallButton["CallButton.jsx"]:::frontend
            FriendCard["FriendCard.jsx"]:::frontend
            PageLoader["PageLoader.jsx"]:::frontend
            Layout["Layout.jsx"]:::frontend
            ThemeSelector["ThemeSelector.jsx"]:::frontend
        end
        subgraph "Hooks & Store"
            direction TB
            useAuthUser["useAuthUser.js"]:::frontend
            useLogin["useLogin.js"]:::frontend
            useSignup["useSignup.js"]:::frontend
            useLogout["useLogout.js"]:::frontend
            ThemeStore["useThemeStore.js"]:::frontend
        end
        subgraph "Lib & Config"
            direction TB
            APIClient["api.js"]:::frontend
            AxiosConfig["axios.js"]:::frontend
            Utils["utils.js"]:::frontend
            Constants["constants"]:::frontend
            AppEntry["App.jsx"]:::frontend
            Main["main.jsx"]:::frontend
            TailwindConfig["tailwind.config.js"]:::frontend
            PostCSSConfig["postcss.config.js"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend"
        direction TB
        Server["server.js"]:::backend
        subgraph "Middleware"
            AuthMiddleware["auth.middleware.js"]:::backend
        end
        subgraph "Routes"
            AuthRoutes["auth.route.js"]:::backend
            ChatRoutes["chat.route.js"]:::backend
            UserRoutes["user.route.js"]:::backend
        end
        subgraph "Controllers"
            AuthController["AuthController"]:::backend
            ChatController["ChatController"]:::backend
            UserController["UserController"]:::backend
        end
        subgraph "Lib"
            StreamLib["stream.js"]:::backend
            DBLib["db.js"]:::backend
        end
        subgraph "Models"
            UserModel["User.js"]:::backend
            FriendRequestModel["FriendRequest.js"]:::backend
        end
    end

    %% External Services and DB
    MongoDB["MongoDB"]:::db
    GetStream["GetStream.io"]:::external

    %% Connections
    LoginPage -->|"uses hooks"| useAuthUser
    SignUpPage -->|"uses hooks"| useSignup
    HomePage -->|"uses hooks"| useAuthUser
    FriendsPage -->|"uses hooks"| useAuthUser
    ChatPage -->|"uses hooks"| useAuthUser
    CallPage -->|"uses hooks"| useAuthUser

    UI_API[ ]:::frontend
    subgraph APIInteraction["REST Interaction"]
        direction TB
        APIClient -->|"HTTP calls"| Server
        APIClient --> AxiosConfig
        APIClient --> Constants
        APIClient --> Utils
    end

    UI_Pages([UI Pages]):::frontend --> APIClient

    Server --> AuthMiddleware
    AuthMiddleware --> AuthRoutes
    AuthMiddleware --> UserRoutes
    AuthMiddleware --> ChatRoutes
    AuthRoutes --> AuthController
    ChatRoutes --> ChatController
    UserRoutes --> UserController

    AuthController --> DBLib
    UserController --> DBLib
    ChatController --> DBLib
    DBLib --> MongoDB

    AuthController --> StreamLib
    ChatController --> StreamLib
    StreamLib --> GetStream

    ChatPage -->|"WebSocket chat/video"| GetStream
    CallPage -->|"WebSocket chat/video"| GetStream

    %% Click Events
    click AuthController "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/backend/src/controllers/auth.controller.js"
    click ChatController "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/backend/src/controllers/chat.controller.js"
    click UserController "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/backend/src/controllers/user.controller.js"
    click AuthMiddleware "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/backend/src/middleware/auth.middleware.js"
    click StreamLib "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/backend/src/lib/stream.js"
    click DBLib "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/backend/src/lib/db.js"
    click AuthRoutes "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/backend/src/routes/auth.route.js"
    click ChatRoutes "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/backend/src/routes/chat.route.js"
    click UserRoutes "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/backend/src/routes/user.route.js"
    click UserModel "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/backend/src/models/User.js"
    click FriendRequestModel "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/backend/src/models/FriendRequest.js"
    click Server "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/backend/src/server.js"
    click LoginPage "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/pages/LoginPage.jsx"
    click SignUpPage "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/pages/SignUpPage.jsx"
    click HomePage "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/pages/HomePage.jsx"
    click FriendsPage "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/pages/FriendsPage.jsx"
    click ChatPage "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/pages/ChatPage.jsx"
    click CallPage "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/pages/CallPage.jsx"
    click NotificationsPage "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/pages/NotificationsPage.jsx"
    click OnboardingPage "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/pages/OnboardingPage.jsx"
    click Navbar "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/components/Navbar.jsx"
    click Sidebar "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/components/Sidebar.jsx"
    click ChatLoader "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/components/ChatLoader.jsx"
    click CallButton "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/components/CallButton.jsx"
    click FriendCard "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/components/FriendCard.jsx"
    click PageLoader "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/components/PageLoader.jsx"
    click Layout "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/components/Layout.jsx"
    click ThemeSelector "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/components/ThemeSelector.jsx"
    click APIClient "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/lib/api.js"
    click AxiosConfig "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/lib/axios.js"
    click Utils "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/lib/utils.js"
    click useAuthUser "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/hooks/useAuthUser.js"
    click useLogin "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/hooks/useLogin.js"
    click useSignup "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/hooks/useSignup.js"
    click useLogout "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/hooks/useLogout.js"
    click ThemeStore "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/store/useThemeStore.js"
    click Constants "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/constants/index.js"
    click AppEntry "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/App.jsx"
    click Main "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/src/main.jsx"
    click TailwindConfig "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/tailwind.config.js"
    click PostCSSConfig "https://github.com/drishti2904/talkify-video_calling_chat_app/blob/main/frontend/postcss.config.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#000;
    classDef backend fill:#D0FFD6,stroke:#28a745,color:#000;
    classDef db fill:#FFD8B0,stroke:#e36209,color:#000;
    classDef external fill:#E8D0FF,stroke:#6f42c1,color:#000;
```
