docs: Bring all documentation up to date for v2.10.1

- architecture/: overview, technology stack, auth (OIDC + built-in
  IndieAuth), syndication (POSSE) rewritten; new database.md,
  deployment.md and indieweb-protocols.md; legacy stack marked historical
- decisions/: reconstructed ADR-060 and ADR-063; 31 status corrections
  (superseded auth ADRs, proposed -> accepted); INDEX rebuilt
- design/: reconstructed the v1.6.0 documents the webmention code cites;
  reports for 18 v2 releases without a design folder; INDEX rebuilt
- projectplan/: BACKLOG rewritten (shipped items removed, open issues from
  the reviews added); RELEASE.md for v2.0.0-v2.10.1; INDEX
- standards/: development setup (uv, tests, DEV_MODE), testing (CI test
  stage), git and release flow, versioning, coding standards, cookies
- README, CLAUDE.md, .env.example (every setting the code reads, with
  defaults) brought up to date
- 137 broken links repaired (old absolute paths, moved files); stale ADR
  references in code comments corrected (comments only)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-03 12:40:19 -07:00
1 parent fa551de197
commit 0716984958
143 files changed
+6222 -8660

No files matched your search

+212 -190
View File
@@ -1,233 +1,255 @@
# Syndication Architecture
# Syndication (POSSE) Architecture
## Overview
StarPunk's syndication architecture provides multiple feed formats for content distribution, ensuring broad compatibility with feed readers and IndieWeb tools while maintaining simplicity.
Current as of v2.10.1. Code: `starpunk/syndication.py`.
## Current State (v1.1.0)
```
┌─────────────┐
│ Database │
│ (Notes) │
└──────┬──────┘
│
┌──────▼──────┐
│ feed.py │
│ (RSS 2.0) │
└──────┬──────┘
│
┌──────▼──────┐
│ /feed.xml │
│ endpoint │
└─────────────┘
```
StarPunk publishes on its own site first and then copies each note to other
networks (POSSE: Publish on your Own Site, Syndicate Elsewhere). Later
edits, unpublishing and deletes follow the copies.
## Target Architecture (v1.1.2+)
```
┌─────────────┐
│ Database │
│ (Notes) │
└──────┬──────┘
│
┌──────▼──────────────────┐
│ Feed Generation Layer │
├──────────┬───────────────┤
│ feed.py │ json_feed.py │
│ RSS/ATOM│ JSON │
└──────────┴───────────────┘
│
┌──────▼──────────────────┐
│ Feed Endpoints │
├─────────┬───────────────┤
│/feed.xml│ /feed.atom │
│ (RSS) │ (ATOM) │
├─────────┼───────────────┤
│ /feed.json │
│ (JSON Feed) │
└─────────────────────────┘
```
> Feeds (RSS, Atom, JSON Feed, OPML) and WebSub are pull and push
> distribution of the site itself, not crossposting. They are described in
> [indieweb-protocols.md](indieweb-protocols.md#feeds). This document
> covered feeds before v2.1.0.
## Design Principles
Decisions: [ADR-065](../decisions/ADR-065-direct-syndication-posse.md)
(GoToSocial, queue model), [ADR-066](../decisions/ADR-066-bluesky-syndication.md)
(Bluesky), [ADR-068](../decisions/ADR-068-likes-and-reposts.md) (likes and
reposts), [ADR-069](../decisions/ADR-069-threads-syndication.md) (Threads),
[ADR-070](../decisions/ADR-070-crosspost-links-and-cards.md) (links and link
cards), and the [v2.9.0 Micropub review](../design/v2.9.0/2026-11-03-micropub-review.md)
(bookmarks, `mp-syndicate-to` default).
### 1. Format Independence
Each syndication format operates independently:
- No shared state between formats
- Failures in one don't affect others
- Can be enabled/disabled individually
## Targets
### 2. Shared Data Access
All formats read from the same data source:
- Single query pattern for notes
- Consistent ordering (newest first)
- Same publication status filtering
A target exists when its credentials are configured. `get_targets()` builds
the list from config on each call and caches one client object per target
in the process.
### 3. Library Leverage
Maximize use of existing libraries:
- `feedgen` for RSS and ATOM
- Native Python `json` for JSON Feed
- No custom XML generation
| Target id | Client | Enabled by | Micropub `uid` | Text limit | Images | Edits follow? |
|---|---|---|---|---|---|---|
| `gotosocial` | `MastodonClient` (any Mastodon-API server) | `GOTOSOCIAL_URL` + `GOTOSOCIAL_ACCESS_TOKEN` | `GOTOSOCIAL_URL/` | `GOTOSOCIAL_MAX_CHARS` (5000) | `GOTOSOCIAL_MAX_MEDIA` (4) | Yes |
| `bluesky` | `BlueskyClient` (AT Protocol, app password) | `BLUESKY_HANDLE` + `BLUESKY_APP_PASSWORD` (`BLUESKY_SERVICE`, default `https://bsky.social`) | `https://bsky.app/profile/<handle>` | `BLUESKY_MAX_CHARS` (300) | 4 | No |
| `threads` | `ThreadsClient` (Meta Graph API) | `THREADS_ACCESS_TOKEN` (`THREADS_USERNAME` for links) | `https://www.threads.com/@<username>` | `THREADS_MAX_CHARS` (500) | `THREADS_MAX_MEDIA` (4) | No |
## Component Design
Display names come from `GOTOSOCIAL_NAME`, `BLUESKY_NAME` and
`THREADS_NAME`. GoToSocial statuses use `GOTOSOCIAL_VISIBILITY` (default
`public`). The GoToSocial token needs `write:statuses` and `write:media`,
plus `read:search` and `write:favourites` for likes and boosts.
### Feed Generation Module (`feed.py`)
**Current Responsibility**: RSS 2.0 generation
**Future Enhancement**: Add ATOM generation function
Bluesky and Threads can't edit posts through their APIs. Once a copy exists
there, edits to the note don't change it, but unpublish and delete still
remove it.
```python
# Pseudocode structure
def generate_rss_feed(notes, config) -> str
def generate_atom_feed(notes, config) -> str # New
```
## Choosing targets
### JSON Feed Module (`json_feed.py`)
**New Component**: Dedicated JSON Feed generation
`select_targets(note_id, target_ids)` records which targets a note goes to.
Every configured target not in the list is disabled; if it already has a
copy, that copy is deleted. Targets the note never went to get no row.
```python
# Pseudocode structure
def generate_json_feed(notes, config) -> str
def format_json_item(note) -> dict
```
| Origin | Targets |
|---|---|
| Admin editor, new note | One checkbox per target, all checked by default |
| Admin editor, edit | Checkboxes reflect the targets currently enabled; saving applies the selection |
| Micropub create | Only the targets in `mp-syndicate-to` (form field, `mp-syndicate-to[]`, or inside JSON `properties`). Values may be a target's `uid` (trailing slash ignored) or its id. **No `mp-syndicate-to` means no crossposting** (v2.9.0; before, all targets) |
| Micropub update / delete | Target selection is unchanged; the change follows existing copies |
### Route Handlers
Simple pass-through to generation functions:
```python
@app.route('/feed.xml') # Existing
@app.route('/feed.atom') # New
@app.route('/feed.json') # New
```
Micropub clients learn the targets from `q=syndicate-to` and `q=config`
(`[{"uid", "name"}]`). Selecting targets for a draft records them; nothing
is sent until the note is published.
## Data Flow
## Data: the `syndications` table (migration 012)
1. **Request**: Client requests feed at endpoint
2. **Query**: Fetch published notes from database
3. **Transform**: Convert notes to format-specific structure
4. **Serialize**: Generate final output (XML/JSON)
5. **Response**: Return with appropriate Content-Type
One row per (note, target), unique on `(note_id, target)`:
## Microformats2 Architecture
| Column | Meaning |
|---|---|
| `enabled` | Whether the note should have a copy on this target |
| `remote_id`, `remote_url` | The copy: status id, `at://` URI, Threads media id, or a `favourite:<id>` / `reblog:<id>` marker for native likes and boosts |
| `state` | `pending`, `synced` or `failed` |
| `version` | Incremented on every change that needs a reconcile |
| `attempts`, `last_error`, `next_attempt_at` | Retry bookkeeping |
| `claimed_until` | Lease held by the worker processing the row |
### Template Layer Enhancement
Microformats2 operates at the HTML template layer:
`note_id` deliberately has no foreign key, so the row outlives a hard
delete and the worker can still remove the copy.
## Change hooks
| Event | Call | Effect |
|---|---|---|
| Admin create/edit | `select_targets()` | Rows set to `pending`, version bumped |
| Micropub create | `select_targets(resolve_targets(mp-syndicate-to))` | After photos are attached |
| `update_note()` (admin or Micropub, including publish/unpublish) | `note_changed(id)` | Every row of the note set to `pending`, version bumped, attempts reset |
| Micropub photo changes | `note_changed(id)` | Same |
| `delete_note()` (soft or hard), `undelete_note()` | `note_changed(id)` | Same |
| Retry button on the edit page | `retry(id)` | That row set to `pending` now, attempts reset |
## Worker
`SyndicationWorker` is a daemon thread started in every gunicorn process
when at least one target is configured (not under `TESTING`). It runs
`process_due()` every `SYNDICATION_POLL_INTERVAL` seconds (default 10), and
loops again immediately while there is work.
`process_due()`:
1. Calls each client's `maintain()` (the Threads token refresh).
2. Selects up to 5 rows that are `pending`, due, and not claimed.
3. Claims each row with an atomic
`UPDATE ... SET claimed_until = now + 5 min WHERE state = 'pending' AND
(claimed_until IS NULL OR claimed_until < now)`. The other processes skip
it. Unlike the Webmention and WebSub workers, there is no file lock: the
row claim is the only coordination.
4. Reconciles the row (below), then records the result.
### Reconcile
```
┌──────────────┐
│ Data Model │
│ (Notes) │
└──────┬───────┘
│
┌──────▼───────┐
│ Templates │
│ + mf2 markup│
└──────┬───────┘
│
┌──────▼───────┐
│ HTML Output │
│ (Semantic) │
└──────────────┘
note published and row enabled?
no → remote copy exists? delete it → (None, None)
yes → copy exists and target can't edit? → keep it as is
copy exists → update (if it's gone remotely: create again)
no copy → create
```
### Markup Strategy
- **Progressive Enhancement**: Add classes without changing structure
- **CSS Independence**: Use mf2-specific classes, not styling classes
- **Validation First**: Test with parsers during development
Deleted notes are not found by `get_note()`, so they count as "not
published".
## Configuration Requirements
### Versions
### New Configuration Variables
```ini
# Author information for h-card
AUTHOR_NAME = "Site Author"
AUTHOR_URL = "https://example.com"
AUTHOR_PHOTO = "/static/avatar.jpg" # Optional
The row's `version` is read when the row is picked up. `_finish()` sets
`state = 'synced'` only if the version is unchanged. If the note was edited
while the send was in flight, the row stays `pending` and is reconciled
again with the new content. `_fail()` does the same.
# Feed settings
FEED_LIMIT = 50
FEED_FORMATS = "rss,atom,json" # Comma-separated
```
### Retries and idempotency
## Performance Considerations
- `SyndicationError(permanent=True)` fails the row immediately. This covers
HTTP 4xx other than 429, a missing target, images too large for Bluesky,
a Threads container in `ERROR`/`EXPIRED`, and Graph API auth/permission
errors (codes 10, 190, 200).
- Other errors retry after `min(30 s × 2^attempts, 6 h)`. After 8 attempts
the row becomes `failed`. The error is shown on the edit page with a
Retry button.
- `RemoteGone` (404, or Graph error 100/33) during an update means the copy
was deleted remotely, so a new one is created. During a delete it counts as
success.
- Duplicate posts after a lost response are prevented as follows:
- GoToSocial: an `Idempotency-Key: starpunk-<row id>-<version>` header.
- Bluesky and Threads: on a retry (`attempts > 0`), the last 25 posts are
searched for one containing the permalink (for Threads reposts, the
reposted URL). A match is adopted instead of posting again.
- Threads' publish step sometimes fails transiently ("Fatal"); it is
retried unless the error is an auth error.
### Caching Strategy
- Feed generation is read-heavy, write-light
- Consider caching generated feeds (5-minute TTL)
- Invalidate cache on note creation/update
## Composing posts
### Resource Usage
- RSS/ATOM: ~O(n) memory for n notes
- JSON Feed: Similar memory profile
- Microformats2: No additional server resources
`Post` carries the note, permalink, tags, the target's character limit,
media files, and for likes, reposts and bookmarks, the URL they point at and
its fetched title (from the reply-context cache).
## Security Considerations
### Text
### Content Sanitization
- HTML in feeds must be properly escaped
- CDATA wrapping for RSS/ATOM
- JSON string encoding for JSON Feed
- No script injection vectors
`compose_text()` builds: body, a blank line, the permalink, a blank line,
the hashtags. If that is too long, the body is cut at a word boundary with
"…"; the permalink always survives. Hashtags (`#` plus the tag's display
name without non-word characters) may take at most a third of the limit. A
bookmark's body starts with `🔖 <bookmarked URL>` (v2.9.0). A photo-only
note starts with the permalink.
### Rate Limiting
- Apply same limits as HTML endpoints
- Consider aggressive caching for feeds
- Monitor for feed polling abuse
| Target | Body format | Links | Hashtags |
|---|---|---|---|
| GoToSocial | The note's Markdown, sent with `content_type: text/markdown`; embedded images removed from the text (sent as attachments) | As written | In the text |
| Bluesky | Plain text from the rendered Markdown | Markdown link text becomes a clickable link facet; bare URLs and `#tags` get link/tag facets (UTF-8 byte offsets) | In the text, as tag facets |
| Threads | Plain text | Markdown links are written `text (url)`, up to 4 different URLs plus the permalink (Threads allows 5); the length counts non-ASCII characters as UTF-8 bytes | None in the text; the first usable tag becomes the post's `topic_tag` |
## Testing Architecture
### Link cards (ADR-070)
### Unit Tests
```
tests/
├── test_feed.py # Enhanced for ATOM
├── test_json_feed.py # New test module
└── test_microformats.py # Template parsing tests
```
- **Bluesky**: if the note has images, they are the embed. Otherwise, if
the note links somewhere, StarPunk builds an `app.bsky.embed.external`
card for the first link. `page_card()` fetches the page (at most 512 KB,
every redirect hop checked against private addresses, 10 s per request,
5 redirects) and reads the Open Graph, Twitter or HTML title, description
and image. The image (at most 5 MB) is shrunk under 1 MB and uploaded as
the thumbnail. If the page can't be fetched, the card has just the URL.
A note without links gets a card for its own permalink, built from the
note without fetching anything.
- **Threads**: no explicit `link_attachment` (Meta rejects one for a page
it hasn't crawled yet). Threads previews the first link in the text by
itself.
- **GoToSocial**: the server makes its own previews.
### Integration Tests
- Validate against external validators
- Test feed reader compatibility
- Verify IndieWeb tool parsing
### Media
## Backwards Compatibility
`_media_files()` collects the note's attached photos first, then images
embedded in the note text that are in this site's media library (some
Micropub clients put uploaded photos in the content). It stops at the
target's image limit. The `large` variant is used when one exists. Alt text
comes from the caption, or from the embedded image's alt.
### URL Structure
- `/feed.xml` remains RSS 2.0 (no breaking change)
- New endpoints are additive only
- Auto-discovery links updated in templates
| Target | Handling |
|---|---|
| GoToSocial | Uploaded via `POST /api/v2/media` with description; re-uploaded on each edit |
| Bluesky | `uploadBlob`; images over 1,000,000 bytes are re-encoded as JPEG at decreasing size and quality, and fail permanently if they still don't fit. Aspect ratio is sent |
| Threads | Meta fetches each image from its public `/media/` URL. Only JPEG and PNG up to 8 MB are used; others are left off. 1 image → `IMAGE` container, 2 or more → `CAROUSEL` of child containers. Alt text up to 1000 characters |
### Database
- No schema changes required
- All features use existing Note model
- No migration needed
Only notes of kind `note` carry media; likes, reposts and bookmarks don't.
## Future Extensibility
### Likes, reposts and bookmarks
### Potential Enhancements
1. Content negotiation on `/feed`
2. WebSub (PubSubHubbub) support
3. Custom feed filtering (by tag, date)
4. Feed pagination for large sites
| Kind | GoToSocial | Bluesky | Threads |
|---|---|---|---|
| Like of a post on that network | Native favourite (`favourite:<id>`) | Native `app.bsky.feed.like` | Not crossposted (the API can't like) |
| Like of anything else | Not crossposted | Not crossposted | Not crossposted |
| Repost without comment, of a post on that network | Native boost (`reblog:<id>`) | Native `app.bsky.feed.repost` | Not native: posts `🔁 title` + URL |
| Repost with comment, of a post on that network | Status: comment, `🔁 title`, URL | Quote post (`app.bsky.embed.record`) | Comment, `🔁 title`, URL |
| Repost of another page | Status: (comment,) `🔁 title`, URL | Post with an external card for the URL | (Comment,) `🔁 title`, URL |
| Bookmark | Ordinary status starting `🔖 <url>` | Ordinary post starting `🔖 <url>` | Ordinary post starting `🔖 <url>` |
### Format Support Matrix
| Format | v1.1.0 | v1.1.2 | v1.2.0 |
|--------|--------|--------|--------|
| RSS 2.0 | ✅ | ✅ | ✅ |
| ATOM | ❌ | ✅ | ✅ |
| JSON Feed | ❌ | ✅ | ✅ |
| Microformats2 | Partial | Partial | ✅ |
"On that network" is decided by the client. GoToSocial resolves the URL
through `/api/v2/search?resolve=true`. Bluesky matches
`https://bsky.app/profile/<actor>/post/<rkey>` and resolves it to a URI and
CID. Native likes and boosts have no URL of their own and nothing to edit.
Deleting the note undoes them (`unfavourite` / `unreblog`, or deleting the
like or repost record). A like that isn't crossposted is recorded as synced
with no remote copy.
## Decision Rationale
## u-syndication
### Why Multiple Formats?
1. **No Universal Standard**: Different ecosystems prefer different formats
2. **Low Maintenance**: Feed formats are stable, rarely change
3. **User Choice**: Let users pick their preferred format
4. **IndieWeb Philosophy**: Embrace plurality and interoperability
`templates/note.html` lists every row that has a `remote_url` as "Also on
<name>", using `<a class="u-syndication" rel="syndication">`. Micropub
`q=source` returns the same URLs as the `syndication` property. The
Webmention worker rejects a webmention whose source is one of the note's
own copies (e.g. backfed by Bridgy), so a copy is never shown as a response
to itself (v2.8.0).
### Why This Architecture?
1. **Simplicity**: Each component has single responsibility
2. **Testability**: Isolated components are easier to test
3. **Maintainability**: Changes to one format don't affect others
4. **Performance**: Can optimize each format independently
## Client sessions and tokens
## References
- [RSS 2.0 Specification](https://www.rssboard.org/rss-specification)
- [ATOM RFC 4287](https://tools.ietf.org/html/rfc4287)
- [JSON Feed Specification](https://www.jsonfeed.org/)
- [Microformats2](https://microformats.org/wiki/microformats2)
- **Bluesky**: `createSession` with the app password, then
`refreshSession` when the access JWT expires (a 401 or `ExpiredToken`
triggers one re-login and retry). The PDS endpoint is taken from the DID
document. Calls are serialized per client with a lock.
- **Threads**: long-lived tokens expire after 60 days. `maintain()` tries a
refresh (`refresh_access_token`, `th_refresh_token`) at most once a day.
The current token is kept in `DATA_PATH/threads_token.json` (mode 0600,
written atomically), together with a SHA-256 "seed" of the configured
token. A different `THREADS_ACCESS_TOKEN` in the config therefore
replaces the saved one. An exclusive `flock` on `threads_token.lock` makes
one gunicorn process refresh while the others pick up its result. A failed
refresh is retried an hour later (network error) or the next day (HTTP
error, e.g. a token less than a day old). The httpx logger is raised to
WARNING because Threads takes the token in the URL, and errors never echo
the URL.
- **GoToSocial**: a static bearer token.
## Known limits
- Bluesky and Threads copies don't follow edits (platform limitation).
Unticking and re-ticking a target makes a new copy.
- Link-card and Threads image fetches check every redirect hop against
private addresses but don't pin DNS, and use a per-request rather than an
overall time limit. Webmention and WebSub fetching use the stricter
`webmention_ssrf` fetcher.
- No per-target choice for Micropub updates: `mp-syndicate-to` is read only
on create.
- Likes of ordinary web pages, and all likes on Threads, stay on the site.