A full-featured RESTful Blog API built with Node.js, Express, and MongoDB, featuring user authentication, role-based access control, post management, comments, likes, caching with Redis, and API documentation using Swagger.
- User Registration & Authentication (JWT & Refresh Tokens)
- Role-Based Access Control (
user,author,admin) - Post CRUD operations with pagination
- Comments and likes on posts
- Auto-promotion to
authorafter first post - Input validation and centralized error handling
- Redis caching for performance
- Swagger UI for interactive API docs
- Dockerized for easy deployment
src/
├── __tests__/
├── api/
│ └── v1/
│ ├── controllers/
│ ├── routes/
├── database/
│ └── models/
│ └── schemas/
│ └── database-connection.js
├── docs/
│ └── swagger.yml
│ └── swagger.js
├── middleware/
├── services/
│ └── caching/
│ └── comments/
│ └── likes/
│ └── posts/
│ └── users/
│ └── validation/
├── utils/
├── app.js
├── config.js
├── server.js- Node.js v18+
- Docker & Docker Compose
- MongoDB & Redis (recommended via Docker)
npm installnpm run devnpm run docker:build:prodnpm run docker:run:prodnpm run docker:compose:devnpm run docker:compose:prod- JWT Access Token in
Authorization: Bearer <token>. - Refresh Token in secure HTTP-only cookie.
- Supports user login/logout and token refreshing.
user– Default registered userauthor– Automatically promoted after first postadmin– Full access to all user/admin routes
Swagger UI available at: API Documentation
Live preview of all endpoints, request/response schemas, and error codes.