Skip to content

A scalable RESTful Blog API built with Node.js, Express, MongoDB, and Redis. Features user authentication, role-based access, posts, comments, likes, caching, and Swagger documentation. Docker-ready for easy deployment.

License

Notifications You must be signed in to change notification settings

EmmanuelM-A/blog-api

Repository files navigation

Blog API

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.

🚀 Features

  • 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 author after first post
  • Input validation and centralized error handling
  • Redis caching for performance
  • Swagger UI for interactive API docs
  • Dockerized for easy deployment

📁 Project Structure

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

Running the Project

🔧 Prerequisites

  • Node.js v18+
  • Docker & Docker Compose
  • MongoDB & Redis (recommended via Docker)

📦 Installation

npm install

▶️ Run the API (Development)

npm run dev

🐳 Docker Usage

Build Production Image

npm run docker:build:prod

Run Production Container

npm run docker:run:prod

Run Development Compose

npm run docker:compose:dev

Run Production Compose

npm run docker:compose:prod

🛡️ Authentication

  • JWT Access Token in Authorization: Bearer <token>.
  • Refresh Token in secure HTTP-only cookie.
  • Supports user login/logout and token refreshing.

🧑‍💻 Roles & Access

  • user – Default registered user
  • author – Automatically promoted after first post
  • admin – Full access to all user/admin routes

📄 API Documentation

Swagger UI available at: API Documentation

Live preview of all endpoints, request/response schemas, and error codes.

📝 License

MIT License

👨‍🏫 Author

Emmanuel Maduka Agbeze

About

A scalable RESTful Blog API built with Node.js, Express, MongoDB, and Redis. Features user authentication, role-based access, posts, comments, likes, caching, and Swagger documentation. Docker-ready for easy deployment.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published