# umahmood/haversine architecture

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

- Interactive diagram: https://gitdiagram.com/umahmood/haversine
- Repository: https://github.com/umahmood/haversine

## Overview

1. This repository is a small, single-purpose Go library: it computes great-circle distance on Earth using the haversine formula. There is no application server, CLI, database, or external runtime dependency; the repo’s “product” is the exported Go package itself.

2. The core architecture is a single library package, `haversine`, implemented primarily in `haversine.go` with package documentation in `doc.go`. The package boundary is the main architectural boundary: consumers import `github.com/umahmood/haversine` and call its exported API.

3. The main public data model is a coordinate type (`Coord`) representing latitude and longitude. The primary public operation is `Distance`, which takes two coordinates and returns the distance between them in two units, miles and kilometers.

4. The internal computation flow is straightforward: caller supplies two geographic points → the library converts/uses the latitude and longitude values in the haversine formula → it calculates the shortest path over the Earth’s surface → it returns the distance in the requested package-defined units. The Earth is treated as a sphere, so this is a geodesic approximation rather than a full ellipsoidal model.

5. The library depends only on Go’s standard math facilities for trigonometric and conversion operations. There are no third-party runtime libraries or infrastructure services involved, which keeps the dependency graph extremely shallow.

6. Tests are separated from the implementation in `haversine_test/`, which indicates black-box or external-package style verification rather than deeply coupled internal tests. The test boundary is therefore: public API in `haversine` on one side, expected distance results on the other.

7. Documentation is part of the repo structure and architecture: the README explains usage, and `doc.go` likely provides package-level GoDoc comments so the package is usable through `godoc`. The README’s example demonstrates the expected consumption pattern from another Go program.

8. The project includes basic CI/quality tooling via `.travis.yml` and the README’s `go test ./...` workflow. That implies the primary validation path is automated test execution across the package and test directory, with no build artifacts beyond Go test/package outputs.

9. Operationally, the repo is a library-only boundary exposed to other Go applications. Its “downstream integration” is any Go service or tool that needs distance calculations, while its “upstream inputs” are simply coordinate pairs.

10. For an architecture diagram, the right shape is: external Go consumer → `haversine` package public API → internal haversine calculation logic → numeric distance outputs, with a separate test lane feeding the same public API and CI running the test suite.

Main entry points: [`haversine.go`](https://github.com/umahmood/haversine/blob/master/haversine.go) (Haversine math), [`.travis.yml`](https://github.com/umahmood/haversine/blob/master/.travis.yml) (CI), [`haversine_test/haversine_test.go`](https://github.com/umahmood/haversine/blob/master/haversine_test/haversine_test.go) (haversine_test), [`doc.go`](https://github.com/umahmood/haversine/blob/master/doc.go) (doc.go)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Library"]
  node_n2["haversine<br/>Go package"]
  node_n3(("Coord<br/>public model<br/>[haversine.go]"))
  node_n4["Distance<br/>public function<br/>[haversine.go]"]
  node_n5{{"Haversine math<br/>calculation core<br/>[haversine.go]"}}
  node_n6["Math stdlib<br/>stdlib dependency"]
  node_n7(("Miles / km<br/>output units<br/>[haversine.go]"))
end

subgraph group_g2["Verification"]
  node_n10["haversine_test<br/>test package<br/>[haversine_test.go]"]
  node_n11["CI<br/>travis config<br/>[.travis.yml]"]
end

subgraph group_g3["Docs"]
  node_n8["doc.go<br/>package docs<br/>[doc.go]"]
  node_n9["README<br/>usage docs<br/>[README.md]"]
end

node_n1["Go consumer<br/>downstream client"]

node_n1 -->|"imports"| node_n2
node_n2 -->|"exposes"| node_n3
node_n2 -->|"exposes"| node_n4
node_n4 -->|"delegates"| node_n5
node_n5 -->|"uses"| node_n6
node_n5 -->|"returns"| node_n7
node_n8 -->|"documents"| node_n2
node_n9 -->|"shows usage"| node_n2
node_n10 -->|"tests"| node_n2
node_n11 -->|"runs"| node_n10
node_n11 -->|"verifies"| node_n2

click node_n3 "https://github.com/umahmood/haversine/blob/master/haversine.go"
click node_n4 "https://github.com/umahmood/haversine/blob/master/haversine.go"
click node_n5 "https://github.com/umahmood/haversine/blob/master/haversine.go"
click node_n7 "https://github.com/umahmood/haversine/blob/master/haversine.go"
click node_n8 "https://github.com/umahmood/haversine/blob/master/doc.go"
click node_n9 "https://github.com/umahmood/haversine/blob/master/README.md"
click node_n10 "https://github.com/umahmood/haversine/blob/master/haversine_test/haversine_test.go"
click node_n11 "https://github.com/umahmood/haversine/blob/master/.travis.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n2,node_n3,node_n4,node_n5,node_n6,node_n7 toneBlue
class node_n10,node_n11 toneAmber
class node_n8,node_n9 toneMint
class node_n1 toneNeutral
```

## Components

### Library

Core exported Go package and its public surface.

- **haversine**: Go package · The exported library boundary consumed as github.com/umahmood/haversine.
- [Coord](https://github.com/umahmood/haversine/blob/master/haversine.go): public model · Latitude/longitude value used as the input point type. · `haversine.go`
- [Distance](https://github.com/umahmood/haversine/blob/master/haversine.go): public function · Main API for computing great-circle distance between two coordinates. · `haversine.go`
- [Haversine math](https://github.com/umahmood/haversine/blob/master/haversine.go): calculation core · Implements the spherical great-circle distance formula and unit conversion flow. · `haversine.go`
- **Math stdlib**: stdlib dependency · Go math functions used for trig, conversion, and numeric operations.
- [Miles / km](https://github.com/umahmood/haversine/blob/master/haversine.go): output units · Distance results returned in miles and kilometers. · `haversine.go`

### Verification

Tests and CI workflow that validate the library.

- [haversine_test](https://github.com/umahmood/haversine/blob/master/haversine_test/haversine_test.go): test package · Black-box tests that exercise the public API from outside the package internals. · `haversine_test/haversine_test.go`
- [CI](https://github.com/umahmood/haversine/blob/master/.travis.yml): travis config · Automation entrypoint that runs the repository test workflow. · `.travis.yml`

### Docs

Human-facing package and usage documentation.

- [doc.go](https://github.com/umahmood/haversine/blob/master/doc.go): package docs · GoDoc package commentary and top-level API description. · `doc.go`
- [README](https://github.com/umahmood/haversine/blob/master/README.md): usage docs · Repository usage guide and example consumption pattern. · `README.md`

### Other components

- **Go consumer**: downstream client · Any Go program that imports the package and calls its API.

## Connections

- Go consumer → haversine: imports · Consumer code depends on the exported package boundary.
- haversine → Coord: exposes · The package publishes coordinate inputs as part of its API.
- haversine → Distance: exposes · The package publishes the main distance computation entrypoint.
- Distance → Haversine math: delegates · Distance is implemented by the haversine calculation flow.
- Haversine math → Math stdlib: uses · The formula relies on standard math operations.
- Haversine math → Miles / km: returns · The computation produces distance values in package-defined units.
- doc.go → haversine: documents · Package docs describe the exported library boundary.
- README → haversine: shows usage · The README demonstrates how another Go program consumes the package.
- haversine_test → haversine: tests · Black-box tests validate the public API from outside the main package internals.
- CI → haversine_test: runs · CI executes the test suite as the primary validation path.
- CI → haversine: verifies · CI checks the package through automated test execution.
