Blogging Platform Backend Development
Specification
Tech Stack: Node.js, Express, MongoDB, JWT (no caching in this phase)
1. Overview
This document outlines the backend architecture and development plan for a blogging platform.
It is designed to enable a small team to collaboratively build a secure, scalable backend API
using Node.js and Express, with MongoDB as the primary data store.
2. Project Structure
/config → Database connection and environment setup
/controllers → Business logic (auth, post, comment handling)
/models → Mongoose schemas for User, Post, Comment
/routes → Express route definitions for APIs
/middleware → JWT auth, error handling, request validation
server.js → Main app entry point
.env → Environment variables
3. Core Features
● User Registration and Login (JWT-based)
● Blog Post Creation, Reading, Updating, Deletion
● Commenting on Posts
● Public User Profiles
● Post Filtering, Sorting, and Pagination
4. Models (MongoDB with Mongoose)
User
● username: String, required, unique
● email: String, required, unique
● password: String (hashed), required
● createdAt: Date
● Optional: bio, profilePicture, socialLinks
Post
● title: String, required
● content: String, required
● tags: [String]
● authorId: ObjectId → User
● createdAt, updatedAt: Date
Comment
● content: String, required
● authorId: ObjectId → User
● postId: ObjectId → Post
● createdAt: Date
5. API Endpoints
Authentication Routes
Method Endpoint Description
POST /api/auth/registe Register new user
r
POST /api/auth/login Login, returns JWT
GET /api/auth/me Get logged-in user info (JWT protected)
User Routes
Method Endpoint Description
GET /api/users/:id Get public user profile
GET /api/users/m Get current user profile
e
PUT /api/users/m Update current user
e
Post Routes
Method Endpoint Description
GET /api/posts List all posts (supports filters)
GET /api/posts/:id Get single post by ID
POST /api/posts Create new post (auth required)
PUT /api/posts/:id Update post (auth + author
only)
DELETE /api/posts/:id Delete post (auth + author only)
Filters (on GET /api/posts)(Optional):
● ?tag=tech – Filter by tag
● ?author=username – Filter by author
● ?page=1&limit=10 – Pagination
● ?sort=latest – Sorting
Comment Routes
Method Endpoint Description
POST /api/comments Add comment to a post (auth)
GET /api/comments/:postId Get comments for a post
DELETE /api/comments/:id Delete own comment (auth only)
6. Middleware
● Auth Middleware: Validates JWT and attaches user to request object.
● Ownership Middleware: Checks if the logged-in user owns the resource
(post/comment).
● Error Handling Middleware: Catches and standardizes errors.
7. Environment Variables (.env)
PORT=5000
MONGODB_URI=<your_mongo_uri>
JWT_SECRET=<your_jwt_secret>
8. Development Notes
● Use Postman to manually test routes.
● Ensure proper error codes: 401 Unauthorized, 403 Forbidden, 404 Not Found,
500 Server Error.
● All write operations (POST, PUT, DELETE) require authentication.
● Passwords must be hashed using bcryptjs.
● Use express-validator for optional input validation.