Skip to content

Add a pluggable persistence adapter so the pair registry survives restarts #70

Description

@1nonlypiece

Add a pluggable persistence adapter for in-memory stores

Description

Every store in src/index.tspairRegistry, pairMeta, apiKeyStore, webhookStore, and eventLog — lives only in process memory. The code comments even acknowledge this ("Process restart resets the map; persistence lands with the database adapter"). A restart wipes all registered pairs, keys, and webhooks. This issue introduces a small persistence abstraction with a default file-backed (JSON) adapter so state survives restarts, without committing to a specific database yet.

Requirements and context

  • Repository scope: StableRoute-Org/Stableroute-backend only.
  • Create src/persistence.ts (create file) exporting a StoreAdapter interface (load(), save(snapshot)) and two implementations: an in-memory no-op adapter (preserving current behavior under tests) and a JSON-file adapter selected by a PERSIST_PATH env var.
  • On startup, hydrate the stores from the adapter; on each mutation (or on a debounced interval) persist a snapshot.
  • Default to the in-memory adapter when PERSIST_PATH is unset and under NODE_ENV=test, so the existing suite is unaffected.
  • Keep all current route behavior and response shapes identical; this adds durability, not new endpoints.
  • Persist atomically (write-temp-then-rename) so a crash mid-write cannot corrupt the snapshot.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b feature/persistence-27-store-adapter
  • Implement changes
    • Write code in: create src/persistence.ts; wire hydration and snapshotting from src/index.ts.
    • Write comprehensive tests in: create src/__tests__/persistence.test.ts — save a snapshot, reload into a fresh store, assert pairs/keys/webhooks restored; assert atomic write via temp file.
    • Add documentation: document PERSIST_PATH and the snapshot format in README.md.
    • Add TSDoc on the StoreAdapter interface and both implementations.
    • Validate security: never persist raw API keys in plaintext if hashing has been adopted; restrict snapshot file permissions.
  • Test and commit

Test and commit

  • Run npm run build, npm run lint, and npm test.
  • Cover edge cases: missing snapshot file, corrupt snapshot, round-trip restore.
  • Paste the full npm test output in the PR.

Example commit message

feat(persistence): add pluggable store adapter with JSON-file backend

Guidelines

  • Minimum 95 percent test coverage for impacted code.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the StableRoute community on Discord for questions, reviews, and faster merges: https://discord.gg/37aCpusvx
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions