This Order Management System is a microservices-based application βοΈ designed to streamline e-commerce operations. It focuses on efficiently managing products π¦, inventory Stockπ, orders ποΈ, and payments π³. The system is built with user authentication π, supporting both vendor π§βπΌ and customer π§βπ§βπ€βπ§ roles. It leverages asynchronous task processing β±οΈ for improved performance and scalability βοΈ. Designed to be cloud-native π, it utilizes Docker π³ for containerization and Consul π§ for service discovery.
The system is composed of distinct microservices, each handling a specific domain:
-
Gateway Service πͺ:
- Serves as the single entry point for all external API requests π¦.
- Manages HTTP routing using Gin π€οΈ.
- Enforces authentication and authorization via middleware π‘οΈ.
- Implements rate limiting using Redis to ensure API stability β³.
- Provides comprehensive API documentation with Swagger π.
- Communicates with backend services using gRPC π£οΈ.
-
Auth Service π‘οΈ:
- Handles all aspects of user authentication and authorization π.
- Manages user registration π, login β , logout πͺ, and secure password management (resetting and forgotten passwords π).
- Generates and rigorously verifies JWT tokens for both access and refresh tokens ποΈ.
- Manages distinct user roles: customer and vendor π§βπΌπ§βπ§βπ€βπ§.
- Persistently stores user data in MongoDB πΎ.
- Publishes critical user-related events to RabbitMQ for asynchronous processing (e.g., user registration, account activation, password resets βοΈ).
-
Product Service π¦:
- Manages the entire product catalog and detailed product information βΉοΈ.
- Empowers vendors to create β, update βοΈ, delete ποΈ, and list products π.
- Stores all product-related information in MongoDB πΎ.
- Dispatches product-related events via RabbitMQ (e.g., product creation, updates, deletions π’).
-
Inventory Service Stockπ:
- Precisely manages product inventory levels π.
- Enables vendors to efficiently create β, update βοΈ, delete ποΈ, and retrieve inventory details for their products π¦.
- Stores inventory data securely in MongoDB πΎ.
-
Order Service ποΈ:
- Oversees the complete order lifecycle: creation β, retrieval π, and cancellation β.
- Calculates order totals accurately and manages order statuses effectively π.
- Stores comprehensive order information in MongoDB πΎ.
- Broadcasts order-related events using RabbitMQ (e.g., order creation, cancellation, successful payments π’).
-
Payment Service π³:
- Facilitates secure payment processing using Stripe π°.
- Generates unique payment links for each order π.
- Processes real-time webhook events from Stripe for immediate payment confirmations and notifications of failures π.
- Interacts with Auth, Product, and Order services via high-performance gRPC π£οΈ.
- Subscribes to relevant order and product events from RabbitMQ to orchestrate payment workflows and maintain data synchronization with Stripe π.
- Sends timely email notifications for order confirmations and cancellations through the Mailer service βοΈ.
-
Mailer Service βοΈ:
- Dedicated to sending emails for crucial events: user registration, account activation, password resets, and order confirmations π§.
- Utilizes Mailpit for efficient local email testing and SMTP for reliable real email delivery π§ͺβ‘οΈπ€.
- Subscribes to user-related events from RabbitMQ to trigger automated email sending processes π¬.
The Order Management System is packed with features, including:
-
User Authentication and Authorization π:
- Streamlined user registration and secure account activation via email verification π§β .
- Secure user login and logout with JWT-based authentication ππͺ.
- Role-Based Access Control (RBAC) to manage permissions for customers and vendors π§βπΌπ§βπ§βπ€βπ§.
- Password recovery and reset functionalities for account security π.
- Refresh token mechanism for seamless access token renewal and persistent sessions π.
-
Product Management π¦:
- Vendors can easily add new products with comprehensive details: name, description, category, and price β.
- Vendors have full control to update and remove their listed products βοΈποΈ.
- Vendors can efficiently list and manage their product offerings with pagination support πβ‘οΈ.
-
Inventory Management Stockπ:
- Vendors can precisely control inventory levels, setting available and threshold quantities for each product π.
- Real-time inventory updates triggered by order placements and cancellations ensure accuracy π.
-
Order Management ποΈ:
- Customers can create orders with multiple items, potentially from various vendors, in a single transaction π.
- Orders are initiated in a "pending" status and transition to "paid" upon successful payment processing β³β‘οΈβ .
- Customers can conveniently view their order details and cancel orders that are still pending πβ.
- Unique payment links are dynamically generated for each order using Stripe for secure checkout ππ³.
- Real-time webhook handling for Stripe payment events ensures immediate order status updates and accurate records ππ.
-
Payment Processing π³:
- Seamless integration with Stripe for secure and reliable payment processing π€π°.
- Automated generation of Stripe Payment Links simplifies the checkout process for customers π.
- Robust handling of Stripe webhook events keeps order statuses synchronized with payment events ππ.
- Supports order cancellations and efficient payment refunds when necessary ββ©οΈ.
-
Email Services βοΈ:
- Automated email notifications for user registration and account activation guide new users π§β .
- Password reset email functionality ensures users can recover access to their accounts securely π§π.
- Order confirmation and cancellation emails keep customers informed about their transactions π§ποΈβ.
-
Monitoring and Tracing π:
- Distributed tracing with Jaeger provides deep insights into request flows across all services, aiding in monitoring and debugging π.
- Centralized logging across all services using Logrus for efficient issue tracking and system analysis πͺ΅.
- Health check endpoints for every service enable proactive monitoring and ensure system health π©Ί.
-
Service Discovery and Configuration π§:
- Consul facilitates dynamic service registration and discovery, enabling services to locate and communicate with each other automatically ππ£οΈ.
- Environment variable-based configuration ensures flexibility and easy deployment across different environments βοΈ.
-
API Security and Rate Limiting π‘οΈβ³:
- JWT-based authentication secures all API endpoints, protecting against unauthorized access π.
- Rate limiting middleware in the Gateway service safeguards against abuse and ensures fair usage π¦.
-
API Documentation π:
- Swagger documentation for the Gateway API provides interactive, up-to-date API exploration and integration resources for developers π.
To run the Order Management System using Docker Compose, ensure you have Docker and Docker Compose installed on your machine.
-
Clone the repository:
git clone <repository_url> cd <repository_directory>
-
Environment Variables:
- Ensure you have configured all necessary environment variables. Example
.env
files are provided in each service directory (e.g.,.envs/auth/.env.example
). - Copy
.env.example
files to.env
and modify the values as needed for your setup. - Pay special attention to database connection strings, RabbitMQ and Redis URIs, Stripe secrets, and JWT secrets.
- Ensure you have configured all necessary environment variables. Example
-
Start the services with Docker Compose:
docker-compose up --build -d
This command builds all the Docker images and starts all services in detached mode.
-
Access the applications:
- Gateway Service & Swagger UI:
http://localhost:8080/api/v1/swagger/index.html
- Mailpit UI:
http://localhost:8025
- RabbitMQ Management UI:
http://localhost:15672
(default credentials areguest:guest
) - Jaeger UI:
http://localhost:16686
- Consul UI:
http://localhost:8500
- mongo-express UI:
http://localhost:8081
- Gateway Service & Swagger UI:
-
Stop the services:
docker-compose down
- Backend Services: Go
- API Gateway Framework: Gin
- Inter-service Communication: gRPC
- Message Broker: RabbitMQ
- In-memory Data Store: Redis
- Database: MongoDB
- Payment Processing: Stripe
- Service Discovery: Consul
- Distributed Tracing: Jaeger
- Email Testing: Mailpit
- Containerization: Docker
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit pull requests, report issues, or suggest new features to improve Gopher Social Backend.