# kea-renov8/befly-be architecture

> Architecture diagram of the GitHub repository kea-renov8/befly-be, 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/kea-renov8/befly-be
- Repository: https://github.com/kea-renov8/befly-be

## Overview

##### Project type and purpose
- This is a Java-based backend mono-repo implementing a microservices architecture for the “ReNov8” platform.
- It comprises three domain services—user, community, consult—plus a shared “common” library.
- Each service is a standalone Spring Boot application, containerized (Docker), with its own Gradle build.

##### File structure
- Top level:
- common/        – shared code (annotations, API payloads, S3 config, exception handling)
- user/          – user management and authentication (JWT, sign-in/up)
- community/     – free/solved posts, comments, empathy, notification via Kafka & SSE
- consult/       – “worry” domain, analysis, chat domain objects
- Each service folder contains: Dockerfile, build.gradle, src/main/java/...Application.java, controller, service, repository, domain, dto packages
- settings.gradle and .github/workflows show a GitHub Actions CI/CD pipeline.

##### Key technical stack (from README and code)
- Spring Boot (Java)
- AWS S3 (file storage) via shared S3Service
- Apache Kafka (event bus for notifications in community service)
- Server-Sent Events (SSE) for real-time notifications
- JWT for authentication (in user service)
- Docker and GitHub Actions for build & deployment
- Gradle multi-project setup

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients and Gateway
    Client["Web/Mobile Client"]:::client
    APIGateway["API Gateway / Load Balancer"]:::gateway

    Client -->|"HTTP Request"| APIGateway

    %% Common Library
    subgraph "common-library" 
        direction TB
        S3Config["S3Config"] 
        S3Service["S3Service"] 
        ExceptionAdvice["ExceptionAdvice"] 
        LoginUser["LoginUser Annotation"] 
    end
    class S3Config,S3Service,ExceptionAdvice,LoginUser library

    %% Services
    subgraph "user-service (Spring Boot)" 
        direction TB
        AppConfig["AppConfig"] 
        JwtProvider["JwtProvider"] 
        AuthController["AuthController"] 
        UserController["UserController"]
    end
    class AppConfig,JwtProvider,AuthController,UserController service

    subgraph "community-service (Spring Boot)"
        direction TB
        NotificationController["NotificationController"]
        NotificationService["NotificationService"]
        KafkaNotificationService["KafkaNotificationService"]
        SSENotificationService["SSENotificationService"]
    end
    class NotificationController,NotificationService,KafkaNotificationService,SSENotificationService service

    subgraph "consult-service (Spring Boot)"
        direction TB
        Worry["Worry Domain"]
        WorryChat["WorryChat Domain"]
    end
    class Worry,WorryChat service

    %% External Services
    KafkaCluster["Kafka Cluster"]:::cloud
    S3Bucket["AWS S3 Bucket"]:::cloud

    %% Databases
    UserDB["user-service DB"]:::db
    CommunityDB["community-service DB"]:::db
    ConsultDB["consult-service DB"]:::db

    %% CI/CD Pipeline
    CI["GitHub Actions CI/CD"]:::pipeline

    %% Flows
    APIGateway -->|Authenticate| AuthController
    AuthController -->|Issues JWT| UserController
    APIGateway -->|JWT Auth| NotificationController
    APIGateway -->|JWT Auth| Worry
    NotificationController --> NotificationService
    NotificationService -->|Publish event| KafkaCluster
    KafkaCluster -->|Consume SSE| SSENotificationService
    NotificationService --> CommunityDB
    UserController --> UserDB
    Worry --> ConsultDB

    %% Common library usage
    S3Config --> S3Service
    S3Service --> S3Bucket
    AuthController --> S3Service
    NotificationController --> S3Service
    AppConfig --> ExceptionAdvice
    AppConfig --> LoginUser

    AppConfig --> S3Service
    JwtProvider --> ExceptionAdvice
    AuthController --> JwtProvider

    NotificationService --> ExceptionAdvice
    KafkaNotificationService --> ExceptionAdvice
    SSENotificationService --> ExceptionAdvice
    Worry --> ExceptionAdvice

    %% CI/CD to services
    CI --> user-service
    CI --> community-service
    CI --> consult-service

    %% Click Events
    click S3Config "https://github.com/kea-renov8/befly-be/blob/develop/common/src/main/java/befly/common/config/S3Config.java"
    click S3Service "https://github.com/kea-renov8/befly-be/blob/develop/common/src/main/java/befly/common/service/S3Service.java"
    click ExceptionAdvice "https://github.com/kea-renov8/befly-be/blob/develop/common/src/main/java/befly/common/exception/ExceptionAdvice.java"
    click LoginUser "https://github.com/kea-renov8/befly-be/blob/develop/common/src/main/java/befly/common/annotations/LoginUser.java"
    click AppConfig "https://github.com/kea-renov8/befly-be/blob/develop/user/src/main/java/befly/user/config/AppConfig.java"
    click JwtProvider "https://github.com/kea-renov8/befly-be/blob/develop/user/src/main/java/befly/user/config/JwtProvider.java"
    click AuthController "https://github.com/kea-renov8/befly-be/blob/develop/user/src/main/java/befly/user/controller/AuthController.java"
    click UserController "https://github.com/kea-renov8/befly-be/blob/develop/user/src/main/java/befly/user/controller/UserController.java"
    click NotificationController "https://github.com/kea-renov8/befly-be/blob/develop/community/src/main/java/befly/community/Controller/NotificationController.java"
    click NotificationService "https://github.com/kea-renov8/befly-be/blob/develop/community/src/main/java/befly/community/Service/NotificationService.java"
    click KafkaNotificationService "https://github.com/kea-renov8/befly-be/blob/develop/community/src/main/java/befly/community/Service/kafka/KafkaNotificationService.java"
    click SSENotificationService "https://github.com/kea-renov8/befly-be/blob/develop/community/src/main/java/befly/community/Service/SSENotificationService.java"
    click Worry "https://github.com/kea-renov8/befly-be/blob/develop/consult/src/main/java/befly/consult/domain/Worry.java"
    click WorryChat "https://github.com/kea-renov8/befly-be/blob/develop/consult/src/main/java/befly/consult/domain/WorryChat.java"
    click CI "https://github.com/kea-renov8/befly-be/blob/develop/.github/workflows/befly-be-dev-ci.yml"
    click CI "https://github.com/kea-renov8/befly-be/blob/develop/.github/workflows/befly-be-dev-cd.yml"
    click CI "https://github.com/kea-renov8/befly-be/blob/develop/.github/workflows/complete-jira-issue.yml"
    click CI "https://github.com/kea-renov8/befly-be/blob/develop/.github/workflows/create-jira-issue.yml"

    %% Styles
    classDef service fill:#f9f,stroke:#333,stroke-width:2px
    classDef db fill:#ccf,stroke:#333,stroke-width:2px
    classDef cloud fill:#cfc,stroke:#333,stroke-width:2px
    classDef pipeline fill:#fcf,stroke:#333,stroke-width:2px
    classDef client fill:#cff,stroke:#333,stroke-width:2px
    classDef gateway fill:#ffc,stroke:#333,stroke-width:2px
    classDef library fill:#efe,stroke:#333,stroke-width:2px
```
