# one-bite/one-bite-be architecture

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

- Interactive diagram: https://gitdiagram.com/one-bite/one-bite-be
- Repository: https://github.com/one-bite/one-bite-be

## Overview

##### Main Components
- Backend Application:
- SpaghettiApplication as the central container running the Spring Boot application.
- TestDataLoader, which helps bootstrapping sample data.
- Controllers:
- OAuthController, ProblemController, and TestController handling incoming HTTP requests.
- Authentication & Security Module:
- Components such as JwtAuthenticationFilter, SecurityConfig, JwtProvider, and related DTOs (JwtTokenDto, LoginRequest, LoginProvider).
- Problem Management Module:
- ProblemService and ProblemController for managing problem creation and solving (including request/response DTOs and Problem entities).
- Data Persistence:
- Repository components (UserRepository, ProblemRepository, etc.) interacting with your underlying database.
- Entities (User, Problem, Badge, etc.) representing data models.
- Caching and External Configurations:
- RedisConfig and RedisService, indicating integration with a Redis cache.
- Exception Handling:
- GlobalExceptionHandler and custom exceptions (InvalidRequestException, ProblemNotFoundException, etc.).
- Configuration & Third-Party Integrations:
- SwaggerConfig for API documentation.
- GoogleLoginService for OAuth integration.
- External OAuth providers (e.g., Google or other configured providers) illustrated as external systems.

##### Relationship and Interaction Flows
- Client/API Gateway:
- Request Routing:
- Requests come into the appropriate controllers (authentication requests to OAuthController, problem-related requests to ProblemController).
- Service Layer:
- Data and Caching:
- Also, indicate interactions with Redis (via RedisService/RedisConfig) for caching or session data.
- Security Workflow:
- JWT-based authentication by showing the JwtAuthenticationFilter intercepting requests before they reach controllers.
- Relationship between the AuthenticationFilter, SecurityConfig, and JwtProvider.
- Exception Handling:
- GlobalExceptionHandler as an overarching component that captures and processes errors or invalid requests.

##### Architectural Patterns and Design Principles
- Layered Architecture (MVC/Service/Repository):
- Clearly separate the presentation layer (controllers), business logic (services), and data access (repositories/entities).
- Security as a Cross-Cutting Concern:
- Detail how authentication and authorization components (JWT, filters, security configurations) integrate at every layer.
- Integration with External Services:
- OAuth integration through the OAuthController and GoogleLoginService along with their connection to external OAuth providers.
- Use of Containerization/Orchestration:

##### Technologies, Frameworks, and Libraries
- Java with Spring Boot (evident from build.gradle and the Spring application structure).
- Security with JWT and OAuth integrations.
- Redis for caching.
- Swagger for API documentation.
- Gradle as the build tool.

##### Final Assembly
- Drill down into layers showing how requests pass through filters and controllers into services and repositories.
- Integrate external components (like OAuth providers and Redis) in the context of their interaction(s) with the main application.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External
    Client["Client (HTTP)"]:::external

    %% Backend Application Container
    subgraph "Backend Application"
        A["SpaghettiApplication"]:::application
        T["TestDataLoader"]:::application
    end

    %% Security & Authentication Module
    subgraph "Authentication & Security Module"
        F["JwtAuthenticationFilter"]:::security
        SC["SecurityConfig"]:::security
        JP["JwtProvider"]:::security
        JTD["JwtTokenDto"]:::dto
        LR["LoginRequest"]:::dto
        LP["LoginProvider"]:::dto
    end

    %% Controllers
    subgraph "Controllers"
        OC["OAuthController"]:::controller
        PC["ProblemController"]:::controller
        TC["TestController"]:::controller
    end

    %% Service Layer
    subgraph "Service Layer"
        GLS["GoogleLoginService"]:::service
        PS["ProblemService"]:::service
        CPR["CreateProblemRequest"]:::dto
        SR["SolveRequest"]:::dto
        SRES["SolveResponse"]:::dto
        RS["RedisService"]:::service
    end

    %% Data Persistence
    subgraph "Data Persistence"
        UR["UserRepository"]:::repository
        PR["ProblemRepository"]:::repository
        PE["Problem"]:::entity
        ENT["Other Entities (Badge, Level, etc.)"]:::entity
    end

    %% Caching & External Config
    subgraph "Caching & External Config"
        RC["RedisConfig"]:::config
        SW["SwaggerConfig"]:::config
    end

    %% Exception Handling
    subgraph "Exception Handling"
        GE["GlobalExceptionHandler"]:::exception
        CE["Custom Exceptions"]:::exception
    end

    %% Deployment & CI/CD
    subgraph "Deployment & CI/CD"
        DF["Dockerfile"]:::deployment
        DC["Docker Compose"]:::deployment
        GH["GitHub Workflows"]:::deployment
    end

    %% External OAuth Provider
    OXP["OAuth Provider (Google)"]:::external

    %% Relationships
    %% Application startup
    A -->|"bootstraps"| F
    A -->|"initializes"| T

    %% Client request flow through security
    Client -->|"HTTP"| F
    F -->|"routes"| OC
    F -->|"routes"| PC
    F -->|"routes"| TC

    %% Security internal flow
    F -->|"uses"| SC
    SC -->|"configures"| JP
    F --- JTD
    F --- LR
    F --- LP

    %% Controller to Service delegation
    OC -->|"delegates"| GLS
    PC -->|"delegates"| PS

    %% OAuth external integration
    GLS -->|"calls"| OXP

    %% Problem Service interactions
    PS -->|"creates"| CPR
    PS -->|"solves"| SR
    PS -->|"returns"| SRES
    PS -->|"persists"| PR
    PS -->|"verifies auth via"| UR

    %% Repository to Entity mapping
    PR -->|"maps to"| PE

    %% Caching interactions
    PS -->|"caches using"| RS
    RS --- RC

    %% Exception Handling (cross-cutting)
    OC --- GE
    PC --- GE
    TC --- GE

    %% Additional Configurations
    SW --- OC
    SW --- PC
    SW --- TC

    %% Click Events
    click A "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/SpaghettiApplication.java"
    click T "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/TestDataLoader.java"
    click OC "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/controller/OAuthController.java"
    click PC "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/controller/ProblemController.java"
    click TC "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/controller/TestController.java"
    click F "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/config/JwtAuthenticationFilter.java"
    click SC "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/config/SecurityConfig.java"
    click JP "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/utils/JwtProvider.java"
    click JTD "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/dto/JwtTokenDto.java"
    click LR "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/dto/request/LoginRequest.java"
    click LP "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/dto/LoginProvider.java"
    click GLS "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/service/GoogleLoginService.java"
    click PS "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/service/ProblemService.java"
    click CPR "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/dto/request/CreateProblemRequest.java"
    click SR "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/dto/request/SolveRequest.java"
    click SRES "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/dto/response/SolveResponse.java"
    click PE "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/entity/Problem.java"
    click UR "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/repository/UserRepository.java"
    click PR "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/repository/ProblemRepository.java"
    click RS "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/service/RedisService.java"
    click RC "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/config/RedisConfig.java"
    click GE "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/exception/GlobalExceptionHandler.java"
    click SW "https://github.com/one-bite/one-bite-be/blob/main/src/main/java/code/rice/bowl/spaghetti/config/SwaggerConfig.java"
    click DF "https://github.com/one-bite/one-bite-be/tree/main/dockerfile"
    click DC "https://github.com/one-bite/one-bite-be/blob/main/docker-compose.yml"
    click GH "https://github.com/one-bite/one-bite-be/tree/main/.github/workflows"

    %% Styles
    classDef external fill:#fce38a,stroke:#e38b29,stroke-width:2px;
    classDef application fill:#95e1d3,stroke:#0b5251,stroke-width:2px;
    classDef security fill:#ff9f1c,stroke:#d35400,stroke-width:2px;
    classDef controller fill:#f67280,stroke:#c0392b,stroke-width:2px;
    classDef service fill:#c06c84,stroke:#6d214f,stroke-width:2px,shape:ellipse;
    classDef dto fill:#f8b195,stroke:#e55039,stroke-width:2px;
    classDef repository fill:#355c7d,stroke:#2c3e50,stroke-width:2px;
    classDef entity fill:#6c5b7b,stroke:#355c7d,stroke-width:2px;
    classDef config fill:#99b898,stroke:#27ae60,stroke-width:2px;
    classDef exception fill:#f8a5c2,stroke:#e55039,stroke-width:2px;
    classDef deployment fill:#f9d423,stroke:#e1a32a,stroke-width:2px;
    
    %% Ensure vertical layout by linking subgraphs accordingly
    Client --- A
    SC --- JP
    RS --- RC
    OC --- SW
    PC --- SW
    TC --- SW
```
