Sign inSign up

hossamgezo/bookstore-api

By hossamgezo

•Updated 4 months ago

Professional Bookstore API built with Node.js, TypeScript, and Clean Architecture.

Image
0

864

hossamgezo/bookstore-api repository overview

ā šŸ“š Bookstore API (V2)

Build Status Website Status DB Status Swagger Docs Docker Hub GitHub License


A professional, high-performance Bookstore system featuring a hybrid RESTful API and MVC architecture, built with Node.js, Express, and TypeScript. This project implements Clean Modular Architecture, robust production security, and a fully automated CI/CD Pipeline.


ā šŸ“ø Project Showcase

ā šŸ  Landing Page (MVC with EJS & Tailwind)

Click the image to visit the live home page.

Welcome UI


ā šŸ“– Interactive API Explorer (Swagger UI)

Click the image to test the API endpoints live.

Swagger UI


ā šŸ›  Tech Stack

Backend & UIDatabase & ValidationDevOps & CI/CDSecurity & Performance
Node.jsMongoDBDockerHelmet
ExpressMongooseGitHub ActionsRateLimit
TypeScriptZodRenderCompression
EJSTailwindHuskyHPP

⁠✨ Key Features & Architecture

ā šŸ—ļø Architecture & Clean Code
  • Modular Design: Fully organized by features (Auth, Users, Books, Authors) for maximum scalability.
  • Hybrid Pattern: Combination of REST API for data exchange and MVC (using EJS & Tailwind) for user workflows.
  • Service Layer: Business logic is decoupled from controllers using a standardized Result Object Pattern.
  • Global Data Transformation: Automated MongoDB _id to id transformation via a custom global plugin.
ā šŸ” Security & Reliability
  • Production Hardening: Protected by Helmet, HPP, and Compression.
  • Rate Limiting: Throttling requests per IP via express-rate-limit to prevent DDoS attacks.
  • Authentication: Secure JWT-based auth with Role-Based Access Control (RBAC).
  • Live Reload: Seamless development experience integrated into the ESM workflow.
⁠⚔ Performance & Automation
  • CI/CD Pipeline: Fully automated GitHub Actions that build and push Docker images on every push to main.
  • Optimized Queries: Advanced Pagination and Filtering helper using Promise.all for high performance.
  • Multi-stage Docker: Extremely small and secure production images using Alpine Linux.

ā šŸ”Œ API Endpoints Overview

For a detailed interactive guide and to test the endpoints live, please visit our Swagger Documentation⁠.

ā šŸ”‘ Auth (Authentication)
  • POST /api/auth/register - Register a new user.
  • POST /api/auth/login - Authenticate user and receive a JWT.
ā šŸ‘¤ User (Administration)
  • GET /api/users - List all users (Admin only).
  • GET /api/users/{id} - Get user details (Owner or Admin).
  • PUT /api/users/{id} - Update user profile.
  • DELETE /api/users/{id} - Delete user account.
ā šŸ” Password (Recovery - MVC)
  • GET /password/forgot-password - Render forgot password view.
  • POST /password/forgot-password - Send reset password link via email.
  • GET /password/reset-password/{id}/{token} - Render reset password form.
  • POST /password/reset-password/{id}/{token} - Set a new password in the database.
ā āœļø Author (Profiles)
  • GET /api/authors - Get all authors with pagination.
  • POST /api/authors - Create a new author (Admin only).
  • GET /api/authors/{id} - Get author by ID.
  • PUT /api/authors/{id} - Update author details (Admin only).
  • DELETE /api/authors/{id} - Delete author by ID (Admin only).
ā šŸ“š Book (Catalog Management)
  • GET /api/books - Get all books (with Pagination & Price Filtering).
  • POST /api/books - Create a new book (Admin only).
  • GET /api/books/{id} - Get book details (Populated with Author).
  • PUT /api/books/{id} - Update book details (Admin only).
  • DELETE /api/books/{id} - Delete book by ID (Admin only).
ā šŸ“‚ Upload (Storage Services)
  • POST /api/upload - Upload a single image using Multer.

ā āš™ļø Configuration & Environment

To run this project locally, you need to set up the following environment variables. Create a .env file in the root directory and populate it with your values:

# APPLICATION CONFIGURATION
PORT=5001
NODE_ENV=development
BASE_URL=http://localhost:5001

# DATABASE CONFIGURATION
MONGO_URI_DEV=mongodb://localhost/bookStoreDB
MONGO_URI_PRO=your_production_mongodb_uri

# SECURITY & AUTHENTICATION
JWT_SECRET_KEY=your_super_secret_key
JWT_EXPIRES_IN=30d
PASSWORD_RESET_EXPIRES_IN=10m

# FRONTEND INTEGRATION (CORS)
CLIENT_URL=http://localhost:3000

# PAGINATION SETTINGS
BOOKS_PER_PAGE=2
AUTHORS_PER_PAGE=2
USERS_PER_PAGE=5

# NODEMAILER CONFIGURATION (SMTP)
[email protected]
USER_PASS=your_app_specific_password

ā šŸ“‚ Project Structure
src/
ā”œā”€ā”€ index.ts            # Entry point & Express app configuration
ā”œā”€ā”€ models/             # Centralized Mongoose Schemas (User, Book, Author)
ā”œā”€ā”€ modules/            # Feature-based modular logic
│   ā”œā”€ā”€ auth/           # Login, Register & JWT Logic
│   ā”œā”€ā”€ user/           # User management & Administration
│   ā”œā”€ā”€ book/           # Catalog management & Price filtering
│   ā”œā”€ā”€ author/         # Author profiles & Data seeding
│   ā”œā”€ā”€ password/       # MVC Password recovery workflow
│   └── upload/         # File storage & Multer integration
│       └── docs/       # Integrated Swagger YAML definitions per module
ā”œā”€ā”€ shared/             # Cross-cutting concerns & Infrastructure
│   ā”œā”€ā”€ config/         # DB Connection & Swagger JSDoc Setup
│   ā”œā”€ā”€ helpers/        # Query, Response, and Mongoose utility functions
│   ā”œā”€ā”€ middlewares/    # Auth guards, Error handling, and Logger
│   ā”œā”€ā”€ types/          # Global TypeScript interfaces & Express extensions
│   └── validations/    # Shared Zod validation schemas
└── styles/             # Tailwind input CSS
ā”œā”€ā”€ views/              # EJS Templates for MVC views (Welcome & Password Reset)
ā”œā”€ā”€ public/             # Static assets (Compiled CSS & Uploaded images)

ā šŸš€ Getting Started

⁠🐳 Run with Docker

Launch the entire environment (API + Database) with a single command:

docker-compose up -d
ā šŸ’» Local Development
npm run dev  # Start API only
npm run mvc  # Start API + Tailwind + Views

ā šŸ‘Øā€šŸ’» Connect with Me


Developed with precision by Hossam Gouda
Front-End Engineer focused on building scalable and maintainable user interfaces.

Tag summary

Content type

Image

Digest

sha256:3e7dd1614…

Size

72.1 MB

Last updated

4 months ago

docker pull hossamgezo/bookstore-api:v2