Skip to content

Latest commit

 

History

History
195 lines (129 loc) · 7.23 KB

CONTRIBUTING.md

File metadata and controls

195 lines (129 loc) · 7.23 KB

Contributing to Compar:IA

Thanks for your interest in contributing! This guide covers everything you need to get the project running locally and start contributing.

Getting started

Prerequisites

  • Python 3.13+
  • Node.js + yarn
  • uv (installed automatically by make install-backend if missing)

Install dependencies

make install

Running locally (without Docker)

Local dev uses env vars set manually. Postgres and Redis are started via Docker.

Copy the example env file and fill in the required values:

cp .env.example .env

Set OPENROUTER_API_KEY for real LLM calls, or uncomment MOCK_RESPONSE=true to skip them. Set it before your first make db-migrate: migrations copy it onto the OpenRouter endpoint row, and from then on the key belongs to that endpoint and is edited at /admin/llms/endpoints. The prompt checks still read it from the environment when no key is set at /admin/prompt-checks. For the DA instance, change COMPARIA_INSTANCE_NAME=da and point COMPARIA_DB_URI to the DA database.

Start Postgres and Redis, then run:

make db
make redis
source .env
make dev      # backend on :8008, frontend on :5173

For the DA instance, copy .env.example and set COMPARIA_INSTANCE_NAME=da and COMPARIA_DB_URI to the DA database before sourcing.

Local SSO with Keycloak (development only)

make keycloak starts a throwaway Keycloak in Docker (devops/instances/keycloak/), creates a comparia client and a test user, and prints the values to enter at /admin/authentification. make keycloak-down stops it. It runs in Keycloak's start-dev mode with default admin credentials and plain http on localhost: use it for local development only, never on a deployed instance. Set COMPARIA_API_URL="http://localhost:8008" in your .env so the callback reaches the backend directly (see .env.example).


Running with Docker (per instance)

Each instance has its own Docker Compose file. Secrets are loaded from KeePass automatically. A shared Postgres and Redis are started automatically.

make up-fr      # Start FR instance (backend + frontend + postgres + redis)
make down-fr    # Stop FR instance
make logs-fr    # Follow FR instance logs

make up-da      # Start DA instance
make down-da    # Stop DA instance
make logs-da    # Follow DA instance logs

These commands load secrets from a KeePass database (~/comparia_dev.kdbx by default). You can use the team's shared database or create your own, with one entry per variable, in groups instances/fr or instances/da, with username = variable name and password = value. See devops/instances/fr/.env.fr.example and devops/instances/da/.env.da.example for the full variable list.

Override the database path with:

KEEPASS_DB=/path/to/other.kdbx make up-fr

To start only the shared infrastructure:

make db         # Start shared Postgres
make redis      # Start shared Redis

Database

Default local URI (set in .env.example):

  • FR: postgresql://comparia:comparia@localhost:5432/comparia
make db                # Start Postgres via Docker (creates the default comparia database)
make db-reset-data     # Wipe Postgres volumes and restart fresh

Schema is managed with Alembic. Migration scripts live in utils/database/alembic/versions/. COMPARIA_DB_URI must be exported before running any migration command.

First-time setup on a fresh database:

make db
source .env
make db-migrate        # applies all migrations, creates tables

After modifying a SQLModel in utils/database/models/:

make db-migrate-generate MSG="describe your change"
make db-migrate
make db-migrate-status   # show current migration revision

Working on a copy of another instance's database (a production dump, for example) needs that instance's COMPARIA_ENCRYPTION_KEY in your .env. Without it, debug mode falls back to a fixed development key that opens none of the copied secrets: every endpoint's models are disabled, and the backend logs one error per row at startup.


Models

Models live in the database, not in a file. Add them at /admin/llms (see the admin panel guide), or import a JSON file:

./comparia-cli llms import path/to/llms-data.json
./comparia-cli llms export      # writes the current catalogue to data/llms-data.json

The CLI

./comparia-cli is the way in to everything that is not an HTTP request. Every command takes --help.

./comparia-cli generate rankings     # recompute the leaderboard
./comparia-cli generate datasets     # build and publish the datasets
./comparia-cli db --help             # migrations, archiving, admin seeding
./comparia-cli maintenance on        # put the instance behind a maintenance page
./comparia-cli llms --help           # import and export the model catalogue
./comparia-cli internal all          # regenerate frontend types and i18n schemas

It needs COMPARIA_DB_URI, so source .env first.


Datasets

Prerequisites: COMPARIA_DB_URI configured, and at least one enabled destination in the admin panel. Add --dry-run to build the datasets locally and send them nowhere.

make dataset-export           # Send the datasets to the configured destinations
make dataset-export-dry-run   # Build them locally and send them nowhere

Testing

# Frontend unit tests
cd frontend && npx vitest --run

# Frontend E2E tests (requires build first)
cd frontend && yarn run build && npx playwright test

# Lint & type check
cd frontend && yarn run lint
cd frontend && yarn run check

Translating the platform

The frontend uses @inlang/paraglide-js for i18n. Currently supported locales: en (default), da, fr, it, lt, nb-NO, sv.

Translation files live in frontend/locales/messages/. There are more files there than there are supported locales, because a language only counts once it is listed in SupportedLocale in utils/i18n.py. ./comparia-cli internal i18n copies that list into frontend/comparia.inlang/settings.json.

To add one: copy en.json, translate it, add the code to SupportedLocale, run ./comparia-cli internal i18n, then enable it for your instance at /admin/locales.


Architecture

  • frontend/: SvelteKit frontend (Vite, TailwindCSS, French Design System). Runs on port 5173.
  • backend/main.py: FastAPI entry point. Runs on port 8008.
  • backend/arena/: Core arena logic (streaming, voting, rate limiting, persistence).
  • devops/instances/: Per-instance Docker Compose files and env examples (fr, da).
  • devops/instances/postgres/: Shared Postgres compose and schema init.
  • devops/instances/redis/: Shared Redis compose.
  • devops/keepassxc/: KeePass env loader script.
  • utils/: Database models and migrations, the model catalogue, dataset export, ranking.
  • internal/: Code generation for frontend types and i18n schemas.
  • docs/: Self-hosting and the admin panel.

Almost all runtime configuration lives in the admin panel rather than in code or .env: models, languages, branding, legal pages, dataset destinations.