···11+# atBB Monorepo
22+33+**atBB** is a decentralized BB-style forum built on the AT Protocol. Users own their posts on their own PDS; the forum's AppView indexes and serves them. Lexicon namespace: `space.atbb.*` (domain `atbb.space` is owned). License: AGPL-3.0.
44+55+The master project plan with MVP phases and progress tracking lives at `docs/atproto-forum-plan.md`.
66+77+## Packages
88+99+| Package | Description | Port |
1010+|---------|-------------|------|
1111+| `@atbb/lexicon` | AT Proto lexicon definitions (YAML) + generated TypeScript types | — |
1212+| `@atbb/appview` | Hono JSON API server — indexes forum data, serves API | 3000 |
1313+| `@atbb/web` | Hono JSX + HTMX server-rendered web UI — calls appview API | 3001 |
1414+| `@atbb/spike` | PDS read/write test script for validating AT Proto operations | — |
1515+1616+**Dependency chain:** `@atbb/lexicon` builds first (generates types), then `@atbb/appview` and `@atbb/web` build in parallel. Turbo handles this via `^build`.
1717+1818+## Development
1919+2020+### Setup
2121+2222+```sh
2323+devenv shell # enter Nix dev shell (Node.js, pnpm, turbo)
2424+pnpm install # install all workspace dependencies
2525+cp .env.example .env # configure environment variables
2626+```
2727+2828+### Commands
2929+3030+```sh
3131+pnpm build # build all packages (lexicon → appview + web)
3232+pnpm dev # start all dev servers with hot reload
3333+pnpm clean # remove all dist/ directories
3434+devenv up # start appview + web servers via process manager
3535+pnpm --filter @atbb/appview dev # run a single package
3636+pnpm --filter @atbb/spike spike # run the PDS spike script
3737+```
3838+3939+### Environment Variables
4040+4141+See `.env.example`. Key variables:
4242+4343+- `PORT` — server port (appview: 3000, web: 3001)
4444+- `FORUM_DID` — the forum's AT Proto DID
4545+- `PDS_URL` — URL of the forum's PDS
4646+- `APPVIEW_URL` — URL the web package uses to reach the appview API
4747+- `FORUM_HANDLE`, `FORUM_PASSWORD` — forum service account credentials (for spike/writes)
4848+4949+## Lexicon Conventions
5050+5151+- **Source of truth is YAML** in `packages/lexicon/lexicons/`. Never edit generated JSON or TypeScript.
5252+- **Build pipeline:** YAML → JSON (`scripts/build.ts`) → TypeScript (`@atproto/lex-cli gen-api`).
5353+- **Adding a new lexicon:** Create a `.yaml` file under `lexicons/space/atbb/`, run `pnpm --filter @atbb/lexicon build`.
5454+- **Record keys:** Use `key: tid` for collections (multiple records per repo). Use `key: literal:self` for singletons.
5555+- **References:** Use `com.atproto.repo.strongRef` wrapped in named defs (e.g., `forumRef`, `subjectRef`).
5656+- **Extensible fields:** Use `knownValues` (not `enum`) for strings that may grow (permissions, reaction types, mod actions).
5757+- **Record ownership:**
5858+ - Forum DID owns: `forum.forum`, `forum.category`, `forum.role`, `modAction`
5959+ - User DID owns: `post`, `membership`, `reaction`
6060+6161+## AT Protocol Conventions
6262+6363+- **Unified post model:** There is no separate "topic" type. A `space.atbb.post` without a `reply` ref is a topic starter; one with a `reply` ref is a reply.
6464+- **Reply chains:** `replyRef` has both `root` (thread starter) and `parent` (direct parent) — same pattern as `app.bsky.feed.post`.
6565+- **MVP trust model:** The AppView holds the Forum DID's signing keys directly and writes forum-level records on behalf of admins/mods after verifying their role. This will be replaced by AT Protocol privilege delegation post-MVP.
6666+6767+## TypeScript / Hono Gotchas
6868+6969+- **`@types/node` is required** as a devDependency in every package that uses `process.env` or other Node APIs. `tsx` doesn't need it at runtime, but `tsc` builds will fail without it.
7070+- **Hono JSX `children`:** Use `PropsWithChildren<T>` from `hono/jsx` for components that accept children. Unlike React, Hono's `FC<T>` does not include `children` implicitly.
7171+- **HTMX attributes in JSX:** The `typed-htmx` package provides types for `hx-*` attributes. See `packages/web/src/global.d.ts` for the augmentation.
7272+- **Glob expansion in npm scripts:** `@atproto/lex-cli` needs file paths, not globs. Use `bash -c 'shopt -s globstar && ...'` to expand `**/*.json` in npm scripts.
7373+7474+## Git Conventions
7575+7676+- Do not include `Co-Authored-By` lines in commit messages.
7777+- `prior-art/` contains git submodules (Rust AppView, original lexicons, delegation spec) — reference material only, not used at build time.
7878+- Worktrees with submodules need `submodule deinit --all -f` then `worktree remove --force` to clean up.