# john-smilga/mern-jobify-v2 architecture

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

- Interactive diagram: https://gitdiagram.com/john-smilga/mern-jobify-v2
- Repository: https://github.com/john-smilga/mern-jobify-v2

## Overview

##### Project Type and Purpose
- This is a full-stack “Jobify” application:
- Front-end SPA built with Vite + React + React Router + React Query + Styled-Components + Recharts.
- Back-end REST API built with Node.js + Express, MongoDB (via Mongoose), JWT authentication, file uploads to Cloudinary.

##### File Structure for Architectural Layers
- client/ → React application (pages, components, assets, utils).
- server.js, routes/, controllers/, models/, middleware/, utils/ → Express API.
- populate.js for initial data seeding; utils/mockData.json for test jobs.
- Configuration files: .env, package.json, vite.config.js, .gitignore.

##### Main Components & Responsibilities
a. Front-end Client
- React Router layout/pages: Landing, Register/Login, Dashboard (nested routes: AddJob, AllJobs, Stats, Profile, Admin).
- React Query for data fetching & caching.
- Axios/customFetch wrapper for HTTP calls to `/api/v1/*`.
- UI components (FormRow, Job, JobInfo, ChartsContainer, StatsContainer, PageBtnContainer, etc.).
b. Express API
- Middleware chain: helmet, express-mongo-sanitize, rate-limiter, cookie-parser, multer (file parsing), authMiddleware (JWT), validationMiddleware, errorHandlerMiddleware.
- Routers: authRouter (`/api/v1/auth`), jobRouter (`/api/v1/jobs`), userRouter (`/api/v1/users`).
- Controllers: handle CRUD, auth, stats, file upload logic (Cloudinary).
- Mongoose models: UserModel, JobModel.
c. Data Stores & External Services
- MongoDB Atlas (jobs & users collections).
- Cloudinary (user avatars).
- Local file buffer via Multer + DataURI → Cloudinary upload.
- HttpOnly cookies for JWT.

##### Relationships & Data Flows
- Browser → React SPA → HTTP(S) (via Axios/customFetch, proxied in dev by Vite) → Express API.
- Express parses JWT from HttpOnly cookie → authMiddleware → controllers.
- Controllers interact with Mongoose to read/write MongoDB.
- Profile updates: Multer parses file → DataURI → Cloudinary API → returns URL → saved in User document.
- Controllers return JSON → React Query updates cache & UI.
- React Router loaders/actions drive data fetching & mutations (formData → API calls → redirects/toasts).

##### Architectural Patterns & Principles
- Front-end: SPA with route-based code organization, loader/action pattern, server-state management via React Query.
- Back-end: RESTful MVC-style layering: middleware → router → controller → model.
- Stateless authentication (JWT in cookie).
- Modular error handling (custom error classes + express-async-errors).
- Security hardening: helmet, express-mongo-sanitize, express-rate-limit.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client (React/Vite)"
        direction TB
        Main["main.jsx"]:::frontend
        App["App.jsx"]:::frontend
        subgraph "Pages"
            direction TB
            Landing["Landing.jsx"]:::frontend
            Register["Register.jsx"]:::frontend
            Login["Login.jsx"]:::frontend
            DashboardLayout["DashboardLayout.jsx"]:::frontend
            AddJob["AddJob.jsx"]:::frontend
            AllJobs["AllJobs.jsx"]:::frontend
            StatsPage["Stats.jsx"]:::frontend
            Profile["Profile.jsx"]:::frontend
            Admin["Admin.jsx"]:::frontend
            ErrorPage["Error.jsx"]:::frontend
            DeleteJob["DeleteJob.jsx"]:::frontend
            EditJob["EditJob.jsx"]:::frontend
        end
        Query["React Query (useQuery/useMutation)"]:::frontend
        Fetch["customFetch (Axios)"]:::frontend
        Components["UI Components"]:::frontend
    end

    %% Server Side
    subgraph "Server/API (Express)"
        direction TB
        API["server.js"]:::backend
        Middleware["Middleware Stack"]:::backend
        Routers["Routers"]:::backend
        Controllers["Controllers"]:::backend
        Models["Mongoose Models"]:::backend
    end

    %% External Services
    MongoDB["MongoDB Atlas"]:::external
    Cloudinary["Cloudinary"]:::external

    %% Connections
    Main --> App
    App --> Landing
    App --> Register
    App --> Login
    App --> DashboardLayout
    DashboardLayout --> AddJob
    DashboardLayout --> AllJobs
    DashboardLayout --> StatsPage
    DashboardLayout --> Profile
    DashboardLayout --> Admin
    DashboardLayout --> DeleteJob
    DashboardLayout --> EditJob
    Landing --> Query
    Register --> Query
    Login --> Query
    DashboardLayout --> Query
    Query --> Fetch
    Fetch -->|"HTTP requests"| API
    API --> Middleware
    Middleware --> Routers
    Routers --> Controllers
    Controllers --> Models
    Controllers -->|DB query| MongoDB
    Controllers -->|Upload API| Cloudinary
    Controllers -->|JSON response| Fetch
    Fetch -->|update cache/UI| Query

    %% Click Events
    click Main "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/main.jsx"
    click App "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/App.jsx"
    click Landing "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/pages/Landing.jsx"
    click Register "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/pages/Register.jsx"
    click Login "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/pages/Login.jsx"
    click DashboardLayout "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/pages/DashboardLayout.jsx"
    click AddJob "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/pages/AddJob.jsx"
    click AllJobs "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/pages/AllJobs.jsx"
    click StatsPage "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/pages/Stats.jsx"
    click Profile "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/pages/Profile.jsx"
    click Admin "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/pages/Admin.jsx"
    click ErrorPage "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/pages/Error.jsx"
    click DeleteJob "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/pages/DeleteJob.jsx"
    click EditJob "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/pages/EditJob.jsx"
    click Fetch "https://github.com/john-smilga/mern-jobify-v2/blob/main/client/src/utils/customFetch.js"
    click Routers "https://github.com/john-smilga/mern-jobify-v2/blob/main/routes/authRouter.js"
    click Routers "https://github.com/john-smilga/mern-jobify-v2/blob/main/routes/jobRouter.js"
    click Routers "https://github.com/john-smilga/mern-jobify-v2/blob/main/routes/userRouter.js"
    click Controllers "https://github.com/john-smilga/mern-jobify-v2/blob/main/controllers/authController.js"
    click Controllers "https://github.com/john-smilga/mern-jobify-v2/blob/main/controllers/jobController.js"
    click Controllers "https://github.com/john-smilga/mern-jobify-v2/blob/main/controllers/userController.js"
    click Models "https://github.com/john-smilga/mern-jobify-v2/blob/main/models/UserModel.js"
    click Models "https://github.com/john-smilga/mern-jobify-v2/blob/main/models/JobModel.js"
    click API "https://github.com/john-smilga/mern-jobify-v2/blob/main/server.js"
    click MongoDB "https://github.com/john-smilga/mern-jobify-v2/blob/main/populate.js"
    click Cloudinary "https://github.com/john-smilga/mern-jobify-v2/blob/main/utils/mockData.json"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#1E88E5,color:#1E88E5;
    classDef backend fill:#E8F5E9,stroke:#43A047,color:#2E7D32;
    classDef external fill:#FFF3E0,stroke:#FB8C00,color:#E65100;
```
