# daisuke8000/management-backend architecture

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

- Interactive diagram: https://gitdiagram.com/daisuke8000/management-backend
- Repository: https://github.com/daisuke8000/management-backend

## Overview

##### Project Type and Purpose
- This is a backend API server built in Go designed to record mahjong game results.
- It handles functionalities like recording games, managing match history, tracking scores and rankings, user authentication, and more.
- It is intended to serve the data needs of a frontend (referenced in the README as a separate repository) by exposing RESTful endpoints.

##### Main Components
a. API Entry Point:
- main.go: Represents the starting point where the server is bootstrapped.
- Configuration files (go.mod, go.sum) which set up dependencies.

b. HTTP Routing and Controllers:
- Under src/routes/routes.go: Define the endpoints that map incoming HTTP requests.

c. Middleware:
- In src/middleware/authorization.go, the middleware is likely enforcing security (authentication/authorization) before the controllers handle requests. Represent this as a layer between the incoming request and the controllers.

d. Data Management Layer:
- Models (in src/models): Represent domain entities such as user, match, history, and grade.

e. Command-Line Utilities / Fake Data Generators:
- Under src/commands (files like matchAddFaker.go and userAddFaker.go): These components are likely used for testing or populating the database with test data. Represent these as auxiliary tools that interact with the same data layer.

f. Containerization and Deployment:
- Files such as Dockerfile, docker-compose.yml, docker-compose.prod.yml, and related scripts (e.g., entrypoint.sh, develop-entrypoint.sh) indicate the deployment strategy.

g. Build and Development Tools:
- The Makefile for triggering different modes (development with “make develop” and production with “make final”) is critical to the build/deploy pipelines.

##### Relationships and Interactions
- How client requests (from the separate frontend mentioned in the README) flow into the system:
- That each request passes through the Authorization middleware before reaching the appropriate controllers.
- Controllers making calls to the data layer (models and database), representing CRUD operations.
- Command components (commands folder) either as triggered routines or one-off utilities that also interact directly with the data layer.
- In your deployment section, show containers grouping the codebase, and emphasize that Docker-compose is used to orchestrate services.

##### Architectural Patterns & Design Principles
- The project is structured in a modular fashion similar to an MVC (Model-View-Controller) design:
- Models for data.
- Controllers for business logic.
- Routes for mapping HTTP requests.
- Middleware for cross-cutting concerns like authorization.
- That even though it’s a backend API server, the structure supports maintenance and scalability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client/Frontend"
        FE("Client / Frontend"):::client
    end

    %% API Server Layer
    subgraph "API Server"
        AP("API Gateway (main.go)"):::apigateway
        Conf("Configuration Files (go.mod & go.sum)"):::config
        Route("HTTP Routing (src/routes/routes.go)"):::routes
        MW("Authorization Middleware (src/middleware/authorization.go)"):::middleware
        subgraph "Controllers"
            Auth("Auth Controller (src/controllers/authController.go)"):::controller
            Hist("History Controller (src/controllers/historyController.go)"):::controller
            MatchC("Match Controller (src/controllers/matchController.go)"):::controller
            UserC("User Controller (src/controllers/userController.go)"):::controller
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        subgraph "Models"
            Grade("Grade Model (src/models/grade.go)"):::model
            HModel("History Model (src/models/history.go)"):::model
            MModel("Match Model (src/models/match.go)"):::model
            GenModel("General Model (src/models/model.go)"):::model
            UserModel("User Model (src/models/user.go)"):::model
        end
        DB("Database (src/database/database.go)"):::database
    end

    %% Command Utilities
    subgraph "Command Utilities"
        MatchFaker("Match Data Faker (src/commands/matchAddFaker.go)"):::command
        UserFaker("User Data Faker (src/commands/userAddFaker.go)"):::command
    end

    %% Containerization & Deployment
    subgraph "Containerization & Deployment"
        Docker("Dockerfile (docker/Dockerfile)"):::docker
        DockerCompose("Docker Compose (docker-compose.yml & docker-compose.prod.yml)"):::docker
        Entrypoint("Entrypoint Scripts (entrypoint.sh, develop-entrypoint.sh)"):::docker
    end

    %% Build & Development Tools
    subgraph "Build & Development Tools"
        Make("Makefile"):::build
    end

    %% Connections
    FE -->|"requests"| AP
    AP -->|"loads"| Conf
    AP -->|"routes"| Route
    Route -->|"passesThrough"| MW
    MW -->|"calls"| Auth
    MW -->|"calls"| Hist
    MW -->|"calls"| MatchC
    MW -->|"calls"| UserC

    Auth -->|"CRUD"| DB
    Hist -->|"CRUD"| DB
    MatchC -->|"CRUD"| DB
    UserC -->|"CRUD"| DB

    UserModel ---|"mapsTo"| DB
    MModel ---|"mapsTo"| DB
    HModel ---|"mapsTo"| DB
    Grade ---|"mapsTo"| DB
    GenModel ---|"mapsTo"| DB

    MatchFaker -->|"populates"| DB
    UserFaker -->|"populates"| DB

    AP -->|"deployedVia"| Docker
    Docker -->|"orchestratedBy"| DockerCompose
    DockerCompose -->|"runs"| Entrypoint
    AP -->|"buildsWith"| Make

    %% Click Events
    click AP "https://github.com/daisuke8000/management-backend/blob/develop/main.go"
    click Conf "https://github.com/daisuke8000/management-backend/blob/develop/go.mod"
    click Route "https://github.com/daisuke8000/management-backend/blob/develop/src/routes/routes.go"
    click MW "https://github.com/daisuke8000/management-backend/blob/develop/src/middleware/authorization.go"
    click Auth "https://github.com/daisuke8000/management-backend/blob/develop/src/controllers/authController.go"
    click Hist "https://github.com/daisuke8000/management-backend/blob/develop/src/controllers/historyController.go"
    click MatchC "https://github.com/daisuke8000/management-backend/blob/develop/src/controllers/matchController.go"
    click UserC "https://github.com/daisuke8000/management-backend/blob/develop/src/controllers/userController.go"
    click Grade "https://github.com/daisuke8000/management-backend/blob/develop/src/models/grade.go"
    click HModel "https://github.com/daisuke8000/management-backend/blob/develop/src/models/history.go"
    click MModel "https://github.com/daisuke8000/management-backend/blob/develop/src/models/match.go"
    click GenModel "https://github.com/daisuke8000/management-backend/blob/develop/src/models/model.go"
    click UserModel "https://github.com/daisuke8000/management-backend/blob/develop/src/models/user.go"
    click DB "https://github.com/daisuke8000/management-backend/blob/develop/src/database/database.go"
    click MatchFaker "https://github.com/daisuke8000/management-backend/blob/develop/src/commands/matchAddFaker.go"
    click UserFaker "https://github.com/daisuke8000/management-backend/blob/develop/src/commands/userAddFaker.go"
    click Docker "https://github.com/daisuke8000/management-backend/tree/develop/docker/Dockerfile"
    click DockerCompose "https://github.com/daisuke8000/management-backend/blob/develop/docker-compose.yml"
    click Entrypoint "https://github.com/daisuke8000/management-backend/blob/develop/entrypoint.sh"
    click Make "https://github.com/daisuke8000/management-backend/tree/develop/Makefile"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef apigateway fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef config fill:#98FB98,stroke:#000,stroke-width:2px;
    classDef routes fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef middleware fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef controller fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef model fill:#F08080,stroke:#000,stroke-width:2px;
    classDef database fill:#CD5C5C,stroke:#000,stroke-width:2px;
    classDef command fill:#20B2AA,stroke:#000,stroke-width:2px;
    classDef docker fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef build fill:#F0E68C,stroke:#000,stroke-width:2px;
```
