# codixor/rs-geoip architecture

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

- Interactive diagram: https://gitdiagram.com/codixor/rs-geoip
- Repository: https://github.com/codixor/rs-geoip

## Overview

rs-geoip is an offline IP geolocation library with country lookups as the default feature and optional IPv4 city lookup. Users load a local country database or city pack, query an address, and receive a country code, coordinates, or no match. Separate build tools create country databases and city-pack artifacts; the README documents these capabilities, but the sampled sources do not establish a complete builder-to-pack pipeline. City lookup supports flat, paged, mmap, and optional embedded packs. Relationships reflect shown calls or README statements; unsampled builder wiring is omitted.

Main entry points: [`src/local.rs`](https://github.com/codixor/rs-geoip/blob/main/src/local.rs) (City resolver), [`src/country/mod.rs`](https://github.com/codixor/rs-geoip/blob/main/src/country/mod.rs) (Country database), [`src/country/format.rs`](https://github.com/codixor/rs-geoip/blob/main/src/country/format.rs) (Country format), [`src/ip_city_pack.rs`](https://github.com/codixor/rs-geoip/blob/main/src/ip_city_pack.rs) (City pack readers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_country["Country lookup"]
  node_country_db[("Country database<br/>[mod.rs]")]
  node_country_format["Country format<br/>[format.rs]"]
  node_country_errors["Country errors<br/>[error.rs]"]
end

subgraph group_city["City lookup"]
  node_city_resolver["City resolver<br/>[local.rs]"]
  node_city_pack[("City pack readers<br/>[ip_city_pack.rs]")]
  node_builtin_packs["Embedded packs<br/>[builtin.rs]"]
  node_city_errors["City errors<br/>[error.rs]"]
end

subgraph group_country_tools["Country tools"]
  node_country_builder["Country builder"]
end

subgraph group_city_tools["City tools"]
  node_city_json_builder["City data builder"]
  node_flat_pack_builder["Flat pack builder"]
  node_paged_pack_builder["Paged pack builder"]
  node_flat_pack_lookup["Flat pack CLI"]
  node_paged_pack_lookup["Paged pack CLI"]
end

node_caller(("Application"))
node_country_data["Country CSV feeds"]

node_caller -->|"loads and queries"| node_country_db
node_country_db -->|"decodes bytes"| node_country_format
node_country_data -->|"provides CSVs"| node_country_builder
node_caller -->|"loads and queries"| node_city_resolver
node_city_resolver -->|"delegates lookup"| node_city_pack
node_city_resolver -->|"loads embedded bytes"| node_builtin_packs

click node_country_db "https://github.com/codixor/rs-geoip/blob/main/src/country/mod.rs"
click node_country_format "https://github.com/codixor/rs-geoip/blob/main/src/country/format.rs"
click node_country_errors "https://github.com/codixor/rs-geoip/blob/main/src/country/error.rs"
click node_city_resolver "https://github.com/codixor/rs-geoip/blob/main/src/local.rs"
click node_city_pack "https://github.com/codixor/rs-geoip/blob/main/src/ip_city_pack.rs"
click node_builtin_packs "https://github.com/codixor/rs-geoip/blob/main/src/builtin.rs"
click node_city_errors "https://github.com/codixor/rs-geoip/blob/main/src/error.rs"
click node_country_builder "https://github.com/codixor/rs-geoip/blob/main/src/bin/rs-geo-country-build.rs"
click node_city_json_builder "https://github.com/codixor/rs-geoip/blob/main/src/bin/build_ip_city_json.rs"
click node_flat_pack_builder "https://github.com/codixor/rs-geoip/blob/main/src/bin/build_ip_city_pack.rs"
click node_paged_pack_builder "https://github.com/codixor/rs-geoip/blob/main/src/bin/build_ip_city_pack_paged.rs"
click node_flat_pack_lookup "https://github.com/codixor/rs-geoip/blob/main/src/bin/lookup_ip_city_pack.rs"
click node_paged_pack_lookup "https://github.com/codixor/rs-geoip/blob/main/src/bin/lookup_ip_city_pack_paged.rs"

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_country_db,node_country_format,node_country_errors toneBlue
class node_city_resolver,node_city_pack,node_builtin_packs,node_city_errors toneAmber
class node_country_builder toneMint
class node_city_json_builder,node_flat_pack_builder,node_paged_pack_builder,node_flat_pack_lookup,node_paged_pack_lookup toneRose
class node_caller,node_country_data toneIndigo
```

## Components

### Country lookup

- [Country database](https://github.com/codixor/rs-geoip/blob/main/src/country/mod.rs): `src/country/mod.rs`
- [Country format](https://github.com/codixor/rs-geoip/blob/main/src/country/format.rs): `src/country/format.rs`
- [Country errors](https://github.com/codixor/rs-geoip/blob/main/src/country/error.rs): `src/country/error.rs`

### City lookup

- [City resolver](https://github.com/codixor/rs-geoip/blob/main/src/local.rs): `src/local.rs`
- [City pack readers](https://github.com/codixor/rs-geoip/blob/main/src/ip_city_pack.rs): `src/ip_city_pack.rs`
- [Embedded packs](https://github.com/codixor/rs-geoip/blob/main/src/builtin.rs): `src/builtin.rs`
- [City errors](https://github.com/codixor/rs-geoip/blob/main/src/error.rs): `src/error.rs`

### Country tools

- [Country builder](https://github.com/codixor/rs-geoip/blob/main/src/bin/rs-geo-country-build.rs): `src/bin/rs-geo-country-build.rs`

### City tools

- [City data builder](https://github.com/codixor/rs-geoip/blob/main/src/bin/build_ip_city_json.rs): `src/bin/build_ip_city_json.rs`
- [Flat pack builder](https://github.com/codixor/rs-geoip/blob/main/src/bin/build_ip_city_pack.rs): `src/bin/build_ip_city_pack.rs`
- [Paged pack builder](https://github.com/codixor/rs-geoip/blob/main/src/bin/build_ip_city_pack_paged.rs): `src/bin/build_ip_city_pack_paged.rs`
- [Flat pack CLI](https://github.com/codixor/rs-geoip/blob/main/src/bin/lookup_ip_city_pack.rs): `src/bin/lookup_ip_city_pack.rs`
- [Paged pack CLI](https://github.com/codixor/rs-geoip/blob/main/src/bin/lookup_ip_city_pack_paged.rs): `src/bin/lookup_ip_city_pack_paged.rs`

### Other components

- **Application**
- **Country CSV feeds**

## Connections

- Application → Country database: loads and queries (evidence: `README.md`)
- Country database → Country format: decodes bytes (evidence: `src/country/mod.rs`)
- Country CSV feeds → Country builder: provides CSVs (evidence: `README.md`)
- Application → City resolver: loads and queries (evidence: `README.md`)
- City resolver → City pack readers: delegates lookup (evidence: `src/local.rs`)
- City resolver → Embedded packs: loads embedded bytes (evidence: `src/local.rs`)
