# jagrut-bhole/promptvision architecture

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

- Interactive diagram: https://gitdiagram.com/jagrut-bhole/promptvision
- Repository: https://github.com/jagrut-bhole/promptvision

## Overview

##### Project type and purpose
- This is a full-stack web application (“AI Image Generation Website”) that lets users generate AI images via Pollinations AI, authenticate with JWT, and share or browse a community gallery.
- Frontend: React.js + TailwindCSS, served via Vite.
- Backend: Node.js + Express.js, using MongoDB + Mongoose, with JWT/bcrypt for authentication.

##### File structure
- Top level: two directories, **client/** and **server/**.
- **client/** contains a React/Vite app:
– src/components (UI components, pages under src/pages), src/services/api.js for Axios calls, src/contexts/AuthContext, src/hooks/useAuth.
– Build config: vite.config.js, package.json, etc.
- **server/** contains an Express API:
– src/routes (auth.routes.js, image.routes.js)
– src/controllers (user.controllers.js, image.controllers.js)
– src/models (user.models.js, image.models.js)
– src/middlewares (auth.middlewares.js)
– src/db (Mongo connection), src/utils (apiError, apiResponse, asyncHandler)
– Entry point: src/index.js → app.js
- Config files: .env for server settings (port, CORS, JWT secrets, Mongo URI).

##### README for additional insights
- Tech stack, features, API endpoints, project structure.
- Mentions external dependency: Pollinations AI.

a. Main components
– **Frontend (React App)**
– **Backend API (Express Server)**
– **Database (MongoDB)**
– **External AI Service (Pollinations API)**
– **Authentication layer (JWT, bcrypt)**
b. Relationships & interactions
1. User’s browser → React UI
2. React UI uses Axios to call Backend REST API endpoints (`/api/auth/*`, `/api/images/*`).
3. Backend:
- Auth routes → auth.middleware validates/refreshes JWT → controllers handle register/login/logout → Mongoose persists/fetches users.
- Image routes → controllers call Pollinations API to generate images → stored in Mongo, returned to client.
– UI → API (HTTP request/response)
– API → MongoDB (read/write)
– API → External AI Service (HTTP)
c. Architectural patterns
– **Layered backend:** routes → controllers → models → database.
– **Middleware pipeline:** CORS, JSON parsing, auth validation.
– **Component-based frontend:** pages, reusable UI components, context for auth state.
d. Key technologies to label
– Frontend: React.js, TailwindCSS, React Router, Axios, Framer Motion
– Backend: Node.js, Express.js, Mongoose, JWT, bcrypt
– Database: MongoDB
– External Service: Pollinations AI

##### Detailed steps for the principal software engineer
- From Browser → API (include HTTP: GET/POST).
- From API → MongoDB (CRUD).
- From API → Pollinations AI (POST prompt → image).
- Blue for frontend, green for backend, yellow for DB, orange for external.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client (React App)"
        direction TB
        Browser["User Browser"]:::user
        ReactApp["React App"]:::frontend
        subgraph "Client Internals"
            direction TB
            MainEntry["main.jsx"]:::frontend
            GlobalStyles["index.css"]:::frontend
            ViteConfig["vite.config.js"]:::frontend
            Components["UI Components"]:::frontend
            ProtectedRoute["ProtectedRoute.jsx"]:::frontend
            AuthContext["AuthContext.jsx"]:::frontend
            AuthHook["useAuth.js"]:::frontend
            ApiService["api.js"]:::frontend
            Pages["Pages"]:::frontend
        end
    end

    %% Server Side
    subgraph "Server (Express API)"
        direction TB
        EntryServer["index.js"]:::backend
        AppSetup["app.js"]:::backend
        Constants["constants.js"]:::backend
        DBConn["db/index.js"]:::backend
        subgraph "Routes"
            direction TB
            AuthRoutes["auth.routes.js"]:::backend
            ImageRoutes["image.routes.js"]:::backend
        end
        subgraph "Controllers"
            direction TB
            UserCtrl["user.controllers.js"]:::backend
            ImageCtrl["image.controllers.js"]:::backend
        end
        subgraph "Models"
            direction TB
            UserModel["user.models.js"]:::backend
            ImageModel["image.models.js"]:::backend
        end
        Middleware["auth.middlewares.js"]:::backend
        subgraph "Utils"
            direction TB
            ApiError["apiError.js"]:::backend
            ApiResponse["apiResponse.js"]:::backend
            AsyncHandler["asyncHandler.js"]:::backend
        end
    end

    %% Database and External AI
    DB["MongoDB"]:::database
    ExternalAI["Pollinations AI"]:::external

    %% Connections
    Browser --> ReactApp
    ReactApp --> MainEntry
    MainEntry --> Components
    ReactApp --> ApiService
    ApiService -->|HTTP Requests| EntryServer

    EntryServer --> AppSetup
    AppSetup --> Constants
    AppSetup --> DBConn
    DBConn --> DB
    AppSetup --> Middleware
    AppSetup --> AuthRoutes
    AppSetup --> ImageRoutes

    AuthRoutes --> UserCtrl
    ImageRoutes --> ImageCtrl

    UserCtrl --> UserModel
    ImageCtrl --> ImageModel

    UserCtrl --> DB
    ImageCtrl --> DB
    ImageCtrl -->|Generate Image| ExternalAI

    %% Click Events
    click MainEntry "https://github.com/jagrut-bhole/promptvision/blob/main/client/src/main.jsx"
    click GlobalStyles "https://github.com/jagrut-bhole/promptvision/blob/main/client/src/index.css"
    click ViteConfig "https://github.com/jagrut-bhole/promptvision/blob/main/client/vite.config.js"
    click Components "https://github.com/jagrut-bhole/promptvision/tree/main/client/src/components"
    click ProtectedRoute "https://github.com/jagrut-bhole/promptvision/blob/main/client/src/components/ProtectedRoute.jsx"
    click AuthContext "https://github.com/jagrut-bhole/promptvision/blob/main/client/src/contexts/AuthContext.jsx"
    click AuthHook "https://github.com/jagrut-bhole/promptvision/blob/main/client/src/hooks/useAuth.js"
    click ApiService "https://github.com/jagrut-bhole/promptvision/blob/main/client/src/services/api.js"
    click Pages "https://github.com/jagrut-bhole/promptvision/tree/main/client/src/pages"
    click EntryServer "https://github.com/jagrut-bhole/promptvision/blob/main/server/src/index.js"
    click AppSetup "https://github.com/jagrut-bhole/promptvision/blob/main/server/src/app.js"
    click Constants "https://github.com/jagrut-bhole/promptvision/blob/main/server/src/constants.js"
    click DBConn "https://github.com/jagrut-bhole/promptvision/blob/main/server/src/db/index.js"
    click AuthRoutes "https://github.com/jagrut-bhole/promptvision/blob/main/server/src/routes/auth.routes.js"
    click ImageRoutes "https://github.com/jagrut-bhole/promptvision/blob/main/server/src/routes/image.routes.js"
    click Middleware "https://github.com/jagrut-bhole/promptvision/blob/main/server/src/middlewares/auth.middlewares.js"
    click UserCtrl "https://github.com/jagrut-bhole/promptvision/blob/main/server/src/controllers/user.controllers.js"
    click ImageCtrl "https://github.com/jagrut-bhole/promptvision/blob/main/server/src/controllers/image.controllers.js"
    click UserModel "https://github.com/jagrut-bhole/promptvision/blob/main/server/src/models/user.models.js"
    click ImageModel "https://github.com/jagrut-bhole/promptvision/blob/main/server/src/models/image.models.js"
    click ApiError "https://github.com/jagrut-bhole/promptvision/blob/main/server/src/utils/apiError.js"
    click ApiResponse "https://github.com/jagrut-bhole/promptvision/blob/main/server/src/utils/apiResponse.js"
    click AsyncHandler "https://github.com/jagrut-bhole/promptvision/blob/main/server/src/utils/asyncHandler.js"

    %% Styles
    classDef frontend fill:#AEDFF7,stroke:#0366d6,color:#000
    classDef backend fill:#C8F7C5,stroke:#28a745,color:#000
    classDef database fill:#FFF5BA,stroke:#f1c40f,color:#000
    classDef external fill:#FFD2A6,stroke:#e67e22,color:#000
    classDef user fill:#D6EAF8,stroke:#2980b9,color:#000
```
