This project consists of multiple microservices, each handling specific functionality within the system. The services include User Service, Product Service, Order Service, and GraphQL Gateway. Each microservice is containerized using Docker and communicates with other services via HTTP APIs.
- Microservices Overview
- Features
- Technologies Used
- Prerequisites
- Getting Started
- Microservices List
- REST API Endpoints
- GraphQL API
- Postman Collection
- License
- User Service: Handles user registration, authentication, and user management.
- Product Service: Manages product creation, updates, and listings.
- Order Service: Manages customer orders, including order creation and retrieval.
- GraphQL Gateway: A single API gateway that interacts with all microservices and exposes a unified GraphQL API to the clients.
- User Management: Register, authenticate, and fetch users.
- Product Management: Add, update, fetch, and list products.
- Order Management: Place orders, fetch orders by ID, and list all orders.
- GraphQL API: Centralized API to access all services via GraphQL.
- Go (Golang): Backend for all microservices.
- Kafka: As a event stream for stream management.
- PostgreSQL: For persistent data storage.
- GraphQL: API for flexible data querying.
- JWT: For secure authentication and authorization.
- Docker: For containerization and managing microservices.
Ensure the following are installed:
- Docker: Version 19 or later.
To start the entire system:
-
Clone the repository:
git clone https://github.com/hari134/pratilipi.git cd pratilipi
-
Build and run the services:
docker compose up --build
-
Create the kafka topics:
docker exec -it kafka /bin/bash kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic user-registered kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic product-created kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic order-placed kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic inventory-updated
-
Access the GraphQL Playground at http://localhost:8084.
- User Service: Accessible at port
8081
, responsible for user-related operations. - Product Service: Accessible at port
8082
, manages product information. - Order Service: Accessible at port
8083
, manages order processing. - GraphQL Gateway: Accessible at port
8084
, consolidates all services under one API.
Below are the REST API endpoints exposed by each microservice:
-
User Service (port
8081
):POST /users/register
: Register a new user.POST /users/login
: Authenticate a user.GET /users/{id}
: Fetch user details by ID.GET /users
: Fetch All users.
-
Product Service (port
8082
):POST /products
: Create a new product.GET /products/{id}
: Fetch product details by ID.GET /products
: List all products.
-
Order Service (port
8083
):POST /orders
: Create a new order.GET /orders/{id}
: Fetch order details by ID.GET /orders
: List all orders.
The GraphQL API supports:
- User Queries: Register, login, and fetch user data.
- Product Queries: Create, update, and fetch product information.
- Order Queries: Place orders, fetch orders by ID, and list all orders.
You can test the APIs with the following Postman collection:
- To interact with the GraphQL services, you need to register a user and then log in using the User Service to obtain a JWT token.
- After logging in, include the JWT token in the Authorization header of subsequent GraphQL requests.
- The
registerUser
mutation is the only GraphQL operation that does not require theAuthorization
header.
This project is licensed under the MIT License.