# a-c-g/back-end architecture

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

- Interactive diagram: https://gitdiagram.com/a-c-g/back-end
- Repository: https://github.com/a-c-g/back-end

## Overview

##### Main Components

a. Client Layer:
- Web Browser Interface
- Static Resources (HTML, JS)
- Templates (chat.html, description.html, etc.)

b. Application Layer:
- Spring Boot Application Server with the following components:
- Controllers Package
- UserController
- GithubApiController
- JGitController
- WebSocket Controller (GreetingController)
- Services Package
- AutoCommitService
- GithubApiService
- JGitService
- UserService
- Security & Configuration
- SecurityConfig
- SwaggerConfig
- WebSocketConfig

c. Data Layer:
- MySQL Database (indicated by JpaRepository usage)
- Entity Models (User, Message, etc.)

d. External Services:
- GitHub API Integration
- OAuth Authentication

##### Component Relationships

- Client → Application Server (HTTP/HTTPS)
- WebSocket connections for chat functionality
- Application Server → MySQL Database
- Application Server → GitHub API
- OAuth flow between Client → Application Server → GitHub

##### Specific Implementation Details

- Blue rectangles for Spring components
- Purple clouds for external services
- Orange hexagons for security components
- Yellow rectangles for client-side components

##### Key Flows to Highlight

a. Authentication Flow:
- GitHub OAuth login process
- Security filter chain

b. Auto-Commit Flow:
- Scheduled commit process
- GitHub repository creation
- JGit operations

c. WebSocket Chat Flow:
- Real-time message handling
- User connection management

##### Additional Elements

Supporting components:
- Nginx reverse proxy
- AWS infrastructure
- GitHub Actions CI/CD pipeline
- Gradle build system

##### Architectural Patterns to Emphasize

- MVC pattern implementation
- RESTful API structure
- WebSocket implementation
- Repository pattern for data access

##### External Services Layer

Remember to add annotations for:
- Security configurations
- WebSocket endpoints
- Database connections
- API integration points
- Scheduled tasks for auto-commit functionality

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef client fill:#FFE5CC,stroke:#000
    classDef server fill:#B3E0FF,stroke:#000
    classDef database fill:#90EE90,stroke:#000
    classDef external fill:#E6E6FA,stroke:#000
    classDef security fill:#FFB366,stroke:#000
    classDef config fill:#FFD700,stroke:#000

    %% Client Layer
    subgraph ClientLayer
        Browser["Web Browser"]
        StaticRes["Static Resources"]
        Templates["Templates"]
        AppJS["app.js"]
    end

    %% Network Layer
    NGINX["NGINX Reverse Proxy"]

    %% Application Layer
    subgraph AppServer["Spring Boot Application Server"]
        %% Controllers
        subgraph Controllers
            UserCtrl["UserController"]
            GithubCtrl["GithubApiController"]
            JGitCtrl["JGitController"]
            WSCtrl["WebSocket Controller"]
        end

        %% Services
        subgraph Services
            AutoCommitSvc["AutoCommitService"]
            GithubApiSvc["GithubApiService"]
            JGitSvc["JGitService"]
            UserSvc["UserService"]
        end

        %% Config
        subgraph Config
            SecConfig["SecurityConfig"]
            WSConfig["WebSocketConfig"]
            SwaggerConfig["SwaggerConfig"]
        end

        %% Exception Handling
        ExHandler["Global Exception Handler"]
    end

    %% Data Layer
    subgraph DataLayer
        MySQL[(MySQL Database)]
        UserEntity["User Entity"]
        MessageEntity["Message Entity"]
        UserRepo["User Repository"]
    end

    %% External Services
    subgraph ExternalServices
        GitHubAPI["GitHub API"]
        OAuth["OAuth Service"]
    end

    %% Relationships
    Browser --> NGINX
    NGINX --> AppServer
    Browser -.->|WebSocket| WSCtrl
    
    %% Controller Dependencies
    UserCtrl --> UserSvc
    GithubCtrl --> GithubApiSvc
    JGitCtrl --> JGitSvc
    WSCtrl --> UserSvc
    
    %% Service Dependencies
    UserSvc --> UserRepo
    GithubApiSvc --> GitHubAPI
    AutoCommitSvc --> JGitSvc
    JGitSvc --> GitHubAPI
    
    %% Data Access
    UserRepo --> MySQL
    
    %% OAuth Flow
    Browser --> OAuth
    OAuth --> GitHubAPI

    %% Click Events
    click StaticRes "https://github.com/A-C-G/back-end/tree/main/src/main/resources/static"
    click Templates "https://github.com/A-C-G/back-end/tree/main/src/main/resources/templates"
    click AppJS "https://github.com/A-C-G/back-end/blob/main/src/main/resources/static/app.js"
    click UserCtrl "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/controller/UserController.java"
    click GithubCtrl "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/controller/GithubApiController.java"
    click JGitCtrl "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/controller/JGitController.java"
    click WSCtrl "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/controller/GreetingController.java"
    click AutoCommitSvc "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/service/AutoCommitService.java"
    click GithubApiSvc "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/service/GithubApiService.java"
    click JGitSvc "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/service/JGitService.java"
    click UserSvc "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/service/UserService.java"
    click SecConfig "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/config/SecurityConfig.java"
    click WSConfig "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/config/WebSocketConfig.java"
    click SwaggerConfig "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/config/SwaggerConfig.java"
    click UserEntity "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/entity/User.java"
    click MessageEntity "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/entity/Message.java"
    click UserRepo "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/repository/UserJpaRepository.java"
    click ExHandler "https://github.com/A-C-G/back-end/blob/main/src/main/java/com/project/ACG/exception/GlobalExceptionHandler.java"

    %% Styling
    class Browser,StaticRes,Templates,AppJS client
    class UserCtrl,GithubCtrl,JGitCtrl,WSCtrl server
    class AutoCommitSvc,GithubApiSvc,JGitSvc,UserSvc server
    class MySQL database
    class GitHubAPI,OAuth external
    class SecConfig,WSConfig,SwaggerConfig config
    class ExHandler security
```
