Skip to content

Zaiidmo/eBooks-API

πŸ“š Books Service API

The Books Service API is a core backend microservice within the eBooks Application, built with NestJS and deeply integrated into AWS Cloud Infrastructure.
It manages all book-related operations β€” from catalog management to user borrowing, returning, and analytics β€” while maintaining security, scalability, and seamless communication between microservices.


πŸš€ Overview

This service powers the library and catalog domain of the eBooks ecosystem.
Every request from users passes securely through the AWS API Gateway, which validates Cognito-issued JWT tokens before routing traffic to backend microservices such as Books, Auth, and others.

This architecture ensures a fully managed, cloud-native, and secure workflow β€” combining serverless authentication, dynamic scaling, and real-time monitoring.


πŸ” Authentication Flow

All user requests are authenticated using AWS Cognito and validated through API Gateway Authorizers before reaching this service.

User β†’ AWS Cognito (login/signup) β†’ Token (JWT)
     ↓
AWS API Gateway (Authorizer + Routing)
     ↓
Books Service (NestJS + DynamoDB + S3)

🧭 The Books Service API itself doesn’t handle authentication logic. It trusts the identity verified by Cognito via API Gateway.


✨ Core Features

  • Librarian Operations

    • Create, update, delete, and fetch books.
    • Upload and manage book covers with AWS S3.
    • Manage catalog data stored in DynamoDB.
  • User Operations

    • Borrow and return books.
    • Token validation and authorization through API Gateway and Cognito.
  • Statistics & Insights

    • Generate data insights on book borrowing and user engagement.
  • Scalability & Monitoring

    • Built for performance using DynamoDB and CloudWatch for observability.
  • Microservice Architecture

    • Fully managed through AWS API Gateway, secured with IAM roles.

🧩 AWS Services Overview

AWS Service Purpose
Cognito Handles authentication and user identity (JWT issuance).
API Gateway Entry point for all client requests; validates Cognito tokens and routes to microservices.
DynamoDB Stores all book and borrowing data with scalable performance.
S3 Stores and retrieves book cover images and media files.
CloudWatch Collects logs, tracks metrics, and monitors API performance.
CloudFront Distributes static assets for frontend and improves latency.
IAM Manages permissions between AWS services and microservices.

🧠 Architecture Overview

src/
β”œβ”€β”€ app.module.ts              # Root module configuration
β”œβ”€β”€ books/                     # Books domain logic
β”‚   β”œβ”€β”€ dto/                   # DTOs for book operations
β”‚   β”œβ”€β”€ entities/              # Book schema definitions
β”‚   β”œβ”€β”€ books.controller.ts    # REST endpoints
β”‚   β”œβ”€β”€ books.service.ts       # Core business logic
β”‚   β”œβ”€β”€ books.repository.ts    # DynamoDB data layer
β”‚   └── books.module.ts        # Module setup
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ dynamodb.config.ts     # DynamoDB client setup
β”‚   β”œβ”€β”€ s3.config.ts           # S3 configuration
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ s3.service.ts          # File handling & uploads
β”‚   β”œβ”€β”€ app.controller.ts
β”‚   └── app.service.ts
β”œβ”€β”€ main.ts                    # Application entry point
└── test/                      # Jest tests

βš™οΈ Setup & Installation

Prerequisites

  • Node.js v18+
  • NestJS CLI (npm i -g @nestjs/cli)
  • AWS account with configured credentials
  • DynamoDB Table and S3 Bucket created

Installation

git clone https://github.com/Zaiidmo/eBooks-API.git
cd eBooks-API
npm install
cp .env.example .env

Configure environment variables:

cp .env.example .env

Update the newly created .env file with proper variables


πŸ§ͺ Running & Testing

Development

npm run start:dev

Production

npm run build
npm run start:prod

Testing

npm test
npm run test:cov

πŸ”Œ API Endpoints

Librarian Routes

Method Endpoint Description
POST /books Add a new book
PUT /books/:id Update book details
DELETE /books/:id Delete a book
GET /books List all books
GET /books/:id Get book details

User Routes

Method Endpoint Description
POST /books/:id/borrow Borrow a book
POST /books/:id/return Return a book

Statistics

Method Endpoint Description
GET /books/statistics Retrieve usage metrics

🧱 CI/CD Pipeline (Jenkins)

Stages:

  1. Build: npm ci && npm run build
  2. Test: Executes automated test suite
  3. Dockerize: Builds and tags Docker image
  4. Deploy: Pushes to EC2 or ECR via Jenkins agents
  5. Monitor: Tracks metrics via AWS CloudWatch

🧰 Tech Stack

Layer Technology
Language TypeScript
Framework NestJS
Database AWS DynamoDB
Storage AWS S3
Auth Flow Cognito + API Gateway Authorizer
Monitoring AWS CloudWatch
Delivery AWS CloudFront
CI/CD Jenkins + Docker + EC2

🌐 Related Repository

The corresponding Frontend Application (handling Cognito authentication and user interaction) is available here:
πŸ‘‰ eBooks Frontend


πŸ§‘β€πŸ’» Contributing

Contributions are welcome!
To propose an improvement or fix, please open a pull request or issue.
πŸ“§ Contact: [email protected]


πŸͺͺ License

Licensed under the MIT License.
Β© 2025 β€” Crafted by TheVlpha. You’ll know when you see it.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published