# prgrms-be-devcourse/nbe4-5-3-team04 architecture

> Architecture diagram of the GitHub repository prgrms-be-devcourse/nbe4-5-3-team04, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prgrms-be-devcourse/nbe4-5-3-team04
- Repository: https://github.com/prgrms-be-devcourse/nbe4-5-3-team04

## Overview

##### Main Components
- Frontend – The Next.js application (in the “frontend” folder) that handles the UI/UX aspects and interacts with backend APIs. Include subcomponents like:
- Pages for posts, chat, member profiles, notifications, etc.
- Utility libraries and service layers (e.g., authentication service, notification service, map components).
- Backend – The Spring Boot application (in the “backend” folder) that serves as the API server. Key modules include:
- Domain modules such as:
▸ Chat (with WebSocket configuration, controllers, DTOs, repositories, services)
▸ Member (user management, social features such as follow functionality)
▸ Notification (with REST and SSE controllers, event listener, and service)
▸ Place (location-related functionalities)
▸ Post (handling posts, comments, likes, scraps including validations and mappers)
▸ Rank (providing ranking and popularity functionalities)
- Global configurations (security, aspect logging, web configuration, error handling, etc.)
- Dockerfile and Gradle build scripts indicating build automation and containerization setup.
- Database – Represent your database (MySQL, with H2 for testing) which supports the backend data persistence.
- External Services – Indicate integrations such as:
- Social Login (social authentication via Naver and Google).
- WebSocket for real-time chat.
- Possibly external API providers for maps (as seen from “kakaoMapLoader.ts”) and other services.

##### Interactions and Data Flow
- The Frontend communicates with the Backend via REST APIs for data (members, posts, notifications, etc.) and WebSocket endpoints (for live chat).
- Authentication flows would show browser–>authentication endpoints (also handling OAuth social login) and then proceeding with member operations.
- The Backend then interacts with the Database (CRUD operations on various domain entities) and uses internal service layers to coordinate business logic.
- Additionally, the backend might publish domain events (notification events, etc.) and, through SSE (Server-Sent Events) or WebSocket, push updates to the frontend.

##### Architectural Patterns & Design Principles
- Layered Architecture (Controller → Service → Repository → Entity): Each domain (chat, member, etc.) follows this pattern for separation of concerns.
- Micro-modular design within the backend: Each functional domain is segregated into its own package tree, making it clean to show modules such as “chat,” “member,” “notification,” “place,” “post,” and “rank.”
- Use of WebSockets for chat and SSE for notifications, which illustrates event-driven communication between components.
- Containerization: Include Docker components for both backend and frontend for deployment consistency.
- CI/CD Pipelines: GitHub workflows for CI and CD are part of the repository, indicating automated builds and tests.

##### Elements
- Clear Labels: Name each component (e.g., “Next.js Frontend,” “Spring Boot Backend – Chat Module”, “Member Management Module”, “MySQL Database”).
- Deployment and CI/CD: Optionally denote the Docker containers and GitHub workflows to illustrate the DevOps side.
- Communication Patterns: Highlight API calls, WebSocket channels for chat, and SSE for notifications.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Cluster
    subgraph "Frontend"
        F1["Next.js Frontend"]:::frontend
        F2["Pages & Components"]:::frontend
        F3["Utility Libs (src/lib)"]:::frontend
        F4["Utility Utils (src/app/utils)"]:::frontend
    end

    %% Backend Cluster
    subgraph "Backend"
        B1["Spring Boot Backend"]:::backend
        subgraph "Backend Modules"
            B2["Chat Module"]:::backend
            B2a["WebSocketConfig"]:::backend
            B3["Member Module"]:::backend
            B4["Notification Module"]:::backend
            B5["Place Module"]:::backend
            B6["Post Module"]:::backend
            B7["Rank Module"]:::backend
            B8["Global Config"]:::backend
            B8a["Security Config"]:::backend
            B9["Auth Service"]:::backend
        end
    end

    %% Database Node
    D1["MySQL Database (with H2 testing)"]:::database

    %% External Services Cluster
    subgraph "External Services"
        E1["Social Login Providers"]:::external
        E2["Kakao Map Service"]:::external
    end

    %% Deployment & CI/CD Cluster
    subgraph "Deployment & CI/CD"
        C1["Backend Docker"]:::container
        C2["Frontend Docker"]:::container
        C3["Docker Compose"]:::container
        C4["Build Automation (Gradle & Workflows)"]:::container
    end

    %% Connections between Frontend components
    F1 --> F2
    F1 --> F3
    F1 --> F4

    %% Frontend to Backend API calls
    F2 -->|"REST_API"| B1
    F2 -->|"Chat(WebSocket)"| B2
    F2 -->|"Member(REST)"| B3
    F2 -->|"Notifications(REST/SSE)"| B4
    F2 -->|"Posts(REST)"| B6
    F2 -->|"Ranking(REST)"| B7

    %% Frontend Utility using External Map Service
    F4 -->|"MapIntegration"| E2

    %% Internal Backend Module Relationships
    B2 --> B2a
    B3 -->|"UsesOAuth"| E1
    B4 -->|"PushUpdates"| F2

    %% Each Backend Module performs CRUD to the Database
    B2 -->|"CRUD"| D1
    B3 -->|"CRUD"| D1
    B4 -->|"CRUD"| D1
    B5 -->|"CRUD"| D1
    B6 -->|"CRUD"| D1
    B7 -->|"CRUD"| D1

    %% Deployment Connections
    F1 -->|"Containerized"| C2
    B1 -->|"Containerized"| C1
    C1 --> C3
    C2 --> C3
    C3 --> C4

    %% Click Events
    click F2 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/tree/main/frontend/src/app"
    click F3 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/tree/main/frontend/src/lib"
    click F4 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/tree/main/frontend/src/app/utils"
    click B2 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/tree/main/backend/src/main/kotlin/com/project2/domain/chat"
    click B2a "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/blob/main/backend/src/main/kotlin/com/project2/domain/chat/config/WebSocketConfig.kt"
    click B3 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/tree/main/backend/src/main/kotlin/com/project2/domain/member"
    click B4 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/tree/main/backend/src/main/kotlin/com/project2/domain/notification"
    click B5 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/tree/main/backend/src/main/kotlin/com/project2/domain/place"
    click B6 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/tree/main/backend/src/main/kotlin/com/project2/domain/post"
    click B7 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/tree/main/backend/src/main/kotlin/com/project2/domain/rank"
    click B8 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/tree/main/backend/src/main/kotlin/com/project2/global"
    click B8a "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/blob/main/backend/src/main/kotlin/com/project2/global/security/SecurityConfig.kt"
    click B9 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/blob/main/backend/src/main/kotlin/com/project2/domain/member/service/AuthService.kt"
    click C1 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/tree/main/backend/Dockerfile"
    click C2 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/tree/main/frontend/Dockerfile"
    click C3 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/blob/main/docker/docker-compose.yml"
    click C4 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/blob/main/backend/build.gradle.kts"
    click E2 "https://github.com/prgrms-be-devcourse/nbe4-5-3-team04/blob/main/frontend/src/lib/kakaoMapLoader.ts"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef backend fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px;
    classDef database fill:#FFECB3,stroke:#F57F17,stroke-width:2px;
    classDef external fill:#F8BBD0,stroke:#AD1457,stroke-width:2px;
    classDef container fill:#D1C4E9,stroke:#4A148C,stroke-width:2px;
```
