# mhistiak3/mindscribe architecture

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

- Interactive diagram: https://gitdiagram.com/mhistiak3/mindscribe
- Repository: https://github.com/mhistiak3/mindscribe

## Overview

##### Project type and purpose
- MindScribe is a full-stack, monolithic web application for blogging.
- Backend: Node.js + Express.js server handling routing, business logic, session management.
- Frontend: EJS templates rendered server-side, plus client-side JS, CSS, images served from a public folder.
- Database: MongoDB (via Mongoose) for users, blogs, sessions (connect-mongo).
- External services: Cloudinary for image storage, Markdown-it/highlight.js for Markdown parsing and syntax highlighting.

##### File structure
- Top-level:
- app.js – entry point
- public/ – static assets (css, images, client-side js modules)
- views/ – EJS templates (pages + partials)
- src/ – MVC backbone:
– config/ (DB, Cloudinary, Markdown, session)
– routes/ (Express routers per feature)
– controllers/ (per-feature business logic)
– models/ (UserModel, BlogModel)
– middlewares/ (userAuth)
– utilities/ (helpers: pagination, reading time, image utilities)
- Config files: .env for env vars, package.json for deps.
- Patterns: MVC, layered architecture (presentation → controllers → models).

##### Key README insights
- Auth (register, login/logout) using express-session + connect-mongo.
- CRUD on blogs (create, read, update, delete).
- Public vs authenticated routes.
- Cloudinary for image uploads.
- EJS for server-side rendering, client JS for dynamic pieces (dialogs, toasts, visit counts).

##### Main components & relationships
a. Presentation Layer
- Browser (UI): EJS-rendered HTML + client JS modules (login.js, createBlog.js, etc.) + CSS.
- Static asset server: Express serves /public.
b. Application Layer
- Express server (app.js)
– Middleware chain: dotenv, session, connect-mongo, userAuth, compression, routers.
– Routing: routes/* → controllers/*.
– Controllers invoke Mongoose models and utilities, then render views or JSON.
c. Data Layer
- MongoDB database: collections for users, blogs, sessions.
- Mongoose ODM for schema and queries.
- -mongo session store.
d. External Services
- Cloudinary API for image uploads.
- markdown-it & highlight.js for parsing blog content.

Interactions:
1. Browser → HTTP request → Express router.
2. Router → Controller → (optionally) Middleware checks auth.
3. Controller → Model (Mongoose) → MongoDB.
4. Controller → Cloudinary SDK (for image uploads).
5. Controller → render EJS view or send JSON.
6. Response → Browser.

##### Architectural patterns & design principles
- MVC: clear separation of concerns (views, controllers, models).
- Layered architecture: presentation, business logic, data access.
- RESTful routing for blog & auth endpoints.
- Middleware pipelines for cross-cutting concerns (auth, sessions, compression).
- Utility modules for reusable functions (pagination, reading time, image handling).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["Browser\n(UI: EJS templates, Client JS, CSS)"]:::client
        Static["Static Assets\n(public/)"]:::client
        Views["EJS Templates\n(views/)"]:::client
    end

    %% Application Layer
    subgraph "Application Layer"
        Server["Express Server\n(app.js)"]:::server
        Env["Environment Config\n(.env)"]:::server
        Deps["Dependencies & Scripts\n(package.json)"]:::server
        Config["Server Config Loader\n(src/config/index.js)"]:::server
        Router["Express Routers\n(src/routes/)"]:::server
        AuthMW["Auth Middleware\n(userAuthMiddleware)"]:::server
        Controllers["Controllers\n(src/controllers/)"]:::server
        Utils["Utilities\n(src/utilities/)"]:::server
    end

    %% Data & External Services
    subgraph "Data & External Services"
        Models["Mongoose Models\n(src/models/)"]:::server
        MongoCFG["Mongoose Config\n(src/config/mongoose_config.js)"]:::server
        SessionStore["Session Store\n(connect-mongo)"]:::db
        CloudCFG["Cloudinary Config\n(src/config/cloudinary_config.js)"]:::external
        Cloud["Cloudinary API"]:::external
        MDcfg["Markdown-it Config\n(src/config/markdown_it_config.js)"]:::external
        MD["Markdown Parser\n(markdown-it & highlight.js)"]:::external
        MongoDB["MongoDB"]:::db
    end

    %% Connections
    Browser -->|HTTP Request| Router
    Browser --> Static
    Browser --> Views
    Static -->|Served by| Server
    Server -->|loads| Env
    Server -->|loads| Deps
    Server -->|initializes| Config
    Server -->|uses| Router
    Router -->|protects| AuthMW
    AuthMW -->|guards| Controllers
    Router -->|routes to| Controllers
    Controllers -->|query| Models
    Controllers -->|query| MongoDB
    Controllers -->|upload| Cloudinary
    Controllers -->|configures| CloudCFG
    Controllers -->|parse| MD
    Controllers -->|uses| Utils
    Controllers -->|stores sessions| SessionStore
    Config -->|configures| MongoCFG
    Config -->|configures| CloudCFG
    Config -->|configures| MDcfg

    %% Click Events
    click Server "https://github.com/mhistiak3/mindscribe/blob/master/app.js"
    click Env "https://github.com/mhistiak3/mindscribe/blob/master/.env"
    click Deps "https://github.com/mhistiak3/mindscribe/blob/master/package.json"
    click Static "https://github.com/mhistiak3/mindscribe/tree/master/public/"
    click Views "https://github.com/mhistiak3/mindscribe/tree/master/views/"
    click Config "https://github.com/mhistiak3/mindscribe/blob/master/src/config/index.js"
    click Router "https://github.com/mhistiak3/mindscribe/tree/master/src/routes/"
    click AuthMW "https://github.com/mhistiak3/mindscribe/blob/master/src/middlewares/userAuthMiddleware.js"
    click Controllers "https://github.com/mhistiak3/mindscribe/tree/master/src/controllers/"
    click Utils "https://github.com/mhistiak3/mindscribe/tree/master/src/utilities/"
    click Models "https://github.com/mhistiak3/mindscribe/tree/master/src/models/"
    click MongoCFG "https://github.com/mhistiak3/mindscribe/blob/master/src/config/mongoose_config.js"
    click CloudCFG "https://github.com/mhistiak3/mindscribe/blob/master/src/config/cloudinary_config.js"
    click MDcfg "https://github.com/mhistiak3/mindscribe/blob/master/src/config/markdown_it_config.js"

    %% Styles
    classDef client fill:#E0F7FA,stroke:#00838F,color:#006064;
    classDef server fill:#E8F5E9,stroke:#2E7D32,color:#1B5E20;
    classDef db fill:#FFF3E0,stroke:#EF6C00,color:#E65100;
    classDef external fill:#F3E5F5,stroke:#8E24AA,color:#6A1B9A
```
