# ahobsonsayers/abs-tract architecture

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

- Interactive diagram: https://gitdiagram.com/ahobsonsayers/abs-tract
- Repository: https://github.com/ahobsonsayers/abs-tract

## Overview

##### Project Overview and Type
- abs-tract is a single-service, containerized application written in Go. It acts as a metadata provider for AudiobookShelf by supplying book metadata from various providers (currently Goodreads and Kindle).
- The project is “all-in-one” in that it contains both the HTTP API server and the separate metadata provider implementations. It is meant to be run in Docker (with Dockerfile, docker-compose.yaml) and comes with CI/CD pipelines (via GitHub workflows).

##### Analyzing the File Structure and Its Implications
- Top-Level Directories/Files:
– Files like go.mod, go.sum, and main.go indicate a Go application. The presence of configuration files (.dockerignore, Dockerfile, docker-compose.yaml) confirms a containerized deployment.
– The directory “server” contains the HTTP server code: router.go (for routing), server.go, and auto-generated server code (server.gen.go) which likely help wire up the API based on an OpenAPI specification.
– The “goodreads” and “kindle” directories each have their own Go files (and tests) which implement the logic for calling external services, parsing responses, and formatting metadata.
– The “schema” folder holds an OpenAPI YAML file that defines the API specifications, suggesting that parts of the server code might be auto-generated or validated against this contract.
– The “utils” directory groups common helper functions (HTTP, URL handling, etc.) used across the application.

##### Main Components
a. API Gateway / HTTP Server:
– Represent the HTTP server as the central component. Include the “server” package, with components for routing (server/router.go) and HTTP handling.
– Annotate that the server uses the OpenAPI specification (schema/openapi.yaml) for API contract/documentation.

b. Metadata Provider Modules:
– Highlight that each provider has a set of functionalities (search, constructing a metadata response) and separate test files for ensuring correctness.

c. Utilities and Shared Modules:
– Represent a shared utilities module (“utils”) which supports HTTP communication and URL handling across providers.

d. External Dependencies / Client Invocations:
– Include underlying external services (if applicable) like the Goodreads API and Kindle Store endpoints from which data is retrieved.

e. Docker Infrastructure and CI/CD:
– Although not the core runtime architecture, you may annotate that Docker deployment (via Dockerfile and docker-compose.yaml) and GitHub workflows (in the .github directory) provide the continuous integration and deployment pipeline.

##### Relationships and Data Flow
- From the HTTP server, indicate how requests are dispatched to the respective metadata provider modules (e.g., /goodreads endpoints go to the Goodreads provider, /kindle endpoints go to the Kindle provider).
- Possible data flow from the providers outbound to the external APIs (i.e., remote Goodreads API calls or Kindle store requests) even if these are abstracted inside each provider.
- Also, show that the utils module supports and is used by both the server and providers.

##### Architectural Patterns
- This project follows a modular layered design:
- Presentation/API Layer: The server and router which expose endpoints.
- Business/Domain Layer: The provider-specific logic for Goodreads and Kindle.
- Utility / Infrastructure Layer: Common utilities and shared helper functions.
- Principles like separation of concerns (each provider manages its own metadata logic) and the use of an API contract (OpenAPI spec in the schema folder).

##### Final Assembly
- A connection from the providers to an “External API” component (representing Goodreads API and Kindle store endpoints) if one wishes to display external calls.

## Diagram (Mermaid)

```mermaid
flowchart TD 
    %% External Clients
    External["External Clients"]:::external
    External -->|"HTTP_request"| APIServer["HTTP API Server"]:::api

    %% Docker Container: Core Application Components
    subgraph "Docker Container"
        direction TB
        APIServer
        GRProvider["Goodreads Provider"]:::provider
        KindleProvider["Kindle Provider"]:::provider
        Utils["Utilities Module"]:::utils
        OpenAPI["OpenAPI Specification"]:::apiSpec
    end

    %% Relationships from API Server
    APIServer -->|"/goodreads"| GRProvider
    APIServer -->|"/kindle"| KindleProvider
    APIServer -->|"uses"| OpenAPI
    APIServer -->|"utilizes"| Utils

    %% Providers using Utilities
    GRProvider -->|"utilizes"| Utils
    KindleProvider -->|"utilizes"| Utils

    %% Providers External API calls (dashed arrows)
    GRProvider ---|"calls"| ExtGR["Goodreads API"]:::external
    KindleProvider ---|"calls"| ExtKindle["Kindle Store API"]:::external

    %% CI/CD and Deployment Annotations
    subgraph "CI/CD and Deployment"
        direction TB
        Docker["Docker Infrastructure"]:::deployment
        CICD["CI/CD Pipelines"]:::deployment
    end

    %% Annotations connecting runtime to deployment
    APIServer -.-> Docker
    APIServer -.-> CICD

    %% Click Events
    click APIServer "https://github.com/ahobsonsayers/abs-tract/blob/main/server/server.go"
    click APIServer "https://github.com/ahobsonsayers/abs-tract/blob/main/server/router.go"
    click APIServer "https://github.com/ahobsonsayers/abs-tract/blob/main/server/server.gen.go"
    click OpenAPI "https://github.com/ahobsonsayers/abs-tract/blob/main/schema/openapi.yaml"
    click GRProvider "https://github.com/ahobsonsayers/abs-tract/tree/main/goodreads/"
    click KindleProvider "https://github.com/ahobsonsayers/abs-tract/tree/main/kindle/"
    click Utils "https://github.com/ahobsonsayers/abs-tract/tree/main/utils/"
    click Docker "https://github.com/ahobsonsayers/abs-tract/tree/main/Dockerfile"
    click Docker "https://github.com/ahobsonsayers/abs-tract/blob/main/docker-compose.yaml"
    click CICD "https://github.com/ahobsonsayers/abs-tract/tree/main/.github/workflows/"

    %% Styles
    classDef api fill:#A2D2FF,stroke:#000,stroke-width:2px;
    classDef provider fill:#FFD6A5,stroke:#000,stroke-width:2px;
    classDef utils fill:#CAFFBF,stroke:#000,stroke-width:2px;
    classDef apiSpec fill:#FFADAD,stroke:#000,stroke-width:2px;
    classDef external fill:#BDB2FF,stroke:#000,stroke-width:2px;
    classDef deployment fill:#FFFFBA,stroke:#000,stroke-width:2px;
```
