# katriyda/orderfood architecture

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

- Interactive diagram: https://gitdiagram.com/katriyda/orderfood
- Repository: https://github.com/katriyda/orderfood

## Overview

##### Project Type and Purpose
- This is a backend service for an online ordering system, built with Spring Boot. It handles authentication (including JWT authorization), order processing, and management of dishes and dish types.
- External components such as the separate user and manager front-ends and the relational database (which users need to set up manually).

##### Analyzing the File Structure
- The top-level structure includes configuration (under the "config" package), controllers, domain objects (entities such as Dish, DishType, Order, and User), mappers (data access layer, likely using MyBatis), service interfaces and their implementations, utilities (for handling JWTs), and tests.
- The directory tree follows standard Maven project conventions, with the separation of Java source files (src/main/java) and resources (src/main/resources). This indicates adherence to common Spring Boot practices.
- Notice the interceptor (JwtInterceptor) and configuration files for JWT (JwtConfig) and web settings (WebConfig). These clearly imply security and web request handling components integrated into the application.
- The project includes SQL initialization scripts and an application configuration file (application.yml) that references database connectivity and file storage paths.

##### Key Components
a. Front-End Clients:

b. Backend API Layer (the Spring Boot application):
- Controllers: Represented as distinct components (e.g., DishController, OrderController, LoginController, etc.) that handle HTTP requests and responses.
- Services: These components (e.g., DishService, OrderService) encapsulate the business logic.
- Mappers: Illustrate how data is persisted by mapping between domain objects and the database. This layer typically uses frameworks such as MyBatis.
- Domain Models: Core entities like Dish, Order, User, etc.
- Security & Interceptors: Include the custom authorization filters, JWT configurations, and the JwtInterceptor that validates requests.
- Configuration: Include custom configuration classes (e.g., CustomAuthorization, WebConfig) which govern application behavior.
- Utility classes: For instance, JwtUtils facilitates the handling of JWT tokens.

c. Database:

##### Architectural Relationships and Data Flow
- That the front-end clients interact with the backend API via HTTP(S) requests.
- That controllers in the Spring Boot application delegate business operations to the service layer.
- Demonstrate how service implementations access persistence via the mapper layer.
- Security by showing how the authentication flow is managed via JwtConfig, JwtUtils, and JwtInterceptor.
- Dependency relationships, such as configuration settings affecting multiple layers (e.g., web configuration affecting both controllers and interceptors).

##### Design Principles and Patterns
- The architecture follows common Spring Boot patterns with a clear separation of concerns:
- MVC Pattern: Controllers handle requests and responses; Services manage business logic; Mappers serve as the data access layer.
- Layered Architecture: Clearly segregated layers (controller, service, data access) which promote maintainability.
- Security: Implementation of JWT-based authentication and authorization.
- Use of dependency injection, modular component design, and testing (unit tests under src/test).

##### Technologies and Frameworks
- Spring Boot for application configuration and web services.
- Maven for project build and dependency management.
- Possibly MyBatis (or a similar ORM) for mapper-based database interaction.
- JWT for authentication and security.
- A relational database (e.g., MySQL) configured via application.yml.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Frontend Clients
    A("User Frontend"):::external
    B("Admin Frontend"):::external

    %% Main Application
    C("OrderfoodApplication (Spring Boot)"):::backend

    %% Backend API Layer - Controllers
    subgraph "Controllers Layer"
        D("DishController"):::controller
        E("OrderController"):::controller
        F("LoginController"):::controller
        G("DataController"):::controller
        H("DishTypeController"):::controller
        I("FileUploadController"):::controller
        J("StatusController"):::controller
        K("UserController"):::controller
    end

    %% Service Layer
    subgraph "Service Layer"
        L("DishService"):::service
        M("OrderService"):::service
        N("LoginService"):::service
        O("DataService"):::service
        P("DishTypeService"):::service
        Q("FileUploadService"):::service
        R("StatusService"):::service
        S("UserService"):::service
    end

    %% Data Access (Mapper Layer)
    subgraph "Mapper Layer"
        T("DishMapper"):::mapper
        U("DishTypeMapper"):::mapper
        V("OrderMapper"):::mapper
        W("UserMapper"):::mapper
    end

    %% Domain Models
    subgraph "Domain Models"
        X("Dish"):::domain
        Y("DishType"):::domain
        Z("Order"):::domain
        AA("User"):::domain
        AB("DishVO"):::domain
        AC("ApiResponse"):::domain
    end

    %% Security & Configuration
    subgraph "Security & Config"
        AD("JwtConfig/CustomAuthorization"):::security
        AE("JwtInterceptor"):::security
        AF("WebConfig"):::config
        AG("application.yaml"):::config
    end

    %% Utility Components
    subgraph "Utilities"
        AH("JwtUtils"):::utility
    end

    %% Database
    subgraph "Database"
        AI(("MySQL: online_order")):::database
    end

    %% Relationships: External Clients to Main App
    A -->|"HTTP(S) request"| C
    B -->|"HTTP(S) request"| C

    %% Main Application bootstraps Controllers
    C -->|"initializes"| D
    C -->|"initializes"| E
    C -->|"initializes"| F
    C -->|"initializes"| G
    C -->|"initializes"| H
    C -->|"initializes"| I
    C -->|"initializes"| J
    C -->|"initializes"| K

    %% Controllers delegate to Services
    D -->|"calls"| L
    E -->|"calls"| M
    F -->|"calls"| N
    G -->|"calls"| O
    H -->|"calls"| P
    I -->|"calls"| Q
    J -->|"calls"| R
    K -->|"calls"| S

    %% Services use Domain Models
    L -->|"processes"| X
    M -->|"processes"| Z
    N -->|"processes"| AA
    P -->|"processes"| Y

    %% Services interact with Mappers (Data Access)
    L -->|"invokes"| T
    M -->|"invokes"| V
    N -->|"invokes"| W
    S -->|"invokes"| U

    %% Mappers persist data to Database
    T -->|"persists"| AI
    U -->|"persists"| AI
    V -->|"persists"| AI
    W -->|"persists"| AI

    %% Security: JWT Interceptor validates requests before Controllers process them
    AE ---|"intercepts"| D
    AE ---|"intercepts"| E
    AE ---|"intercepts"| F
    AE ---|"intercepts"| G
    AE ---|"intercepts"| H
    AE ---|"intercepts"| I
    AE ---|"intercepts"| J
    AE ---|"intercepts"| K

    %% Security configuration flow
    AD -->|"configures"| AE
    AF -->|"configures"| D
    AF -->|"configures"| E
    AF -->|"configures"| F
    AF -->|"configures"| G
    AF -->|"configures"| H
    AF -->|"configures"| I
    AF -->|"configures"| J
    AF -->|"configures"| K

    %% Utility usage in Security
    AH -->|"assists"| AE

    %% Click Events
    click C "https://github.com/katriyda/orderfood/blob/master/src/main/java/tk/katr/orderfood/OrderfoodApplication.java"
    click D "https://github.com/katriyda/orderfood/tree/master/src/main/java/tk/katr/orderfood/controller"
    click L "https://github.com/katriyda/orderfood/tree/master/src/main/java/tk/katr/orderfood/service"
    click M "https://github.com/katriyda/orderfood/tree/master/src/main/java/tk/katr/orderfood/service/impl"
    click T "https://github.com/katriyda/orderfood/tree/master/src/main/java/tk/katr/orderfood/mapper"
    click X "https://github.com/katriyda/orderfood/tree/master/src/main/java/tk/katr/orderfood/domain"
    click AD "https://github.com/katriyda/orderfood/blob/master/src/main/java/tk/katr/orderfood/config/JwtConfig.java"
    click AE "https://github.com/katriyda/orderfood/blob/master/src/main/java/tk/katr/orderfood/interceptor/JwtInterceptor.java"
    click AF "https://github.com/katriyda/orderfood/blob/master/src/main/java/tk/katr/orderfood/config/WebConfig.java"
    click AG "https://github.com/katriyda/orderfood/blob/master/src/main/resources/application.yaml"
    click AH "https://github.com/katriyda/orderfood/blob/master/src/main/java/tk/katr/orderfood/utils/JwtUtils.java"
    click AI "https://github.com/katriyda/orderfood/blob/master/src/main/resources/sql/order_food.sql"

    %% Styles
    classDef external fill:#AEDFF7,stroke:#036,stroke-width:2px;
    classDef backend fill:#F7D6AE,stroke:#A63,stroke-width:2px;
    classDef controller fill:#F0E68C,stroke:#B8860B,stroke-width:2px;
    classDef service fill:#98FB98,stroke:#2E8B57,stroke-width:2px;
    classDef mapper fill:#FFB6C1,stroke:#C71585,stroke-width:2px;
    classDef domain fill:#D8BFD8,stroke:#8B008B,stroke-width:2px;
    classDef security fill:#FFC0CB,stroke:#FF69B4,stroke-width:2px;
    classDef config fill:#E0FFFF,stroke:#20B2AA,stroke-width:2px;
    classDef utility fill:#FFFACD,stroke:#DAA520,stroke-width:2px;
    classDef database fill:#FFEFD5,stroke:#FF8C00,stroke-width:2px;
```
