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> |
||
|---|---|---|
| .. | ||
| config | ||
| deploy | ||
| services | ||
| shared | ||
| .gitignore | ||
| LICENSE | ||
| pyproject.toml | ||
| README.md | ||
navi-backend
Monorepo of small, single-responsibility HTTP services extracted from the recon
codebase as part of the recon ↔ Navi decoupling project. Each service owns a
slice of the /api/* surface that navi.echo6.co depends on, runs behind the
existing Caddy/Authentik edge, and is fronted by the navi.echo6.co nginx vhost.
See HANDOFF-recon-navi-decoupling-v3.md for the full plan. This repo is
extraction #1: navi-traffic.
Layout
navi-backend/
├── shared/ # cross-service helpers, imported by every service
│ ├── auth.py # get_user_id(req), require_auth decorator (Authentik header)
│ └── admin_info.py # build_info_response(), mask_key(), time_dependency()
├── services/
│ └── navi_traffic/ # extraction #1 — TomTom traffic tile proxy (:8421)
│ ├── app.py # Flask factory (create_app) + gunicorn entry
│ ├── traffic.py # /api/traffic/flow/<z>/<x>/<y>.png (ported from recon)
│ ├── admin.py # /api/admin/navi-traffic/info (§4.5 admin convention)
│ └── tests/
└── deploy/
├── systemd/navi-traffic.service
└── nginx/navi-traffic.conf.snippet
Service directories use an underscore (navi_traffic) so they're importable
Python packages; the service name stays navi-traffic (hyphen) in systemd,
nginx, and the admin-info service field.
Setup
Single workspace, single virtualenv:
python -m venv .venv
.venv/bin/pip install -e .
Test
.venv/bin/pytest services/navi_traffic/tests/ -v
Run (local)
TOMTOM_API_KEY=... .venv/bin/gunicorn 'services.navi_traffic.app:create_app()' \
--bind 127.0.0.1:8421 --workers 2
The admin-info convention (§4.5)
Every service exposes GET /api/admin/<service-name>/info, gated by require_auth,
returning a uniform shape: service, version (git SHA), port, config, env
(names + masked values), dependencies (upstream health checks), filesystem,
runtime (uptime / request count / last error). No aggregator — a future admin
panel fans out to each service in parallel.