# hustle-sonigra/writo architecture

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

- Interactive diagram: https://gitdiagram.com/hustle-sonigra/writo
- Repository: https://github.com/hustle-sonigra/writo

## Overview

#### Purpose and Runtime
Writo is a server-rendered blogging platform: users authenticate, publish/manage posts, browse/search a feed, and like posts. It runs on Node.js with Express, renders HTML through EJS, and persists user/post/like relationships in MongoDB via Mongoose. Deployment configuration is present in `vercel.json`; the README identifies Render as the live deployment target.

#### Application Bootstrap
`app.js` is the HTTP application entry point. It is responsible for assembling Express middleware, database initialization, static asset serving, EJS view rendering, and route mounting. MongoDB connectivity is isolated in `config/db.js`, creating a boundary between application startup and persistence infrastructure.

#### HTTP Routing and Controller Boundary
Routes map request paths to feature controllers:
- Authentication routes: `routes/authRoutes.js` → `controllers/authController.js`
- Post/feed routes: `routes/postRoutes.js` → `controllers/postController.js`

Controllers are the primary orchestration layer. They receive HTTP input, invoke models, enforce feature-level behavior such as author-only modification, and select EJS views or redirects as responses.

#### Authentication and Authorization
Authentication is JWT-based. `controllers/authController.js` handles signup/login and token issuance; `middleWare/authMiddleWare.js` verifies requests and establishes authenticated-user context for protected operations. This separates identity verification from post business logic. Protected routes then permit authenticated users to create/manage content, while controllers enforce ownership for edits/deletes.

#### Domain Persistence Model
MongoDB/Mongoose models define the core relational graph:
- `Models/user.js` represents accounts and their identity/authentication data.
- `Models/post.js` represents authored blog content and associations to authors and likes.

The essential data relationship is user → authored posts and post → users who liked it. Controllers query and update these documents to render author details, feeds, post pages, and like state.

#### Content, Feed, Search, and Likes Flow
Post requests enter `routes/postRoutes.js`, pass authentication middleware where required, and are processed by `controllers/postController.js`. The controller creates, updates, deletes, fetches, searches, and likes posts through `Models/post.js` and related user records. Results are rendered into feed, detail, author/profile, search, create, and update screens, including `views/feed.ejs`, `views/blog.ejs`, `views/searchFeed.ejs`, and `views/profile.ejs`.

Likes have a small client/server boundary: browser-side interaction lives in `public/javascripts/like.js`, while persistence and count updates remain controller/model responsibilities.

#### Presentation Layer
EJS templates are server-side presentation endpoints, not a separate SPA. Key entry screens are `views/index.ejs`, `views/login.ejs`, and `views/home.ejs`; content workflows use `views/create.ejs` and `views/update.ejs`. Static CSS and browser JavaScript are served from `public/`, notably `public/stylesheets/` and `public/javascripts/like.js`.

Main entry points: [`app.js`](https://github.com/hustle-sonigra/writo/blob/main/app.js) (Express bootstrap), [`controllers/postController.js`](https://github.com/hustle-sonigra/writo/blob/main/controllers/postController.js) (Post controller), [`routes/postRoutes.js`](https://github.com/hustle-sonigra/writo/blob/main/routes/postRoutes.js) (Post routes), [`Models/user.js`](https://github.com/hustle-sonigra/writo/blob/main/Models/user.js) (User model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP application"]
  node_app["Express bootstrap<br/>Node/Express app<br/>[app.js]"]
  node_db[("MongoDB initialization<br/>database connector<br/>[db.js]")]
end

subgraph group_auth["Identity &amp; access"]
  node_auth_routes["Auth routes<br/>Express router<br/>[authRoutes.js]"]
  node_auth_middleware{{"JWT verification<br/>auth middleware<br/>[authMiddleWare.js]"}}
  node_auth_controller["Auth controller<br/>[authController.js]"]
  node_user_model["User model<br/>Mongoose model<br/>[user.js]"]
end

subgraph group_content["Content domain"]
  node_post_routes["Post routes<br/>Express router<br/>[postRoutes.js]"]
  node_post_controller["Post controller<br/>[postController.js]"]
  node_post_model["Post model<br/>Mongoose model<br/>[post.js]"]
  node_mongodb[("MongoDB<br/>persistence store")]
end

subgraph group_presentation["Server presentation"]
  node_ejs["EJS renderer<br/>server view engine"]
  node_entry_views["Entry views<br/>EJS templates<br/>[index.ejs]"]
  node_feed_views["Feed &amp; detail views<br/>EJS templates<br/>[feed.ejs]"]
  node_editor_views["Post editor views<br/>EJS templates<br/>[create.ejs]"]
  node_like_client["Like interaction<br/>browser JavaScript<br/>[like.js]"]
  node_static_assets["Static styles<br/>public assets"]
end

node_app -->|"initializes"| node_db
node_db -->|"connects"| node_mongodb
node_app -->|"mounts"| node_auth_routes
node_app -->|"mounts"| node_post_routes
node_app -->|"configures"| node_ejs
node_app -->|"serves"| node_static_assets
node_auth_routes -->|"dispatches"| node_auth_controller
node_post_routes -->|"protects writes"| node_auth_middleware
node_post_routes -->|"dispatches"| node_post_controller
node_auth_controller -->|"creates/authenticates"| node_user_model
node_post_controller -->|"queries and updates"| node_post_model
node_post_controller -->|"loads authors"| node_user_model
node_user_model -->|"persists"| node_mongodb
node_post_model -->|"persists"| node_mongodb
node_post_model -.->|"author and likes"| node_user_model
node_auth_controller -->|"renders or redirects"| node_entry_views
node_post_controller -->|"renders"| node_feed_views
node_post_controller -->|"renders"| node_editor_views
node_ejs -->|"renders"| node_entry_views
node_ejs -->|"renders"| node_feed_views
node_ejs -->|"renders"| node_editor_views
node_like_client -->|"like requests"| node_post_routes

click node_app "https://github.com/hustle-sonigra/writo/blob/main/app.js"
click node_db "https://github.com/hustle-sonigra/writo/blob/main/config/db.js"
click node_auth_routes "https://github.com/hustle-sonigra/writo/blob/main/routes/authRoutes.js"
click node_post_routes "https://github.com/hustle-sonigra/writo/blob/main/routes/postRoutes.js"
click node_auth_middleware "https://github.com/hustle-sonigra/writo/blob/main/middleWare/authMiddleWare.js"
click node_auth_controller "https://github.com/hustle-sonigra/writo/blob/main/controllers/authController.js"
click node_post_controller "https://github.com/hustle-sonigra/writo/blob/main/controllers/postController.js"
click node_user_model "https://github.com/hustle-sonigra/writo/blob/main/Models/user.js"
click node_post_model "https://github.com/hustle-sonigra/writo/blob/main/Models/post.js"
click node_entry_views "https://github.com/hustle-sonigra/writo/blob/main/views/index.ejs"
click node_feed_views "https://github.com/hustle-sonigra/writo/blob/main/views/feed.ejs"
click node_editor_views "https://github.com/hustle-sonigra/writo/blob/main/views/create.ejs"
click node_like_client "https://github.com/hustle-sonigra/writo/blob/main/public/javascripts/like.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_db toneBlue
class node_auth_routes,node_auth_middleware,node_auth_controller,node_user_model toneAmber
class node_post_routes,node_post_controller,node_post_model,node_mongodb toneMint
class node_ejs,node_entry_views,node_feed_views,node_editor_views,node_like_client,node_static_assets toneRose
```

## Components

### HTTP application

- [Express bootstrap](https://github.com/hustle-sonigra/writo/blob/main/app.js): Node/Express app · Assembles middleware, database, static assets, views, and routes. · `app.js`
- [MongoDB initialization](https://github.com/hustle-sonigra/writo/blob/main/config/db.js): database connector · `config/db.js`

### Identity & access

- [Auth routes](https://github.com/hustle-sonigra/writo/blob/main/routes/authRoutes.js): Express router · `routes/authRoutes.js`
- [JWT verification](https://github.com/hustle-sonigra/writo/blob/main/middleWare/authMiddleWare.js): auth middleware · Establishes authenticated-user context for protected requests. · `middleWare/authMiddleWare.js`
- [Auth controller](https://github.com/hustle-sonigra/writo/blob/main/controllers/authController.js): controller · Handles signup, login, and JWT issuance. · `controllers/authController.js`
- [User model](https://github.com/hustle-sonigra/writo/blob/main/Models/user.js): Mongoose model · Account identity and authentication data. · `Models/user.js`

### Content domain

- [Post routes](https://github.com/hustle-sonigra/writo/blob/main/routes/postRoutes.js): Express router · `routes/postRoutes.js`
- [Post controller](https://github.com/hustle-sonigra/writo/blob/main/controllers/postController.js): controller · Orchestrates feed, search, posts, likes, and ownership checks. · `controllers/postController.js`
- [Post model](https://github.com/hustle-sonigra/writo/blob/main/Models/post.js): Mongoose model · Blog content with author and like associations. · `Models/post.js`
- **MongoDB**: persistence store

### Server presentation

- **EJS renderer**: server view engine
- [Entry views](https://github.com/hustle-sonigra/writo/blob/main/views/index.ejs): EJS templates · Landing, login, and home screens. · `views/index.ejs`
- [Feed & detail views](https://github.com/hustle-sonigra/writo/blob/main/views/feed.ejs): EJS templates · Feed, blog detail, search results, and profile pages. · `views/feed.ejs`
- [Post editor views](https://github.com/hustle-sonigra/writo/blob/main/views/create.ejs): EJS templates · Create and update post workflows. · `views/create.ejs`
- [Like interaction](https://github.com/hustle-sonigra/writo/blob/main/public/javascripts/like.js): browser JavaScript · Sends browser-side like interactions to the server. · `public/javascripts/like.js`
- **Static styles**: public assets

## Connections

- Express bootstrap → MongoDB initialization: initializes
- MongoDB initialization → MongoDB: connects
- Express bootstrap → Auth routes: mounts
- Express bootstrap → Post routes: mounts
- Express bootstrap → EJS renderer: configures
- Express bootstrap → Static styles: serves
- Auth routes → Auth controller: dispatches
- Post routes → JWT verification: protects writes
- Post routes → Post controller: dispatches
- Auth controller → User model: creates/authenticates
- Post controller → Post model: queries and updates
- Post controller → User model: loads authors
- User model → MongoDB: persists
- Post model → MongoDB: persists
- Post model → User model: author and likes
- Auth controller → Entry views: renders or redirects
- Post controller → Feed & detail views: renders
- Post controller → Post editor views: renders
- EJS renderer → Entry views: renders
- EJS renderer → Feed & detail views: renders
- EJS renderer → Post editor views: renders
- Like interaction → Post routes: like requests
