# marcelofabianov/gocambio architecture

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

- Interactive diagram: https://gitdiagram.com/marcelofabianov/gocambio
- Repository: https://github.com/marcelofabianov/gocambio

## Overview

##### Project type and purpose
- This is a Go-based client-server application (a lightweight microservice system) packaged with Docker Compose.
- The **server** exposes an HTTP endpoint that fetches USD→BRL quotes from an external API, persists them in SQLite, and returns the JSON.
- The **client** invokes that server endpoint, extracts the “bid” value, and writes it to a text file.

##### File structure
- Top level
- docker-compose.yml – orchestrates two services (server & client) and named volumes for persistence.
- go.mod / go.sum – Go module definitions.
- .dockerignore / .gitignore – ignore rules for Docker build and VCS.
- Directories
- server/
– server.go: HTTP API logic, external-API call, SQLite persistence.
– Dockerfile: builds the server container.
- client/
– client.go: HTTP client logic, file write.
– Dockerfile: builds the client container.

##### README for additional insights
- Timeouts managed via Go’s context:
- 200 ms for external API call
- 10 ms for DB write
- 300 ms total for client→server call
- Volumes:
- server_data (cotacoes.db)
- client_output (cotacao.txt)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Docker Compose"
        direction TB
        Compose["Docker Compose Orchestrator"]:::orchestrator
        subgraph "Containers"
            direction TB
            Server["go-server Container"]:::container
            Client["go-client Container"]:::container
        end
        subgraph "Volumes"
            direction TB
            ServerVol["server_data Volume"]:::volume
            ClientVol["client_output Volume"]:::volume
        end
    end

    External["AwesomeAPI (economia.awesomeapi.com.br)"]:::external
    DB["SQLite DB (cotacoes.db)"]:::database

    Client -->|"1. HTTP GET /cotacao\n300ms timeout"| Server
    Server -->|"2. HTTP GET External API\n200ms timeout"| External
    Server -->|"3. SQLite WRITE\n10ms timeout"| DB
    Client -->|"4. WRITE cotacao.txt"| ClientVol
    Server -->|Mounted| ServerVol

    %% Project files
    subgraph "Project Files"
        direction TB
        GoMod["go.mod"]:::file
        GoSum["go.sum"]:::file
        Dockerignore[".dockerignore"]:::file
        Gitignore[".gitignore"]:::file
        Readme["README.md"]:::file
    end

    classDef container fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef orchestrator fill:#87CEFA,stroke:#000,stroke-width:1px;
    classDef database fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px,stroke-dasharray: 5 5;
    classDef volume fill:#FFFACD,stroke:#000,stroke-width:1px,stroke-dasharray: 2 2;
    classDef file fill:#F5F5F5,stroke:#000,stroke-width:1px,stroke-dasharray: 2 2;

    %% Click events
    click Compose "https://github.com/marcelofabianov/gocambio/blob/main/docker-compose.yml"
    click Server "https://github.com/marcelofabianov/gocambio/tree/main/server/Dockerfile"
    click Client "https://github.com/marcelofabianov/gocambio/tree/main/client/Dockerfile"
    click Server "https://github.com/marcelofabianov/gocambio/blob/main/server/server.go"
    click Client "https://github.com/marcelofabianov/gocambio/blob/main/client/client.go"
    click GoMod "https://github.com/marcelofabianov/gocambio/blob/main/go.mod"
    click GoSum "https://github.com/marcelofabianov/gocambio/blob/main/go.sum"
    click Dockerignore "https://github.com/marcelofabianov/gocambio/blob/main/.dockerignore"
    click Gitignore "https://github.com/marcelofabianov/gocambio/blob/main/.gitignore"
    click Readme "https://github.com/marcelofabianov/gocambio/blob/main/README.md"
```
