This project is a microservices-based e-commerce platform using Node.js, TypeScript, GraphQL, MongoDB, and Kafka.
- Prerequisites
- Project Structure
- Installation
- Configuration
- Running the Application
- Development
- API Documentation
- Troubleshooting
Ensure you have the following installed on your system:
- Node.js (v18 or later)
- Docker and Docker Compose
- Git
├── apps
│ ├── graphql-gateway
│ ├── order-service
│ ├── product-service
│ └── user-service
├── packages
│ ├── eslint-config
│ ├── shared
│ ├── typescript-config
│ └── ui
├── docker-compose.yml
├── package.json
└── README.md
- Clone the repository:
git clone https://github.com/Pheewww/microservices-backend
cd microservices-backend
- Set up environment variables:
- Copy the
.env.example
file in each service directory to.env
- Update the
.env
files with your specific configuration
- Update Graphql configuration:
- change graphql service env as per your designed ports for each service
-
Start the application using Docker:
docker-compose up --build
. This command will build the Docker images and start all the services. -
The ( Default ) services will be available at:
- GraphQL Gateway: http://localhost:4000
- User Service: http://localhost:3001
- Product Service: http://localhost:3002
- Order Service: http://localhost:3003
To run the application in development mode:
- In root dir,
npm install
thennpm run build
to build all services. - Then start the services:
npm run dev
- To run a specific service:
cd <service-directory>
thennpm run build
thennpm run dev
Replace <service-name>
with graphql-gateway, user-service, product-service, or order-service.
use backendApis.postman_collection.json
file
Create User
mutation RegisterUser {
registerUser(
input: {
name: "john doww"
email: "[email protected]"
password: "secure11"
role: "admin"
}
) {
name
email
role
token //copy it if user is admin
id
}
}
Get User by ID
user(id: "670504d3ff2ee3e8e456ccb4") {
name
email
role
}
}
Get All Users
query Users {
users {
name
email
role
}
}
Update User Profile
mutation UpdateUserProfile {
updateUserProfile(
id: "6705261cd87d7e3cd63b1c10"
name: "john doeee"
email: "[email protected]"
) {
id
name
email
}
}
Get All Products
query Product {
products {
productId
name
price
stock
createdAt
}
}
Get Product by ID
query Product {
product(id: "6705111ae8b42dfc570afe15") {
productId
name
price
stock
createdAt
}
}
Create Product (ADMIN ONLY, needs token)
// Send Copied Token as Auth Header
mutation PlaceOrder {
createProduct(
input: { productId: 122222, name: "asdas", price: 100, stock: 1000 }
) {
productId
name
price
stock
createdAt
}
}
Place an Order
mutation PlaceOrder {
placeOrder(
input: {
orderId: 1222
userId: "6705261cd87d7e3cd63b1c10"
productId: 123
quantity: 10
}
) {
orderId
userId
productId
quantity
createdAt
status
}
}
Place an Order
mutation PlaceOrder2 {
placeOrder(input: { orderId: 444, userId: "userId", productId: 123, quantity: 10 }) {
orderId
userId
productId
quantity
createdAt
status
}
}
Get All Orders
query Orders {
orders {
orderId
userId
productId
quantity
createdAt
status
}
}
Get Order by ID
query Order {
order(id: "67052a245e1cf09a57aab44a") {
orderId
userId
productId
quantity
createdAt
status
}
}
support for update product and update order is not at present, they are in postman apis at present
- GraphQL API: Access the GraphQL Playground at http://localhost:4000/graphql when the application is running.
-
If you encounter connection issues with MongoDB Atlas, ensure your IP address is whitelisted in the Atlas dashboard.
-
For Kafka connection issues, check if the Kafka service is running and the broker addresses are correct in your service configurations.
-
If a service fails to start, check the Docker logs: