E-commerce system developed with microservices architecture for product inventory management and sales, implementing asynchronous communication and JWT authentication.
The system consists of 4 main microservices:
- Single entry point for all requests
- Intelligent routing to microservices
- Rate limiting and caching
- Implemented with Ocelot
- User authentication and authorization
- JWT token generation and validation
- User management (Client and Manager)
- Password encryption with BCrypt
- Sales order management
- Stock validation before confirmation
- Asynchronous communication with stock service
- Sales status control (Pending, Confirmed, Canceled, Unauthorized)
- Product and inventory management
- Available and reserved quantity control
- Stock reservation and release processing
- Product CRUD operations
- .NET 8: Main framework
- Entity Framework Core: ORM for data access
- MySQL: Relational database
- RabbitMQ: Message broker for asynchronous communication
- MassTransit: Library for RabbitMQ abstraction
- JWT: Authentication and authorization
- Ocelot: API Gateway
- BCrypt.NET: Password encryption
- Serilog: Logging system
- Docker & Docker Compose: Containerization
- xUnit: Unit testing framework
- Bogus: Test data generation
The system uses asynchronous events via RabbitMQ:
- SaleCreated β StockService reserves stock
- SaleItemsReservedResponse β SalesService confirms the sale
- SaleConfirmed β StockService removes from stock
- SaleCanceled β StockService releases reserved stock
SaleCreated: New order createdSaleItemsReservedResponse: Items successfully reservedSaleCreationFailed: Sale creation failureSaleConfirmed: Sale confirmedSaleCanceled: Sale canceledStockReleased: Stock releasedStockCanceled: Stock cancellation
- Client: Can make purchases and check their orders
- Manager: Can manage products, inventory, and create new managers
POST /auth/login- User loginPOST /auth/register/user- Client registrationPOST /auth/register/manager- Manager registration (requires Manager authentication)
- New product registration
- Product information updates
- Product and price queries
- Available and reserved stock queries
- Item reservation and release
- Stock removal
- Order creation
- Order history queries
- Pending order cancellation
- Docker
- Docker Compose
- Clone the repository:
git clone https://github.com/Alekssandher/ECommerce-Microservices/
cd ECommerce-Microservices- Build and run the containers:
docker-compose up --build- Wait for services to be ready:
- MySQL: Port 3306
- RabbitMQ: Ports 5672 (AMQP) and 15672 (Management UI)
- API Gateway: Port 5001
- API Gateway: http://localhost:5001
- RabbitMQ Management: http://localhost:15672 (guest/guest)
- AuthService: http://localhost:5004
- SalesService: http://localhost:5002
- StockService: http://localhost:5003
POST /auth/login
POST /auth/register/user
POST /auth/register/manager (Manager only)GET /products # List products
GET /products/{productId} # Get product
POST /products # Create product (Manager only)
PUT /products # Update product (Manager only)GET /stock/{productId} # Get stock (Manager only)
GET /stock/{productId}/available # Get available stock (Manager only)
POST /stock/{productId}/reserve/{quantity} # Reserve stock (Manager only)
POST /stock/{productId}/release/{quantity} # Release stock (Manager only)
DELETE /stock/{productId}/remove/{quantity} # Remove stock (Manager only)GET /sales/{id} # Get sale (Client only)
PATCH /sales/{id} # Update sale (Client only)
DELETE /sales/{id} # Cancel sale (Client only)The project includes comprehensive unit tests for:
- Mappers
- Models
- Services
dotnet test- AuthService: Models, JWT services, and mappers
- SalesService: Models, sales services, and mappers
- StockService: Models, product/stock services, and mappers
βββ AuthService/ # Authentication microservice
βββ Services/
β βββ SalesService/ # Sales microservice
β βββ StockService/ # Stock microservice
βββ Gateway/ # API Gateway
βββ Shared/ # Shared libraries
β βββ Extensions/ # Extensions for JWT, RabbitMQ, etc.
β βββ Messages/ # Communication events
β βββ Middlewares/ # Global exception middleware
β βββ ModelViews/ # DTOs and standardized responses
βββ ECommerce-Microservices.Tests/ # Test projects
βββ docker-compose.yml # Docker configuration
βββ README.md
Each microservice has its own database:
users_auth_service: User and authentication datasales_micro_service: Sales and order datastock_micro_service: Product and inventory data
- Serilog: Structured logging for all services
- Health Checks:
/healthendpoint in each service - RabbitMQ Management: Web interface for queue monitoring
- JWT authentication with symmetric keys
- Role-based authorization (Client/Manager)
- Password encryption with BCrypt
- Rate limiting in API Gateway
- Input validation on all endpoints
- Separation of Concerns: Each microservice has a single responsibility
- Event-Driven Architecture: Asynchronous communication via events
- Exception Handling: Global middleware for exception handling
- Logging: Structured logs in all services
- Testing: Comprehensive unit test coverage
- Containerization: Fully dockerized application
- Database per Service: Each microservice with its own database
- Fork the project
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for more details.
For questions or support, please contact through GitHub issues.