navi/backend/deploy/nginx
malice 34df49a9cd Add navi-places service (extraction #5) (#5)
New services/navi_places/ on :8425 — the heaviest extraction. Ports recon's
/api/place family with the two wiki dependencies decoupled to HTTP.

Routes (public, mirroring recon):
  GET /api/place/<osm_type>/<int:osm_id>   (Nominatim -> Overpass fallback + enrich)
  GET /api/place/wikidata/<wikidata_id>     (Wikidata entity)
  -> 200 / 400 / 404 / 502, same response shapes as recon.

Enrichment chain (recon order): Overture (PostGIS) -> Google Places -> wiki
rewrite -> wiki index. The two wiki paths are now HTTP to recon (the 2.1 GB
wiki_index.db and Kiwix/wiki_cache stay in recon — see [[reference-echo6-edge-topology]]):
  - wiki_client.enrich_via_recon  -> recon /api/wiki-enrich  (PR #8)  [has_kiwix_wiki]
  - wiki_rewrite_client.rewrite_via_recon -> recon /api/wiki-rewrite (PR #9) [has_wiki_rewriting]
    (per-tag loop over the <=4 wiki extratags, mirroring recon's _enrich_wiki_links)
Both clients degrade gracefully (None / status 'original') on error/timeout.

Data ownership (see [[feedback-navi-backend-data-ownership]]):
  - place_cache.db migrates to /var/lib/navi-backend/place_cache.db (env
    NAVI_PLACE_CACHE_DB). place_cache.py auto-creates the FULL schema on first
    open — place_cache (incl. the google_place_id/google_data/google_fetched_at
    columns recon added by migration) + google_api_calls — so a fresh DB serves
    both cache_put and the Google daily-cap/cache. WAL, shared module conn.
  - overture stays in external PG (OVERTURE_DB_* env), verbatim port of recon's
    pool (1,3) + _pool_failed latch, with reset_pool()+probe_db() added.
  - wiki_index.db / Kiwix stay in recon, reached via the two HTTP endpoints.

Modules: place_cache.py, overture.py (verbatim+probe), google_places.py
(daily cap via env GOOGLE_PLACES_DAILY_CAP; DB via shared place_cache conn),
wiki_client.py + wiki_rewrite_client.py (HTTP, RECON_BASE_URL default
http://127.0.0.1:8420), osm_categories.py (vendored for humanize_category),
place_detail.py (orchestrator), config.py (feature flags from the vendored
profile via NAVI_PROFILES_DIR), place_route.py, admin.py, app.py.

Feature gates read from the vendored profile (config.py), matching recon:
has_overture_enrichment / has_google_places_enrichment / has_kiwix_wiki /
has_wiki_rewriting — flag off => that enricher is skipped entirely.

admin.py (§4.5): 2 secrets masked (OVERTURE_DB_PASSWORD, GOOGLE_PLACES_API_KEY);
3 dependency probes — overture-postgis (SELECT 1), recon-wiki-enrich and
recon-wiki-rewrite (GET with no params, expect HTTP 400 = route alive).

Deploy: systemd unit (:8425) + nginx snippet (^~ /api/place, no trailing slash,
no proxy_cache; public, no Caddy edit — TIER 2 already through nginx since #2).

Tests (13; recon had zero for this module): validation (400), cache hit (no
upstream), nominatim hit, nominatim-miss->overpass fallback, both-fail 502,
not-found 404, wikidata happy + invalid, overture gated-off (no PG call),
wiki-rewrite-via-http local hit + original pass-through, wiki-enrich-via-http
field merge. Full suite 59. See ../recon_refactor/extraction-5-phase-a.md,
-wiki-enrich-investigation.md, -wiki-rewrite-investigation.md, and PRs #8/#9.

Co-authored-by: Matt Johnson <mj@k7zvx.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 17:00:06 -06:00
..
navi-config.conf.snippet Add navi-config service (extraction #2 PR-B) 2026-05-22 08:25:06 -06:00
navi-contacts.conf.snippet Add navi-contacts service (extraction #3) 2026-05-22 10:59:37 -06:00
navi-landclass.conf.snippet Add navi-landclass service (extraction #4) (#4) 2026-05-22 12:08:58 -06:00
navi-places.conf.snippet Add navi-places service (extraction #5) (#5) 2026-05-22 17:00:06 -06:00
navi-traffic.conf.snippet nginx: use ^~ prefix on /api/traffic/ to beat .png regex catch-all (fixes latent 404 bug) 2026-05-22 00:07:49 -06:00