Decidim, reimplemented on the AT Protocol: participatory democracy as records in people's own repos
README.md

dispersal #

Decidim, reimplemented on the AT Protocol.

Decidim is the participatory democracy platform that cities, cooperatives and associations use to run processes, assemblies, proposals, meetings and debates. It is a Rails application with everything in one database. dispersal keeps Decidim's model, vocabulary and URLs, and moves the data onto the protocol: what an organisation publishes is in the organisation's repo, what participants contribute is in their own, and the web site is one reader among others. An agent, a bot or somebody's own app can take part by writing records, without asking the site for an API key.

An existing Decidim installation can be imported through its public API. The import keeps Decidim's identifiers, so the installation's links keep working.

How Decidim maps onto records #

All lexicons are under it.mycopunk.dispersal.*, in lexicons/ (generated by npm run lexicons from scripts/lexicons.mjs).

Decidim Record Lives in
Organization organization (rkey self) the organisation's repo
Participatory process, its steps process the organisation's repo
Assembly assembly the organisation's repo
Process group processGroup the organisation's repo
Component (with its settings) component the organisation's repo
Taxonomy; older categories and scopes taxonomy the organisation's repo
Proposal proposal its author's repo (official ones: the organisation's)
Proposal answer and state proposalAnswer the organisation's repo
Meeting, agenda, closing report meeting its author's repo, usually the organisation's
Debate debate its author's repo
Page page the organisation's repo
Blog post post the organisation's repo
Comment, with alignment comment its author's repo
Endorsement (like) like the participant's repo
Follow follow the participant's repo
Comment vote commentVote the participant's repo
Moderation (hiding) moderation the organisation's repo
Proposal vote (support) vote the participant's PDS, in the organisation's ballot space
Meeting registration registration the participant's PDS, in the ballot space

Texts are translated fields, as in Decidim: arrays of {locale, text}. Rich text is HTML from the small set of elements Decidim's editor produces, and is sanitised on the way out.

Imported records carry an origin (installation, identifier, URL, reference, and the tallies that could not be imported one by one) and, where the author has no account on the protocol, an author with their name and profile on the original installation.

Not there yet: budgets, surveys, accountability, sortitions, initiatives, conferences, elections, verifications (authorisations), notifications, amendments, proposal versions, co-authors, attachments as blobs (imported files stay where they were and are linked), and a way for an imported author to claim what they wrote.

How it works #

 participants' repos ─┐                         ┌─ pages (Decidim's URLs)
 organisation's repo ─┼─▶ indexer ─▶ index ─────┼─ XRPC queries
 ballot space ────────┘   (rules)   (SQLite)    └─ admin
        ▲                                │
        └──────────── outbox ◀───────────┘  what the organisation writes
  • One way in. Every record goes through server/indexer.js, whether it came from a form on the site, from the firehose (Jetstream), from an it.mycopunk.dispersal.notifyOfUpdate call or from the importer. It decides what counts: the record must be valid, must point at something of this organisation, and the component it lands in must allow it. These are Decidim's rules, restated for a world where anybody can write a record in their own repo.
  • The organisation's outbox. What the organisation publishes is indexed at once and queued for its repo (server/org.js), which gets it in batches, within an hourly allowance and backing off when the PDS says so. An instance works before the organisation account has signed in, and an import of tens of thousands of records does not need to fit in a rate limit. Imported records are held back until an administrator releases them.
  • The ballot space. Decidim shows how many people supported a proposal, not who. Supports and meeting registrations therefore go in a space of the organisation's, of type it.mycopunk.dispersal.ballot, under the managedspace policy with the instance as managing app (server/ballots.js). Everybody may write there, only the organisation can read, and the instance counts by syncing the space as the organisation. The organisation can see who supported what, as a Decidim operator can in the database; nobody else can.
  • Moderation is local. The organisation cannot delete from somebody else's repo. Hiding is a moderation record that this instance honours.

For agents and integrations #

Every instance explains itself at /protocol. In short:

  • read with the XRPC queries on the instance (getOrganization, listSpaces, listProposals, listMeetings, listDebates, getThread) or straight from the repos;
  • take part by creating a record in your own repo whose component (or subject) is the at-uri of what you are contributing to;
  • POST /xrpc/it.mycopunk.dispersal.notifyOfUpdate {"uri": …} to have it indexed at once; the answer says whether it was accepted and, if not, why.

Running it #

npm install
npm test        # unit tests, then end to end against a local PLC + PDS
npm run dev     # the same local network with a seeded organisation, on http://localhost:3238

In npm run dev, sign in as commons.test (the organisation), alice.test or bob.test. Set DISPERSAL_DEV_IMPORT=https://meta.decidim.org (with DISPERSAL_DEV_SPACES and DISPERSAL_DEV_LIMIT to narrow it) to import a real installation into the playground.

Importing a Decidim installation #

From the admin page, or:

DISPERSAL_ORG=org.example.com npx dispersal import https://decidim.example.org --space processes/some-slug

The importer (importer/) reads the installation's public GraphQL API, so it needs no access to the server, and sees only what is public: no accounts, no individual votes (tallies are kept), no private spaces, no authors that the installation hides (blocked accounts come out as deleted participants), no component settings (imported components come in closed to new proposals, with comments and likes on). It adapts to the Decidim version by dropping the fields an installation does not have. Running it again updates what changed. It is deliberately slow, a few requests a second at most; a large installation takes hours.

Deploying #

./deploy.sh (an sm service; see service.json, compose.yaml, Dockerfile). The instance needs:

Variable
DISPERSAL_ORG the organisation account, DID or handle (required)
DISPERSAL_ORIGIN where it is served
DISPERSAL_DATA where the index is kept
DISPERSAL_ADMINS DIDs that can administer, besides the organisation account
DISPERSAL_PUBLISH_PER_HOUR how fast the outbox empties (default 1200)
DISPERSAL_JETSTREAM the Jetstream to listen to, or off

Then sign in on the site once as the organisation account. That binds it: the instance can publish to its repo and create the ballot space. The account's PDS has to support spaces for supports and registrations to work; participants on a PDS that does not can do everything else.

Licence #

AGPL-3.0-or-later, as Decidim.