# samratghosh291/blogify architecture

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

- Interactive diagram: https://gitdiagram.com/samratghosh291/blogify
- Repository: https://github.com/samratghosh291/blogify

## Overview

##### Project type and purpose
- This is a full-stack web application built with Node.js, Express and MongoDB.
- Purpose: provide user authentication and CRUD operations for blogs, rendered via EJS templates and exposing REST endpoints.

##### File structure
- Top-level files:
- index.js – Express app entry point
- .env.sample – environment variables template
- package.json / package-lock.json – dependencies & scripts
- Directories:
- routes/ – Express route handlers (user.js, blog.js)
- middleware/ – request-level middleware (authentication)
- services/ – business-logic utilities (auth, Cloudinary image uploads)
- models/ – Mongoose schema definitions (User, Blog, Comment)
- views/ – EJS templates with partials for server-side rendering
- public/ – static assets + uploaded images

##### README for additional insights
- Uses RESTful endpoints under /user and /blog
- Reads/writes to MongoDB via Mongoose
- Expects .env with PORT and MONGODB_URI
- Renders server‐side views (no SPA framework)

## Diagram (Mermaid)

```mermaid
graph TB
    Client["Client (Browser)"]:::external

    subgraph "Express.js Server"
        direction TB
        Index["index.js (Entry Point)"]:::internal
        Env[".env.sample"]:::internal
        Static["Static Server"]:::static
        RouterUser["User Routes (/user)"]:::internal
        RouterBlog["Blog Routes (/blog)"]:::internal
        AuthMW["Auth Middleware"]:::internal
        ServiceAuth["Auth Service"]:::internal
        ServiceCloud["Cloudinary Service"]:::internal
        ViewEngine["View Engine (EJS)"]:::internal
        ModelUser["UserModel"]:::internal
        ModelBlog["BlogModel"]:::internal
        ModelComment["CommentModel"]:::internal
        Package["package.json / package-lock.json"]:::static
        README["README.md"]:::static
    end

    DB["MongoDB"]:::db
    Cloud["Cloudinary API"]:::external

    Client -->|"HTTP Request"| Static
    Static -->|"serves assets"| Client

    Client -->|"HTTP Request"| RouterUser
    Client -->|"HTTP Request"| RouterBlog

    RouterUser --> AuthMW
    RouterBlog --> AuthMW

    AuthMW --> ServiceAuth
    RouterUser --> ServiceAuth
    RouterBlog --> ServiceAuth

    RouterBlog --> ServiceCloud
    ServiceCloud --> Cloud

    RouterUser --> ModelUser
    RouterBlog --> ModelBlog
    RouterBlog --> ModelComment

    ModelUser --> DB
    ModelBlog --> DB
    ModelComment --> DB

    RouterUser --> ViewEngine
    RouterBlog --> ViewEngine
    ViewEngine --> Client

    Index --> RouterUser
    Index --> RouterBlog
    Index --> Static
    Index --> AuthMW
    Index --> ServiceAuth
    Index --> ViewEngine

    click Index "https://github.com/samratghosh291/blogify/blob/main/index.js"
    click Env "https://github.com/samratghosh291/blogify/blob/main/.env.sample"
    click RouterUser "https://github.com/samratghosh291/blogify/blob/main/routes/user.js"
    click RouterBlog "https://github.com/samratghosh291/blogify/blob/main/routes/blog.js"
    click AuthMW "https://github.com/samratghosh291/blogify/blob/main/middleware/authentication.js"
    click ServiceAuth "https://github.com/samratghosh291/blogify/blob/main/services/auth.js"
    click ServiceCloud "https://github.com/samratghosh291/blogify/blob/main/services/cloudinary.js"
    click ModelUser "https://github.com/samratghosh291/blogify/blob/main/models/user.model.js"
    click ModelBlog "https://github.com/samratghosh291/blogify/blob/main/models/blog.model.js"
    click ModelComment "https://github.com/samratghosh291/blogify/blob/main/models/comment.model.js"
    click Static "https://github.com/samratghosh291/blogify/tree/main/public/"
    click README "https://github.com/samratghosh291/blogify/blob/main/README.md"
    click Package "https://github.com/samratghosh291/blogify/blob/main/package.json"
    click Static "https://github.com/samratghosh291/blogify/tree/main/public/image"
    click Static "https://github.com/samratghosh291/blogify/tree/main/public/uploads"
    click ViewEngine "https://github.com/samratghosh291/blogify/blob/main/views/home.ejs"
    click ViewEngine "https://github.com/samratghosh291/blogify/blob/main/views/blog.ejs"
    click ViewEngine "https://github.com/samratghosh291/blogify/blob/main/views/addBlog.ejs"
    click ViewEngine "https://github.com/samratghosh291/blogify/blob/main/views/signin.ejs"
    click ViewEngine "https://github.com/samratghosh291/blogify/blob/main/views/signup.ejs"
    click ViewEngine "https://github.com/samratghosh291/blogify/blob/main/views/partials/head.ejs"
    click ViewEngine "https://github.com/samratghosh291/blogify/blob/main/views/partials/nav.ejs"
    click ViewEngine "https://github.com/samratghosh291/blogify/blob/main/views/partials/script.ejs"

    classDef internal fill:#a2fca2,stroke:#333,stroke-width:1px
    classDef external fill:#f96,stroke:#333,stroke-width:1px
    classDef db fill:#aaf,stroke:#333,stroke-width:1px
    classDef static fill:#ccc,stroke:#333,stroke-width:1px
```
