# sachinggsingh/vichar_manthan architecture

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

- Interactive diagram: https://gitdiagram.com/sachinggsingh/vichar_manthan
- Repository: https://github.com/sachinggsingh/vichar_manthan

## Overview

##### Project Type and Purpose
- Full-stack web application (MVC pattern).
- Purpose: Users can sign up/in, create, edit, view, and delete blog posts. Images and static assets are served from a public directory.

##### File Structure
- Top-level files:
- app.js – Express app entry point
- .env – environment variables
- Directories:
- routes/ – Express routes (blog.js, user.js)
- controller/ – route handlers (userCTRL.js)
- services/ – business logic/auth (auth.js)
- middleware/ – request guards (authentication.js)
- models/ – Mongoose schemas (blog.js, user.js)
- views/ – EJS templates (pages & partials)
- public/ – static assets (CSS, images, uploads)

##### Key Architectural Patterns & Components
- MVC layers:
- View layer: EJS templates
- Controller layer: routes → controller functions
- Model layer: Mongoose models
- Layered services: authentication logic separated into services and middleware.
- Monolithic Express server hosting both static and dynamic content.
- MongoDB as the primary datastore (could be a replica set or Atlas).
- File uploads stored in public/uploads (no separate file-storage service).

##### Main Components
a. Client Browser
- Sends HTTP(S) requests, receives HTML/CSS/JS.
b. Reverse Proxy / Load Balancer (optional)
c. Express.js Server
- app.js: configures middleware, routes, view engine.
- Middleware: authentication.js
- Routes: user.js, blog.js
- Controllers: userCTRL.js
- Services: auth.js
- Models: user.js, blog.js
d. MongoDB Cluster
- Collections: users, blogs
e. Static File Store
- public/ folder (images, CSS, site manifest, uploaded files)
f. Optional External Services
- Email service for notifications
- Cloud storage (if migrating uploads off-premise)

##### Interactions & Data Flows
1. Client → (1) HTTP GET / POST → Express server
2. Express → authentication middleware → controller
3. Controller → service layer → model/DB
4. DB → returns data → model → service → controller
5. Controller → renders EJS view or returns JSON
6. Public assets served directly from Express (static middleware)
7. Uploads: controller writes to public/uploads

##### Final Checklist
- All components clearly labeled.
- Static content path separated from dynamic routes.
- Optional scaling components (load balancer, CDN for static assets, replica set for MongoDB).

## Diagram (Mermaid)

```mermaid
flowchart TB
    Client["Client Browser"]:::client
    LB["Load Balancer / Reverse Proxy"]:::proxy

    subgraph "Express App"
        direction TB
        subgraph "Routes Layer"
            direction TB
            BlogRoutes["Blog Routes"]:::server
            UserRoutes["User Routes"]:::server
        end
        subgraph "Middleware Layer"
            direction TB
            AuthMiddleware["Authentication Middleware"]:::server
        end
        subgraph "Controller Layer"
            direction TB
            UserController["User Controller"]:::server
        end
        subgraph "Service Layer"
            direction TB
            AuthService["Authentication Service"]:::server
        end
        subgraph "Model Layer"
            direction TB
            BlogModel["Blog Model"]:::db
            UserModel["User Model"]:::db
        end
    end

    subgraph "View Layer"
        direction TB
        HomePage["Home Page"]:::view
        BlogList["Blog Listing"]:::view
        BlogDetails["Blog Details"]:::view
        EditBlog["Edit Blog"]:::view
        Profile["User Profile"]:::view
        SignIn["Sign In"]:::view
        SignUp["Sign Up"]:::view
        Head["partials/head.ejs"]:::view
        Navbar["partials/navbar.ejs"]:::view
        Footer["partials/footer.ejs"]:::view
        Script["partials/script.ejs"]:::view
    end

    DB["MongoDB Cluster"]:::db
    Static["Static Assets (public/)"]:::storage
    Email["Email Service"]:::external

    Client -->|"HTTP Request"| LB
    LB --> BlogRoutes
    LB --> UserRoutes

    BlogRoutes --> AuthMiddleware
    UserRoutes --> AuthMiddleware
    AuthMiddleware --> UserController
    UserController --> AuthService
    AuthService --> UserModel
    AuthService --> BlogModel
    UserModel --> DB
    BlogModel --> DB

    UserController -->|"renders"| HomePage
    UserController --> BlogList
    UserController --> BlogDetails
    UserController --> EditBlog
    UserController --> Profile
    UserController --> SignIn
    UserController --> SignUp

    Client -->|"load static"| Static

    AuthService --> Email

    classDef client fill:#8FBC8F,stroke:#333,stroke-width:1px
    classDef proxy fill:#B0C4DE,stroke:#333,stroke-width:1px
    classDef server fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef db fill:#FFA500,stroke:#333,stroke-width:1px
    classDef storage fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef view fill:#87CEFA,stroke:#333,stroke-width:1px
    classDef external fill:#DA70D6,stroke:#333,stroke-width:1px

    click BlogRoutes "https://github.com/sachinggsingh/vichar_manthan/blob/main/routes/blog.js"
    click UserRoutes "https://github.com/sachinggsingh/vichar_manthan/blob/main/routes/user.js"
    click AuthMiddleware "https://github.com/sachinggsingh/vichar_manthan/blob/main/middleware/authentication.js"
    click UserController "https://github.com/sachinggsingh/vichar_manthan/blob/main/controller/userCTRL.js"
    click AuthService "https://github.com/sachinggsingh/vichar_manthan/blob/main/services/auth.js"
    click BlogModel "https://github.com/sachinggsingh/vichar_manthan/blob/main/models/blog.js"
    click UserModel "https://github.com/sachinggsingh/vichar_manthan/blob/main/models/user.js"
    click HomePage "https://github.com/sachinggsingh/vichar_manthan/blob/main/views/home.ejs"
    click BlogList "https://github.com/sachinggsingh/vichar_manthan/blob/main/views/blog.ejs"
    click BlogDetails "https://github.com/sachinggsingh/vichar_manthan/blob/main/views/blog-details.ejs"
    click EditBlog "https://github.com/sachinggsingh/vichar_manthan/blob/main/views/edit-blog.ejs"
    click Profile "https://github.com/sachinggsingh/vichar_manthan/blob/main/views/profile.ejs"
    click SignIn "https://github.com/sachinggsingh/vichar_manthan/blob/main/views/signin.ejs"
    click SignUp "https://github.com/sachinggsingh/vichar_manthan/blob/main/views/signup.ejs"
    click Head "https://github.com/sachinggsingh/vichar_manthan/blob/main/views/partials/head.ejs"
    click Navbar "https://github.com/sachinggsingh/vichar_manthan/blob/main/views/partials/navbar.ejs"
    click Footer "https://github.com/sachinggsingh/vichar_manthan/blob/main/views/partials/footer.ejs"
    click Script "https://github.com/sachinggsingh/vichar_manthan/blob/main/views/partials/script.ejs"
    click Static "https://github.com/sachinggsingh/vichar_manthan/tree/main/public/"
```
