How hustle-sonigra/writo works
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 Express bootstrap · postController.js Post controller · postRoutes.js Post routes · user.js User model
Components 16
HTTP application
- Express bootstrap · Assembles middleware, database, static assets, views, and routes.
app.js - MongoDB initialization
config/db.js
Identity & access
- Auth routes
routes/authRoutes.js - JWT verification · Establishes authenticated-user context for protected requests.
middleWare/authMiddleWare.js - Auth controller · Handles signup, login, and JWT issuance.
controllers/authController.js - User model · Account identity and authentication data.
Models/user.js
Content domain
- Post routes
routes/postRoutes.js - Post controller · Orchestrates feed, search, posts, likes, and ownership checks.
controllers/postController.js - Post model · Blog content with author and like associations.
Models/post.js - MongoDB
Server presentation
- EJS renderer
- Entry views · Landing, login, and home screens.
views/index.ejs - Feed & detail views · Feed, blog detail, search results, and profile pages.
views/feed.ejs - Post editor views · Create and update post workflows.
views/create.ejs - Like interaction · Sends browser-side like interactions to the server.
public/javascripts/like.js - Static styles
Connections 22
- 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