# yosp313/basic-api_go architecture

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

- Interactive diagram: https://gitdiagram.com/yosp313/basic-api_go
- Repository: https://github.com/yosp313/basic-api_go

## Overview

##### Main Components

A. External Layer (Client Interaction)
- HTTP Client/Consumer
- REST API Endpoints
- Docker Container (noted from Dockerfile presence)

B. Application Layers (Top to Bottom)
1. Routes Layer
2. Middleware Layer
3. Controllers Layer
4. Services Layer
5. Models Layer (Data Access)
6. Database Layer (SQLite)

- [Client Layer]
- ↓
- [Docker Container]
- ↓
- [Routes Layer (routes/routes.go)]
- ↓
- [Middleware Layer (middleware/middleware.go)]
- ↓
- [Controllers Layer]
- ↓
- [Services Layer]
- ↓
- [Models Layer]
- ↓
- [Database (SQLite)]

##### Component Details

a. Routes Layer:
- Main endpoints (/product, /, /ip)
- To respective controllers

b. Controllers:
- BasicControllers (for / and /ip endpoints)
- ProductControllers (for CRUD operations)
- Connection to Services layer

c. Services Layer:
- ProductServices (business logic)
- Connection to Models layer

d. Models Layer:
- ProductModel (data structure and DB operations)
- GORM integration

##### Additional Elements

a. A Configuration Component:
- Configs/configs.go connection to other layers
- Role in system configuration

b. Utils Component:
- Utils/utils.go as a cross-cutting concern
- To all layers that might use utilities

##### Technical Details to Note

- GORM as the ORM tool
- SQLite as the database
- Go version
- Key dependencies

##### Implementation Notes

- HTTP methods (GET, POST, PUT, DELETE) next to relevant routes
- Error handling flow (based on TODO item)

Use tools like:
- Lucidchart

##### The data flow from client request to database operation and back

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions while avoiding implementation-specific details that might change frequently.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        HTTP[HTTP Client/Consumer]:::client
    end

    subgraph Infrastructure
        Docker[Docker Container]:::infrastructure
        click Docker "https://github.com/yosp313/basic-api_Go/tree/main/Dockerfile"
    end

    subgraph Application
        Server[Server Entry Point]:::app
        click Server "https://github.com/yosp313/basic-api_Go/blob/main/server.go"

        subgraph Routes
            Router[Routes Handler]:::routes
            click Router "https://github.com/yosp313/basic-api_Go/blob/main/routes/routes.go"
        end

        subgraph Middleware
            MW[Request Middleware]:::middleware
            click MW "https://github.com/yosp313/basic-api_Go/blob/main/middleware/middleware.go"
        end

        subgraph Controllers
            BC[Basic Controllers]:::controller
            PC[Product Controllers]:::controller
            click BC "https://github.com/yosp313/basic-api_Go/blob/main/controllers/BasicControllers.go"
            click PC "https://github.com/yosp313/basic-api_Go/blob/main/controllers/ProductControllers.go"
        end

        subgraph Services
            PS[Product Services]:::service
            click PS "https://github.com/yosp313/basic-api_Go/blob/main/services/ProductServices.go"
        end

        subgraph Models
            PM[Product Model]:::model
            click PM "https://github.com/yosp313/basic-api_Go/blob/main/models/ProductModel.go"
        end

        subgraph Support
            Config[Configuration]:::support
            Utils[Utilities]:::support
            click Config "https://github.com/yosp313/basic-api_Go/blob/main/configs/configs.go"
            click Utils "https://github.com/yosp313/basic-api_Go/blob/main/utils/utils.go"
        end
    end

    subgraph Database
        DB[(SQLite)]:::database
    end

    %% Connections
    HTTP --> Docker
    Docker --> Server
    Server --> Router
    Router --> MW
    MW --> BC & PC
    BC & PC --> PS
    PS --> PM
    PM --> DB
    
    %% Support connections
    Config -.-> Server
    Config -.-> Router
    Config -.-> DB
    Utils -.-> BC
    Utils -.-> PC
    Utils -.-> PS
    Utils -.-> PM

    %% Styles
    classDef client fill:#a8d1f0
    classDef infrastructure fill:#d3d3d3
    classDef app fill:#90EE90
    classDef routes fill:#98FB98
    classDef middleware fill:#FFE4B5
    classDef controller fill:#98FB98
    classDef service fill:#98FB98
    classDef model fill:#98FB98
    classDef support fill:#DDA0DD
    classDef database fill:#FFA07A

    %% Legend
    subgraph Legend
        L1[Client]:::client
        L2[Infrastructure]:::infrastructure
        L3[Application Components]:::app
        L4[Middleware]:::middleware
        L5[Support Components]:::support
        L6[(Database)]:::database
    end
```
