Build, test and extend
Set up a development copy, run the API, web app, extension and docs, run every check the CI runs, and learn the repository's conventions before you change code.
On this page
Requirements#
- Node 22 and Yarn 4 through Corepack. The Yarn version is pinned in the root
package.json. - PostgreSQL for the API (any recent version; CI uses 17).
- ffmpeg for video features and the frame tests (
apt install ffmpeg). - In a sandbox that blocks the default registry, set
COREPACK_NPM_REGISTRY=https://registry.npmjs.orgso Corepack can fetch Yarn.
corepack enable
yarn install
yarn build:libs # builds packages/schema and packages/renderRun it#
The API needs a database and three values:
export DATABASE_URL=postgres://user:[email protected]:5432/socialcrawl
export JWT_SECRET="$(openssl rand -base64 48)"
export ADMIN_PASSWORD_HASH="$(printf '%s' 'a password of 12+ chars' | yarn workspace @social-crawl/api hash-password)"
export DB_SYNCHRONIZE=true STORAGE_DIR=./storage PORT=4000
yarn dev:api # builds the libs, then nest start --watchThe web app, in another terminal:
API_URL=http://127.0.0.1:4000 yarn dev:web # http://localhost:3000The extension: yarn workspace @social-crawl/extension build creates apps/extension/dist. In Chrome open chrome://extensions, turn on Developer mode, Load unpacked, and choose dist. In development the API serves that folder as the download in Settings (EXTENSION_DIR, default ../extension/dist).
These docs:
yarn workspace @social-crawl/docs dev # builds the content, then next dev
yarn workspace @social-crawl/docs build # a static export in apps/docs/outThe checks (the same ones CI runs)#
yarn npm audit --all --recursive # fails on any advisory
yarn workspace @social-crawl/web lint
yarn workspace @social-crawl/api lint
yarn workspace @social-crawl/docs lint
yarn lint:libs # the packages and the extension
yarn workspace @social-crawl/web format:check
yarn workspace @social-crawl/schema typecheck
yarn workspace @social-crawl/render typecheck
yarn workspace @social-crawl/extension typecheck
yarn workspace @social-crawl/api typecheck
yarn workspace @social-crawl/schema test
yarn workspace @social-crawl/render test
yarn workspace @social-crawl/api test
yarn workspace @social-crawl/web test
yarn workspace @social-crawl/docs test
yarn workspace @social-crawl/docs check # the docs' own content checksRun the API tests with a real PostgreSQL, as CI does. Without MIGRATION_TEST_URL the real-database tests (the database copy and delete) are skipped, and a change to the tables passes locally and then fails in CI:
MIGRATION_TEST_URL=postgres://postgres:postgres@localhost:5432/postgres yarn workspace @social-crawl/api testUse any empty PostgreSQL 16 or newer. PostgreSQL refuses to run as root.
The extension's browser tests need Chromium:
CHROMIUM_PATH=<chromium binary> yarn workspace @social-crawl/extension testThe web app build writes the route types that tsc needs, so run yarn workspace @social-crawl/web build before npx tsc --noEmit there.
Conventions#
- TypeScript everywhere the tool accepts it. A JavaScript file needs a stated reason.
- Linting is ESLint 10 across the web app, the API, the docs, the packages and the extension. A rule is switched off on one line, with a reason:
// eslint-disable-next-line <rule> -- reason. Formatting is Prettier's job. - Packages: official, first-party packages only. Check a package's publisher, maintenance, licence and install scripts, then the audit, before adding it. In an existing project keep its package manager (Yarn here).
- No polyfills. Use what the target browsers support, or decide on purpose.
- No community UI kits. The web app's
components/uiare its own, on Radix primitives and Tailwind. - Icons: Tabler first (
@tabler/icons-react), another set only when Tabler has nothing good. - Nothing is saved that was not on the post. Frames of a video are made for a download and not stored. The one exception is a transcript, which can be deleted.
- Posts are data first.
post.jsonis the source of truth; pages are drawn from it.
Where to change things#
| You want to | Change |
|---|---|
| Support a new site | A reader in apps/extension/src (see Extension internals), a viewer in the web app, and a renderer in packages/render. |
| Read one site's article better | A site rule: no code (see Site rules). |
| Add a field to a post | packages/schema first, then the reader, the renderer and the viewer. |
| Add an API route | A controller in apps/api/src/<area>. A route with no @Scopes is web only. If the browser needs it, add it to the allowlist in apps/web/src/lib/proxy-allowlist.ts. Then run yarn workspace @social-crawl/docs routes. |
| Add a table | An entity in the area, added to apps/api/src/entities.ts (the database copy uses that list). There are no migrations. |
| Add a setting | In apps/api/src/config/env.ts (with a limit), in docker-compose.yml, in .env.example, and in Environment variables. |
| Change the look | The web app's colours and spacing are tokens in apps/web/src/app/globals.css, shared in spirit with these docs. |
| Add a platform adapter for pasted links | Implement PlatformAdapter (apps/api/src/adapters/platform-adapter.ts): parse(url) and fetchPost(ref). Bluesky is the example. |
Branches and pull requests#
Code lives on main, and you never push to it. Work on a branch and open a pull request. main is what Dokploy deploys, so CI must be green before a merge.