# milwil-2/climb-graphdb architecture

> Architecture diagram of the GitHub repository milwil-2/climb-graphdb, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/milwil-2/climb-graphdb
- Repository: https://github.com/milwil-2/climb-graphdb

## Overview

1. **What this repo is**
   - `climb-graphdb` is a Python project centered on a **graph-backed climbing network**. The code is split into a reusable domain package, a small API layer, and offline sync/validation jobs.

2. **Primary data stores and boundaries**
   - The architecture clearly separates a **source relational database** from a **graph database**:
     - `src/climber_network/source/pg.py` reads from Postgres.
     - `src/climber_network/graph/client.py` wraps graph access, almost certainly Neo4j given the `cypher/` folder.
   - `cypher/schema_constraints.cypher` defines graph constraints/schema rules, showing the graph model is an explicit part of the system.

3. **Core domain library**
   - `src/climber_network/` is the shared business logic layer. It contains:
     - `config.py` for environment/runtime configuration
     - `vocab.py` for canonical terms/labels used across the app
     - `geo/` for geocoding and location normalization
     - `travel/` for travel-distance formulas
     - `elo/` for expected-score / rating math
     - `graph/` for graph DB connectivity
     - `source/` for reading from the relational source
   - This package is the main dependency of both the API and the sync jobs.

4. **Ingestion and synchronization pipeline**
   - The `sync/` directory contains offline jobs that move and enrich data:
     - `sync/pg_to_neo4j.py` likely performs the main relational-to-graph migration.
     - `sync/geo.py` adds geospatial enrichment.
     - `sync/travel.py` computes or backfills travel relationships/metrics.
     - `sync/validate_elo.py` checks rating-model consistency.
   - These scripts form the batch/data engineering layer of the repo.

5. **Geospatial enrichment path**
   - `src/climber_network/geo/geocode.py` plus `sync/geo.py` indicate a pipeline step that turns raw location data into geocoded coordinates or standardized place data.
   - This enrichment likely feeds the graph model and any travel-distance calculations.

6. **Travel and scoring logic**
   - `src/climber_network/travel/formulas.py` contains the core distance/relationship math used by the sync layer.
   - `src/climber_network/elo/expected.py` provides the expected-value calculations for Elo-style ratings, with `sync/validate_elo.py` verifying the model against stored data.
   - These are domain-calculation subsystems, not presentation code.

7. **API layer**
   - `api/` is the runtime-facing layer:
     - `api/index.py` is the entrypoint
     - `api/db.py` manages database access
     - `api/queries.py` holds graph/data queries
     - `api/rag.py` adds an LLM-assisted retrieval layer
     - `api/static/index.html` is a bundled static frontend or landing page
   - The API appears to be a thin orchestration layer over the shared domain package and graph/database clients.

8. **Retrieval-augmented answering**
   - The presence of `api/rag.py` and the test fixture `groq_ask_response.json` suggests an LLM-backed question-answering path, likely using **Groq** as the model provider.
   - This sits on top of graph/query results rather than replacing them, so the graph remains the source of truth and the LLM is an interpretation layer.

9. **Deployment shape**
   - `vercel.json` and `.vercelignore` indicate the API/static surface is intended for **Vercel-style deployment**.
   - The repo is Python-first (`pyproject.toml`, `uv.lock`) with a small static asset, so the runtime is likely serverless or lightweight web-service oriented rather than a large always-on backend.

10. **Testing and contract coverage**
   - `tests/` covers the major boundaries separately: config, geocoding, travel formulas, Elo validation, source DB access, graph/network behavior, API/query/RAG behavior, and sync flows.
   - The fixtures show the project uses recorded external responses, which is important for diagramming the system as dependent on both graph/database state and external AI/geocoding services.

11. **Operational / developer tooling**
   - `.github/workflows/ci.yml`, `.pre-commit-config.yaml`, and the `.claude/` helpers show a fairly mature developer workflow with CI and review automation.
   - These are not core runtime systems, but they reinforce that the repo is organized around repeatable sync, validation, and API behavior.

12. **Likely end-to-end flow**
   - Data originates in Postgres or other source inputs → sync jobs normalize/geocode/compute travel and Elo-related data → graph client writes into Neo4j with schema constraints → API queries the graph → optional RAG layer turns query results into natural-language answers.

Main entry points: [`src/climber_network/graph/client.py`](https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/graph/client.py) (Graph client), [`api/index.py`](https://github.com/milwil-2/climb-graphdb/blob/main/api/index.py) (API entry), [`api/rag.py`](https://github.com/milwil-2/climb-graphdb/blob/main/api/rag.py) (RAG), [`api/queries.py`](https://github.com/milwil-2/climb-graphdb/blob/main/api/queries.py) (Queries)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_api["API layer"]
  node_api_index["API entry<br/>web entrypoint<br/>[index.py]"]
  node_api_db["DB access<br/>api db<br/>[db.py]"]
  node_api_queries["Queries<br/>api query layer<br/>[queries.py]"]
  node_api_rag["RAG<br/>llm answer layer<br/>[rag.py]"]
  node_api_static["Static UI<br/>frontend asset<br/>[index.html]"]
end

subgraph group_group_domain["Domain package"]
  node_config["Config<br/>[config.py]"]
  node_vocab["Vocab<br/>canonical terms<br/>[vocab.py]"]
  node_geo_geocode["Geocode<br/>geo normalization<br/>[geocode.py]"]
  node_travel_formulas["Travel math<br/>distance formulas<br/>[formulas.py]"]
  node_elo_expected["Elo math<br/>rating formulas<br/>[expected.py]"]
  node_graph_client[("Graph client<br/>graph db client<br/>[client.py]")]
end

subgraph group_group_sync["Sync jobs"]
  node_sync_pg_neo4j["Pg to graph<br/>migration job<br/>[pg_to_neo4j.py]"]
  node_sync_geo["Geo sync<br/>enrichment job<br/>[geo.py]"]
  node_sync_travel["Travel sync<br/>batch job<br/>[travel.py]"]
  node_sync_validate_elo["Elo check<br/>validation job<br/>[validate_elo.py]"]
end

subgraph group_group_data["Data model"]
  node_source_pg[("Postgres source<br/>source db reader<br/>[pg.py]")]
  node_cypher_schema["Schema rules<br/>graph constraints"]
end

node_api_index -->|"serves"| node_api_queries
node_api_index -->|"answers with"| node_api_rag
node_api_index -->|"hosts"| node_api_static
node_api_queries -->|"reads"| node_graph_client
node_api_db -->|"connects to"| node_source_pg
node_api_rag -->|"retrieves"| node_api_queries
node_api_rag -->|"interprets"| node_vocab
node_sync_pg_neo4j -->|"extracts from"| node_source_pg
node_sync_pg_neo4j -->|"writes to"| node_graph_client
node_sync_geo -->|"uses"| node_geo_geocode
node_sync_geo -->|"updates"| node_graph_client
node_sync_travel -->|"computes"| node_travel_formulas
node_sync_travel -->|"stores"| node_graph_client
node_sync_validate_elo -->|"checks"| node_elo_expected
node_sync_validate_elo -->|"reads"| node_graph_client
node_graph_client -->|"follows"| node_cypher_schema
node_source_pg -->|"configures"| node_config
node_graph_client -->|"configures"| node_config
node_geo_geocode -->|"uses"| node_config
node_travel_formulas -->|"normalizes"| node_vocab
node_elo_expected -->|"normalizes"| node_vocab

click node_api_index "https://github.com/milwil-2/climb-graphdb/blob/main/api/index.py"
click node_api_db "https://github.com/milwil-2/climb-graphdb/blob/main/api/db.py"
click node_api_queries "https://github.com/milwil-2/climb-graphdb/blob/main/api/queries.py"
click node_api_rag "https://github.com/milwil-2/climb-graphdb/blob/main/api/rag.py"
click node_api_static "https://github.com/milwil-2/climb-graphdb/blob/main/api/static/index.html"
click node_config "https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/config.py"
click node_vocab "https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/vocab.py"
click node_geo_geocode "https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/geo/geocode.py"
click node_travel_formulas "https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/travel/formulas.py"
click node_elo_expected "https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/elo/expected.py"
click node_graph_client "https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/graph/client.py"
click node_source_pg "https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/source/pg.py"
click node_cypher_schema "https://github.com/milwil-2/climb-graphdb/blob/main/cypher/schema_constraints.cypher"
click node_sync_pg_neo4j "https://github.com/milwil-2/climb-graphdb/blob/main/sync/pg_to_neo4j.py"
click node_sync_geo "https://github.com/milwil-2/climb-graphdb/blob/main/sync/geo.py"
click node_sync_travel "https://github.com/milwil-2/climb-graphdb/blob/main/sync/travel.py"
click node_sync_validate_elo "https://github.com/milwil-2/climb-graphdb/blob/main/sync/validate_elo.py"

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_api_index,node_api_db,node_api_queries,node_api_rag,node_api_static toneBlue
class node_config,node_vocab,node_geo_geocode,node_travel_formulas,node_elo_expected,node_graph_client toneAmber
class node_sync_pg_neo4j,node_sync_geo,node_sync_travel,node_sync_validate_elo toneMint
class node_source_pg,node_cypher_schema toneRose
```

## Components

### API layer

Runtime-facing query and answer layer.

- [API entry](https://github.com/milwil-2/climb-graphdb/blob/main/api/index.py): web entrypoint · Starts the API runtime. · `api/index.py`
- [DB access](https://github.com/milwil-2/climb-graphdb/blob/main/api/db.py): api db · Database connection and access helper. · `api/db.py`
- [Queries](https://github.com/milwil-2/climb-graphdb/blob/main/api/queries.py): api query layer · Graph and data queries served by the API. · `api/queries.py`
- [RAG](https://github.com/milwil-2/climb-graphdb/blob/main/api/rag.py): llm answer layer · Retrieval-augmented response generation. · `api/rag.py`
- [Static UI](https://github.com/milwil-2/climb-graphdb/blob/main/api/static/index.html): frontend asset · Bundled landing page or lightweight frontend. · `api/static/index.html`

### Domain package

Shared climbing network logic used by API and sync jobs.

- [Config](https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/config.py): runtime config · Environment and runtime settings. · `src/climber_network/config.py`
- [Vocab](https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/vocab.py): canonical terms · Shared labels and naming conventions. · `src/climber_network/vocab.py`
- [Geocode](https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/geo/geocode.py): geo normalization · Location normalization and geocoding logic. · `src/climber_network/geo/geocode.py`
- [Travel math](https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/travel/formulas.py): distance formulas · Travel-distance and relationship calculations. · `src/climber_network/travel/formulas.py`
- [Elo math](https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/elo/expected.py): rating formulas · Expected-score calculations for Elo-style ratings. · `src/climber_network/elo/expected.py`
- [Graph client](https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/graph/client.py): graph db client · Wraps access to the graph database. · `src/climber_network/graph/client.py`

### Sync jobs

Offline enrichment, migration, and validation workflows.

- [Pg to graph](https://github.com/milwil-2/climb-graphdb/blob/main/sync/pg_to_neo4j.py): migration job · Main relational-to-graph sync pipeline. · `sync/pg_to_neo4j.py`
- [Geo sync](https://github.com/milwil-2/climb-graphdb/blob/main/sync/geo.py): enrichment job · Adds geospatial enrichment to graph data. · `sync/geo.py`
- [Travel sync](https://github.com/milwil-2/climb-graphdb/blob/main/sync/travel.py): batch job · Backfills travel relationships and metrics. · `sync/travel.py`
- [Elo check](https://github.com/milwil-2/climb-graphdb/blob/main/sync/validate_elo.py): validation job · Validates rating-model consistency. · `sync/validate_elo.py`

### Data model

Graph schema and source relational boundary.

- [Postgres source](https://github.com/milwil-2/climb-graphdb/blob/main/src/climber_network/source/pg.py): source db reader · Reads from the relational source database. · `src/climber_network/source/pg.py`
- [Schema rules](https://github.com/milwil-2/climb-graphdb/blob/main/cypher/schema_constraints.cypher): graph constraints · Graph constraints and schema declarations. · `cypher/schema_constraints.cypher`

## Connections

- API entry → Queries: serves · API entry delegates to query layer.
- API entry → RAG: answers with · API can route requests through the RAG layer.
- API entry → Static UI: hosts · API serves bundled static content.
- Queries → Graph client: reads · Queries execute against the graph client.
- DB access → Postgres source: connects to · API database helper reaches the relational source when needed.
- RAG → Queries: retrieves · RAG depends on structured query results.
- RAG → Vocab: interprets · Uses canonical terms to shape responses.
- Pg to graph → Postgres source: extracts from · Main sync job reads source rows from Postgres.
- Pg to graph → Graph client: writes to · Main sync job populates the graph database.
- Geo sync → Geocode: uses · Geo sync relies on geocoding and normalization.
- Geo sync → Graph client: updates · Enriched location data is written back to the graph.
- Travel sync → Travel math: computes · Travel job uses shared distance formulas.
- Travel sync → Graph client: stores · Travel relationships and metrics are persisted in the graph.
- Elo check → Elo math: checks · Validation compares stored ratings to expected-score math.
- Elo check → Graph client: reads · Validation inspects graph-stored rating data.
- Graph client → Schema rules: follows · Graph access operates within explicit schema constraints.
- Postgres source → Config: configures · Source DB access is driven by shared runtime config.
- Graph client → Config: configures · Graph connection settings come from shared config.
- Geocode → Config: uses · Geocoding depends on runtime settings.
- Travel math → Vocab: normalizes · Travel calculations use canonical domain terms.
- Elo math → Vocab: normalizes · Elo math uses shared domain terminology.
