/api/v1/federation gains:
- GET /posts, DELETE /posts/{id}: manage your own posts from the UI.
- GET /preview/weekly: what the weekly summary would say right now, for
the week still in progress - never posted or stored. Backed by a new
weekly.preview() and schedule.current_week_start().
- GET /profiles/{username}/posts/{post_uuid} (public, unauthenticated):
backs the UI's post page, which can't itself speak ActivityPub.
Settings gain timezone/post_weekly_summary/post_milestones, already
present in sharing.EDITABLE since phase 3 step 2 but never added to
SharingSettingsSchema, so the API was silently dropping them from
responses. timezone validates against the same is_valid_timezone() the
service layer uses, with a dedicated marshmallow validator.
Fixed a real gap found while wiring the post page: ids.post_page_url()
took a username but never put it in the URL, so post.html would have
had no way to know whose post to look up. It's now ?u=<username>&id=<uuid>.
Sharing page gets a "What to post" section (weekly summary and
milestones toggles, a timezone field with a browser-supplied IANA
datalist where Intl.supportedValuesOf exists, and a live preview).
New posts.html lists a user's posts with delete (mirroring followers.js's
confirm-before-destructive-action pattern); new post.html is the public
landing page for a post's `url`, reached by browsers redirected from the
raw ActivityPub endpoint.
Verified by hand against a local dev server and a real browser: sign in,
enable sharing, preview and publish, list and delete a post, and follow
the ActivityPub redirect through to the public post page and its 404
after deletion - fixed one bug found this way (the preview box was
collapsing the summary's line breaks).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
scrobbler.federation
ActivityPub support, kept apart from the rest of the app so it can be changed, replaced
or switched off without touching anything else. Design: docs/design/activitypub.md.
Boundary rules (enforced by tests/test_federation_boundary.py)
-
Nothing outside this package imports it, except
create_app()callingfederation.init_app(app). The core reports what happened through the domain events inscrobbler.events; this package subscribes to them. -
protocol/is pure: no Flask, SQLAlchemy, Werkzeug orscrobblerimports. Signature schemes, vocabulary and document formats live there. -
The rest of this package uses only the core's public surface:
scrobbler.__version__scrobbler.api.get_api(to register federation's API blueprint and document its paths)scrobbler.eventsscrobbler.extensions(db)scrobbler.workerscrobbler.services.*scrobbler.api.decoratorsscrobbler.schemas
So no core models and no core metrics; federation defines its own.
-
Off means off. With
FEDERATION_ENABLEDunset,init_appregisters no routes, no event receivers and no worker tasks.
Configuration
| Variable | Meaning |
|---|---|
FEDERATION_ENABLED |
1 to turn federation on (default off) |
FEDERATION_DOMAIN |
Handle domain, normally the web UI's host: users are @name@<domain>. Permanent once anyone follows. |
FEDERATION_BASE_URL |
Public https:// URL actors live under (<base>/users/<name>). Normally the web UI's origin, with the UI's nginx forwarding the ActivityPub paths to the API. |
FEDERATION_KEY_SECRET |
32+ characters; encrypts actors' private keys at rest (HKDF → Fernet). Back it up; never change it. |
FEDERATION_SIGNATURE_SCHEMES |
Outgoing signing order; the next scheme is tried only on a 401. Default draft-cavage,rfc9421 |
FEDERATION_BLOCKED_DOMAINS |
Comma-separated domains (subdomains included) refused at the inbox |
FEDERATION_DELIVERY_CONCURRENCY |
Parallel deliveries per worker (1-32, default 4) |
FEDERATION_INSECURE_TESTING |
Tests only. Allows http:// and private addresses; refused unless the domain is under .test |
The UI container forwards these paths to the API when API_INTERNAL_URL is set (see docker/ui-config.sh):
/.well-known/webfinger,/.well-known/nodeinfo,/.well-known/host-meta/nodeinfo/,/users/,/inbox,/actor
Every ActivityPub ID is built from FEDERATION_BASE_URL, never from the incoming request.
Layout
| Module | Holds |
|---|---|
protocol/ |
Pure protocol code: media types, vocabulary, WebFinger, NodeInfo, host-meta, and signatures/ (draft-cavage and RFC 9421, one module each) |
net.py |
The SSRF-safe HTTP client, the only way out |
outbound.py |
Signed GETs (as the instance actor) and POSTs (as a user), with scheme fallback on 401 |
remote.py |
Remote actors: fetched, validated, cached; key id to actor |
inbox.py |
Intake (no network) and worker processing: signature check, identity checks, handlers by activity type |
followers.py |
Follower state: follows, undo, approve, remove, block, sharing off |
activities.py |
Activities we send (Accept, Reject, Block, Undo), stored and queued per inbox |
delivery.py |
The delivery worker task: leases, retries with backoff, gone inboxes, gauges |
models.py |
federation_* tables |
keys.py |
Key pairs, created once and encrypted at rest |
sharing.py |
Per-user settings, and who is sharing |
ids.py |
Our ActivityPub ids, all from FEDERATION_BASE_URL |
web.py |
The endpoints other servers call |
api.py and schemas.py |
/api/v1/federation/* for the web UI |
openapi.py |
OpenAPI descriptions of web.py's endpoints |
metrics.py |
Federation's own Prometheus metrics |
Worker tasks
federation.inbox (process received activities), federation.deliver (send queued ones), federation.inbox.maintenance (re-queue stalled, prune after 30 days) and federation.gauges (queue and follower gauges). All are registered only when federation is on.
Interop
scripts/interop/run.sh runs Scrobbler against a real GoToSocial server on a private .test network and checks the whole follow life cycle. CI runs it on every push. GoToSocial 0.22.1 ignores a Reject of an already-accepted follow (a TODO in its code, fixed on its main branch), so that one check on its side is skipped until a release includes the fix.
Migrations
Federation's tables (all prefixed federation_) live in their own Alembic branch,
labelled federation, so they can be changed or dropped without touching core
migrations:
uv run flask --app scrobbler db migrate --head federation@head -m "…" # federation tables
uv run flask --app scrobbler db migrate --head core@head -m "…" # everything else
uv run flask --app scrobbler db upgrade heads # apply both branches
When generating a federation migration, check it only touches federation_* tables.
Autogenerate compares all models, so core changes would otherwise leak into it.