# minhtumtn/the-duck-note architecture

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

- Interactive diagram: https://gitdiagram.com/minhtumtn/the-duck-note
- Repository: https://github.com/minhtumtn/the-duck-note

## Overview

##### Main Components
- API Gateway: Acts as the single entry point (handles authentication filtering and request routing).
- Eureka Server: Manages service registration and discovery.
- Authentication Service: Manages user authentication, JWT generation/validation, and security.
- Notification Service: Listens for events (via RabbitMQ) and sends out notifications.
- Profile Service: Responsible for managing user profiles.
- Redis Demo: A demo or example service, likely illustrating caching mechanisms using Redis.
- Commons Module: Shared constants, DTOs, entities, and utility classes common to the other services.
- Data Store (MySQL): Used by several services (as seen with MySQL data files).
- RabbitMQ: The message broker used for asynchronous communication among services.

##### Relationships & Interactions
- The API Gateway routes external API calls to the proper microservice endpoints (authentication, profile, etc.).
- All services are registered with the Eureka Server for discovery and fault tolerance.
- The Authentication Service uses JWT for secure communication and intercalls; it is also likely accessed by other services when verifying user tokens.
- The Notification Service listens to RabbitMQ messages (with configurations defined in both the API gateway and notification service) to push alerts or notifications.
- The Profile and Authentication services interact via Feign clients (or REST calls) to exchange user information.
- The Redis Demo service communicates with Redis (as evident from its Redis configuration) and may also interact with MySQL for persistent storage.
- The shared commons module supports multiple services with common utilities and data models.

##### Architectural Patterns and Components
- Microservices Architecture: Each service runs as an independent module with its own configuration and lifecycle.
- Service Discovery: Eureka Server enables dynamic discovery which the API Gateway and other services use to locate endpoints.
- API Gateway Pattern: Centralizes entry point, authentication filtering, and possibly load balancing.
- Message-driven communication: RabbitMQ is used to decouple parts of the system for asynchronous processing.
- Shared library/component: The Commons module helps reduce duplication of business and shared logic.
- Data Persistence: Multiple services likely interact with a common or separate MySQL instance, as seen by the extensive MySQL data directory.

– Show external client requests entering through the API Gateway.
– Represent each service’s connection to the MySQL database if applicable.
– Frontend components: In this case, even though there’s no UI component explicitly in the file structure, the API gateway serves as the interface.
– Backend services: Authentication, Profile, Notification, Eureka Server, Redis Demo.
– Infrastructure components: RabbitMQ, MySQL.
d. Architectural patterns:
– Clearly denote the microservices with annotated notes explaining the role (for example, “Authentication Service: Handles JWT security logic”, “Notification Service: Listens on RabbitMQ for events”).
– Highlight the role of the Commons module (shared across services).
e. Deployment details:
– Indicate that Docker (and docker-compose.yml) is used to orchestrate running containers.
– You might also indicate that RabbitMQ is launched as a container (as per the README commands).

## Diagram (Mermaid)

```mermaid
flowchart TD
    ExternalClient["External Client"]:::external

    subgraph "API Layer"
        apiGateway["API Gateway"]:::apigateway
    end

    subgraph "Service Layer"
        auth["Authentication Service"]:::backend
        profileService["Profile Service"]:::backend
        notificationService["Notification Service"]:::backend
        redisDemo["Redis Demo Service"]:::backend
        commonsModule["Commons Module"]:::commons
    end

    subgraph "Infrastructure"
        eureka["Eureka Server"]:::infrastructure
        rmq["RabbitMQ"]:::infrastructure
        mysql["MySQL Data Store"]:::datastore
    end

    subgraph "RabbitMQ Configurations"
        rmqConfigAPI["Config"]:::infrastructure
        rmqConfigNoti["Config"]:::infrastructure
    end

    %% External client to API Gateway
    ExternalClient -->|"requests"| apiGateway

    %% API Gateway routes to services
    apiGateway -->|"routesTo"| auth
    apiGateway -->|"routesTo"| profileService

    %% Direct communication between services
    auth -->|"validatesWith"| profileService

    %% Commons Module usage (dotted lines)
    auth ---|"uses"| commonsModule
    profileService ---|"uses"| commonsModule
    notificationService ---|"uses"| commonsModule
    redisDemo ---|"uses"| commonsModule

    %% Service registration with Eureka Server (bidirectional)
    apiGateway <-->|"registers"| eureka
    auth <-->|"registers"| eureka
    profileService <-->|"registers"| eureka
    notificationService <-->|"registers"| eureka
    redisDemo <-->|"registers"| eureka

    %% Messaging via RabbitMQ
    apiGateway -->|"sendsMsg"| rmq
    auth -->|"sendsMsg"| rmq
    rmq -->|"deliversMsg"| notificationService

    %% Data persistence to MySQL
    auth -->|"persistsData"| mysql
    profileService -->|"persistsData"| mysql
    notificationService -->|"persistsData"| mysql
    redisDemo -->|"persistsData"| mysql

    %% RabbitMQ configurations (dotted connections)
    rmqConfigAPI -.->|"configures"| rmq
    rmqConfigNoti -.->|"configures"| rmq

    %% Click Events
    click apiGateway "https://github.com/minhtumtn/the-duck-note/tree/master/api-gateway/"
    click eureka "https://github.com/minhtumtn/the-duck-note/tree/master/eureka-server/"
    click auth "https://github.com/minhtumtn/the-duck-note/tree/master/authentication/"
    click profileService "https://github.com/minhtumtn/the-duck-note/tree/master/profile/"
    click notificationService "https://github.com/minhtumtn/the-duck-note/tree/master/notification/"
    click redisDemo "https://github.com/minhtumtn/the-duck-note/tree/master/redis-demo/"
    click commonsModule "https://github.com/minhtumtn/the-duck-note/tree/master/commons/"
    click mysql "https://github.com/minhtumtn/the-duck-note/tree/master/.idx/.data/mysql"
    click rmqConfigAPI "https://github.com/minhtumtn/the-duck-note/blob/master/api-gateway/src/main/java/com/theduck/note/api_gateway/config/RabbitMQConfig.java"
    click rmqConfigNoti "https://github.com/minhtumtn/the-duck-note/blob/master/notification/src/main/java/com/theduck/note/notification/config/RabbitMQConfig.java"

    %% Styles
    classDef external fill:#ffefc1,stroke:#333,stroke-width:2px;
    classDef apigateway fill:#f9d9eb,stroke:#333,stroke-width:2px;
    classDef backend fill:#f0f8ff,stroke:#333,stroke-width:2px;
    classDef commons fill:#e6ffe6,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#e8eaf6,stroke:#333,stroke-width:2px;
    classDef datastore fill:#ffe6cc,stroke:#333,stroke-width:2px;
```
