Research: CLI Full-Stack Parity
Feature: 031-cli-fullstack-parityDate: 2026-11-16 Spec: spec.md
1. Existing Codebase Audit
CLI Architecture & Import Boundaries (src/camply/cli/, pyproject.toml)
src/camply/cli/main.pydefinesCamplyCLI, a lazyclick.Groupthat resolvesserve,db,providers,recreation-areas,campgrounds, andcampsiteson demand so unrelated command groups do not import each other's dependencies.pyproject.tomlenforces two critical Import Linter contracts oncamply.cliandcamply.core:- Component dependency layers:
cli | server | worker→core→notifications | providers→db→__about__. - Base dependencies stay optional-free:
camply.cli.**,camply.core.**,camply.notifications.**,camply.providers.**, andcamply.db.**cannot importfastapi,uvicorn,gunicorn,orjson,jwt,cryptography,prometheus_client,celery,redis,psycopg, orsentry_sdk.
- Component dependency layers:
- Implication: Because
camply.notifications(PushoverProvider,NtfyProvider,NotificationDTO) andcamply.db.notification_config(validate_ntfy_url) already reside in lower base-only layers,camply.cliandcamply.corecan import them directly without violating any Import Linter contract or requiringserver/distributedextras.
Foreground Availability & Filtering (src/camply/core/search.py, src/camply/db/availability.py)
CampsiteDTO(src/camply/providers/dto.py) already normalizescampsite_id,campsite_name,campsite_type(TENT,RV,CABIN,OTHER),is_electric,is_accessible,permitted_equipment, andmax_vehicle_lengthacross all 26 providers (completed in feature 030).PROVIDERSandget_provider_filter_capabilities(src/camply/providers/__init__.py) already exposeProviderFilterCapabilities(preferred_types, require_electric, require_accessible, min_rv_length)per provider class.- Gap:
camply.core.search.SearchRequestand_stays()currently only filter by date windows, weekday nights, and exact stay length (nights), ignoringcampsite_type,is_electric,is_accessible,max_vehicle_length, and--campsiteID/name selectors.
Notifications (src/camply/notifications/)
PushoverProvider(src/camply/notifications/pushover.py) andNtfyProvider(src/camply/notifications/ntfy.py) implement asyncsend_accepted(...) -> boolusinghttpx2andjiter(both in base dependencies).- Gap: The CLI has no
--notificationsoption, notest-notificationscommand, and no seen-opening deduplication tracker (in-memory or file-backed) for foreground or single-pass CLI runs.
Discovery & Database Metadata (src/camply/cli/discovery.py, src/camply/cli/db.py)
BaseProvider.search()andProviderSearchQuery(src/camply/providers/dto.py) already validatelimit: int = Field(default=50, ge=1, le=1000, strict=True), whilesrc/camply/cli/discovery.pyhardcodesDISPLAY_LIMIT = 50andRESULT_PROBE = DISPLAY_LIMIT + 1.camply db metadata(src/camply/cli/db.py) currently only accepts numeric--provider-id(1–26orall), whereascamply.cli.providers.provider_entries()maps canonical CLI names (RecreationDotGov,ReserveCalifornia, etc.) and class names to provider IDs.
2. Technical Decisions
Decision 1: Shared Site-Attribute & Campsite-ID Filtering in camply.core.search
- Decision: Extend
SearchRequestinsrc/camply/core/search.pywith optional filter fields (campsites,campsite_types,require_electric,require_accessible,min_rv_length) and evaluate them in_stays()before constructing sliding stays, using the exact same boolean predicates ascamply.db.availability.matches_scan_filters:campsite_types: site'scampsite_type.valueis inrequest.campsite_types(when non-empty).require_electric:site.is_electric is True.require_accessible:site.is_accessible is True(unknown/false fails closed).min_rv_length:site.max_vehicle_length is not None and site.max_vehicle_length >= request.min_rv_length(unknown/Nonefails closed).campsites:site.campsite_id.strip()matches an exact selector ORsite.campsite_name.strip().casefold()matches a casefolded selector (when non-empty).
- Rationale: Keeps CLI and web availability filtering 100% consistent without requiring a database
UserScanORM instance during stateless CLI runs. - Alternatives considered: Constructing a transient
UserScanORM model incamply.core.searchand callingmatches_scan_filters— rejected becausecoreshould stay lightweight and decoupled from SQLAlchemy ORM instantiation for stateless CLI invocations.
Decision 2: Upfront Provider Filter Capability Validation & Display
- Decision: Validate requested site-attribute filters (
--campsite-type,--electric,--accessible,--rv-length) againstprovider_class.filter_capabilitiesincampsites_cmdbefore resolving targets or making HTTP requests. Updaterender_providersinsrc/camply/cli/output.pyto list supported site filters alongside discovery and availability capabilities. - Rationale: Matches
/api/scansvalidation (_validate_provider_filter_supportinsrc/camply/server/routers/scans.py) and satisfiesFR-001,FR-002, andSC-002. - Alternatives considered: Warning and ignoring unsupported filters — rejected by specification edge cases and
SC-002.
Decision 3: Stateless CLI Notification Resolution & Delivery
- Decision: Introduce
src/camply/cli/notifications.pyto handle:- Credential/config resolution from
--notifications(pushover,ntfy) and environment variables (PUSHOVER_USER_KEY,PUSHOVER_APP_TOKEN,NTFY_TOPIC,NTFY_SERVER_URL,NTFY_ACCESS_TOKEN). - Validation before polling:
- When
--notificationsis omitted, zero notification environment variables are read or validated. - When
pushoveris selected, bothPUSHOVER_USER_KEYandPUSHOVER_APP_TOKENmust be non-blank. - When
ntfyis selected, a valid topic (^[A-Za-z0-9_-]{1,64}$) and HTTP(S) server URL (validate_ntfy_url, defaulting tohttps://ntfy.sh) are required, and anyNTFY_ACCESS_TOKENmust be printable ASCII.
- When
- Delivery via existing
PushoverProvider(client)andNtfyProvider(client)insrc/camply/notifications/. camply test-notificationscommand registered lazily inCamplyCLI: requires at least one--notificationschannel, sends a testNotificationDTOviasend_accepted, and raisesclick.ClickException(exit code 1) if any selected channel fails or rejects the message.
- Credential/config resolution from
- Rationale: Reuses existing base-package notification providers, keeps secret tokens out of shell process arguments/history, and satisfies
FR-003andFR-008. - Alternatives considered: Reading credentials from
.camplyYAML files or databaseUserrows — rejected during/speckit-clarify(Q2).
Decision 4: Seen-Opening Deduplication & Optional State File
- Decision: Identify each qualifying stay by a canonical string key
"{provider_id}:{campground_id}:{campsite_id}:{arrival.isoformat()}:{checkout.isoformat()}".- During
monitor()(or a single check when--state-fileis provided), maintainseen_keys: set[str]. - On each successful
check_availability()cycle:- Compute
current_keys = {stay_key(stay) for stay in stays}. - Filter
new_stays = [stay for stay in stays if stay_key(stay) not in seen_keys]. - Replace
seen_keys = current_keys(and atomically write sorted keys as JSON to--state-filewhen configured). - Dispatch external notifications only for
new_stays. Transient notification delivery errors are logged as sanitized warnings on stderr without aborting the watch loop.
- Compute
- If
check_availability()raises an upstream provider error,seen_keysand the state file remain untouched so previously open stays are not falsely treated as closed and reopened on recovery.
- During
- Rationale: Satisfies
FR-004andSC-003for both continuous loops and cron-driven--search-once --state-fileinvocations without requiring SQLite/PostgreSQL. - Alternatives considered: Persisting state in the application SQLite database — rejected to keep
camply campsites100% database-free (Q4).
Decision 5: Run-Mode Controls (--search-once, --interval) & Discovery Limit (--limit)
- Decision:
- Add
--search-once(is_flag=True, defaultFalse) and--interval(click.IntRange(min=5), default10minutes) tocamply campsites. When--search-onceis set,campsitesexecutes onecheck_availability()cycle, renders output, sends any configured notifications, saves--state-fileif set, and exits cleanly (0). - Add
--limit(click.IntRange(min=1, max=500), default50) tocamply recreation-areasandcamply campgrounds. Requestlimit + 1fromBaseProvider.search(..., limit=limit + 1)(well withinProviderSearchQuery'sle=1000ceiling) to preserve accurate truncation warnings when more than--limitresults exist.
- Add
- Rationale: Satisfies
FR-005andFR-006while protecting upstream providers from sub-5-second polling and preserving existing truncation detection.
Decision 6: Structured JSON Output (--json) & Stream Separation
- Decision: Add
--json(is_flag=True, defaultFalse) toproviders,recreation-areas,campgrounds, andcampsites.- On
campsites,--jsonrequires--search-once(if--jsonis passed without--search-once, raiseclick.UsageError("--json requires --search-once on campsites.")so stdout always receives a single valid JSON array/document). - When
--jsonis active,set_up_loggingroutes all log records (includingINFOandCAMPLY) tostderrsostdoutcontains exclusively the serialized JSON payload.
- On
- Rationale: Satisfies
FR-007and ensurescamply ... --json | jqworks cleanly even when warnings or debug logs are emitted.