# nota0515/guardian architecture

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

- Interactive diagram: https://gitdiagram.com/nota0515/guardian
- Repository: https://github.com/nota0515/guardian

## Overview

##### Project type and purpose
- Guardian is a full-stack web application whose primary goal is to guide users through DSA problems by offering hints and step-by-step approaches (not full code solutions).
- The README confirms it is built with a React/Vite frontend, an Express/Node.js backend, and integrates with an external AI chat service (“geminiChat”).

##### File structure
- Top-level directories:
- backend – contains an Express app (controllers, routes, middleware, models, service, config, index.js).
- frontend – contains a Vite/React app (pages, components, assets, API wrappers, styling).
- Configuration/deployment files: vercel.json in both frontend and backend, indicating Vercel hosting; vite.config.js, tailwind.config.js; db.js for database connection.
- Architectural patterns:
- MVC-style organization on the backend (models, controllers, routes, middleware).
- Service layer (backend/service/geminiChat.js) for external-AI integration.
- Front-end componentization (React components under src/components, pages under src/pages).

##### README for additional insights
- Tech stack: React + Vite, Tailwind CSS, Axios on the frontend; Node.js Express backend; external AI hints provider.
- App relies on an API (this backend) and may also call an external AI service (Gemini).

##### Elements
- Labels: each component (“React App,” “Express API,” “MongoDB,” “Gemini AI Service,” “Browser”)
- From Browser to React App (UI events)
- From React App to Express API (Axios calls)
- From Express controllers to DB and to Gemini service
- From DB back to Express, then to React, then to Browser
- Another for server-side components
- A third for external services
- A fourth for persistent storage

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client Side
    subgraph "Client"
        BROWSER["Browser"]:::client
    end

    %% Frontend Layer
    subgraph "Frontend (React/Vite)" 
        direction TB
        FE_SRC["Frontend Source (src)"]:::frontend
        MAIN["main.jsx"]:::frontend
        APP["App.jsx"]:::frontend
        API_WRAPPER["API Wrapper (Axios)"]:::frontend
        subgraph "Pages"
            HOME["Home.jsx"]:::frontend
            LOGIN["Login.jsx"]:::frontend
            SIGNUP["Signup.jsx"]:::frontend
            PRICING["Pricing.jsx"]:::frontend
        end
        COMPONENTS["Shared UI Components"]:::frontend
        VITE_CONFIG["vite.config.js"]:::frontend
        TAILWIND_CONFIG["tailwind.config.js"]:::frontend
        FE_VERCEL["vercel.json"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express API)"
        direction TB
        INDEX["index.js"]:::backend
        DB_CONFIG["db.js"]:::backend
        subgraph "Controllers"
            AUTH_CTRL["authController.js"]:::backend
            CHAT_CTRL["chatController.js"]:::backend
        end
        subgraph "Routes"
            AUTH_ROUTES["authRoutes.js"]:::backend
            CONV_ROUTES["conversationRoutes.js"]:::backend
            CHAT_ROUTES["chats.js"]:::backend
        end
        AUTH_MW["authmiddleware.js"]:::backend
        subgraph "Models"
            USER_MODEL["User.js"]:::backend
            CHATS_MODEL["Chats.js"]:::backend
        end
        SERVICE["geminiChat.js"]:::backend
        BE_VERCEL["vercel.json"]:::backend
    end

    %% External Services and DB
    subgraph "External & Storage"
        direction TB
        DB["MongoDB"]:::database
        GEMINI["Gemini AI Service"]:::external
    end

    %% Connections
    BROWSER -->|"UI Load"| MAIN
    MAIN -->|"renders"| APP
    APP -->|"uses"| API_WRAPPER
    API_WRAPPER -->|"HTTP Requests"| INDEX

    INDEX -->|"connects"| DB_CONFIG
    INDEX -->|"registers routes"| AUTH_ROUTES
    INDEX -->|"registers routes"| CONV_ROUTES
    INDEX -->|"registers routes"| CHAT_ROUTES

    AUTH_ROUTES -->|"calls"| AUTH_CTRL
    CONV_ROUTES -->|"calls"| CHAT_CTRL
    CHAT_ROUTES -->|"calls"| CHAT_CTRL

    AUTH_CTRL -->|"uses middleware"| AUTH_MW
    AUTH_CTRL -->|"CRUD"| USER_MODEL
    CHAT_CTRL -->|"CRUD"| CHATS_MODEL
    CHAT_CTRL -->|"calls service"| SERVICE

    USER_MODEL -->|"queries"| DB
    CHATS_MODEL -->|"queries"| DB
    SERVICE -->|"API Request"| GEMINI

    GEMINI -->|"response"| SERVICE
    SERVICE -->|"hints"| CHAT_CTRL
    CHAT_CTRL -->|"response"| INDEX
    AUTH_CTRL -->|"response"| INDEX
    INDEX -->|"response"| API_WRAPPER
    API_WRAPPER -->|"data"| APP
    APP -->|"update UI"| BROWSER

    %% Click Events Frontend
    click FE_SRC "https://github.com/nota0515/guardian/tree/main/frontend/src"
    click MAIN "https://github.com/nota0515/guardian/blob/main/frontend/src/main.jsx"
    click APP "https://github.com/nota0515/guardian/blob/main/frontend/src/App.jsx"
    click API_WRAPPER "https://github.com/nota0515/guardian/blob/main/frontend/src/api/index.js"
    click HOME "https://github.com/nota0515/guardian/blob/main/frontend/src/pages/Home.jsx"
    click LOGIN "https://github.com/nota0515/guardian/blob/main/frontend/src/pages/Login.jsx"
    click SIGNUP "https://github.com/nota0515/guardian/blob/main/frontend/src/pages/Signup.jsx"
    click PRICING "https://github.com/nota0515/guardian/blob/main/frontend/src/pages/Pricing.jsx"
    click COMPONENTS "https://github.com/nota0515/guardian/tree/main/frontend/src/components"
    click TAILWIND_CONFIG "https://github.com/nota0515/guardian/blob/main/frontend/tailwind.config.js"
    click VITE_CONFIG "https://github.com/nota0515/guardian/blob/main/frontend/vite.config.js"
    click FE_VERCEL "https://github.com/nota0515/guardian/blob/main/frontend/vercel.json"

    %% Click Events Backend
    click INDEX "https://github.com/nota0515/guardian/blob/main/backend/index.js"
    click DB_CONFIG "https://github.com/nota0515/guardian/blob/main/backend/config/db.js"
    click AUTH_CTRL "https://github.com/nota0515/guardian/blob/main/backend/controller/authController.js"
    click CHAT_CTRL "https://github.com/nota0515/guardian/blob/main/backend/controller/chatController.js"
    click AUTH_ROUTES "https://github.com/nota0515/guardian/blob/main/backend/routes/authRoutes.js"
    click CONV_ROUTES "https://github.com/nota0515/guardian/blob/main/backend/routes/conversationRoutes.js"
    click CHAT_ROUTES "https://github.com/nota0515/guardian/blob/main/backend/routes/chats.js"
    click AUTH_MW "https://github.com/nota0515/guardian/blob/main/backend/middleware/authmiddleware.js"
    click USER_MODEL "https://github.com/nota0515/guardian/blob/main/backend/models/User.js"
    click CHATS_MODEL "https://github.com/nota0515/guardian/blob/main/backend/models/Chats.js"
    click SERVICE "https://github.com/nota0515/guardian/blob/main/backend/service/geminiChat.js"
    click BE_VERCEL "https://github.com/nota0515/guardian/blob/main/backend/vercel.json"

    %% Styles
    classDef client fill:#E3F2FD,stroke:#90CAF9,color:#0D47A1;
    classDef frontend fill:#E8F5E9,stroke:#66BB6A,color:#1B5E20;
    classDef backend fill:#FFF3E0,stroke:#FFA726,color:#E65100;
    classDef database fill:#EFEBE9,stroke:#BCAAA4,color:#4E342E;
    classDef external fill:#F3E5F5,stroke:#AB47BC,color:#6A1B9A;
```
