# prashantbtkl/distributed-debounce architecture

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

- Interactive diagram: https://gitdiagram.com/prashantbtkl/distributed-debounce
- Repository: https://github.com/prashantbtkl/distributed-debounce

## Overview

##### Main Components
- API Layer – Representing the entrypoint for incoming requests. This is implemented in the debouncer/api/api.go file and wired up via debouncer/main.go.
- Configuration & Initialization – The debouncer/config/config.json and associated model/config.go hold configuration settings that bootstrap the service.
- Core Business Logic – The debouncing mechanism resides in debouncer/model/debounce_buffer.go. This is where the key logic to “debounce” incoming events is likely implemented.
- Messaging Integration (RabbitMQ) – There are two main layers:
- Model/Integration: debouncer/model/rabbitmq.go might describe how the service models RabbitMQ messaging.
- Service Layer: debouncer/services/rabbitmq/amq.go and rabbitmq/services/rabbitmq/rabbitmq.go encapsulate the details to connect and interact with RabbitMQ.
- Data Storage – The debouncer/services/store directory contains files (pg_store.go and store.go) that likely interact with a PostgreSQL database for persistence.

a. Main Components (Nodes):
- API Server: Label a component “Debounce API” (highlight debouncer/api/api.go and main.go).
- Config & Initialization: A node labeled “Configuration” (from config/config.json and model/config.go).
- Debounce Logic: A node labeled “Debounce Engine” (from model/debounce_buffer.go).
- Messaging:
▪ “RabbitMQ Integration (Model)” for model/rabbitmq.go.
▪ “RabbitMQ Service” for services/rabbitmq components.
- Data Store: A node labeled “PostgreSQL Store Service” (from services/store/pg_store.go).
- Deployment: Optionally, note the “Deployment Environment” with a focus on containers (reference deploy/rabbitmq).

- “Debounce Engine” to the “RabbitMQ Integration” components to show messages being published/consumed.
- Similarly, show an interaction between the “Debounce Engine” and the “PostgreSQL Store Service” (indicating data persistence).
- How configuration data flows into the service initialization.

c. Architectural Patterns and Design Principles:
- The project uses a microservice pattern focusing on a single responsibility – debouncing.
- It separates concerns clearly by isolating API routing, business logic, and external integrations.
- Use modular design principles: each directory (config, model, services) encapsulates a specific part of the system logic.
- Leverage containerization and deployment best practices (as seen in the deploy folder for RabbitMQ).

- For a microservice architecture like this one, emphasize the clear separation between the API handling interface, the business logic (debounce mechanism), and the external dependencies (RabbitMQ messaging and database storage).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Layer
    subgraph "API Layer"
        DebounceAPI["Debounce API (entrypoint via main.go)"] 
    end

    %% Configuration & Initialization
    subgraph "Configuration & Initialization"
        ConfigManager["Configuration Manager"]
    end

    %% Core Business Logic
    subgraph "Core Business Logic"
        DebounceEngine["Debounce Buffer Logic"]
    end

    %% Messaging Integration
    subgraph "Messaging Integration"
        RabbitMQIntegration["RabbitMQ Integration (Model)"]
        RabbitMQService["RabbitMQ Service"]
    end

    %% Data Storage
    subgraph "Data Storage"
        PGStoreService["PostgreSQL Store Service"]
    end

    %% External Systems
    subgraph "External Systems"
        RabbitMQBroker["RabbitMQ Broker"]
        ExternalDataStore["External Data Store"]
    end

    %% Deployment Environment
    subgraph "Deployment Environment"
        RabbitMQDeployment["RabbitMQ Deployment"]
    end

    %% Relationships
    ConfigManager -->|"init"| DebounceAPI
    DebounceAPI -->|"forwards request"| DebounceEngine
    DebounceEngine -->|"sends event"| RabbitMQIntegration
    DebounceEngine -->|"persists data"| PGStoreService
    RabbitMQIntegration -->|"routes message"| RabbitMQService
    RabbitMQIntegration -->|"connects"| RabbitMQBroker
    RabbitMQService -->|"publishes to"| RabbitMQBroker
    PGStoreService -->|"stores in"| ExternalDataStore
    RabbitMQService -->|"deployed on"| RabbitMQDeployment

    %% Styling for clear separation and colours
    classDef internal fill:#bbf,stroke:#333,stroke-width:2px;
    classDef external fill:#fdd,stroke:#c33,stroke-width:2px,stroke-dasharray: 5 5;
    classDef deployment fill:#cfc,stroke:#393,stroke-width:2px;
    
    class DebounceAPI,ConfigManager,DebounceEngine,RabbitMQIntegration,RabbitMQService,PGStoreService internal;
    class RabbitMQBroker,ExternalDataStore external;
    class RabbitMQDeployment deployment;

    %% Click Events
    click DebounceAPI "https://github.com/prashantbtkl/distributed-debounce/blob/main/debouncer/api/api.go"
    click ConfigManager "https://github.com/prashantbtkl/distributed-debounce/blob/main/debouncer/config/config.json"
    click DebounceEngine "https://github.com/prashantbtkl/distributed-debounce/blob/main/debouncer/model/debounce_buffer.go"
    click RabbitMQIntegration "https://github.com/prashantbtkl/distributed-debounce/blob/main/debouncer/model/rabbitmq.go"
    click RabbitMQService "https://github.com/prashantbtkl/distributed-debounce/blob/main/debouncer/services/rabbitmq/amq.go"
    click PGStoreService "https://github.com/prashantbtkl/distributed-debounce/blob/main/debouncer/services/store/pg_store.go"
    click RabbitMQDeployment "https://github.com/prashantbtkl/distributed-debounce/tree/main/deploy/rabbitmq/Dockerfile"
```
