# 0xvitae/ns-archaeology-hackathon-001 architecture

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

- Interactive diagram: https://gitdiagram.com/0xvitae/ns-archaeology-hackathon-001
- Repository: https://github.com/0xvitae/ns-archaeology-hackathon-001

## Overview

1. **Repository shape**
   This is a mostly file-based geospatial analysis pipeline, not a conventional app with a database. The core outputs are CSV, GeoJSON, HTML map layers, and annotated images stored under `data/`, with notebooks used for exploratory work and small Python scripts used for repeatable steps.

2. **Primary workflow**
   The project moves through a staged pipeline: collect external archaeological datasets, consolidate them into a master catalog, derive areas of interest (AOIs), fetch satellite tiles for those AOIs, run AI-based tile analysis, then review and annotate the highest-confidence candidates in a browser-based viewer.

3. **Data ingestion boundary**
   `data/external/` is the raw/reference-data boundary. It contains sources from UNESCO, academic CSVs, government SIGDA exports, OpenStreetMap, Wikidata/Wikipedia, other curated sources, and YouTube transcript-derived material. These are treated as inputs, not working outputs.

4. **Master dataset consolidation**
   `data/master/` holds the normalized cross-source site catalog, with `all_sites_master.csv` and `all_sites_master_cleaned.csv` as central reference tables. `scripts/clean_master.py` is the obvious normalization step that turns heterogeneous source data into a consistent master list used downstream.

5. **AOI discovery and selection**
   `data/checkpoint_2/` represents the AOI discovery stage. It contains merged AOI layers, filtered survey areas, top-ranked candidate AOIs, and thematic overlays like river candidates and desert unexplored zones. The notebooks in `notebooks/checkpoint_2/` and `scripts/merge_aoi.py` are the main producers here.

6. **Spatial context layers**
   `data/layers/` adds domain-specific reference geometry such as ancient river systems and Norte Chico river valleys. These layers feed the AOI reasoning and the map viewer as contextual overlays, helping rank or interpret candidate sites against hydrology and settlement patterns.

7. **Satellite tile acquisition**
   `data/checkpoint_3/` is the imagery capture stage. `scripts/grab_tiles.py` and `notebooks/checkpoint_3/grab_tiles.ipynb` generate a `tile_manifest.csv` and store the tile images under `data/checkpoint_3/tiles`. The README makes clear this stage depends on the Google Maps Static API at zoom 18, so this is the main external data-fetching boundary.

8. **AI analysis and detection**
   `data/checkpoint_4/` contains the analysis outputs: `analysis_results.csv`, `analysis_results.geojson`, and `pipeline_selection.geojson`. `scripts/analyze_tiles.py` is the analysis stage that sends tiles to Google Gemini for archaeological feature detection, producing confidence-ranked detections and candidate selections.

9. **Annotation stage**
   `scripts/annotate_sites.py` and `notebooks/checkpoint_4/annotate_sites.ipynb` handle post-processing of strong detections into human-reviewable overlays. This is where the project turns machine-detected candidates into visually annotated artifacts for inspection and reporting.

10. **Review interface and orchestration**
   `viewer.html` is the main front-end review surface, served by `scripts/server.py`. The Flask server exposes pipeline-control endpoints (`/api/run-pipeline`, `/api/pipeline-status`, `/api/pipeline-logs`, `/api/datasets`) and supports interactive review features like confidence filtering, dataset overlays, and live log streaming.

11. **Notebook vs. script boundary**
   The notebooks are organized by checkpoint and appear to be the research/prototyping layer, while the scripts are the operational layer that the server and repeatable pipeline actions rely on. This separation is important for the architecture diagram: notebooks generate and explain results, scripts execute the pipeline, and the viewer consumes the resulting files.

12. **Notable side subsystem**
   `scripts/yt_archaeology/` is a separate mini-application for processing YouTube archaeology content, with its own scanner/server assets and transcript index. It appears adjacent to the main satellite-detection pipeline rather than central to it, but it contributes an additional evidence source under `data/external/youtube/`.

Main entry points: [`data/checkpoint_2`](https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/data/checkpoint_2) (AOI layers), [`scripts/analyze_tiles.py`](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/analyze_tiles.py) (Tile analysis), [`viewer.html`](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/viewer.html) (Viewer UI), [`data/checkpoint_4`](https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/data/checkpoint_4) (Analysis outputs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g1["Raw inputs"]
  node_n1[("External sources<br/>source boundary")]
  node_n2[("Spatial layers<br/>context geometry")]
end

subgraph group_g2["Core pipeline"]
  node_n3[("Master catalog<br/>normalized dataset")]
  node_n4["Clean master<br/>normalization script<br/>[clean_master.py]"]
  node_n5[("AOI layers<br/>AOI outputs")]
  node_n6["AOI merge<br/>AOI builder<br/>[merge_aoi.py]"]
  node_n7["AOI notebooks<br/>exploration notebooks"]
  node_n8["Tile manifest<br/>imagery manifest<br/>[tile_manifest.csv]"]
  node_n9["Tile grabber<br/>fetch script<br/>[grab_tiles.py]"]
  node_n10["Tile notebook<br/>imagery notebook<br/>[grab_tiles.ipynb]"]
  node_n11["Tile analysis<br/>detection script<br/>[analyze_tiles.py]"]
  node_n12[("Analysis outputs<br/>detection results")]
  node_n13["Analyze notebook<br/>analysis notebook"]
  node_n14["Annotate sites<br/>post-process script<br/>[annotate_sites.py]"]
  node_n15["Annotate notebook<br/>annotation notebook"]
end

subgraph group_g3["Review surface"]
  node_n16["Viewer UI<br/>browser reviewer<br/>[viewer.html]"]
  node_n17["Pipeline server<br/>flask orchestrator<br/>[server.py]"]
end

subgraph group_g4["YouTube mini-app"]
  node_n18["YouTube archaeology<br/>side subsystem"]
  node_n19["YT scanner<br/>content scanner<br/>[scanner.py]"]
  node_n20["YT server<br/>mini server<br/>[server.py]"]
end

node_n1 -->|"source data"| node_n4
node_n4 -->|"builds"| node_n3
node_n2 -->|"context"| node_n5
node_n3 -->|"inputs"| node_n6
node_n6 -->|"produces"| node_n5
node_n7 -.->|"prototypes"| node_n6
node_n5 -->|"AOIs"| node_n9
node_n9 -->|"creates"| node_n8
node_n10 -.->|"experiments"| node_n9
node_n8 -->|"feeds"| node_n11
node_n11 -->|"writes"| node_n12
node_n13 -.->|"reviews"| node_n11
node_n12 -->|"candidates"| node_n14
node_n15 -.->|"refines"| node_n14
node_n14 -->|"publishes"| node_n16
node_n5 -->|"overlays"| node_n16
node_n12 -->|"results"| node_n16
node_n17 -->|"serves"| node_n16
node_n17 -->|"orchestrates"| node_n11
node_n18 -.->|"adjacent input"| node_n1
node_n19 -->|"processes"| node_n18
node_n20 -->|"hosts"| node_n18

click node_n1 "https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/data/external"
click node_n2 "https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/data/layers"
click node_n3 "https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/data/master"
click node_n4 "https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/clean_master.py"
click node_n5 "https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/data/checkpoint_2"
click node_n6 "https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/merge_aoi.py"
click node_n7 "https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/notebooks/checkpoint_2"
click node_n8 "https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/data/checkpoint_3/tile_manifest.csv"
click node_n9 "https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/grab_tiles.py"
click node_n10 "https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/notebooks/checkpoint_3/grab_tiles.ipynb"
click node_n11 "https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/analyze_tiles.py"
click node_n12 "https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/data/checkpoint_4"
click node_n13 "https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/notebooks/checkpoint_4/analyze_tiles.ipynb"
click node_n14 "https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/annotate_sites.py"
click node_n15 "https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/notebooks/checkpoint_4/annotate_sites.ipynb"
click node_n16 "https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/viewer.html"
click node_n17 "https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/server.py"
click node_n18 "https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/scripts/yt_archaeology"
click node_n19 "https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/yt_archaeology/scanner.py"
click node_n20 "https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/yt_archaeology/server.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_n1,node_n2 toneBlue
class node_n3,node_n4,node_n5,node_n6,node_n7,node_n8,node_n9,node_n10,node_n11,node_n12,node_n13,node_n14,node_n15 toneAmber
class node_n16,node_n17 toneMint
class node_n18,node_n19,node_n20 toneRose
```

## Components

### Raw inputs

External and contextual source data treated as inputs to the pipeline.

- [External sources](https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/data/external): source boundary · Raw archaeological and reference inputs from curated external collections. · `data/external`
- [Spatial layers](https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/data/layers): context geometry · Domain context layers such as river systems and valley geometry. · `data/layers`

### Core pipeline

Staged processing from normalization through AOI discovery, tile capture, analysis, and annotation.

- [Master catalog](https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/data/master): normalized dataset · Cross-source site catalog used as the downstream reference table. · `data/master`
- [Clean master](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/clean_master.py): normalization script · Consolidates heterogeneous source data into the cleaned master list. · `scripts/clean_master.py`
- [AOI layers](https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/data/checkpoint_2): AOI outputs · Merged, filtered, and ranked areas-of-interest layers and maps. · `data/checkpoint_2`
- [AOI merge](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/merge_aoi.py): AOI builder · Produces merged AOI layers from notebooks and scripted transforms. · `scripts/merge_aoi.py`
- [AOI notebooks](https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/notebooks/checkpoint_2): exploration notebooks · Checkpoint 2 notebooks for ranking, hydrology, and AOI reasoning. · `notebooks/checkpoint_2`
- [Tile manifest](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/data/checkpoint_3/tile_manifest.csv): imagery manifest · Generated list of satellite tile requests and captured imagery references. · `data/checkpoint_3/tile_manifest.csv`
- [Tile grabber](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/grab_tiles.py): fetch script · Fetches satellite tiles for AOIs from the external map imagery API. · `scripts/grab_tiles.py`
- [Tile notebook](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/notebooks/checkpoint_3/grab_tiles.ipynb): imagery notebook · Notebook workflow for generating the tile manifest and imagery capture outputs. · `notebooks/checkpoint_3/grab_tiles.ipynb`
- [Tile analysis](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/analyze_tiles.py): detection script · Runs AI-based feature detection over tiles and emits ranked results. · `scripts/analyze_tiles.py`
- [Analysis outputs](https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/data/checkpoint_4): detection results · Confidence-ranked detections and selected candidate geometries. · `data/checkpoint_4`
- [Analyze notebook](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/notebooks/checkpoint_4/analyze_tiles.ipynb): analysis notebook · Checkpoint 4 notebook for the detection stage and result inspection. · `notebooks/checkpoint_4/analyze_tiles.ipynb`
- [Annotate sites](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/annotate_sites.py): post-process script · Turns strong detections into human-reviewable annotated artifacts. · `scripts/annotate_sites.py`
- [Annotate notebook](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/notebooks/checkpoint_4/annotate_sites.ipynb): annotation notebook · Notebook for reviewing and annotating candidate sites. · `notebooks/checkpoint_4/annotate_sites.ipynb`

### Review surface

Browser-based inspection and orchestration layer for reviewing pipeline outputs.

- [Viewer UI](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/viewer.html): browser reviewer · HTML front-end for exploring datasets, overlays, confidence filters, and annotations. · `viewer.html`
- [Pipeline server](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/server.py): flask orchestrator · Serves the viewer and exposes pipeline control, status, logs, and dataset endpoints. · `scripts/server.py`

### YouTube mini-app

Adjacent subsystem for transcript-based archaeology evidence extraction.

- [YouTube archaeology](https://github.com/0xvitae/ns-archaeology-hackathon-001/tree/main/scripts/yt_archaeology): side subsystem · Transcript and index processing for archaeology-related YouTube evidence. · `scripts/yt_archaeology`
- [YT scanner](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/yt_archaeology/scanner.py): content scanner · Processes YouTube transcripts and supports the adjacent evidence-mining workflow. · `scripts/yt_archaeology/scanner.py`
- [YT server](https://github.com/0xvitae/ns-archaeology-hackathon-001/blob/main/scripts/yt_archaeology/server.py): mini server · Local server and UI assets for the YouTube archaeology subsystem. · `scripts/yt_archaeology/server.py`

## Connections

- External sources → Clean master: source data · External source tables and geodata are normalized into the master catalog.
- Clean master → Master catalog: builds · Cleaning and consolidation produce the master site reference tables.
- Spatial layers → AOI layers: context · Hydrology and valley layers inform AOI discovery and ranking.
- Master catalog → AOI merge: inputs · The master catalog is used to derive and merge candidate AOIs.
- AOI merge → AOI layers: produces · AOI merging writes the checkpoint 2 spatial outputs.
- AOI notebooks → AOI merge: prototypes · Checkpoint 2 notebooks develop and explain AOI generation logic.
- AOI layers → Tile grabber: AOIs · Selected AOIs drive satellite tile acquisition.
- Tile grabber → Tile manifest: creates · Tile requests are recorded as a manifest for capture runs.
- Tile notebook → Tile grabber: experiments · Notebook workflow supports tile-grabbing and manifest generation.
- Tile manifest → Tile analysis: feeds · Captured tiles are analyzed for archaeological feature detection.
- Tile analysis → Analysis outputs: writes · Analysis results are stored as CSV and GeoJSON outputs.
- Analyze notebook → Tile analysis: reviews · Checkpoint 4 notebook documents and iterates on detection logic.
- Analysis outputs → Annotate sites: candidates · High-confidence detections are post-processed into annotations.
- Annotate notebook → Annotate sites: refines · Notebook workflow supports manual review and annotation artifacts.
- Annotate sites → Viewer UI: publishes · Annotated outputs are consumed by the browser-based viewer.
- AOI layers → Viewer UI: overlays · AOI layers are also visualized in the review interface.
- Analysis outputs → Viewer UI: results · Detection results are inspected in the viewer.
- Pipeline server → Viewer UI: serves · The Flask server hosts the review UI.
- Pipeline server → Tile analysis: orchestrates · Server endpoints can launch or monitor pipeline execution.
- YouTube archaeology → External sources: adjacent input · YouTube-derived evidence contributes to the broader external source boundary.
- YT scanner → YouTube archaeology: processes · The scanner is the main processing component of the YouTube subsystem.
- YT server → YouTube archaeology: hosts · The mini-app server exposes the subsystem UI and assets.
