Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Backend

REST API for the Raven scholarly publication platform. Handles publications, versioning, contributors, organizations, comments, notifications, and authentication.

Stack: Node.js 24 · TypeScript · Hono · MySQL (Drizzle ORM) · S3


Getting started

pnpm install

Copy and fill in raven.toml (see Configuration):

pnpm dev          # dev server with watch (port 7001)
pnpm build        # compile to dist/
pnpm start        # run compiled output

Database

pnpm db:migrate   # apply pending migrations
pnpm db:generate  # generate migrations from schema changes
pnpm db:push      # push schema directly (dev only)

db:migrate skips migrations unless MIGRATION_DATABASE_URI is set.


Configuration

The server reads raven.toml (or a path set via RAVEN_CONFIG). Environment variables override TOML values when set.

KeyDefaultDescription
DATABASE_URI—MySQL connection string (required)
MIGRATION_DATABASE_URI—MySQL connection string for migrations. If unset, MySQL migrations are skipped
PG_DATABASE_URI—Postgres connection string for the job queue (required). MIGRATION_PG_DATABASE_URI defaults to it
BASE_URL_WEB—Frontend origin (used in emails, CORS)
BASE_URL_ADMIN—Admin UI origin
BASE_URL_API—API origin
SERVER_HOST0.0.0.0Bind address
SERVER_PORT7001Listen port
ENVIRONMENT—Set to production in production. Otherwise notification emails are only logged and auth rate limiting is off
JWT_SECRET_KEYdev-secret-key-change-in-productionSigns notification unsubscribe links. Must be set in production
BETTER_AUTH_SECRETCHANGE_MEBetterAuth secret. Must be set in production
AWS_*—S3 credentials, bucket, and endpoints (see raven.example.toml for a local S3-compatible service like Garage)
IMG_DIRimgs/Local folder for user and organization avatars. Use a persistent volume
MAILGUN_API_KEY—Outbound email
MAILGUN_API_URLThe Stacks’ Mailgun domainMailgun messages endpoint, like https://api.mailgun.net/v3/<your-domain>/messages
DATACITE_*—DOI registration credentials
DATACITE_PREFIX—DOI prefix for all minted DOIs. DOIs are only minted for organizations with DOI minting enabled.
DATACITE_PUBLISHERThe StacksPublisher name in DOI metadata. When it’s The Stacks, Astera Institute is also added as the hosting institution, so change it for other deployments.
ORCID_*—ORCID OAuth
GOOGLE_*—Google OAuth
PUBLICATION_CREATOR_ORGSArcadia Science, RadialComma-separated names of the organizations whose members can create publications. Site admins always can. Change it for other deployments
REQUIRE_EMAIL_VERIFICATIONtrueEmail/password accounts must verify their email to sign in, so MAILGUN_API_KEY must be set. Google and ORCID sign-in are unaffected
Astera Specific Below--
LINEAR_*-Our contact-us form uses the data to create a Linear task, which requires these keys
PDF_QUEUE_URL—SQS queue that gets a message when a non-MyST version is published. Nothing in the open-source repos reads it, so leave it unset

API routes

All routes are prefixed with /api.

PrefixPurpose
/authLogin, signup, token refresh, ORCID/Google SSO
/usersUser profiles, search, avatar upload
/publicationsPublications and versioned content
/commentsThreaded comments with text anchors
/orgsOrganization management
/filesServe files from IMG_DIR (local filesystem)
/notificationsIn-app and email notifications
/sitemapXML sitemap
/healthHealth check
Astera Specific Below-
/contact-us[Astera specific] Accepts form data that is submitted to linear, contingent on the above variables

Project structure

src/
├── index.ts          # Entry point — starts the server
├── app.ts            # Hono app, middleware, route wiring
├── config.ts         # Config loading from raven.toml
├── db/
│   ├── index.ts      # DB connection
│   └── schema.ts     # Drizzle schema
├── lib/
│   ├── auth.ts       # BetterAuth setup
│   ├── mail.ts       # Mailgun email
│   ├── media.ts      # S3 image upload
│   └── references.ts # Reference extraction
├── api-v0/           # v0 routes, also served under /api
└── api-v1/           # v1 routes

For how MyST publications are stored and built, see MyST publications.


Testing

pnpm test         # run unit tests (vitest)
pnpm typecheck    # type-check without emitting
DATACITE_NAME="[user]" DATACITE_PASSWORD="[pass]" DATACITE_PREFIX="[prefix]" pnpm exec vitest run datacite-live.test  # Run datacite-live tests

Integration tests use tests/raven.test.toml and a real database. See the integration tests README for the full test environment setup.


Authentication