hackers.pub Hall

The Stacks (models)

ja· en· ko
If you're new hereThe ledger room that decides the shape and storage of data—posts, accounts, and the rest.

You can see how the whole world of a federated social network—posts, follows, blocks, votes, reports—fits into 54 ledgers. For anyone building their own federated app, these stacks are a floor-plan reference.

At the core is a small custom called runInTransaction(). If you're already inside a transaction, you ride along; if outside, it opens a new one. Every wing in the hall leans on this single custom.

Highlights

  • Visibility is built two ways, as a pgEnum and a TS union: public / unlisted / followers / direct / none
  • Each concept has a file and a test paired (post.ts/post.test.ts). And the tests are even split by scene of life—lifecycle, remote, draft
  • The relationship map in relations.ts is shared by one and the same sheet—both the graphql inquiry room (Pothos drizzle) and these stacks

A passage from the sutra

export const POST_VISIBILITIES = [
  "public",
  "unlisted",
  "followers",
  "direct",
  "none",
] as const;

export const postVisibilityEnum = pgEnum("post_visibility", POST_VISIBILITIES);
models/schema.ts L31-L39— The five levels of visibility, in the ledger's words

Floor plan

models/schema.ts
The 54-table ledger and its pgEnums
models/db.ts
The Database/Transaction types and runInTransaction
models/relations.ts
The relationship map among the ledgers
models/post.ts
The representative volume. Post creation/sync/remote ingestion

Neighboring rooms

Outside links