# ADR-059: Tour Planner AI Uses a Dedicated Sidecar Proxy — Not the Shared AI Finance Proxy

## Status

Accepted, 2026-06-22.

## Status History

```yaml
status_history:
  - date: 2026-06-22
    status: Proposed
    changed_by: hkl
    reason: Formalising dedicated Tour AI proxy decision vs. shared finance proxy
    changed_via: adr-kit (360lm)
  - date: 2026-06-22
    status: Accepted
    changed_by: hkl
    reason: tour-ai-proxy on port 8774 live; separate from AI Finance proxy on port 8772
    changed_via: adr-kit (360lm)
```

## Context

The 360lm platform has multiple AI-powered proxy services: `ai-finance-proxy` (port 8772, handles Finance AI features) and `tour-ai-proxy` (port 8774, handles Tour Planner AI). When Tour Planner AI features were being designed, the existing `ai-finance-proxy` was available and a question arose: should Tour Planner reuse it, or use a separate proxy? The Tour Planner AI operations (`/analyze` for itinerary analysis, `/route` for route optimization, `/replan` for day replanning, `/maps` for map data) are domain-specific and operationally distinct from Finance AI.

## Decision

Tour Planner AI uses `tour-ai-proxy` (port 8774) — a dedicated sidecar proxy separate from `ai-finance-proxy`. Each domain's AI proxy handles only its domain's operations.

Rationale:
- **Different model requirements:** Tour Planner requires map-context reasoning and multi-day itinerary optimization; Finance AI handles expense classification and document parsing — different prompts, different model parameters, possibly different model tiers.
- **Independent scaling and restarts:** a Tour AI deployment or config change does not affect Finance AI and vice versa.
- **Operational isolation:** Finance AI downtime does not impact Tour Planner AI and vice versa.
- **Domain cohesion:** Tour Planner operations (`/analyze`, `/route`, `/replan`, `/maps`) would be awkward in a "finance" proxy URL namespace.

New AI-powered features must create a domain-specific proxy rather than routing through an existing proxy from a different domain.

**Decision Maker:** hkl

## Alternatives Considered

- **Single shared AI proxy with route namespacing (e.g. /ai/finance/*, /ai/tour/*).** Rejected: single proxy becomes a shared failure point across all AI features; any deployment, config change, or crash affects all AI consumers simultaneously; different domain prompts/configs in one service require complex routing logic.
- **No proxy (call Claude/Gemini API directly from PWA client, key in JS).** Rejected: API keys would be exposed in client-side JS; rate-limiting and error handling must be duplicated per PWA; no opportunity for server-side prompt enhancement or model selection.
- **Extend ai-finance-proxy with Tour routes.** Rejected: "Finance" proxy hosting Tour Planner operations violates domain cohesion; cross-domain route addition in one service creates coupling — a Finance proxy restart for a config change would interrupt Tour Planner mid-session.

## Consequences

**Positive:**
- Tour AI and Finance AI are independently deployable and configurable.
- Domain-specific proxy URL namespace (`/tour-ai/`) is self-documenting.
- Independent restart/crash isolation — Finance AI issue does not affect Tour Planner.

**Negative / Trade-offs:**
- More Docker containers to manage (one per AI domain).
- Shared boilerplate code (auth, error handling, retry) must be kept in sync across proxy services — or extracted to a shared library if drift becomes significant.

**Risks and mitigations:**
- Shared boilerplate diverges across proxies: mitigated by extracting common auth/retry middleware to a shared module (when drift is observed, not proactively — ponytail rule); currently both proxies are small enough that duplication is acceptable. // ponytail: upgrade trigger=3+ proxy services with diverged auth middleware

## Related Decisions

- ADR-025 (self-hosted Ollama alongside cloud AI) — both proxies may call Ollama for applicable tasks.
- ADR-017 (Traefik routing) — both proxies exposed via Traefik with domain-specific routes.
- ADR-010 (cross-schema data via proxy) — same proxy pattern extended to AI inference.

## References

- `memory/dbt_infra.md` — AI Finance proxy port 8772; Tour AI proxy port 8774
- `memory/dbt_tour_planner.md` — tour-ai-proxy handles /analyze, /route, /replan, /maps
- `docker-compose.yml` — tour-ai-proxy container definition
