# rafaeldsal/ecommerce-service architecture

> Architecture diagram of the GitHub repository rafaeldsal/ecommerce-service, 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/rafaeldsal/ecommerce-service
- Repository: https://github.com/rafaeldsal/ecommerce-service

## Overview

##### Project Type and Purpose
- This is a monolithic backend service—a Spring Boot e-commerce API (“Minha Prata”) that exposes REST endpoints for user, product, order, category, payment, authentication, and order‐history management. It applies clean architecture principles (layered design) and integrates with external systems (MySQL, Redis, Kafka, external CEP and Mail services).

##### File Structure Analysis
- Top-level:
- pom.xml, Docker Compose (MySQL)
- src/main/java/com/rafaeldsal/ws/minhaprata/…
- src/main/resources/application.properties (app config, DB, JWT)
- Layered packages under com/rafaeldsal/ws/minhaprata:
- configuration (security, Kafka, Redis)
- controller (REST endpoints)
- dto (request/response payloads)
- exception (error handling)
- integration (external REST/mail services)
- listener & consumer (Redis expirations, Kafka consumers)
- producer (Kafka producers)
- mapper (DTO↔entity mapping)
- model (JPA entities, Redis models, enums)
- repository (Spring Data JPA + Redis)
- service & service.impl (business logic)
- utils (helper classes)
- Test folder contains unit tests.

##### README Insights
- Describes a layered architecture (configuration, controller, service, repository).
- Uses Java 17, Spring Boot (Web, Data JPA, Security), Flyway, Docker Compose for MySQL, JWT auth.
- Emphasizes clean architecture and SOLID.

##### Diagramming Guidance
a. Main Components
1. API Layer (Controllers)
2. Service Layer (Service interfaces + implementations)
3. Data Layer
– JPA Repositories → MySQL
– Redis Repositories → Redis (caching, recovery codes, pending orders)
4. Integration Layer
– External CEP REST service
– External Mail service
5. Messaging Infrastructure
– Kafka Producer → “payment-intent” topic
– Kafka Consumers → payment status updates, notifications
6. Security Layer
– JWT filter, AuthenticationAspect, SecurityConfig
b. Relationships & Interactions
– HTTP requests → Controllers → Services → Repositories / integration / producers
– Services publish events via KafkaProducer → Kafka topics
– Kafka Consumers listen to topics → update DB or notify clients
– Redis listener reacts to key expirations → invokes business logic
– Controllers secured by SecurityFilter → AuthenticationAspect → JWT validation
c. Architectural Patterns & Principles
– Layered (Presentation, Business, Data)
– Dependency Injection (Spring)
– Publish–Subscribe (Kafka)
– Event-Driven (Kafka + Redis keyspace notifications)
– Clean Architecture (separation of concerns, DTOs, mappers, interfaces)
– SOLID (single responsibility: controllers, services, repositories)
d. Key Technologies
– Spring Boot (Web MVC, DI, Security)
– Spring Data JPA + Flyway → MySQL
– Spring Data Redis
– Spring for Apache Kafka
– JWT (bearer tokens)
– Docker Compose (MySQL container)
– Lombok, MapStruct (for mappers if used), Maven

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["HTTP Client"]:::external
    Client -->|HTTP request| SecurityFilter

    subgraph "Security Layer"
        SecurityFilter["SecurityFilter"]:::security
        AuthAspect["AuthenticationAspect"]:::security
        SecurityConfig["SecurityConfig"]:::security
        AuthenticationController["AuthenticationController"]:::security
    end
    SecurityFilter --> AuthenticationController
    AuthenticationController --> AuthAspect
    AuthAspect --> Controllers

    subgraph "Controller Layer"
        Controllers["UserController, OrderController, etc."]:::internal
    end
    Controllers --> ServicesIface

    subgraph "Service Layer"
        ServicesIface["Service Interfaces"]:::internal
        ServicesImpl["Service Implementations"]:::internal
    end
    click ServicesIface "https://github.com/rafaeldsal/ecommerce-service/tree/main/src/main/java/com/rafaeldsal/ws/minhaprata/service"
    click ServicesImpl "https://github.com/rafaeldsal/ecommerce-service/tree/main/src/main/java/com/rafaeldsal/ws/minhaprata/service/impl"
    ServicesIface --> ServicesImpl

    subgraph "Data Layer"
        subgraph "JPA Repositories"
            JPA["JPA Repositories"]:::internal
        end
        subgraph "Redis Repositories"
            RedisRepo["Redis Repositories"]:::internal
        end
        JPA --> MySQL
        RedisRepo --> Redis
    end
    click JPA "https://github.com/rafaeldsal/ecommerce-service/tree/main/src/main/java/com/rafaeldsal/ws/minhaprata/repository/jpa"
    click RedisRepo "https://github.com/rafaeldsal/ecommerce-service/tree/main/src/main/java/com/rafaeldsal/ws/minhaprata/repository/redis"
    ServicesImpl --> JPA
    ServicesImpl --> RedisRepo

    subgraph "Integration Layer"
        CepIntf["CepIntegration"]:::internal
        CepImpl["CepIntegrationImpl"]:::internal
        MailIntf["MailIntegration"]:::internal
        MailImpl["MailIntegrationImpl"]:::internal
    end
    click CepIntf "https://github.com/rafaeldsal/ecommerce-service/blob/main/src/main/java/com/rafaeldsal/ws/minhaprata/integration/CepIntegration.java"
    click CepImpl "https://github.com/rafaeldsal/ecommerce-service/blob/main/src/main/java/com/rafaeldsal/ws/minhaprata/integration/impl/CepIntegrationImpl.java"
    click MailIntf "https://github.com/rafaeldsal/ecommerce-service/blob/main/src/main/java/com/rafaeldsal/ws/minhaprata/integration/MailIntegration.java"
    click MailImpl "https://github.com/rafaeldsal/ecommerce-service/blob/main/src/main/java/com/rafaeldsal/ws/minhaprata/integration/impl/MailIntegrationImpl.java"
    ServicesImpl --> CepIntf
    CepIntf --> CepImpl
    ServicesImpl --> MailIntf
    MailIntf --> MailImpl
    CepImpl -->|REST| ExternalCEP
    MailImpl -->|REST| ExternalMail

    subgraph "Messaging Infrastructure"
        KafkaProducerConfig["KafkaProducerConfig"]:::config
        PaymentIntentPublisher["PaymentIntentPublisher"]:::messaging
        PaymentIntentPublisherImpl["PaymentIntentPublisherImpl"]:::messaging
        PaymentStatusConsumer["PaymentStatusUpdateConsumer"]:::messaging
        PaymentNotifierConsumer["PaymentStatusNotifierConsumer"]:::messaging
        RedisListener["RedisKeyExpirationListener"]:::messaging
    end
    click KafkaProducerConfig "https://github.com/rafaeldsal/ecommerce-service/blob/main/src/main/java/com/rafaeldsal/ws/minhaprata/configuration/kafka/KafkaProducerConfig.java"
    click PaymentIntentPublisher "https://github.com/rafaeldsal/ecommerce-service/blob/main/src/main/java/com/rafaeldsal/ws/minhaprata/producer/PaymentIntentPublisher.java"
    click PaymentIntentPublisherImpl "https://github.com/rafaeldsal/ecommerce-service/blob/main/src/main/java/com/rafaeldsal/ws/minhaprata/producer/impl/PaymentIntentPublisherImpl.java"
    click PaymentStatusConsumer "https://github.com/rafaeldsal/ecommerce-service/blob/main/src/main/java/com/rafaeldsal/ws/minhaprata/consumer/PaymentStatusUpdateConsumer.java"
    click PaymentNotifierConsumer "https://github.com/rafaeldsal/ecommerce-service/blob/main/src/main/java/com/rafaeldsal/ws/minhaprata/consumer/PaymentStatusNotifierConsumer.java"
    click RedisListener "https://github.com/rafaeldsal/ecommerce-service/blob/main/src/main/java/com/rafaeldsal/ws/minhaprata/listener/RedisKeyExpirationListener.java"
    ServicesImpl -->|publish| PaymentIntentPublisher
    PaymentIntentPublisher --> PaymentIntentPublisherImpl
    PaymentIntentPublisherImpl -->|to topic| Kafka
    Kafka -->|consumes| PaymentStatusConsumer
    Kafka -->|consumes| PaymentNotifierConsumer
    Redis -->|key-expire event| RedisListener
    RedisListener --> ServicesImpl
    PaymentStatusConsumer --> ServicesImpl
    PaymentNotifierConsumer --> ServicesImpl

    MySQL["MySQL"]:::external
    Redis["Redis"]:::external
    Kafka["Kafka Broker"]:::external
    ExternalCEP["CEP Service"]:::external
    ExternalMail["Mail Service"]:::external

    subgraph "Configuration"
        RedisConfig["RedisConfig"]:::config
        AppEntry["MinhaPrataApplication"]:::config
        AppProps["application.properties"]:::config
        Flyway["Flyway Migrations"]:::config
    end
    click RedisConfig "https://github.com/rafaeldsal/ecommerce-service/blob/main/src/main/java/com/rafaeldsal/ws/minhaprata/configuration/redis/RedisConfig.java"
    click AppEntry "https://github.com/rafaeldsal/ecommerce-service/blob/main/src/main/java/com/rafaeldsal/ws/minhaprata/MinhaPrataApplication.java"
    click AppProps "https://github.com/rafaeldsal/ecommerce-service/blob/main/src/main/resources/application.properties"
    click Flyway "https://github.com/rafaeldsal/ecommerce-service/blob/main/src/main/resources/db/migration/V1__create_initial_tables.sql"

    classDef internal fill:#D6EAF8,stroke:#1F618D
    classDef external fill:#D5F5E3,stroke:#196F3D
    classDef security fill:#FAD7A0,stroke:#B9770E
    classDef messaging fill:#E8DAEF,stroke:#6C3483
    classDef config fill:#F2F3F4,stroke:#A6ACAF
```
