Title: Spec: Solid + ActivityPub Federation Architecture · Issue #51 · JavaScriptSolidServer/JavaScriptSolidServer · GitHub
Open Graph Title: Spec: Solid + ActivityPub Federation Architecture · Issue #51 · JavaScriptSolidServer/JavaScriptSolidServer
X Title: Spec: Solid + ActivityPub Federation Architecture · Issue #51 · JavaScriptSolidServer/JavaScriptSolidServer
Description: Overview This document describes how JSS (JavaScriptSolidServer) implements ActivityPub federation while maintaining full Solid protocol compatibility. This represents a working bridge between two decentralized web standards. Status: ✅ P...
Open Graph Description: Overview This document describes how JSS (JavaScriptSolidServer) implements ActivityPub federation while maintaining full Solid protocol compatibility. This represents a working bridge between two ...
X Description: Overview This document describes how JSS (JavaScriptSolidServer) implements ActivityPub federation while maintaining full Solid protocol compatibility. This represents a working bridge between two ...
Opengraph URL: https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/issues/51
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Spec: Solid + ActivityPub Federation Architecture","articleBody":"## Overview\n\nThis document describes how JSS (JavaScriptSolidServer) implements ActivityPub federation while maintaining full Solid protocol compatibility. This represents a working bridge between two decentralized web standards.\n\n**Status**: ✅ Production-tested federation with Mastodon (Jan 5, 2026)\n\n**Tested servers**:\n- solid.social\n- phone.solid.live \n- melvincarvalho.com\n\n---\n\n## Architecture\n\n### The Core Insight: Content Negotiation\n\nThe key architectural decision is using **content negotiation** to serve both Solid and ActivityPub from the same identity URL:\n\n```mermaid\nflowchart LR\n A[\"GET /profile/card\"] --> B{\"Accept header?\"}\n B -->|\"text/html\"| C[\"HTML profile page\u003cbr>(Mashlib)\"]\n B -->|\"text/turtle\"| D[\"Solid WebID\u003cbr>(Turtle RDF)\"]\n B -->|\"application/ld+json\"| E[\"Solid WebID\u003cbr>(JSON-LD)\"]\n B -->|\"application/activity+json\"| F[\"ActivityPub Actor\"]\n```\n\nThis means:\n- **Same URL** for WebID and AP Actor: `https://example.com/profile/card#me`\n- **No duplication** of identity data\n- **Protocol-aware** responses based on client needs\n- **Backwards compatible** with existing Solid apps\n\n### Component Architecture\n\n```mermaid\nflowchart TB\n subgraph JSS[\"JSS Server (Fastify)\"]\n subgraph Protocols[\"Protocol Handlers\"]\n LDP[\"🗄️ \u003cb>Solid LDP\u003c/b>\u003cbr>Resources\u003cbr>Containers\u003cbr>ACLs\u003cbr>PATCH\"]\n AP[\"📡 \u003cb>ActivityPub\u003c/b>\u003cbr>Actor\u003cbr>Inbox\u003cbr>Outbox\u003cbr>WebFinger\"]\n Nostr[\"⚡ \u003cb>Nostr Relay\u003c/b>\u003cbr>NIP-01 events\u003cbr>Subscriptions\u003cbr>WebSocket\"]\n end\n DB[(\"💾 \u003cb>SQLite Storage\u003c/b>\u003cbr>better-sqlite3 or sql.js\")]\n end\n \n LDP --> DB\n AP --> DB\n Nostr --> DB\n```\n\n---\n\n## Key Files\n\n| File | Purpose |\n|------|---------|\n| `src/ap/index.js` | Fastify plugin, routes, WebFinger, NodeInfo |\n| `src/ap/routes/actor.js` | Actor JSON-LD generator with publicKey |\n| `src/ap/routes/inbox.js` | Receive activities, verify signatures, handle Follow/Accept |\n| `src/ap/routes/outbox.js` | GET collection, POST to create/deliver notes |\n| `src/ap/routes/collections.js` | Followers/Following collections |\n| `src/ap/store.js` | SQLite storage (followers, posts, activities, actor cache) |\n| `src/ap/keys.js` | RSA keypair generation and persistence |\n| `src/server.js` | Content negotiation route for /profile/card |\n\n---\n\n## How It Works\n\n### 1. Discovery (WebFinger)\n\n```http\nGET /.well-known/webfinger?resource=acct:melvin@solid.social\n```\n\nResponse:\n```json\n{\n \"subject\": \"acct:melvin@solid.social\",\n \"links\": [\n {\n \"rel\": \"self\",\n \"type\": \"application/activity+json\",\n \"href\": \"https://solid.social/profile/card#me\"\n }\n ]\n}\n```\n\n### 2. Actor Retrieval\n\nWhen Mastodon fetches the actor URL with `Accept: application/activity+json`:\n\n```json\n{\n \"@context\": [\"https://www.w3.org/ns/activitystreams\", \"https://w3id.org/security/v1\"],\n \"type\": \"Person\",\n \"id\": \"https://solid.social/profile/card#me\",\n \"preferredUsername\": \"melvin\",\n \"inbox\": \"https://solid.social/profile/card/inbox\",\n \"outbox\": \"https://solid.social/profile/card/outbox\",\n \"publicKey\": {\n \"id\": \"https://solid.social/profile/card#main-key\",\n \"owner\": \"https://solid.social/profile/card#me\",\n \"publicKeyPem\": \"-----BEGIN PUBLIC KEY-----\\n...\"\n }\n}\n```\n\n**Key insight**: The publicKey is generated on server start and injected into the Actor response. It never touches the actual WebID file - it's \"virtual\" via content negotiation.\n\n### 3. Follow Handshake\n\n```mermaid\nsequenceDiagram\n participant M as 🐘 Mastodon\n participant J as 🔷 JSS\n \n M->>J: POST /inbox (Follow)\n Note over M,J: HTTP Signature\n \n Note over J: 1. Parse signature header\u003cbr>2. Fetch sender's actor\u003cbr>3. Verify signature\u003cbr>4. Store follower\n \n J-->>M: 202 Accepted\n J->>M: POST /inbox (Accept)\n Note over M,J: HTTP Signature\n```\n\n### 4. Posting to Followers\n\n```http\nPOST /profile/card/outbox\nContent-Type: application/json\n\n{\"content\": \"Hello from my Solid pod!\"}\n```\n\nServer:\n1. Creates Note activity with unique ID\n2. Stores in local SQLite\n3. Delivers to all follower inboxes with HTTP signatures\n4. Returns 201 with activity JSON\n\n---\n\n## Bugs & Workarounds Discovered\n\n### 1. User-Agent Header Required (Critical)\n\n**Problem**: Mastodon blocks requests without User-Agent header, returning empty responses.\n\n**Symptom**: `fetchActor()` returned null, signature verification failed.\n\n**Fix** (`src/ap/routes/inbox.js`):\n```javascript\nconst response = await fetch(fetchUrl, {\n headers: {\n 'Accept': 'application/activity+json',\n 'User-Agent': 'JSS/1.0 (+https://github.com/JavaScriptSolidServer/JavaScriptSolidServer)'\n }\n})\n```\n\n**Lesson**: Always include User-Agent in ActivityPub fetches.\n\n### 2. SQLite datetime() Syntax\n\n**Problem**: `datetime(\"now\")` with double quotes fails - SQLite interprets it as column name.\n\n**Symptom**: `no such column: \"now\"` error when caching actors.\n\n**Fix** (`src/ap/store.js`):\n```javascript\n// Wrong\n'INSERT INTO actors (id, data, fetched_at) VALUES (?, ?, datetime(\"now\"))'\n\n// Correct \n\"INSERT INTO actors (id, data, fetched_at) VALUES (?, ?, datetime('now'))\"\n```\n\n**Lesson**: SQLite uses single quotes for string literals, double quotes for identifiers.\n\n### 3. Content-Type Header Setting\n\n**Problem**: Using `reply.header('Content-Type', ...)` in Fastify hooks didn't work reliably.\n\n**Symptom**: Responses returned `application/octet-stream` instead of `application/activity+json`.\n\n**Fix**: Use dedicated route with `reply.type()`:\n```javascript\nfastify.route({\n method: 'GET',\n url: '/profile/card',\n handler: async (request, reply) => {\n if (wantsActivityPub(request)) {\n return reply\n .type('application/activity+json')\n .send(actorHandler(request))\n }\n // Fall through to LDP handler\n }\n})\n```\n\n### 4. Protocol Detection Behind Proxies\n\n**Problem**: Cloudflare tunnels don't always pass `X-Forwarded-Proto`.\n\n**Symptom**: Actor URLs showed `http://` instead of `https://`.\n\n**Fix** (`src/ap/routes/actor.js`):\n```javascript\nlet protocol = request.headers['x-forwarded-proto']\nif (!protocol) {\n // Cloudflare uses cf-visitor header\n const cfVisitor = request.headers['cf-visitor']\n if (cfVisitor) {\n const parsed = JSON.parse(cfVisitor)\n protocol = parsed.scheme\n }\n}\n// Assume HTTPS for public domains\nif (!protocol && !host.match(/^(localhost|127\\.|192\\.168\\.|10\\.)/)) {\n protocol = 'https'\n}\n```\n\n### 5. Scoped Plugin Decorations\n\n**Problem**: Fastify decorations in plugins aren't accessible from parent routes.\n\n**Symptom**: `actorHandler` not found when trying to use in server.js hook.\n\n**Fix**: Export handler via module-level variable:\n```javascript\n// src/ap/index.js\nlet sharedActorHandler = null\nexport function getActorHandler() { return sharedActorHandler }\n\n// In plugin\nsharedActorHandler = createActorHandler(config, keypair)\n```\n\n### 6. Android/Termux Compatibility\n\n**Problem**: `better-sqlite3` requires native compilation that fails on Android.\n\n**Fix**: Fallback to `sql.js` (WASM):\n```javascript\ntry {\n const Database = (await import('better-sqlite3')).default\n db = new Database(path)\n} catch (e) {\n // Fall back to sql.js\n const initSqlJs = (await import('sql.js')).default\n const SQL = await initSqlJs()\n db = new SQL.Database()\n}\n```\n\n---\n\n## Current Limitations\n\n1. **No authentication on outbox POST** - Anyone can post (should require Solid-OIDC)\n2. **No pagination** on collections\n3. **No DELETE** for posts (Tombstone activity)\n4. **No reply handling** - Incoming replies not stored/displayed\n5. **No media attachments** - Text-only notes\n6. **No avatar/banner** - Actor lacks `icon` and `image` fields\n7. **Single-user only** - Multi-user would need path-based actors\n\n---\n\n## Areas for Further Work\n\n### High Priority\n\n1. **Authentication for posting**\n - Require Solid-OIDC token for outbox POST\n - Verify token matches actor\n\n2. **Receive and display replies**\n - Store incoming Create activities with inReplyTo\n - Expose via API or dashboard\n\n3. **Avatar support**\n - Pull from Solid WebID `foaf:img` or `vcard:hasPhoto`\n - Add `icon` field to Actor\n\n### Medium Priority\n\n4. **Nostr ↔ ActivityPub bridge**\n - kind:1 events → AP Notes\n - AP Notes → kind:1 events\n - Unified identity via `alsoKnownAs`\n\n5. **Likes and boosts**\n - Handle incoming Like/Announce\n - Allow creating Like/Announce activities\n\n6. **Collection pagination**\n - OrderedCollectionPage for outbox/followers/following\n - Cursor-based or page-based\n\n### Lower Priority\n\n7. **Dashboard UI**\n - View followers, posts, stats\n - Compose and send posts\n - Require authentication\n\n8. **Multi-user support**\n - `/~username/profile/card#me` as actor\n - Per-user keypairs and storage\n\n9. **Shared inbox optimization**\n - Deduplicate deliveries to same instance\n - Use shared inbox endpoint\n\n---\n\n## Configuration\n\nEnable ActivityPub with CLI flags:\n\n```bash\njss start --activitypub --ap-username melvin --ap-display-name \"Melvin Carvalho\"\n```\n\nOr in config:\n```json\n{\n \"activitypub\": true,\n \"apUsername\": \"melvin\",\n \"apDisplayName\": \"Melvin Carvalho\"\n}\n```\n\n---\n\n## Testing Checklist\n\n- [ ] WebFinger returns correct actor URL\n- [ ] Actor endpoint returns valid JSON-LD with publicKey\n- [ ] NodeInfo endpoint returns server info\n- [ ] Follow from Mastodon triggers Accept response\n- [ ] Follower appears in /profile/card/followers\n- [ ] POST to outbox creates and delivers Note\n- [ ] Post appears in follower's timeline\n- [ ] Unfollow removes from followers collection\n\n---\n\n## References\n\n- [ActivityPub Spec](https://www.w3.org/TR/activitypub/)\n- [HTTP Signatures](https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures)\n- [WebFinger](https://webfinger.net/)\n- [Solid Protocol](https://solidproject.org/TR/protocol)\n- [microfed library](https://github.com/micro-fed/microfed.org)\n- [JSS Source](https://github.com/JavaScriptSolidServer/JavaScriptSolidServer)\n\n---\n\n## Version History\n\n| Version | Changes |\n|---------|---------|\n| 0.0.64 | Initial AP infrastructure |\n| 0.0.65 | Add User-Agent header, error logging |\n| 0.0.66 | Fix SQLite datetime syntax |\n| 0.0.67 | Add outbox POST for creating/delivering posts |\n\n---\n\n*This spec is LLM-friendly and designed to provide full context for future development sessions.*\n","author":{"url":"https://github.com/melvincarvalho","@type":"Person","name":"melvincarvalho"},"datePublished":"2026-01-05T08:55:25Z","url":"https://github.com/JavaScriptSolidServer/JavaScriptSolidServer/issues/51"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:036f6a48-8389-a976-6491-6cdc5ce21b6a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E16A:2C4C9:2CE6116:3B3D97B:6B039813 |
| html-safe-nonce | cee6e3d2a742f32b23454a77dbb59d9669ba08fb7afe40f6a5bc05452c771c8f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTZBOjJDNEM5OjJDRTYxMTY6M0IzRDk3Qjo2QjAzOTgxMyIsInZpc2l0b3JfaWQiOiI4ODM3MjkyNDYzNDMwNTM5MjgzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d0ab8315c5295206fa26c1b68b4706abacbd0f5ca55cb12cefe69ad673acd4e6 |
| hovercard-subject-tag | issue:3780678849 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/JavaScriptSolidServer/JavaScriptSolidServer/51/issue_layout |
| twitter:image | https://opengraph.githubassets.com/09ce2ca5d60138f0b84fffc245c69529fb2e3e76bbf4fd5872dfd7dd9dbb912a/JavaScriptSolidServer/JavaScriptSolidServer/issues/51 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/09ce2ca5d60138f0b84fffc245c69529fb2e3e76bbf4fd5872dfd7dd9dbb912a/JavaScriptSolidServer/JavaScriptSolidServer/issues/51 |
| og:image:alt | Overview This document describes how JSS (JavaScriptSolidServer) implements ActivityPub federation while maintaining full Solid protocol compatibility. This represents a working bridge between two ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | melvincarvalho |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/JavaScriptSolidServer/JavaScriptSolidServer git https://github.com/JavaScriptSolidServer/JavaScriptSolidServer.git |
| octolytics-dimension-user_id | 205442424 |
| octolytics-dimension-user_login | JavaScriptSolidServer |
| octolytics-dimension-repository_id | 958025407 |
| octolytics-dimension-repository_nwo | JavaScriptSolidServer/JavaScriptSolidServer |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 958025407 |
| octolytics-dimension-repository_network_root_nwo | JavaScriptSolidServer/JavaScriptSolidServer |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width