# ni5arga/sightline architecture

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

- Interactive diagram: https://gitdiagram.com/ni5arga/sightline
- Repository: https://github.com/ni5arga/sightline

## Overview

#### Purpose and Runtime
Sightline is a Next.js geospatial search application for discovering physical infrastructure in OpenStreetMap (OSM). It runs on Node.js 18+ and is deployable to Vercel; it has no required environment variables or owned database. The application relies on public Nominatim, Overpass, and OSM map-tile services.

#### Application Entry and Composition
The root layout and primary page compose the client experience and global styling:
- `app/layout.tsx`
- `app/page.tsx`
- `app/globals.css`

The page coordinates query state, selected results, filters, and interactions among the search input, list, map, asset details, and sharing controls.

#### Search Interaction Layer
User input begins in the query and filter UI, while results are presented in synchronized list and geographic views:
- `components/SearchBar.tsx`
- `components/Filters.tsx`
- `components/ResultList.tsx`
- `components/MapView.tsx`

Search requests cross the browser/server boundary through `POST /api/search`. `MapView` is the Leaflet-based visualization boundary; it renders returned asset geometry/locations rather than querying OSM directly. `components/AssetInfoModal.tsx` exposes per-asset details, and `components/ShareButton.tsx` shares application/search state.

#### Server API Boundary
The search orchestration endpoint is:
- `app/api/search/route.ts`

It accepts natural-language or structured criteria, drives parsing, geographic resolution, OSM retrieval, and caching, then returns normalized search results to the frontend. A separate proxy-style geocoding endpoint exists at:
- `app/api/nominatim/route.ts`

This separates browser callers from direct external geocoder access and centralizes integration behavior.

#### Query Interpretation and Domain Model
The query pipeline recognizes asset types, aliases, qualifiers such as operator and region, and proximity/radius syntax:
- `lib/parser.ts`
- `lib/search-index.ts`
- `lib/types.ts`

`parser.ts` converts raw user text into structured search intent. `search-index.ts` is the domain catalog/index supporting the broad infrastructure taxonomy. `types.ts` defines contracts shared across API, data-processing, and UI layers, making it the primary schema boundary for parsed queries and returned assets.

#### Geographic Resolution and OSM Retrieval
Location intent is resolved before asset retrieval:
- `lib/geo.ts`
- `lib/overpass.ts`

`geo.ts` calls Nominatim to turn place names into coordinates or bounding areas. `overpass.ts` maps parsed asset constraints and resolved geography into Overpass QL, calls the public Overpass API, and converts OSM elements into application results. External-data boundaries are material: Nominatim is subject to its 1 request/second policy, and Overpass supports read-only, fair-use queries; OSM completeness and accuracy are not guaranteed.

#### Caching and Operational Constraints
The backend uses process-local in-memory caching:
- `lib/cache.ts`
- `app/api/search/route.ts`

Cache reads/writes reduce repeat external calls but are not durable or shared across serverless instances, so behavior can vary after restart or across Vercel invocations. There is no authentication, persistence layer, background monitoring worker, or proprietary data source indicated by this repository. Linting is enforced in CI through `.github/workflows/lint.yml`.

Main entry points: [`app/page.tsx`](https://github.com/ni5arga/sightline/blob/main/app/page.tsx) (Search page), [`app/api/search/route.ts`](https://github.com/ni5arga/sightline/blob/main/app/api/search/route.ts) (Search API), [`lib/parser.ts`](https://github.com/ni5arga/sightline/blob/main/lib/parser.ts) (Query parser), [`lib/overpass.ts`](https://github.com/ni5arga/sightline/blob/main/lib/overpass.ts) (OSM retriever)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Next.js Client"]
  node_page["Search page<br/>page composition<br/>[page.tsx]"]
  node_layout["Root layout<br/>app shell<br/>[layout.tsx]"]
  node_search_ui["Search and filters<br/>query UI<br/>[SearchBar.tsx]"]
  node_results["Result list<br/>result UI<br/>[ResultList.tsx]"]
  node_map["Map view<br/>Leaflet map<br/>[MapView.tsx]"]
  node_asset_modal["Asset details<br/>detail UI<br/>[AssetInfoModal.tsx]"]
  node_share["Share controls<br/>sharing UI<br/>[ShareButton.tsx]"]
end

subgraph group_server["Server API"]
  node_search_api{{"Search API<br/>POST /api/search<br/>[route.ts]"}}
  node_nominatim_api{{"Geocoding proxy<br/>API route<br/>[route.ts]"}}
  node_cache[("Process-local cache<br/>in-memory cache<br/>[cache.ts]")]
end

subgraph group_domain["Search Domain"]
  node_parser["Query parser<br/>intent parser<br/>[parser.ts]"]
  node_search_index["Infrastructure catalog<br/>domain index<br/>[search-index.ts]"]
  node_types["Shared contracts<br/>domain schema<br/>[types.ts]"]
  node_geo["Geographic resolver<br/>geocoding client<br/>[geo.ts]"]
  node_overpass["OSM retriever<br/>Overpass client<br/>[overpass.ts]"]
end

subgraph group_external["Public OSM Services"]
  node_nominatim(("Nominatim<br/>public geocoder"))
  node_overpass_service(("Overpass API<br/>public OSM query API"))
  node_tiles(("OSM map tiles<br/>public tile service"))
end

node_layout -->|"hosts"| node_page
node_search_ui -->|"query and filters"| node_page
node_page -->|"POST search"| node_search_api
node_search_api -->|"normalized assets"| node_page
node_page -->|"renders results"| node_results
node_page -->|"renders assets and selection"| node_map
node_page -->|"opens selected asset"| node_asset_modal
node_page -->|"shares app state"| node_share
node_map -->|"loads tiles"| node_tiles
node_search_api -->|"reads and writes"| node_cache
node_search_api -->|"parses query"| node_parser
node_parser -->|"matches taxonomy"| node_search_index
node_parser -->|"produces intent"| node_types
node_search_api -->|"resolves location"| node_geo
node_search_api -->|"retrieves assets"| node_overpass
node_geo -->|"geocodes place"| node_nominatim
node_nominatim_api -->|"proxies geocoding"| node_nominatim
node_overpass -->|"queries OSM"| node_overpass_service
node_overpass -->|"normalizes assets"| node_types

click node_page "https://github.com/ni5arga/sightline/blob/main/app/page.tsx"
click node_layout "https://github.com/ni5arga/sightline/blob/main/app/layout.tsx"
click node_search_ui "https://github.com/ni5arga/sightline/blob/main/components/SearchBar.tsx"
click node_results "https://github.com/ni5arga/sightline/blob/main/components/ResultList.tsx"
click node_map "https://github.com/ni5arga/sightline/blob/main/components/MapView.tsx"
click node_asset_modal "https://github.com/ni5arga/sightline/blob/main/components/AssetInfoModal.tsx"
click node_share "https://github.com/ni5arga/sightline/blob/main/components/ShareButton.tsx"
click node_search_api "https://github.com/ni5arga/sightline/blob/main/app/api/search/route.ts"
click node_nominatim_api "https://github.com/ni5arga/sightline/blob/main/app/api/nominatim/route.ts"
click node_parser "https://github.com/ni5arga/sightline/blob/main/lib/parser.ts"
click node_search_index "https://github.com/ni5arga/sightline/blob/main/lib/search-index.ts"
click node_types "https://github.com/ni5arga/sightline/blob/main/lib/types.ts"
click node_geo "https://github.com/ni5arga/sightline/blob/main/lib/geo.ts"
click node_overpass "https://github.com/ni5arga/sightline/blob/main/lib/overpass.ts"
click node_cache "https://github.com/ni5arga/sightline/blob/main/lib/cache.ts"

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_page,node_layout,node_search_ui,node_results,node_map,node_asset_modal,node_share toneBlue
class node_search_api,node_nominatim_api,node_cache toneAmber
class node_parser,node_search_index,node_types,node_geo,node_overpass toneMint
class node_nominatim,node_overpass_service,node_tiles toneRose
```

## Components

### Next.js Client

- [Search page](https://github.com/ni5arga/sightline/blob/main/app/page.tsx): page composition · Coordinates query, selection, filters, results, map, and sharing state. · `app/page.tsx`
- [Root layout](https://github.com/ni5arga/sightline/blob/main/app/layout.tsx): app shell · `app/layout.tsx`
- [Search and filters](https://github.com/ni5arga/sightline/blob/main/components/SearchBar.tsx): query UI · `components/SearchBar.tsx`
- [Result list](https://github.com/ni5arga/sightline/blob/main/components/ResultList.tsx): result UI · `components/ResultList.tsx`
- [Map view](https://github.com/ni5arga/sightline/blob/main/components/MapView.tsx): Leaflet map · Renders returned asset geometry without querying OSM directly. · `components/MapView.tsx`
- [Asset details](https://github.com/ni5arga/sightline/blob/main/components/AssetInfoModal.tsx): detail UI · `components/AssetInfoModal.tsx`
- [Share controls](https://github.com/ni5arga/sightline/blob/main/components/ShareButton.tsx): sharing UI · `components/ShareButton.tsx`

### Server API

- [Search API](https://github.com/ni5arga/sightline/blob/main/app/api/search/route.ts): POST /api/search · Orchestrates parsing, geographic resolution, retrieval, caching, and normalized results. · `app/api/search/route.ts`
- [Geocoding proxy](https://github.com/ni5arga/sightline/blob/main/app/api/nominatim/route.ts): API route · Centralizes browser access to Nominatim. · `app/api/nominatim/route.ts`
- [Process-local cache](https://github.com/ni5arga/sightline/blob/main/lib/cache.ts): in-memory cache · Non-durable and unshared across serverless instances. · `lib/cache.ts`

### Search Domain

- [Query parser](https://github.com/ni5arga/sightline/blob/main/lib/parser.ts): intent parser · `lib/parser.ts`
- [Infrastructure catalog](https://github.com/ni5arga/sightline/blob/main/lib/search-index.ts): domain index · Defines asset taxonomy, aliases, and qualifiers. · `lib/search-index.ts`
- [Shared contracts](https://github.com/ni5arga/sightline/blob/main/lib/types.ts): domain schema · Defines parsed-query and asset-result contracts shared by API, processing, and UI. · `lib/types.ts`
- [Geographic resolver](https://github.com/ni5arga/sightline/blob/main/lib/geo.ts): geocoding client · `lib/geo.ts`
- [OSM retriever](https://github.com/ni5arga/sightline/blob/main/lib/overpass.ts): Overpass client · Builds Overpass QL and converts OSM elements into application results. · `lib/overpass.ts`

### Public OSM Services

- **Nominatim**: public geocoder · Subject to a 1 request/second policy.
- **Overpass API**: public OSM query API · Read-only public OSM data service.
- **OSM map tiles**: public tile service

## Connections

- Root layout → Search page: hosts
- Search and filters → Search page: query and filters
- Search page → Search API: POST search
- Search API → Search page: normalized assets
- Search page → Result list: renders results
- Search page → Map view: renders assets and selection
- Search page → Asset details: opens selected asset
- Search page → Share controls: shares app state
- Map view → OSM map tiles: loads tiles
- Search API → Process-local cache: reads and writes
- Search API → Query parser: parses query
- Query parser → Infrastructure catalog: matches taxonomy
- Query parser → Shared contracts: produces intent
- Search API → Geographic resolver: resolves location
- Search API → OSM retriever: retrieves assets
- Geographic resolver → Nominatim: geocodes place
- Geocoding proxy → Nominatim: proxies geocoding
- OSM retriever → Overpass API: queries OSM
- OSM retriever → Shared contracts: normalizes assets
