# erlendromo/forsete-atr architecture

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

- Interactive diagram: https://gitdiagram.com/erlendromo/forsete-atr
- Repository: https://github.com/erlendromo/forsete-atr

## Overview

##### Project type and purpose
- This is a Go-based REST API microservice called “forsete-atr” that implements a Handwritten Text Recognition (HTR) pipeline.
- It is containerized with Docker (CPU/GPU variants), orchestrated via Docker Compose, and its infrastructure is provisioned via Terraform.
- It exposes a versioned API (`/forsete-atr/v1/…`) with Swagger UI docs.

##### File structure
- Top-level:
- `main.go`, `go.mod`, `go.sum` – entry point & dependency manifest
- `docker/`, `docker-compose.yaml` – Dockerfiles and Compose definitions for CPU/GPU deployments
- `backend/` – Terraform configs for provisioning cloud resources (e.g., Openstack instances, networking)
- `scripts/` – helper scripts to bootstrap environments on Linux/Mac/Windows
- CI/CD: `.github/workflows/` (build, test, terraform-destroy) and `.github/actions/` (format, test_go, validate)
- `docs/` – Swagger JSON/YAML and Go doc stub
- `src/` directory follows a layered structure:
- `src/api/` – HTTP adapters (handlers, middleware, router)
- `src/cmd/rest/` – CLI entry for REST server
- `src/config/` – environment and config loading
- `src/domain/` – core business logic:
– `htrflow` (pipeline orchestration)
– `image` (image processing)
– `modelstore` (model persistence & retrieval)
– `pipeline/step` (individual pipeline stages)
- `src/util/` – shared utilities (error handling, logging, timing)

##### README for additional insights
- Deployment targets: CPU vs. GPU containers
- Environment variables and ports must match Terraform (`API_PORT` = `application_port`)
- Usage patterns: Makefile targets (`composecpu`, `composegpu`, `attach`, `composedown`)
- API discovery via Swagger UI

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer & Repo
    Dev["Developer Workstation"]:::external -->|push code| Repo["GitHub Repository"]:::external

    %% CI/CD
    subgraph "CI/CD Pipeline"
        direction TB
        GH_Workflows["Workflows"]:::ci
        GH_Actions["Actions"]:::ci
    end
    Repo -->|trigger| GH_Workflows
    GH_Workflows -->|uses| GH_Actions
    GH_Actions -->|build/test/validate| ImageRegistry["Docker Image Registry"]:::runtime

    %% Infrastructure Provisioning
    ImageRegistry -->|artifact| Terraform["Terraform (backend/)"]:::infra
    Terraform -->|apply| CloudInfra["Cloud VM & Network"]:::infra

    %% Container Orchestration
    CloudInfra -->|deploy| DockerCompose["Docker Compose"]:::infra
    DockerCompose -->|start| Service["HTR API Service Container"]:::runtime

    %% Client Data Flow
    Client["API Client"]:::external -->|HTTP requests| Service
    Service -->|HTTP responses| Client

    %% External Dependency
    Service -->|reads/writes| ModelStoreExt["ModelStore (S3 or Volume)"]:::runtime

    %% REST API Service Internal Structure
    subgraph "REST API Service" 
        direction TB
        subgraph "API Layer"
            direction TB
            Router["Router"]:::code
            Middleware["Middleware"]:::code
            Handlers["Handlers"]:::code
        end
        subgraph "Domain Layer"
            direction TB
            HTRFlow["HTRFlow"]:::code
            ImageComp["Image Processing"]:::code
            ModelStoreComp["ModelStore Logic"]:::code
            Pipeline["Pipeline Coordination"]:::code
            subgraph "Pipeline Steps"
                direction TB
                ExportStep["ExportStep"]:::code
                ModelStep["ModelStep"]:::code
                OrderStep["OrderStep"]:::code
                StepInterface["Step Interface"]:::code
            end
        end
        subgraph "Config & Util"
            direction TB
            Config["Configuration Loader"]:::code
            Util["Utilities"]:::code
        end

        %% Internal Connections
        Router -->|route| Middleware -->|process| Handlers
        Handlers -->|invoke| HTRFlow -->|orchestrates| Pipeline
        Pipeline --> ExportStep & ModelStep & OrderStep & StepInterface
        Handlers -->|use| ImageComp
        HTRFlow -->|use| ModelStoreComp
        ServiceConfig["Env & Config"]:::code
        ServiceConfig --> Config & Util
    end

    %% Styles
    classDef infra fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef runtime fill:#90EE90,stroke:#333,stroke-width:1px
    classDef ci fill:#FFA500,stroke:#333,stroke-width:1px
    classDef code fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef external fill:#CCCCCC,stroke:#333,stroke-width:1px

    %% Click Events
    click Dev "https://github.com/erlendromo/forsete-atr/tree/main/n/a"
    click Repo "https://github.com/erlendromo/forsete-atr/tree/main/n/a"
    click GH_Workflows "https://github.com/erlendromo/forsete-atr/tree/main/.github/workflows/"
    click GH_Actions "https://github.com/erlendromo/forsete-atr/tree/main/.github/actions/"
    click ImageRegistry "https://github.com/erlendromo/forsete-atr/tree/main/docker/"
    click Terraform "https://github.com/erlendromo/forsete-atr/tree/main/backend/"
    click CloudInfra "https://github.com/erlendromo/forsete-atr/tree/main/backend/"
    click DockerCompose "https://github.com/erlendromo/forsete-atr/blob/main/docker-compose.yaml"
    click Service "https://github.com/erlendromo/forsete-atr/blob/main/src/cmd/rest/rest.go"
    click ModelStoreExt "https://github.com/erlendromo/forsete-atr/blob/main/src/domain/modelstore/modelstore.go"

    %% Top-level files
    click main.go "https://github.com/erlendromo/forsete-atr/blob/main/main.go"
    click go.mod "https://github.com/erlendromo/forsete-atr/blob/main/go.mod"
    click go.sum "https://github.com/erlendromo/forsete-atr/blob/main/go.sum"

    %% Docker
    click DockerCompose "https://github.com/erlendromo/forsete-atr/blob/main/docker-compose.yaml"
    click CPU_Dockerfile "https://github.com/erlendromo/forsete-atr/tree/main/docker/Dockerfile"
    click GPU_Compose "https://github.com/erlendromo/forsete-atr/blob/main/docker/docker-compose-gpu.yaml"

    %% CI/CD Workflows
    click Dev_Workflow "https://github.com/erlendromo/forsete-atr/blob/main/.github/workflows/dev.yaml"
    click Feature_Workflow "https://github.com/erlendromo/forsete-atr/blob/main/.github/workflows/feature.yaml"
    click TF_Destroy_Workflow "https://github.com/erlendromo/forsete-atr/blob/main/.github/workflows/terraform-destroy.yaml"

    %% CI/CD Actions
    click Format_Action "https://github.com/erlendromo/forsete-atr/blob/main/.github/actions/format/action.yaml"
    click TestGo_Action "https://github.com/erlendromo/forsete-atr/blob/main/.github/actions/test_go/action.yaml"
    click Validate_Action "https://github.com/erlendromo/forsete-atr/blob/main/.github/actions/validate/action.yaml"

    %% Scripts
    click Scripts "https://github.com/erlendromo/forsete-atr/tree/main/scripts/"
    click HTRFlow_Script "https://github.com/erlendromo/forsete-atr/blob/main/scripts/htrflow.sh"
    click Linux_Script "https://github.com/erlendromo/forsete-atr/blob/main/scripts/linux.sh"
    click MacOS_Script "https://github.com/erlendromo/forsete-atr/blob/main/scripts/macos.sh"
    click Windows_Script "https://github.com/erlendromo/forsete-atr/blob/main/scripts/windows.bat"

    %% API Layer
    click Router "https://github.com/erlendromo/forsete-atr/blob/main/src/api/router/router.go"
    click HTTPRouter "https://github.com/erlendromo/forsete-atr/blob/main/src/api/router/httprouter/httprouter.go"
    click HTTPSRouter "https://github.com/erlendromo/forsete-atr/blob/main/src/api/router/httpsrouter/httpsrouter.go"
    click Middleware "https://github.com/erlendromo/forsete-atr/blob/main/src/api/middleware/context.go"
    click Logger_MW "https://github.com/erlendromo/forsete-atr/blob/main/src/api/middleware/logger.go"
    click StatusResp_MW "https://github.com/erlendromo/forsete-atr/blob/main/src/api/middleware/statusresponsewriter.go"
    click ATR_Basic "https://github.com/erlendromo/forsete-atr/blob/main/src/api/handler/atr/basichandler.go"
    click ATR_TipNote "https://github.com/erlendromo/forsete-atr/blob/main/src/api/handler/atr/tipnotehandler.go"
    click Model_Line "https://github.com/erlendromo/forsete-atr/blob/main/src/api/handler/model/linehandler.go"
    click Model_Handler "https://github.com/erlendromo/forsete-atr/blob/main/src/api/handler/model/modelhandler.go"
    click Region_Handler "https://github.com/erlendromo/forsete-atr/blob/main/src/api/handler/model/regionhandler.go"
    click Text_Handler "https://github.com/erlendromo/forsete-atr/blob/main/src/api/handler/model/texthandler.go"
    click Status_Handler "https://github.com/erlendromo/forsete-atr/blob/main/src/api/handler/status/statushandler.go"

    %% CLI Entry
    click REST_CLI "https://github.com/erlendromo/forsete-atr/blob/main/src/cmd/rest/rest.go"

    %% Config
    click Config "https://github.com/erlendromo/forsete-atr/blob/main/src/config/config.go"

    %% Domain Layer
    click HTRFlow "https://github.com/erlendromo/forsete-atr/blob/main/src/domain/htrflow/htrflow.go"
    click ImageComp "https://github.com/erlendromo/forsete-atr/blob/main/src/domain/image/image.go"
    click ModelStoreComp "https://github.com/erlendromo/forsete-atr/blob/main/src/domain/modelstore/modelstore.go"
    click Model_Def "https://github.com/erlendromo/forsete-atr/blob/main/src/domain/modelstore/model/model.go"
    click Pipeline "https://github.com/erlendromo/forsete-atr/blob/main/src/domain/pipeline/pipeline.go"
    click ExportStep "https://github.com/erlendromo/forsete-atr/blob/main/src/domain/pipeline/step/exportstep.go"
    click ModelStep "https://github.com/erlendromo/forsete-atr/blob/main/src/domain/pipeline/step/modelstep.go"
    click OrderStep "https://github.com/erlendromo/forsete-atr/blob/main/src/domain/pipeline/step/orderstep.go"
    click StepInterface "https://github.com/erlendromo/forsete-atr/blob/main/src/domain/pipeline/step/step.go"

    %% Utilities
    click Util "https://github.com/erlendromo/forsete-atr/blob/main/src/util/constant.go"
    click Errors_Util "https://github.com/erlendromo/forsete-atr/blob/main/src/util/errors.go"
    click Logdata_Util "https://github.com/erlendromo/forsete-atr/blob/main/src/util/logdata.go"
    click Timer_Util "https://github.com/erlendromo/forsete-atr/blob/main/src/util/timer.go"
    click Writer_Util "https://github.com/erlendromo/forsete-atr/blob/main/src/util/writer.go"

    %% Docs
    click Docs "https://github.com/erlendromo/forsete-atr/tree/main/docs/"
    click SwaggerJSON "https://github.com/erlendromo/forsete-atr/blob/main/docs/swagger.json"
    click SwaggerYAML "https://github.com/erlendromo/forsete-atr/blob/main/docs/swagger.yaml"
    click DocsGo "https://github.com/erlendromo/forsete-atr/blob/main/docs/docs.go"
```
