# sathwikreddy15/nextpad architecture

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

- Interactive diagram: https://gitdiagram.com/sathwikreddy15/nextpad
- Repository: https://github.com/sathwikreddy15/nextpad

## Overview

##### Project type and purpose
- This is a full-stack web application (“Nextpad”) allowing writers to create, edit, soft-delete, and share literary works and allowing users to comment.
- Technology stack: React (Vite) frontend, Node.js/Express backend, MongoDB database, JWT-based auth, deployed on Vercel.

##### Main components
a. Frontend (React + Vite)
- Main.jsx / App.jsx
- Components folder: Landing, Home, Article, NewArticle, ModifyArticle, UserProfile, Login, Register, Navbar, Footer
- Context API providers: urlContext, userContext, myContext
- HTTP client: axiosWithToken
b. Backend (Node.js + Express)
- index.js (Express app entry point)
- APIs folder: user-api.js (CRUD for users/articles), verifyToken.js (JWT middleware), Util.js (utility functions)
c. Database
- MongoDB (hosted via MONGODB_URI from .env)
d. Deployment / External Services
- Vercel for hosting frontend and backend
- MongoDB Atlas (or equivalent)
- JWT issuer/validator

##### Relationships & interactions
- The user’s browser loads the React SPA from Vercel.
- React Context provides base API URL and user state.
- User actions (login, fetch articles, post comment) trigger axiosWithToken calls to the Express API.
- Express routes in index.js forward requests to specific API controllers in the APIs folder.
- verifyToken middleware protects private endpoints by validating the JWT from request headers.
- Controllers perform business logic and read/write data in MongoDB.
- Responses flow back through Express to the React client, which updates UI state via Context.

##### Architectural patterns & design principles
- Frontend: Component-based architecture with Context API for global state management.
- Backend: Modular route handlers (APIs folder) with middleware (verifyToken), following an MVC-like separation (controllers/utilities).
- Stateless, RESTful API design; JWT for authentication.
- Soft deletes on articles implemented via a “deleted” flag in the database (business logic in Util.js).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Deployment / External Services"
        VercelFE["Vercel Hosting (Frontend)"]:::deployment
        VercelBE["Vercel Hosting (Backend)"]:::deployment
        Env[".env (MONGODB_URI, PORT)"]:::deployment
    end

    subgraph "Client Browser"
        Browser["User Browser"]:::external
    end

    subgraph "Frontend (React + Vite)"
        Main["main.jsx"]:::frontend
        App["App.jsx"]:::frontend
        AX["axiosWithToken"]:::frontend

        subgraph "Context Providers"
            URL["urlContext"]:::frontend
            UserCtx["userContext"]:::frontend
            MyCtx["myContext"]:::frontend
        end

        subgraph "Components"
            Landing["Landing Component"]:::frontend
            Home["Home Component"]:::frontend
            ArticleC["Article Component"]:::frontend
            NewArt["NewArticle Component"]:::frontend
            ModArt["ModifyArticle Component"]:::frontend
            Profile["UserProfile Component"]:::frontend
            Login["Login Component"]:::frontend
            Register["Register Component"]:::frontend
            Navbar["Navbar Component"]:::frontend
            Footer["Footer Component"]:::frontend
        end
    end

    subgraph "Backend (Express API)"
        Index["index.js"]:::backend

        subgraph "APIs & Middleware"
            UserAPI["user-api.js"]:::backend
            Verify["verifyToken.js"]:::backend
            Util["Util.js"]:::backend
        end
    end

    DB[(MongoDB)]:::db

    VercelFE --> Browser
    VercelBE --> Index
    Browser --> Main
    Main --> App
    App --> URL
    App --> UserCtx
    App --> MyCtx
    App --> Landing
    App --> Home
    App --> ArticleC
    App --> NewArt
    App --> ModArt
    App --> Profile
    App --> Login
    App --> Register
    App --> Navbar
    App --> Footer
    Landing --> AX
    Home --> AX
    ArticleC --> AX
    NewArt --> AX
    ModArt --> AX
    Profile --> AX
    Login --> AX
    Register --> AX
    Navbar --> AX
    Footer --> AX
    AX --> Index
    Index --> Verify
    Verify --> UserAPI
    UserAPI --> Util
    UserAPI --> DB
    DB --> UserAPI
    UserAPI --> Index
    Index --> AX
    AX --> App
    App --> Browser

    click Main "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/main.jsx"
    click App "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/App.jsx"
    click AX "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/axiosWithToken.js"
    click URL "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/context-api/urlContext.js"
    click UserCtx "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/context-api/userContext.js"
    click MyCtx "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/context-api/myContext.js"
    click Landing "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/components/Landing/Landing.jsx"
    click Home "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/components/Home/Home.jsx"
    click ArticleC "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/components/Article/Article.jsx"
    click NewArt "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/components/NewArticle/NewArticle.jsx"
    click ModArt "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/components/ModifyArticle/ModifyArticle.jsx"
    click Profile "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/components/UserProfile/UserProfile.jsx"
    click Login "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/components/Login/Login.jsx"
    click Register "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/components/Register/Register.jsx"
    click Navbar "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/components/Navbar/Navbar.jsx"
    click Footer "https://github.com/sathwikreddy15/nextpad/blob/main/FRONTEND/src/components/Footer/Footer.jsx"
    click Index "https://github.com/sathwikreddy15/nextpad/blob/main/BACKEND/api/index.js"
    click UserAPI "https://github.com/sathwikreddy15/nextpad/blob/main/BACKEND/api/APIs/user-api.js"
    click Verify "https://github.com/sathwikreddy15/nextpad/blob/main/BACKEND/api/APIs/verifyToken.js"
    click Util "https://github.com/sathwikreddy15/nextpad/blob/main/BACKEND/api/APIs/Util.js"

    classDef frontend fill:#B3CDE3,stroke:#6497B1,color:#03396C
    classDef backend fill:#CCEBC5,stroke:#66C2A5,color:#006837
    classDef db fill:#FBB4AE,stroke:#FC9272,color:#A50F15
    classDef deployment fill:#D9D9D9,stroke:#BEBEBE,color:#000000
    classDef external fill:#FFFFFF,stroke:#000000,color:#000000
```
