# riadizur/simple_be_with_go_framework architecture

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

- Interactive diagram: https://gitdiagram.com/riadizur/simple_be_with_go_framework
- Repository: https://github.com/riadizur/simple_be_with_go_framework

## Overview

##### Project type and purpose
- This is a backend framework written in Go (“Simple Backend Framework with Go”) that provides:
- HTTP REST API endpoints
- WebSocket support
- SQLite3 integration
- Process logging
- Environment-variable configuration

##### File structure
- Top-level:
- .github/workflows/go.yml → CI/CD pipeline
- install.sh → bootstrap script for Go workspaces and folder structure
- kubota-gasoline-api/ → main application module
- Inside kubota-gasoline-api:
- cmd/main.go → application entrypoint and router setup
- internal/
– database/database.go → DB connection and migrations
– handlers/shift.go, websockets.go → HTTP & WS handlers
– models/shift.go → domain model definitions
- db/kubota_gasoline.db → embedded SQLite file
- log/process.log → runtime log output
- build.sh, build-win.sh → build scripts
- .env → environment configuration

##### README insights
- Emphasizes light-weight “cook-your-code” flow:
- init with install.sh
- write handlers in internal/
- build with build.sh

a. Main components
1. API Server (Go application in cmd/main.go)
2. HTTP REST Layer (handlers/shift.go)
3. WebSocket Layer (handlers/websockets.go)
4. Database Layer (database/database.go)
5. SQLite DB (db/kubota_gasoline.db)
6. Logging Subsystem (log/process.log)
7. Env Config Loader (.env)
8. CI/CD Workflow (.github/workflows/go.yml)
b. Relationships and interactions
- External client → HTTP request → REST handlers → DB layer → SQLite → return data
- External client → WebSocket handshake → WebSocket handler → push updates
- Application init → Env loader reads .env → config struct passed to DB & server
- Any handler/service → logs actions/errors → log/process.log
- CI workflow → on push → triggers tests/build → deploy artifacts
c. Architectural patterns & principles
- Layered architecture (entrypoint → handlers → services/database → persistence)
- Dependency injection via explicit config from .env
- Single-binary Go deployment (static build.sh)
d. Key technologies/frameworks
- Go standard library net/http + Gorilla/WebSocket (or similar)
- mattn/go-sqlite3 driver
- github.com/joho/godotenv (for .env)
- log package writing to file

- Layers: Entry, API, Persistence, Logging, Config, DevOps
- Interactions (DB reads, WS messages)

## Diagram (Mermaid)

```mermaid
flowchart TB
    CI["CI/CD Workflow"]:::devops
    BS["Bootstrap Script"]:::devops

    CI -->|"on push triggers"| Build_L["Linux/Mac Build"]:::devops
    CI -->|"on push triggers"| Build_W["Windows Build"]:::devops

    BS -->|"initial setup"| API["API Server Entry"]:::api

    subgraph "Configuration & Logging"
        ENV["Env Loader (.env)"]:::config
        LOG["Logging Subsystem (process.log)"]:::config
    end

    subgraph "Application Components"
        API
        subgraph "API Layer"
            REST["REST Handler"]:::api
            WS["WS Handler"]:::api
        end
        subgraph "Persistence Layer"
            DBLayer["DB Connection & Migrations"]:::persistence
            Model["Shift Model"]:::persistence
            SQLite["SQLite DB"]:::persistence
        end
    end

    API -->|"registers routes"| REST
    API -->|"registers routes"| WS
    REST -->|"Read/Write Shift Data"| DBLayer
    WS -->|"Read Data & Push Updates"| DBLayer
    DBLayer -->|"Runs Migrations & Queries"| SQLite

    ENV -.->|"inject config"| API
    ENV -.->|"inject config"| DBLayer

    REST -.->|"log actions"| LOG
    WS -.->|"log actions"| LOG
    DBLayer -.->|"log actions"| LOG

    click CI "https://github.com/riadizur/simple_be_with_go_framework/blob/main/.github/workflows/go.yml"
    click BS "https://github.com/riadizur/simple_be_with_go_framework/blob/main/install.sh"
    click Build_L "https://github.com/riadizur/simple_be_with_go_framework/blob/main/kubota-gasoline-api/build.sh"
    click Build_W "https://github.com/riadizur/simple_be_with_go_framework/blob/main/kubota-gasoline-api/build-win.sh"
    click API "https://github.com/riadizur/simple_be_with_go_framework/blob/main/kubota-gasoline-api/cmd/main.go"
    click REST "https://github.com/riadizur/simple_be_with_go_framework/blob/main/kubota-gasoline-api/internal/handlers/shift.go"
    click WS "https://github.com/riadizur/simple_be_with_go_framework/blob/main/kubota-gasoline-api/internal/handlers/websockets.go"
    click DBLayer "https://github.com/riadizur/simple_be_with_go_framework/blob/main/kubota-gasoline-api/internal/database/database.go"
    click Model "https://github.com/riadizur/simple_be_with_go_framework/blob/main/kubota-gasoline-api/internal/models/shift.go"
    click SQLite "https://github.com/riadizur/simple_be_with_go_framework/blob/main/kubota-gasoline-api/db/kubota_gasoline.db"
    click LOG "https://github.com/riadizur/simple_be_with_go_framework/blob/main/kubota-gasoline-api/log/process.log"
    click ENV "https://github.com/riadizur/simple_be_with_go_framework/blob/main/kubota-gasoline-api/.env"

    classDef api fill:#D0E8FF,stroke:#007BFF,color:#000;
    classDef persistence fill:#DFF5D0,stroke:#28A745,color:#000;
    classDef config fill:#FFE5B4,stroke:#FFA500,color:#000;
    classDef devops fill:#E0E0E0,stroke:#6c757d,color:#000;
```
