# lukas-rodrigo/monify architecture

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

- Interactive diagram: https://gitdiagram.com/lukas-rodrigo/monify
- Repository: https://github.com/lukas-rodrigo/monify

## Overview

##### Project Type and Purpose
- This is a Spring-based microservices system (“Monify”) for managing users and financial data, plus an AI-powered chatbot exposed via WhatsApp.
- It uses Spring Cloud Netflix components (Eureka server for service discovery, a Spring Cloud Gateway), an API gateway, multiple independent Spring Boot microservices, and Docker Compose for local orchestration.

##### File-Structure Analysis
- Root: contains docker-compose.yml to orchestrate all services and a README placeholder.
- monify-eureka-server: Service Discovery (Eureka) implementation.
- ms-monify-gateway: Spring Cloud Gateway acting as the single external entry point.
- ms-users: User management microservice (REST controllers, JPA repository).
- ms-finance-monify: Finance management microservice (categories, expenses).
- ms-chatbot-openAi: Chatbot service integrating with OpenAI (uses Feign to call finance & user services, persists conversations).
- ms-whatsapp: Exposes a webhook for WhatsApp messages, forwards them to ms-chatbot-openAi.
- Each service has its own Spring application.yml (profiles for dev/prod) and Dockerfile.

##### Architectural Patterns & Key Components
a. Service Discovery Layer
- monify-eureka-server registers all services and allows dynamic lookup.
b. API Gateway
- ms-monify-gateway routes incoming HTTP/HTTPS traffic to downstream services based on path.
c. Microservices
- ms-users, ms-finance-monify, ms-chatbot-openAi, ms-whatsapp – each with its own domain model, database, and REST API.
d. Inter-service Communication
- OpenFeign clients for synchronous RPC (finance & users clients in chatbot & WhatsApp).
e. External Integrations
- OpenAI REST API (called by ms-chatbot-openAi).
- WhatsApp platform webhook (incoming requests to ms-whatsapp).
f. Persistence
- Each service likely has its own database (not shown but implied by JPA repositories).

- Eureka Server
- API Gateway
- User Service
- Finance Service
- Chatbot Service
- WhatsApp Service
- OpenAI External API
- WhatsApp Platform
- Databases (one per microservice; optional grouping)
1) Client → Gateway → Eureka (to resolve) → target service.
2) WhatsApp Platform → WhatsApp Service → forwards to Chatbot Service.
3) Chatbot Service → Feign → User Service & Finance Service.
4) Chatbot Service → OpenAI API → Chatbot Service → Database.
5) All services register with Eureka.
- Docker Compose at the bottom or side as the orchestration layer that brings up all services.

##### Architectural Patterns & Principles to Call Out
- Microservices decomposition by bounded contexts (users, finance, chatbot, messaging).
- Service discovery for loose coupling and dynamic scaling.
- API Gateway for authentication, routing, and load balancing.
- Synchronous Feign calls but could mention circuit breakers if added later.
- Each service isolated (separate codebase, Docker container, config).

##### Essential Details to Capture
- Service registry interactions (heartbeats/register/unregister).
- API Gateway routing rules (e.g., /users/** → ms-users).
- Feign client usage inside chatbot and WhatsApp services.
- Persistence layer per service (JPA repositories).
- External HTTP integrations (OpenAI key, WhatsApp webhook).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Service Discovery"
        EUREKA["Eureka Server"]:::discovery
    end

    subgraph "API Gateway"
        GATEWAY["API Gateway (ms-monify-gateway)"]:::gateway
    end

    subgraph "Microservices"
        subgraph "User Service"
            USER["ms-users"]:::internal
            USER_DB["Users DB"]:::db
            USER --> USER_DB
        end
        subgraph "Finance Service"
            FIN["ms-finance-monify"]:::internal
            FIN_DB["Finance DB"]:::db
            FIN --> FIN_DB
        end
        subgraph "Chatbot Service"
            CHATBOT["ms-chatbot-openAi"]:::internal
            CHATBOT_DB["Chatbot DB"]:::db
            CHATBOT --> CHATBOT_DB
        end
        subgraph "WhatsApp Service"
            WA["ms-whatsapp"]:::internal
        end
    end

    WHATSAPP_PLATFORM["WhatsApp Platform"]:::external
    OPENAI["OpenAI API"]:::external
    DOCKER["Docker Compose"]:::external

    %% Service Registration
    USER -->|registers| EUREKA
    FIN -->|registers| EUREKA
    CHATBOT -->|registers| EUREKA
    WA -->|registers| EUREKA

    %% Gateway Routing
    GATEWAY -->|"/users/**"| USER
    GATEWAY -->|"/finance/**"| FIN
    GATEWAY -->|"/chatbot/**"| CHATBOT
    GATEWAY -->|"/whatsapp/**"| WA

    %% External Flows
    WHATSAPP_PLATFORM -->|webhook HTTP| WA
    WA -->|Feign→ Chatbot| CHATBOT
    CHATBOT -->|Feign→ User Service| USER
    CHATBOT -->|Feign→ Finance Service| FIN
    CHATBOT -->|HTTP REST→ OpenAI| OPENAI

    %% Orchestration
    DOCKER --> EUREKA
    DOCKER --> GATEWAY
    DOCKER --> USER
    DOCKER --> FIN
    DOCKER --> CHATBOT
    DOCKER --> WA

    %% Click Events
    click EUREKA "https://github.com/lukas-rodrigo/monify/tree/developer/monify-eureka-server/"
    click GATEWAY "https://github.com/lukas-rodrigo/monify/tree/developer/ms-monify-gateway/"
    click USER "https://github.com/lukas-rodrigo/monify/tree/developer/ms-users/"
    click FIN "https://github.com/lukas-rodrigo/monify/tree/developer/ms-finance-monify/"
    click CHATBOT "https://github.com/lukas-rodrigo/monify/tree/developer/ms-chatbot-openAi/"
    click WA "https://github.com/lukas-rodrigo/monify/tree/developer/ms-whatsapp/"
    click DOCKER "https://github.com/lukas-rodrigo/monify/blob/developer/docker-compose.yml"

    %% Styles
    classDef discovery fill:#cfc,stroke:#333,color:#000;
    classDef gateway fill:#cfc,stroke:#333,color:#000;
    classDef internal fill:#bbf,stroke:#333,color:#000;
    classDef external fill:#ffc,stroke:#333,color:#000;
    classDef db fill:#f9f,stroke:#333,color:#000;
```
