# min-trees/toomeet architecture

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

- Interactive diagram: https://gitdiagram.com/min-trees/toomeet
- Repository: https://github.com/min-trees/toomeet

## Overview

##### Project Type and Purpose
- This is a full‑blown, Spring Boot–based microservices application (“Student Social Network”) for Thu Dau Mot University.
- It follows a microservices architecture: separate, independently deployable services (User, Post, Chat, Group, Notification, Socket, Search, plus an API Gateway and a Config repo).

##### File Structure Analysis
- Top‐level directories correspond one‑to‑one with services:
- Config (centralized application configuration)
- Gateway (API Gateway)
- User (user management & auth)
- Post (posts, comments, reactions)
- Chat (real‑time messaging domain logic)
- (community/group management)
- Notification (notification creation & persistence)
- Socket (WebSocket endpoint, event listeners)
- Search (search functionality)
- Each service is a Spring Boot project (pom.xml, src/main/java, src/main/resources).
- Inter‐service communication is both synchronous (REST calls) and asynchronous (RabbitMQ).
- Dockerfiles at each service + docker-compose (in Post) + Docker Swarm for orchestration.

##### Key Architecture Insights from README
- API Gateway: authentication, rate limiting, routing.
- User Service: primary source of truth for user data and JWT generation/validation.
- Inter‑service communication: RabbitMQ for events (Saga pattern for transactional consistency), direct REST for queries.
- Real‑time features: Socket service handles WebSocket connections, listens on RabbitMQ events for chat, notifications, group updates.
- Deployment: Docker Swarm, service discovery via built‑in DNS, monitored by Portainer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Clients (Web/Mobile)"]:::client
    Config["Config Server\n(Spring Cloud Config)"]:::config
    Gateway["API Gateway\n(Spring Cloud Gateway)"]:::gateway

    subgraph "Docker Swarm Cluster"
        subgraph "Infrastructure"
            RabbitMQ["RabbitMQ\n(AMQP Broker)"]:::broker
        end
        subgraph "Services"
            User["User Service\n(Spring Boot)"]:::user
            Post["Post Service\n(Spring Boot)"]:::post
            Group["Group Service\n(Spring Boot)"]:::group
            Chat["Chat Service\n(Spring Boot)"]:::chat
            Notification["Notification Service\n(Spring Boot)"]:::notification
            Socket["Socket Service\n(WebSockets)"]:::socket
            Search["Search Service\n(Elasticsearch)"]:::search
        end
        subgraph "Databases & Cache"
            UserDB[(User DB)]:::db
            Redis[(Redis Cache)]:::cache
            PostDB[(Post DB)]:::db
            GroupDB[(Group DB)]:::db
            ChatDB[(Chat DB)]:::db
            NotificationDB[(Notification DB)]:::db
            Elasticsearch[(Elasticsearch Index)]:::db
        end
    end

    Cloudinary[(Cloudinary)]:::external
    SMTP[(SMTP Service)]:::external

    %% Synchronous calls
    Client -->|HTTPS| Gateway
    Gateway -->|fetch config| Config
    Gateway -->|REST→ User| User
    Gateway -->|REST→ Post| Post
    Gateway -->|REST→ Group| Group
    Gateway -->|REST→ Chat| Chat
    Gateway -->|REST→ Notification| Notification
    Gateway -->|REST→ Search| Search

    User -->|reads/writes| UserDB
    User -->|reads/writes| Redis
    Post -->|reads/writes| PostDB
    Group -->|reads/writes| GroupDB
    Chat -->|reads/writes| ChatDB
    Notification -->|reads/writes| NotificationDB
    Search -->|reads/writes| Elasticsearch
    Post -->|upload image| Cloudinary
    Notification -->|send email| SMTP

    %% Auth calls
    Post -->|"validate token"| User
    Group -->|"validate token"| User
    Chat -->|"validate token"| User
    Notification -->|"validate token"| User
    Search -->|"validate token"| User

    %% Asynchronous event flows
    User -->|publish UserEvent| RabbitMQ
    Post -->|publish PostEvent| RabbitMQ
    Group -->|publish GroupEvent| RabbitMQ
    Chat -->|publish NewMessageEvent| RabbitMQ
    Notification -->|publish NotificationEvent| RabbitMQ

    RabbitMQ -->|subscribe NotificationEvent| Notification
    RabbitMQ -->|subscribe NewMessageEvent| Socket
    RabbitMQ -->|subscribe GroupEvent| Group
    Socket -->|WebSocket→ Clients| Client

    %% Click Events
    click Config "https://github.com/min-trees/toomeet/tree/main/Config/"
    click Gateway "https://github.com/min-trees/toomeet/tree/main/Gateway/"
    click User "https://github.com/min-trees/toomeet/tree/main/User/"
    click Post "https://github.com/min-trees/toomeet/tree/main/Post/"
    click Group "https://github.com/min-trees/toomeet/tree/main/Group/"
    click Chat "https://github.com/min-trees/toomeet/tree/main/Chat/"
    click Notification "https://github.com/min-trees/toomeet/tree/main/Notification/"
    click Socket "https://github.com/min-trees/toomeet/tree/main/Socket/"
    click Search "https://github.com/min-trees/toomeet/tree/main/Search/"

    %% Styles
    classDef client fill:#f2f2f2,stroke:#333,stroke-width:1px
    classDef config fill:#a0c4ff,stroke:#333,stroke-width:1px
    classDef gateway fill:#ffadad,stroke:#333,stroke-width:1px
    classDef user fill:#9bf6ff,stroke:#333,stroke-width:1px
    classDef post fill:#caffbf,stroke:#333,stroke-width:1px
    classDef group fill:#ffd6a5,stroke:#333,stroke-width:1px
    classDef chat fill:#bdb2ff,stroke:#333,stroke-width:1px
    classDef notification fill:#ffb3c1,stroke:#333,stroke-width:1px
    classDef socket fill:#fdffb6,stroke:#333,stroke-width:1px
    classDef search fill:#bde0fe,stroke:#333,stroke-width:1px
    classDef broker fill:#ffc6ff,stroke:#333,stroke-width:1px
    classDef db fill:#e0e0e0,stroke:#333,stroke-width:1px,stroke-dasharray:5 5
    classDef cache fill:#e0e0e0,stroke:#333,stroke-width:1px,stroke-dasharray:2 2
    classDef external fill:#f0f0f0,stroke:#333,stroke-width:1px,stroke-dasharray:5 2
```
