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.
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.
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.
-
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 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. |
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
- Node.js v18+
- NestJS CLI (
npm i -g @nestjs/cli) - AWS account with configured credentials
- DynamoDB Table and S3 Bucket created
git clone https://github.com/Zaiidmo/eBooks-API.git
cd eBooks-API
npm install
cp .env.example .envcp .env.example .envUpdate the newly created .env file with proper variables
npm run start:devnpm run build
npm run start:prodnpm test
npm run test:cov| 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 |
| Method | Endpoint | Description |
|---|---|---|
| POST | /books/:id/borrow |
Borrow a book |
| POST | /books/:id/return |
Return a book |
| Method | Endpoint | Description |
|---|---|---|
| GET | /books/statistics |
Retrieve usage metrics |
Stages:
- Build:
npm ci && npm run build - Test: Executes automated test suite
- Dockerize: Builds and tags Docker image
- Deploy: Pushes to EC2 or ECR via Jenkins agents
- Monitor: Tracks metrics via AWS CloudWatch
| 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 |
The corresponding Frontend Application (handling Cognito authentication and user interaction) is available here:
π eBooks Frontend
Contributions are welcome!
To propose an improvement or fix, please open a pull request or issue.
π§ Contact: [email protected]
Licensed under the MIT License.
Β© 2025 β Crafted by TheVlpha. Youβll know when you see it.