A full-stack backend service built with TypeScript, Express.js, GraphQL, PostgreSQL, and Redis. This API allows users to manage a collection of books and their reviews. It implements caching with Redis and follows a modular, scalable architecture using TypeORM for database interaction.
- Add and fetch books with reviews using GraphQL
- PostgreSQL database with TypeORM
- Redis caching for optimized reads
- Structured error handling and logging
- Unit and integration testing with Jest
- Flexible GraphQL schema with
express-graphql
- Type-safe, production-ready backend using TypeScript
Layer | Technology |
---|---|
Runtime | Node.js, TypeScript |
Framework | Express.js |
Database | PostgreSQL with TypeORM |
Caching | Redis |
API Layer | GraphQL |
Testing | Jest |
Dev Tools | Docker, ts-node, nodemon |
git clone https://github.com/your-username/Book_Review_Backend.git
cd Book_Review_Backend
npm install
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=yourPassword
DB_NAME=book_review
PostgreSQL
docker run --name book-review-db -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=book_review -p 5432:5432 -d postgres
Redis
docker run --name book-review-redis -p 6379:6379 -d redis
Then run :
docker ps
npm run typeorm -- migration:generate src/migrations/InitSchema --dataSource src/ormconfig.ts
npm run typeorm -- migration:run --dataSource src/ormconfig.ts
npm run dev
GraphQL playground will be available at:
http://localhost:4000/graphql
1. Get all books
query {
books {
id
title
author
reviews {
id
content
}
}
}
2. Add a book
mutation {
addBook(title: "1984", author: "George Orwell") {
id
title
author
}
}
3. Add a review
mutation {
addReview(bookId: 1, content: "Amazing read") {
id
content
bookId
}
}
4. Get reviews of a book
query {
reviews(bookId: 1) {
id
content
}
}
npm test
- Name -: Akshat Sharma
- Email -: akshatsharma0610@gmail.com