How seastarlxy/ecommercesystem-microservices works
Project Type and Purpose
• This is a microservices‐based e-commerce backend (UserService as one of the services) written in C++20, employing asynchronous gRPC (wrapped by CallData) and REST via an Envoy API Gateway. It follows Domain-Driven Design (DDD) and layered architecture to deliver high performance, extensibility, and scalability.
Main Components
a. External Clients
• Web/mobile clients or other services making RESTful/HTTP requests.
b. API Gateway (Envoy)
• envoy.yaml handles inbound REST calls, translates to gRPC (via googleapis REST→gRPC transcoding).
c. UserService Microservice
• gRPC Server: server/user_service_server.*
• CallData Adapters (v1 & v2): asynchronous gRPC request handlers (adapter/*)
• Service Layer: service/* – business facades (AuthService, BasicUserService)
• Domain Layer: domain/* – domain entities (User), repository interfaces
• Infrastructure Layer:
• Persistence: PostgreSQL async pool (infrastructure/persistence/postgresql/*), DAOs (.../dao)
• State Storage: Redis client (infrastructure/state_storage/redis_dao/*)
• Threading: Asio thread pool (infrastructure/asio_thread_pool/*)
• Utilities: verification code generator, JWT, bcrypt, logging (spdlog) under utils/*
d. Datastores
• PostgreSQL (persistent user data)
• Redis (verification code/session caching)
e. CI/CD & Build
• GitHub Actions (.github/workflows/ci.yml)
• CMake (UserService/CMakeLists.txt)
• Docker & Docker Compose (envBuild/*)
• vcpkg for dependency management
Component Relationships & Data Flow
1. Client → Envoy API Gateway (REST)
2. Envoy → UserService gRPC endpoint
3. gRPC Server accepts request via CallData adapter →
4. Service Layer invokes Domain logic (entities + repository interfaces) →
5. Infrastructure Layer implements repositories:
• For user records: Async PostgreSQL connection pool → SQL DAOs
• For verification codes: Redis DAO
6. Results bubble back through Service → CallData → gRPC → Envoy → Client
7. Utilities (e.g., code generator, JWT) are invoked within Service/Domain as needed
Architectural Patterns & Principles
• Layered (Presentation/Adapter → Service → Domain → Infrastructure)
• Domain-Driven Design (rich domain models, repository interfaces)
• Asynchronous gRPC pattern using CRTP‐based CallData with object-pool managers
• Dependency Injection via Boost.DI
• Saga pattern (future work) for distributed transactions
• Containerization (Docker/Kubernetes) for microservices