How niezgodam/e-commerce works
Project type and purpose
• This is a full-stack, event-driven e-commerce platform.
• Frontend: React + TypeScript SPA.
• Backend: A suite of Spring Boot microservices (auth, cart, catalog, delivery, inventory, order, payment, user) plus an API Gateway.
• Communication: HTTP/REST via API Gateway, asynchronous domain events over Apache Kafka, and reliable delivery via the outbox pattern.
High-level architectural components
a. Client / Frontend
• React SPA served on port 80/3000 (calls API Gateway).
b. API Gateway
• Single entry point (JWT filter, routing to downstream services).
c. Microservices
• auth-service, cart-service, catalog-service, delivery-service, inventory-service, order-service, payment-service, user-service.
• Each service owns its own database (Flyway migrations) and uses “shared-outbox” for atomic event publication.
• Each service has synchronous controllers (REST), synchronous clients (in API Gateway / other services), plus asynchronous Kafka listeners & producers.
d. Event Bus
• Apache Kafka cluster (topics defined in shared-kafka).
• Shared-events library defines common event types.
e. Shared Libraries
• shared-events (domain event classes)
• shared-outbox (outbox persistence/poller)
• shared-kafka (topic & group definitions)
• shared-jwt (JWT utility)
f. Databases
• One relational database per microservice (PostgreSQL or MySQL – configured via application.properties).
• Outbox tables per service for reliable event publication.
g. External services
• Stripe for payment processing (configured in payment-service via StripeConfig).
Relationships and interactions
• User actions in browser → HTTP(S) → API Gateway → appropriate microservice’s REST controller.
• Inside a service: business logic writes to local database + writes an outbox record in same transaction.
• OutboxPoller (shared-outbox) picks up pending outbox entries and publishes to Kafka.
• Other services subscribe to topics via KafkaListeners and react by updating their own state or producing further events.
• Services may call each other synchronously via Feign/RestTemplate clients (e.g., API Gateway calling CartClient, OrderClient).
• JWT issued by auth-service, validated in API Gateway and downstream filters.
• Payment service interacts with Stripe API synchronously for payment initiation.
Architectural patterns and design principles
• Microservices with bounded contexts per business domain (Cart, Catalog, Order, etc.).
• Event-driven architecture using Kafka for decoupling and eventual consistency.
• Outbox pattern to guarantee atomic DB + event write.
• API Gateway pattern for authentication, routing, cross-cutting concerns.
• Shared libraries to avoid duplication (events, JWT, Kafka metadata, outbox mechanics).
• Each service is independently deployable, horizontally scalable, and owned data/store.
• Modular layout:
• Row 1: Client & API Gateway
• Row 2: Microservices (auth, user, catalog, inventory, cart, order, payment, delivery)
• Row 3: Kafka cluster, Databases, External Stripe