Files
shard-memory/runbooks/bridge-scaffold-layout.md
T

2.0 KiB

Bridge Code Scaffold (initial)

Stack recommendation

  • Python 3.11+
  • FastAPI (API surface)
  • httpx (adapter/chattr clients)
  • sqlite + SQLAlchemy or sqlite3+repo pattern
  • Prometheus client for /metrics

Initial files

chattr-bridge/
  app/
    main.py                  # app startup, wiring workers
    config.py                # env parsing and validation
    logging.py               # structured logger + correlation support
    metrics.py               # Prometheus counters/histograms

    api/
      health.py              # /healthz /readyz
      adapter_events.py      # /adapter/events callback endpoint

    core/
      envelope.py            # canonical schema + validators
      routing.py             # mention/fanout target selection
      conversation.py        # start/reuse/fork rules
      handoff.py             # handoff creation + truncation
      dedupe.py              # dedupe key + TTL checks
      loop_guard.py          # hop/cycle/cooldown/self-echo

    clients/
      chattr_client.py       # read/post interactions
      adapter_client.py      # /ingest calls, ack/error parsing

    store/
      db.py                  # sqlite init/connection
      migrations.py          # schema management
      repo.py                # table operations

    workers/
      poller.py              # inbound chattr polling loop
      retry_worker.py        # retry queue processor

  tests/
    unit/
      test_routing.py
      test_conversation.py
      test_dedupe.py
      test_loop_guard.py
      test_handoff.py
    integration/
      test_adapter_contract.py
      test_retry_queue.py
      test_restart_resume.py

  Dockerfile
  pyproject.toml
  README.md

Phase-0 TODOs

  • Build config struct with sane defaults from v1.1 spec
  • Implement minimal health endpoints
  • Add no-op poll loop with logs only
  • Add sqlite bootstrap and migrations
  • Add first unit tests for routing + dedupe

CI minimum

  • lint
  • type check (optional initially)
  • unit tests
  • integration tests (mock adapters)