This document covers how to set up and develop Ratatoskr locally.
- Bun v1.0 or later
- An OIDC provider (e.g., Authentik) for authentication testing
-
Clone the repository:
git clone <repository-url> cd ratatoskr
-
Install dependencies:
bun install
-
Create a
.envfile (see Configuration below) -
Run database migrations:
bun run db:migrate
-
Start the development server:
bun run dev
Create a .env file in the project root:
# Server
PORT=4151
HOST=0.0.0.0
BASE_URL=http://localhost:4151
# OIDC - Uses PKCE (public client, no secret needed)
OIDC_ISSUER=https://auth.tionis.dev
OIDC_CLIENT_ID=juhMlePBJWwnVCxbnO5bFJJcaMIN0tVahhfqVj2Q
OIDC_REDIRECT_URI=http://localhost:4151/api/v1/auth/callback
# Storage
DATA_DIR=./data
# Optional: Comma-separated additional browser origins for CORS
# (BASE_URL origin is always allowed)
# CORS_ALLOWED_ORIGINS=http://localhost:5173,http://localhost:3000
# Optional: Override default quotas
# DEFAULT_MAX_DOCUMENTS=10000
# DEFAULT_MAX_DOCUMENT_SIZE=10485760
# DEFAULT_MAX_TOTAL_STORAGE=1073741824| Command | Description |
|---|---|
bun run dev |
Start dev server with hot reload |
bun run start |
Start production server |
bun test |
Run tests |
bun test --watch |
Run tests in watch mode |
bun run lint |
Check linting and formatting |
bun run lint:fix |
Auto-fix linting and formatting issues |
bun run typecheck |
Run TypeScript type checking |
bun run db:migrate |
Run database migrations |
src/
├── index.ts # Entry point
├── config.ts # Environment configuration
├── server.ts # Fastify server setup
├── auth/ # Authentication (OIDC, tokens)
├── api/ # REST API routes
├── sync/ # WebSocket sync handler
├── storage/ # Metadata DB + blob file storage
└── lib/ # Shared utilities (ACL, rate limiting, etc.)
Tests use Bun's built-in test runner:
# Run all tests
bun test
# Run specific test file
bun test test/acl.test.ts
# Run in watch mode
bun test --watchThis project uses Biome for linting and formatting:
# Check for issues
bun run lint
# Auto-fix issues
bun run lint:fix
# Format only
bun run formatSQLite is used for metadata and sync storage:
{DATA_DIR}/ratatoskr.dbfor metadata{DATA_DIR}/automerge.dbfor Automerge document state
Migrations run automatically on startup. To run them manually:
bun run db:migrateSee DESIGN.md for the full database schema.
curl http://localhost:4151/healthcurl -X POST http://localhost:4151/api/v1/auth/api-tokens \
-H "Authorization: Bearer <session-token>" \
-H "Content-Type: application/json" \
-d '{"name": "dev-token"}'curl http://localhost:4151/api/v1/documents \
-H "Authorization: Bearer <token>"Set the DEBUG environment variable:
DEBUG=* bun run devThe SQLite database can be inspected with any SQLite client:
sqlite3 ./data/ratatoskr.db