# haiday03/hauisocialmedia_server architecture

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

- Interactive diagram: https://gitdiagram.com/haiday03/hauisocialmedia_server
- Repository: https://github.com/haiday03/hauisocialmedia_server

## Overview

##### Main Components
- Backend Server: The core application located in src/main/java/com/group4/HaUISocialMedia_server. This includes the main Application class (HaUiSocialMediaServerApplication.java).
- Controllers (REST Endpoints): Under the /rest package, these handle the HTTP requests for authentication, posts, notifications, and more.
- Services & Implementations: The business logic is abstracted in the /service and /service/impl packages (including AuthService, PostService, etc.).
- Repositories: Data access handled via Spring Data JPA style interfaces in the /repository package for each domain entity.
- Domain Models: Entities (in the /entity package) represent objects such as User, Group, Post, etc.
- Configuration: Includes setup for security (JWT authentication with JwtAuthenticationEntryPoint, JwtAuthenticationFilter, JwtTokenProvider, WebSecurityConfig) and real-time messaging (WebSocketConfig).
- Data Transfer Objects (DTOs): Located in the /dto package, these are used to transfer data between layers.
- Testing: Tests exist in the /src/test directory.
- Infrastructure & Build: Maven configuration (pom.xml, mvnw scripts) and configuration files (application.properties).

##### Relationships & Interactions
- The Controllers receive HTTP requests, passing data through DTOs.
- Each Controller then calls the relevant Service layer which encapsulates the business logic.
- Services interact with Repositories to persist or fetch data from the database.
- Configuration components (e.g., WebSecurityConfig) integrate with Controller endpoints to enforce security (JWT-based authentication).
- WebSocket components in the configuration and related endpoints support real-time interactions (for chat or notifications).
- Entities and DTOs illustrate the domain model and data transfer across the system.

##### Architectural Patterns & Design Principles
- Layered Architecture: Clearly defined separation in controllers, services, and repositories.
- RESTful API Design: The /rest package is organized to provide API endpoints for different functionalities.
- Security: Use of JWT (Json Web Tokens) with corresponding filters and handlers to secure endpoints.
- Real-Time Communication: Use of WebSocket configuration enabling live updates/notifications.
- Domain-Driven Design: Domain models (Entities) and DTOs capture business data and constraints.

##### Relevant Technologies and Frameworks
- Spring Boot (implied by the typical structure and Application class).
- Spring Security (JWT, authentication filters, access management).
- Spring Data JPA (Repositories and Entities for interacting with the database).
- Maven (for build and dependency management).
- Possibly WebSocket (real-time messaging support).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Backend Server"
        HAPP["HaUiSocialMediaServerApplication"]:::backend
    end

    subgraph "REST Layer"
        REST["REST Controllers\n(Handles API endpoints)"]:::rest
    end

    subgraph "Service Layer"
        SERVICES["Services & Implementations\n(Business logic)"]:::service
    end

    subgraph "Data Layer"
        REPO["Repositories\n(Data Access)"]:::data
        ENTITY["Domain Models (Entities)"]:::data
        DTO["Data Transfer Objects (DTOs)"]:::data
    end

    subgraph "Security"
        JWTEntry["JwtAuthenticationEntryPoint"]:::security
        JWTFilter["JwtAuthenticationFilter"]:::security
        JWTProvider["JwtTokenProvider"]:::security
        WebSec["WebSecurityConfig"]:::security
    end

    subgraph "Real-Time Communication"
        WS["WebSocketConfig"]:::websocket
    end

    subgraph "Application Setup & Config"
        SETUP["SetupData"]:::config
        APPProps["application.properties"]:::config
    end

    subgraph "Testing"
        TEST["Testing Suite"]:::test
    end

    subgraph "Build & Infrastructure"
        POM["pom.xml"]:::build
        MVNW["mvnw (and mvnw.cmd)"]:::build
        MVNDIR[".mvn directory"]:::build
    end

    HAPP -->|"initializes"| REST
    REST -->|"calls"| SERVICES
    SERVICES -->|"accesses"| REPO
    SERVICES -->|"manipulates"| ENTITY
    SERVICES -->|"transfers"| DTO

    REST -->|"securedBy"| JWTEntry
    REST -->|"securedBy"| JWTFilter
    REST -->|"securedBy"| JWTProvider
    REST -->|"securedBy"| WebSec

    SERVICES -->|"updatesInRealtime"| WS

    HAPP -->|"loads"| SETUP
    HAPP -->|"loads"| APPProps

    %% Style Definitions
    classDef backend fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
    classDef rest fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef service fill:#f5cba7,stroke:#a04000,stroke-width:2px;
    classDef data fill:#d2b4de,stroke:#6c3483,stroke-width:2px;
    classDef security fill:#f1948a,stroke:#922b21,stroke-width:2px;
    classDef websocket fill:#7fb3d5,stroke:#21618c,stroke-width:2px;
    classDef config fill:#abebc6,stroke:#1d8348,stroke-width:2px;
    classDef test fill:#d5dbdb,stroke:#7f8c8d,stroke-width:2px;
    classDef build fill:#fad7a0,stroke:#d35400,stroke-width:2px;

    %% Click Events
    click HAPP "https://github.com/haiday03/hauisocialmedia_server/blob/main/src/main/java/com/group4/HaUISocialMedia_server/HaUiSocialMediaServerApplication.java"
    click REST "https://github.com/haiday03/hauisocialmedia_server/tree/main/src/main/java/com/group4/HaUISocialMedia_server/rest"
    click SERVICES "https://github.com/haiday03/hauisocialmedia_server/tree/main/src/main/java/com/group4/HaUISocialMedia_server/service"
    click SERVICES "https://github.com/haiday03/hauisocialmedia_server/tree/main/src/main/java/com/group4/HaUISocialMedia_server/service/impl"
    click REPO "https://github.com/haiday03/hauisocialmedia_server/tree/main/src/main/java/com/group4/HaUISocialMedia_server/repository"
    click ENTITY "https://github.com/haiday03/hauisocialmedia_server/tree/main/src/main/java/com/group4/HaUISocialMedia_server/entity"
    click DTO "https://github.com/haiday03/hauisocialmedia_server/tree/main/src/main/java/com/group4/HaUISocialMedia_server/dto"
    click JWTEntry "https://github.com/haiday03/hauisocialmedia_server/blob/main/src/main/java/com/group4/HaUISocialMedia_server/config/JwtAuthenticationEntryPoint.java"
    click JWTFilter "https://github.com/haiday03/hauisocialmedia_server/blob/main/src/main/java/com/group4/HaUISocialMedia_server/config/JwtAuthenticationFilter.java"
    click JWTProvider "https://github.com/haiday03/hauisocialmedia_server/blob/main/src/main/java/com/group4/HaUISocialMedia_server/config/JwtTokenProvider.java"
    click WebSec "https://github.com/haiday03/hauisocialmedia_server/blob/main/src/main/java/com/group4/HaUISocialMedia_server/config/WebSecurityConfig.java"
    click WS "https://github.com/haiday03/hauisocialmedia_server/blob/main/src/main/java/com/group4/HaUISocialMedia_server/config/WebSocketConfig.java"
    click SETUP "https://github.com/haiday03/hauisocialmedia_server/blob/main/src/main/java/com/group4/HaUISocialMedia_server/config/SetupData.java"
    click APPProps "https://github.com/haiday03/hauisocialmedia_server/blob/main/src/main/resources/application.properties"
    click TEST "https://github.com/haiday03/hauisocialmedia_server/tree/main/src/test"
    click POM "https://github.com/haiday03/hauisocialmedia_server/blob/main/pom.xml"
    click MVNW "https://github.com/haiday03/hauisocialmedia_server/tree/main/mvnw"
    click MVNDIR "https://github.com/haiday03/hauisocialmedia_server/blob/main/.mvn"
```
