# park-seaweed/gin-gorm-prac architecture

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

- Interactive diagram: https://gitdiagram.com/park-seaweed/gin-gorm-prac
- Repository: https://github.com/park-seaweed/gin-gorm-prac

## Overview

##### Project’s Main Components
- Web Server & Routing: The entry point is main.go, which bootstraps the application. The routing is managed under the internal/router directory (e.g., router.go, post_router.go, user_router.go) and sets up the endpoints.
- Controllers: Located in internal/controller, these provide the HTTP handlers for the various endpoints (post_controller.go, user_controller.go).
- Services: Found in internal/service, these files (post_service.go, user_service.go) contain the business logic that the controllers use to process requests.
- Data Access / Repositories: The internal/repository folder includes repository implementations (post_repository.go, user_repository.go) that interface with the database via GORM.
- Models & DTOs: The internal/model directory contains the data models for posts and users, while internal/dto holds Data Transfer Objects used to move data around.
- Configuration: The internal/config package centralizes configuration (including database settings in internal/config/database/gorm_config.go and loader.go) which sets up environment variables and app settings.
- Logging & Middleware: The internal/logger and internal/middleware directories provide logging (with zap, for example) and middleware functionality to inject cross-cutting concerns like logging or error handling.
- Docker Compose: The docker-compose.yaml suggests containerized deployment, possibly orchestrating the application with a database container.

##### Relationships & Interactions
- The application is initiated in main.go where the configuration, logging, and routing setup are triggered.
- The Router maps HTTP calls to Controller functions.
- The Controllers delegate business logic to the Service layer.
- The Services interact with the Repository layer to perform operations against the database using GORM.
- Middleware and Logging components are integrated into the routing (or controller) layer to handle logging and cross-cutting concerns.
- The configuration modules load environment variables and DB settings, which are used across the system.

##### Architectural Patterns and Design Principles
- Layered Architecture: The project follows an MVC-like or layered approach, separating concerns into controllers, services, and repositories.
- Separation of Concerns: Each folder in the internal directory is given a distinct responsibility (routing, business logic, data access, configuration, logging).
- Dependency Injection: Although not explicitly stated, the separation implies that dependencies (e.g., database connections, configuration settings) are passed among layers, facilitating testability and modularity.
- Use of External Configurations and Docker for Deployment: The docker-compose and configuration files promote a containerized and environment-specific setup.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Point and Configuration
    A0["Entry Point: main.go"]:::entry
    subgraph "Configuration"
        O["config.go"]:::config
        P["loader.go"]:::config
        Q["gorm_config.go"]:::config
    end
    %% Web Server & Routing
    subgraph "Web Server & Routing"
        A1["router.go"]:::router
        A2["post_router.go"]:::router
        A3["user_router.go"]:::router
    end
    %% Controllers
    subgraph "Controllers"
        B1["controller.go"]:::controller
        B2["post_controller.go"]:::controller
        B3["user_controller.go"]:::controller
    end
    %% Services
    subgraph "Services"
        C1["post_service.go"]:::service
        C2["user_service.go"]:::service
    end
    %% Repositories
    subgraph "Repositories"
        D1["post_repository.go"]:::repository
        D2["user_repository.go"]:::repository
    end
    %% Models & DTOs
    subgraph "Models & DTOs"
        E1["post.go"]:::model
        E2["user.go"]:::model
        E3["post_dto.go"]:::model
        E4["user_dto.go"]:::model
    end
    %% Logging and Middleware
    R["Logger"]:::logger
    S["Middleware"]:::middleware
    %% Database
    T["Database"]:::db
    %% Docker Compose Deployment
    U["Docker Compose"]:::docker

    %% Relationships
    A0 -->|"InitRouter"| A1
    A0 -->|"loadsConfig"| O
    A1 -->|"HTTPRequest"| B1
    B1 -->|"BizLogicCall"| C1
    C1 -->|"DataAccess"| D1
    D1 -->|"DBQuery"| T

    %% Integration of Logging & Middleware in Router layer
    A1 -->|"usesMW"| S
    A1 -->|"usesLogging"| R

    %% Docker Compose deployment arrows
    U -->|"deploysApp"| A0
    U -->|"deploysDB"| T

    %% Click Events
    click A0 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/main.go"
    click A1 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/router/router.go"
    click A2 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/router/post_router.go"
    click A3 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/router/user_router.go"
    click B1 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/controller/controller.go"
    click B2 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/controller/post_controller.go"
    click B3 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/controller/user_controller.go"
    click C1 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/service/post_service.go"
    click C2 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/service/user_service.go"
    click D1 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/repository/post_repository.go"
    click D2 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/repository/user_repository.go"
    click E1 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/model/post.go"
    click E2 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/model/user.go"
    click E3 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/dto/post_dto.go"
    click E4 "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/dto/user_dto.go"
    click O "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/config/config.go"
    click P "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/config/loader.go"
    click Q "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/config/database/gorm_config.go"
    click R "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/logger/logger.go"
    click S "https://github.com/park-seaweed/gin-gorm-prac/blob/main/internal/middleware/zap_logger.go"
    click U "https://github.com/park-seaweed/gin-gorm-prac/blob/main/docker-compose.yaml"

    %% Styles
    classDef entry fill:#FFEEAD,stroke:#333,stroke-width:2px
    classDef router fill:#B8E0D2,stroke:#333,stroke-width:2px
    classDef controller fill:#FFB347,stroke:#333,stroke-width:2px
    classDef service fill:#CFCFCF,stroke:#333,stroke-width:2px
    classDef repository fill:#F7A1A1,stroke:#333,stroke-width:2px
    classDef model fill:#A1C6EA,stroke:#333,stroke-width:2px
    classDef config fill:#D3B4FF,stroke:#333,stroke-width:2px
    classDef logger fill:#FFDAC1,stroke:#333,stroke-width:2px
    classDef middleware fill:#CAFFBF,stroke:#333,stroke-width:2px
    classDef docker fill:#FFE0F3,stroke:#333,stroke-width:2px
    classDef db fill:#FFF2CC,stroke:#333,stroke-width:2px
```
