# bhargav007dobhal/post-flow-blog-website-updated- architecture

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

- Interactive diagram: https://gitdiagram.com/bhargav007dobhal/post-flow-blog-website-updated-
- Repository: https://github.com/bhargav007dobhal/post-flow-blog-website-updated-

## Overview

##### Project type and purpose
- This is a full-stack blog platform (“Post Flow Blog Website”) with a React front end, a Node.js/Express back end, MySQL for persistent storage, and local file uploads for images.
- Key features: user authentication (JWT), post creation/editing/deletion with image uploads, comments, upvotes, leaderboard, and user profiles.

##### File structure
- Top level: two main folders, **backend/** and **frontend/**, plus documentation and reports in the root.
- backend/
- controllers – request handlers (auth, posts, users, features, metrics)
- middleware – JWT auth, rate limiting, security, caching, performance checks
- models – database connection (db.js, connection pool)
- routes – REST endpoints (/api/auth, /api/posts, /api/users, etc.)
- Uploads – local file storage for post images
- server.js & runMigration.js – main entry point and schema setup scripts
- frontend/
- src/components – reusable UI components (Navbar, UpvoteButton, BookmarkButton)
- src/pages – route-level views (Home, CreatePost, Login, Register, Profile, Leaderboard, PostDetail)
- src/context/AuthContext – global auth state with React Context & JWT management
- src/services/api.js – Axios instance pointing at the Express API
- Tailwind CSS for styling
- Configuration: .env files, package.json, PostCSS/tailwind config files.

##### Architectural patterns and design principles
- Layered MVC style in the backend: Routes → Controllers → Models → Database
- Middleware pipeline for cross-cutting concerns (auth, rate limiting, security)
- Component-based UI in the frontend with Context for global state
- RESTful API between front end and back end
- Local file storage (Uploads folder) for images, managed via middleware

##### Main components and their interactions
a. **Client (Browser / React SPA)**
- Hosted by `npm start` on port 3000
- Renders UI, holds auth state, dispatches HTTP calls via `api.js`
b. **API Server (Express)**
- Listens on port 5001
- Exposes `/api/*` endpoints for auth, posts, comments, likes, users, metrics
- Middlewares: JWT verification, rate limiter, security headers, input validation
c. **Database (MySQL)**
- Tables: users, posts, comments, likes
- Accessed via `models/db.js` using a connection pool
d. **File Storage**
- Local folder `backend/Uploads/` for storing uploaded images
- served as static resources via Express
e. **External Dependencies**
- JWT library for token generation/validation
- Axios for HTTP in the front end
- Tailwind CSS for styling

Interaction flow example:
1. User logs in/registers → React calls `/api/auth` → server controller issues JWT → client stores it in Context
2. User creates a post with image → React form uses Axios multipart POST to `/api/posts` → Express uses security and file-upload middleware → controller saves metadata in MySQL and file on disk → response includes new post data
3. User upvotes a post → React sends POST to `/api/posts/:id/upvote` → server middleware checks JWT and rate limit → controller writes to `likes` table → client refreshes post/leaderboard

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (React SPA)" 
        direction TB
        subgraph "UI Components"
            direction TB
            Navbar["Navbar"]:::frontend
            UpvoteBtn["UpvoteButton"]:::frontend
            BookmarkBtn["BookmarkButton"]:::frontend
        end
        subgraph "Pages"
            direction TB
            Home["Home Page"]:::frontend
            CreatePost["CreatePost Page"]:::frontend
            PostDetail["PostDetail Page"]:::frontend
            Leaderboard["Leaderboard Page"]:::frontend
            Login["Login Page"]:::frontend
            Register["Register Page"]:::frontend
            Profile["Profile Page"]:::frontend
        end
        AuthContext["AuthContext"]:::frontend
        APIService["API Service (axios)"]:::frontend
    end

    UI["User Interaction"]:::frontend

    %% Backend Layer
    subgraph "Backend (Express API)"
        direction TB
        subgraph "Entry & Routes"
            direction TB
            Server["server.js"]:::backend
            Migration["runMigration.js"]:::backend
            AuthRoute["Auth Route (/api/auth)"]:::backend
            PostsRoute["Posts Route (/api/posts)"]:::backend
            UsersRoute["Users Route (/api/users)"]:::backend
            FeaturesRoute["Features Route (/api/features)"]:::backend
            MetricsRoute["Metrics Route (/api/metrics)"]:::backend
        end
        subgraph "Middleware Pipeline"
            direction TB
            AuthM["JWT Auth"]:::backend
            RateM["Rate Limiter"]:::backend
            SecureM["Security/Validation"]:::backend
            SuitM["Feature Suitability"]:::backend
            CacheM["Caching"]:::backend
            PerfM["Performance Checks"]:::backend
        end
        subgraph "Controllers"
            direction TB
            AuthC["AuthController"]:::backend
            PostC["PostController"]:::backend
            UserC["UserController"]:::backend
        end
        subgraph "Models"
            direction TB
            DBPool["dbPool.js"]:::backend
            DB["db.js"]:::backend
        end
        subgraph "File Uploads"
            direction TB
            Uploads["Uploads Folder"]:::storage
        end
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        direction TB
        DBTable["MySQL Database"]:::db
        Storage["Local File Storage"]:::storage
    end

    %% Connections: Frontend to Backend
    UI -->|"User clicks"| Navbar
    navbarFetch[hidden] -->|interacts| UI
    Navbar --> UI
    UI --> AuthContext
    UI --> APIService
    APIService -->|"HTTP/JSON"| Server

    %% Server flow
    Server --> AuthRoute
    Server --> PostsRoute
    Server --> UsersRoute
    Server --> FeaturesRoute
    Server --> MetricsRoute

    AuthRoute --> AuthM
    PostsRoute --> AuthM
    UsersRoute --> AuthM
    FeaturesRoute --> AuthM
    MetricsRoute --> AuthM

    AuthM --> RateM
    RateM --> SecureM
    SecureM --> SuitM
    SuitM --> CacheM
    CacheM --> PerfM

    PerfM --> AuthC
    PerfM --> PostC
    PerfM --> UserC

    AuthC --> DB
    PostC --> DB
    UserC --> DB
    PostC --> Uploads

    DB --> DBTable
    Uploads --> Storage

    %% Click events for frontend
    click Navbar "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/frontend/src/components/Navbar.js"
    click UpvoteBtn "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/frontend/src/components/UpvoteButton.js"
    click BookmarkBtn "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/frontend/src/components/BookmarkButton.js"
    click Home "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/frontend/src/pages/Home.js"
    click CreatePost "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/frontend/src/pages/CreatePost.js"
    click PostDetail "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/frontend/src/pages/PostDetail.js"
    click Leaderboard "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/frontend/src/pages/Leaderboard.js"
    click Login "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/frontend/src/pages/Login.js"
    click Register "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/frontend/src/pages/Register.js"
    click Profile "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/frontend/src/pages/Profile.js"
    click AuthContext "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/frontend/src/context/AuthContext.js"
    click APIService "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/frontend/src/services/api.js"
    click Server "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/server.js"
    click Migration "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/runMigration.js"
    click AuthRoute "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/routes/auth.js"
    click PostsRoute "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/routes/posts.js"
    click UsersRoute "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/routes/users.js"
    click FeaturesRoute "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/routes/features.js"
    click MetricsRoute "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/routes/metrics.js"
    click AuthC "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/controllers/authController.js"
    click PostC "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/controllers/postController.js"
    click UserC "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/controllers/userController.js"
    click AuthM "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/middleware/auth.js"
    click RateM "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/middleware/rateLimiter.js"
    click SecureM "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/middleware/security.js"
    click CacheM "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/middleware/cache.js"
    click PerfM "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/middleware/performance.js"
    click SuitM "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/middleware/functionSuitability.js"
    click DBPool "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/models/dbPool.js"
    click DB "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/blob/main/backend/models/db.js"
    click Uploads "https://github.com/bhargav007dobhal/post-flow-blog-website-updated-/tree/main/backend/Uploads/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#007ACC,color:#000
    classDef backend fill:#E2F7E1,stroke:#28A745,color:#000
    classDef db fill:#FFE5B4,stroke:#D2691E,color:#000
    classDef storage fill:#FFE5B4,stroke:#D2691E,color:#000
    classDef infra fill:#FFE5B4,stroke:#D2691E,color:#000
```
