# ssafy-homeggu/homeggu architecture

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

- Interactive diagram: https://gitdiagram.com/ssafy-homeggu/homeggu
- Repository: https://github.com/ssafy-homeggu/homeggu

## Overview

##### Project Type and Purpose
- This is a full-stack, microservices-based web application (“HOMEGGU”) for second-hand furniture trading.
- Frontend: Next.js (React) + Tailwind CSS, CSR/SSR for SEO.
- Backend: MSA using Spring Boot microservices (user, goods, pay, chat, gateway, discovery, config) plus a Python FastAPI “recommendation” service.
- Infra: Docker on AWS EC2, NGINX LB, Jenkins CI/CD, AWS S3, Redis, RabbitMQ, multiple databases (MySQL, MongoDB).

##### File Structure Highlights
- frontend/ → Next.js app, API layers, 3D assets under public/3d, state stores and hooks under src/.
- backend/
- homeggu-config → Spring Cloud Config Server
- homeggu-discovery → Eureka Discovery Server
- homeggu-gateway → Spring Cloud Gateway, JWT, Redis caching
- homeggu-user, homeggu-goods, homeggu-pay, homeggu-chat → domain services (each with REST controllers, JPA repos, service layers)
- homeggu-recommendation → FastAPI Python service for ML-based recommendations
- exec/ → deployment docs & exec assets

##### Key Architectural Patterns & Tech
- MSA with centralized Config & Discovery, API Gateway routing + security (JWT).
- Each service has its own MySQL schema; recommendation uses MongoDB; Redis for caching and session; RabbitMQ for chat pub/sub and 3D conversion jobs.
- S3 for static & 3D model storage; FeignClient for sync inter-service calls; asynchronous jobs via RabbitMQ.
- CI/CD with Jenkins, containerized via Docker, fronted by NGINX on EC2.

##### Main Components
- Clients (Browser, Mobile)
- Next.js Frontend
- NGINX Load Balancer
- Spring Cloud Gateway
- Service Registry (Eureka Discovery)
- Config Server
- Microservices:
- User Service
- Goods Service
- Pay Service
- Chat Service (with STOMP/WebSocket)
- Recommendation Service (FastAPI)
- Datastores: MySQL (per microservice), MongoDB (recommendations), Redis (cache/session)
- Message Broker: RabbitMQ
- External Storage: AWS S3
- Infra & CI/CD: Docker, Jenkins, AWS EC2

##### Interactions & Data Flows
- Synchronous HTTP:
Browser → NGINX → Gateway → target microservice → its DB.
Microservice A → FeignClient → Microservice B via Gateway/Discovery.
- Asynchronous:
Goods Service → RabbitMQ → Chat/Conversion Worker → S3/MongoDB.
Frontend subscribes to Chat WS feed via Gateway → Chat Service → RabbitMQ.
- Caching:
Gateway/User Service ↔ Redis for JWT blacklisting & session data.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer"
        Browser["Browser"]:::ui
        Mobile["Mobile App"]:::ui
        Frontend["Next.js Frontend"]:::ui
    end

    %% Infra Load Balancer
    NGINX["NGINX Load Balancer"]:::proxy

    %% API & Proxy Layer
    subgraph "API & Proxy"
        Gateway["Spring Cloud Gateway"]:::proxy
        Discovery["Eureka Discovery"]:::proxy
        Config["Config Server"]:::proxy
    end

    %% Backend Services
    subgraph "Backend Services"
        User["User Service"]:::service
        Goods["Goods Service"]:::service
        Pay["Pay Service"]:::service
        Chat["Chat Service"]:::service
        Rec["Recommendation Service (FastAPI)"]:::service
    end

    %% Messaging & Cache
    subgraph "Messaging & Cache"
        Redis["Redis Cache/Session"]:::messaging
        RabbitMQ["RabbitMQ Broker"]:::messaging
    end

    %% Data Storage
    subgraph "Data Storage"
        MySQL["MySQL (User/Goods/Pay/Chat)"]:::storage
        MongoDB["MongoDB (Recommendations)"]:::storage
        S3["AWS S3 Storage"]:::storage
    end

    %% Infra & CI/CD
    subgraph "Infrastructure & CI/CD"
        Docker["Docker"]:::infra
        Jenkins["Jenkins CI/CD"]:::infra
        EC2["AWS EC2"]:::infra
    end

    %% Connections - UI to Infra
    Browser -->|"HTTP/HTTPS"| Frontend
    Mobile -->|"HTTP/HTTPS"| Frontend
    Frontend -->|"HTTP/HTTPS"| NGINX
    Frontend -->|"WS/STOMP"| Chat

    %% Infra Load Balancer to API
    NGINX -->|"HTTP/HTTPS"| Gateway

    %% API & Proxy flows
    Gateway -->|"REST/Feign"| Discovery
    Discovery -->|“service registry”| Gateway
    Gateway -->|"REST/Feign"| User
    Gateway -->|"REST/Feign"| Goods
    Gateway -->|"REST/Feign"| Pay
    Gateway -->|"REST/Feign"| Chat
    Gateway -->|"REST/HTTPS"| Rec
    Gateway -->|"startup config"| Config
    Config -->|“application.yml”| User
    Config -->|“application.yml”| Goods
    Config -->|“application.yml”| Pay
    Config -->|“application.yml”| Chat
    Config -->|“application.yml”| Rec

    %% Services to Datastores
    User -->|"JPA/SQL"| MySQL
    Goods -->|"JPA/SQL"| MySQL
    Pay -->|"JPA/SQL"| MySQL
    Chat -->|"JPA/SQL"| MySQL
    Rec -->|"PyMongo"| MongoDB

    %% Messaging flows
    Goods -->|“AMQP”| RabbitMQ
    Chat -->|“AMQP”| RabbitMQ
    RabbitMQ -->|"AMQP"| Chat
    RabbitMQ -->|"job queue"| Rec
    Gateway -->|"JWT sessions"| Redis
    User -->|"session cache"| Redis

    %% External Storage
    Goods -->|"S3 API"| S3
    User -->|"S3 API"| S3
    Chat -->|"3D uploads"| S3

    %% Infra & CI/CD links
    Docker --> Jenkins
    Jenkins --> EC2
    EC2 --> NGINX
    EC2 --> Gateway
    EC2 --> User
    EC2 --> Goods
    EC2 --> Pay
    EC2 --> Chat
    EC2 --> Rec

    %% Click Events
    click Frontend "https://github.com/ssafy-homeggu/homeggu/tree/main/frontend/"
    click NGINX "https://github.com/ssafy-homeggu/homeggu/tree/main/frontend/Dockerfile"
    click Gateway "https://github.com/ssafy-homeggu/homeggu/tree/main/backend/homeggu-gateway/"
    click Discovery "https://github.com/ssafy-homeggu/homeggu/tree/main/backend/homeggu-discovery/"
    click Config "https://github.com/ssafy-homeggu/homeggu/tree/main/backend/homeggu-config/"
    click User "https://github.com/ssafy-homeggu/homeggu/tree/main/backend/homeggu-user/"
    click Goods "https://github.com/ssafy-homeggu/homeggu/tree/main/backend/homeggu-goods/"
    click Pay "https://github.com/ssafy-homeggu/homeggu/tree/main/backend/homeggu-pay/"
    click Chat "https://github.com/ssafy-homeggu/homeggu/tree/main/backend/homeggu-chat/"
    click Rec "https://github.com/ssafy-homeggu/homeggu/tree/main/backend/homeggu-recommendation/"

    %% Styles
    classDef ui fill:#E0F7FA,stroke:#006064
    classDef proxy fill:#E8F5E9,stroke:#1B5E20
    classDef service fill:#FFF3E0,stroke:#E65100
    classDef messaging fill:#F3E5F5,stroke:#6A1B9A
    classDef storage fill:#EFEBE9,stroke:#4E342E
    classDef infra fill:#ECEFF1,stroke:#37474F
```
