# rithick-11/blog-management-system-api architecture

> Architecture diagram of the GitHub repository rithick-11/blog-management-system-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rithick-11/blog-management-system-api
- Repository: https://github.com/rithick-11/blog-management-system-api

## Overview

##### Main Components

a) Client Layer:
- External clients (Web/Mobile applications) that consume the API
- Connection through HTTPS to the API endpoints

b) API Gateway Layer:
- Vercel deployment (as indicated by vercel.json)
- Main API endpoints groupings (/api/auth, /api/blogs, /api/comments, /api/users)

c) Middleware Layer:
- Authentication middleware (JWT verification)
- Authorization middleware (Role-based access control)

d) Controller Layer (Based on src/controllers):
- AuthController (user authentication, verification)
- BlogController (blog CRUD operations)
- CommentController (comment management)
- UserController (user management)

e) Model Layer (Based on src/models):
- User Model
- Blog Model
- Comment Model

f) External Services:
- Email Service (for verification emails)
- Database (MongoDB, based on the model structure)

**[Client Applications]**
- ↓ HTTPS
**[API Gateway (Vercel)]**
- ↓
**[Middleware Layer]**
- ↓
**[Controllers Layer]**
- ↓
**[Models Layer]**
- ↓
**[Database Layer]**

##### Important Relationships to Highlight

a) Authentication Flow:
- JWT token flow from auth controller to middleware
- Email verification process

b) Data Flow:
- Blog creation/editing flow with role checks
- Comment management flow
- User management flow

##### Access Control Visualization

- Admin: Full access (highlight in red)
- Editor: Blog editing access (highlight in yellow)
- User: Basic access (highlight in green)

##### Specific Implementation Details

a) Authentication Flow:
**[Signup/Login Request] → [Auth Controller] → [Email Service]**
- ↓
- [JWT Generation] → [User Model]

b) Blog Management Flow:
**[Blog Request] → [Auth Middleware] → [Authorization Middleware]**
- ↓
- [Blog Controller] → [Blog Model]

c) Comment System Flow:
**[Comment Request] → [Auth Middleware] → [Comment Controller]**
- ↓
- [Comment Model] ← [Blog Model]

##### Additional Elements

- API endpoint groupings
- Database relationships between models
- Error handling flow
- Email verification process

##### Technical Stack Indicators

- Node.js environment
- Express.js framework (implied by structure)
- MongoDB database
- JWT for authentication
- Email service integration

Remember to:
- Use consistent styling
- Notes for important business logic
- Security checkpoints
- Asynchronous operations

This system design should effectively communicate the architecture of a secure, role-based blog management system with email verification and comprehensive CRUD operations for blogs and comments.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        WC[Web Client]:::client
        MC[Mobile Client]:::client
    end

    subgraph Gateway
        API["API Gateway (Vercel)"]:::gateway
        click API "https://github.com/rithick-11/blog-management-system-api/blob/main/vercel.json"
    end

    subgraph Routes
        AR["Auth Routes"]:::route
        BR["Blog Routes"]:::route
        CR["Comment Routes"]:::route
        UR["User Routes"]:::route
        click AR "https://github.com/rithick-11/blog-management-system-api/blob/main/src/routes/authRouter.js"
        click BR "https://github.com/rithick-11/blog-management-system-api/blob/main/src/routes/blogRouter.js"
        click CR "https://github.com/rithick-11/blog-management-system-api/blob/main/src/routes/commentRouter.js"
        click UR "https://github.com/rithick-11/blog-management-system-api/blob/main/src/routes/userRouter.js"
    end

    subgraph Middleware
        AM["Authentication Middleware"]:::middleware
        RB["Authorization Middleware"]:::middleware
        click AM "https://github.com/rithick-11/blog-management-system-api/blob/main/src/middlewares/authentication.js"
        click RB "https://github.com/rithick-11/blog-management-system-api/blob/main/src/middlewares/authorization.js"
    end

    subgraph Controllers
        AC["Auth Controller"]:::controller
        BC["Blog Controller"]:::controller
        CC["Comment Controller"]:::controller
        UC["User Controller"]:::controller
        click AC "https://github.com/rithick-11/blog-management-system-api/blob/main/src/controllers/authController.js"
        click BC "https://github.com/rithick-11/blog-management-system-api/blob/main/src/controllers/blogController.js"
        click CC "https://github.com/rithick-11/blog-management-system-api/blob/main/src/controllers/commentController.js"
        click UC "https://github.com/rithick-11/blog-management-system-api/blob/main/src/controllers/userController.js"
    end

    subgraph Models
        UM["User Model"]:::model
        BM["Blog Model"]:::model
        CM["Comment Model"]:::model
        click UM "https://github.com/rithick-11/blog-management-system-api/blob/main/src/models/User.js"
        click BM "https://github.com/rithick-11/blog-management-system-api/blob/main/src/models/Blog.js"
        click CM "https://github.com/rithick-11/blog-management-system-api/blob/main/src/models/Comment.js"
    end

    subgraph External
        ES["Email Service"]:::external
        DB[(MongoDB)]:::database
        click ES "https://github.com/rithick-11/blog-management-system-api/blob/main/src/utils/sentMail.js"
    end

    WC & MC --> API
    API --> AR & BR & CR & UR
    AR & BR & CR & UR --> AM
    AM --> RB
    RB --> AC & BC & CC & UC
    AC --> UM
    BC --> BM
    CC --> CM
    UC --> UM
    AC --> ES
    UM & BM & CM --> DB

    classDef client fill:#3498db,stroke:#2980b9,stroke-width:2px
    classDef gateway fill:#2ecc71,stroke:#27ae60,stroke-width:2px
    classDef route fill:#95a5a6,stroke:#7f8c8d,stroke-width:2px
    classDef middleware fill:#e74c3c,stroke:#c0392b,stroke-width:2px
    classDef controller fill:#f1c40f,stroke:#f39c12,stroke-width:2px
    classDef model fill:#e67e22,stroke:#d35400,stroke-width:2px
    classDef external fill:#9b59b6,stroke:#8e44ad,stroke-width:2px
    classDef database fill:#34495e,stroke:#2c3e50,stroke-width:2px
```
