How henriquesaki/cart-purchase works
Project Type and Purpose
• This is a standalone Spring Boot microservice that implements a simple shopping-cart API.
• Features include adding, listing and removing items in a cart, persisting data in SQL Server, and dispatching an email notification when an order is placed (via RabbitMQ).
File-Structure Analysis
• Top-level:
• conf/env.conf – environment variables (DB connection, RabbitMQ, mail).
• application.yaml – Spring configuration.
• swagger.yaml – API schema.
• pom.xml, Maven wrapper – build/dependency management.
• src/main/java/br/com/cartpurchase:
• controller/CartPurchaseController & API interface – REST entry-points.
• service/CartPurchaseServiceImpl – business logic; interacts with repository and messaging.
• repository/CartPurchaseRepository – Spring Data JPA to SQL Server.
• model + dto – domain entities and data-transfer objects.
• CartPurchaseApplication – Spring Boot bootstrap.
• src/test covers unit tests for controllers, service, DTOs and mocks.
Key Technical Stack (from README)
• Java, Spring Boot
• SQL Server (via Spring Data JPA)
• RabbitMQ (for email event)
• JUnit 5 (tests)
• Swagger UI (API docs)
a. Main Components
1) Client / API Consumer (Postman, UI, other services)
2) Cart-Purchase Microservice (Spring Boot):
• REST Controller layer
• Service layer
• Repository layer
• Configuration (DB, RabbitMQ, mail)
3) SQL Server Database
4) RabbitMQ Broker
5) Email Notification Worker / External Mail Service (SMTP or separate microservice)
6) Swagger UI (embedded in microservice)
b. Relationships and Data Flows
• Client → HTTP POST/GET/DELETE → CartPurchaseController
• Controller → calls → CartPurchaseService
• Service → Repository → SQL Server (reads/writes cart data)
• On “place order” → Service publishes “OrderPlaced” event to RabbitMQ exchange
• Email Worker (could be an internal @RabbitListener or separate service) consumes event → sends email via SMTP
• Client can view API schema via Swagger UI endpoint
c. Architectural Patterns & Principles
• Layered Architecture: Controller → Service → Repository
• Dependency Injection (Spring annotations)
• DTO pattern (separate domain models from API payloads)
• Event-driven decoupling (publish/subscribe via RabbitMQ)
• Externalized configuration (application.yaml + env.conf)
d. Key Technologies & Frameworks
• Spring Boot (Web, Data JPA, AMQP)
• Hibernate (ORM)
• RabbitMQ (message broker)
• SQL Server (persistence)
• Swagger (API documentation)
• JUnit 5 (testing)