# henriquesaki/cart-purchase architecture

> Architecture diagram of the GitHub repository henriquesaki/cart-purchase, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/henriquesaki/cart-purchase
- Repository: https://github.com/henriquesaki/cart-purchase

## Overview

##### 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)

## Diagram (Mermaid)

```mermaid
flowchart TB
    classDef internal fill:#D0E8FF,stroke:#0366D6
    classDef external fill:#F0F0F0,stroke:#666666
    classDef db fill:#E2F0D9,stroke:#2E7D32,stroke-width:2px
    classDef broker fill:#FFE0B2,stroke:#EF6C00

    Client["API Consumer"]:::external

    subgraph "Cart-Purchase Microservice"
        cpApp["CartPurchaseApplication"]:::internal

        subgraph "Controller Layer"
            apiInt["CartPurchaseApi"]:::internal
            cpController["CartPurchaseController"]:::internal
        end

        subgraph "Service Layer"
            cpServiceInt["CartPurchaseService"]:::internal
            cpServiceImpl["CartPurchaseServiceImpl"]:::internal
        end

        subgraph "Repository Layer"
            cpRepo["CartPurchaseRepository"]:::internal
        end

        swagger["Swagger UI\n(/api/v1/swagger-ui)"]:::internal

        subgraph "Configuration"
            appYaml["application.yaml"]:::internal
            envConf["env.conf"]:::internal
        end
    end

    SQL["SQL Server"]:::db
    RMQ["RabbitMQ Broker"]:::broker
    emailWorker["Email Worker"]:::external
    mailSvc["SMTP Mail Server"]:::external

    Client -->|"HTTP POST/GET/DELETE\n/api/v1/cart"| cpController
    cpController -->|"calls"| cpServiceImpl
    cpServiceImpl -->|"JPA query"| cpRepo
    cpRepo -->|"reads/writes"| SQL
    cpServiceImpl -->|"AMQP publish\nOrderPlaced"| RMQ
    RMQ -.->|"consume OrderPlaced"| emailWorker
    emailWorker -->|"SMTP send"| mailSvc
    Client -->|"view API docs"| swagger
    envConf -.-> cpApp
    appYaml -.-> cpApp

    click cpApp "https://github.com/henriquesaki/cart-purchase/blob/develop/src/main/java/br/com/cartpurchase/CartPurchaseApplication.java"
    click apiInt "https://github.com/henriquesaki/cart-purchase/blob/develop/src/main/java/br/com/cartpurchase/controller/CartPurchaseApi.java"
    click cpController "https://github.com/henriquesaki/cart-purchase/blob/develop/src/main/java/br/com/cartpurchase/controller/CartPurchaseController.java"
    click cpServiceInt "https://github.com/henriquesaki/cart-purchase/blob/develop/src/main/java/br/com/cartpurchase/service/CartPurchaseService.java"
    click cpServiceImpl "https://github.com/henriquesaki/cart-purchase/blob/develop/src/main/java/br/com/cartpurchase/service/CartPurchaseServiceImpl.java"
    click cpRepo "https://github.com/henriquesaki/cart-purchase/blob/develop/src/main/java/br/com/cartpurchase/repository/CartPurchaseRepository.java"
    click appYaml "https://github.com/henriquesaki/cart-purchase/blob/develop/src/main/resources/application.yaml"
    click envConf "https://github.com/henriquesaki/cart-purchase/blob/develop/conf/env.conf"
```
