This repository contains the architecture and implementation of a BookStore application built using a microservices approach. The application consists of three main services: API Gateway, User Service, and Book Service, along with supporting services like Cassandra and Elasticsearch.
-
API Gateway
- Purpose: Acts as a single entry point for all client requests. It routes requests to the appropriate microservices.
- Port: Exposes port
8080
. - Dependencies: Depends on both the User Service and Book Service.
-
User Service
- Purpose: Manages user-related operations, including registration, authentication, and user profile management.
- Port: Exposes port
8081
.
-
Book Service
- Purpose: Handles operations related to books, such as creating, updating, deleting, and retrieving book information.
- Port: Exposes port
8082
. - Dependencies: Depends on Cassandra for data storage and Elasticsearch for searching capabilities.
-
Cassandra
- Purpose: Serves as the primary database for storing book information.
- Image: Uses the official
cassandra
Docker image. - Port: Exposes port
9042
. - Configuration:
- Cluster Name:
BookStoreCluster
- Data Center:
dc1
- Replication Factor:
1
- Cluster Name:
-
Elasticsearch
- Purpose: Provides search capabilities for the Book Service.
- Image: Uses the official
elasticsearch
Docker image. - Port: Exposes port
9200
. - Configuration:
- Discovery Type:
single-node
- Elastic Password: (set to a secure password)
- Discovery Type:
All services are connected through a Docker network named microservices-network
. This allows them to communicate with each other using their service names as hostnames.
- Docker and Docker Compose installed on your machine.
- Basic knowledge of Go programming language.
-
Clone the repository:
git clone https://github.com/NHadi/GoBookStore.git cd GoBookStore
-
Build and run the services using Docker Compose:
docker-compose up --build
-
Access the services:
- API Gateway:
http://localhost:8080
- User Service:
http://localhost:8081
- Book Service:
http://localhost:8082
- Cassandra: Connect using a CQL client to
cassandra:9042
. - Elasticsearch: Access at
http://localhost:9200
.
- API Gateway:
The Book Service exposes the following endpoints:
- Create Book:
POST /books
- Get Books:
GET /books
- Update Book:
PUT /books/{id}
- Delete Book:
DELETE /books/{id}
- Borrow Book:
POST /books/borrow/{userId}/{bookId}
You can explore these endpoints using tools like Postman or Swagger.
To check the health of the Book Service, access:
GET /health
This endpoint returns a simple "Healthy" message if the service is running correctly.
Contributions are welcome! If you have suggestions for improvements or find bugs, feel free to create an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Gorilla Mux for routing in Go.
- Swagger for API documentation.
- Cassandra for data storage.
- Elasticsearch for search functionality.
For support or inquiries, please contact:
- Name: Nurul Hadi
- Email: [email protected]