Skip to Content
AaviDocs

Run it yourself

Clone the repo, install, set the environment variable names, test, build, run the command-line tools and the live proof, and deploy your own copy.

You need Node 24 and npm. The command-line tools and the tests need no account and no key.

Install, build, test

git clone https://github.com/ramakrishnanhulk20/aavi.git
cd aavi
npm ci
npm run build
npm test

npm run build builds the engine first and the site second, so the site never builds against a stale classifier. The engine's tests refuse any real network call, so a test cannot quietly depend on a live city server. Over half of the test files are property tests written with fast-check.

The Kiro power has its own commands: npm run power:build and npm run power:test.

Run the site on your machine

  1. Run npm ci from the repository root, then npm run build. The site reads @aavi/sources through its built output.
  2. Copy .env.example from the repo root to apps/web/.env.local and fill in the four names the site reads. Next.js reads env files only from apps/web. The file stays out of git.
  3. From apps/web, run npm run dev. The site answers at http://localhost:3000, and the routes at /api/<route>.

Environment variables

.env.example in the repo root lists every name the code reads. This page lists names and where to get each. It holds no value.

NameWhat it isWhere it goesHow to get it
SOCRATA_APP_TOKENA free app token for a Socrata data portal. It is sent as the X-App-Token header to Socrata servers (New York State and Norfolk). Optional on the command line.Your terminal session for the tools. Production only, for the site.Sign in or sign up on a Socrata portal, for example health.data.ny.gov. Open Developer Settings in your profile and create an app token.
DATABASE_URLThe connection string of the read-only database role aavi_readerProduction only, for the siteCreate a Postgres database with any provider. Run the setup script below, which creates the role and writes the string to a file.
KV_REST_API_URLThe REST address of an Upstash Redis databaseProduction onlyIn the Upstash console, create a Redis database, open its page, and copy the https address from the REST tab.
KV_REST_API_TOKENThe REST token of the same databaseProduction onlyCopy the full token from the same REST tab, not the read-only one.
DATABASE_OWNER_URLThe owner connection string of your database, used once to create the rolesYour terminal only. Never the hosting project, never a file in the repo.Copy it from your database provider's console.
WRITER_URL, READER_URLThe two strings the setup script writes, used by the attack scriptYour terminal onlyMade by apps/web/db/setup.mjs.

The command-line tools read SOCRATA_APP_TOKEN from your terminal session. They do not read a .env file. A variable that holds a secret never gets a NEXT_PUBLIC_ prefix.

The Upstash database holds only the per-minute request counters. If it is unreachable, each server instance counts requests itself and keeps a limit.

Command-line tools

Every tool reads live from the city's own server. Where a source is optional, the default is Detroit.

CommandWhat it does
npm run lookup -- [SOURCE] "ADDRESS"One lookup. Prints the full answer or non-answer as JSON.
npm run census -- [SOURCE]The source's own count by class, checked against its plain row count.
npm run sample -- [SOURCE] COUNTReads random records and classifies each. COUNT is 1 to 100.
npm run crosscheck -- [SOURCE]Compares Aavi's class with the city's own whole-line class on every row. Rows milder than the city's class must be zero.
npm run gate -- SOURCEThe city gate. Checks a source's spec against its live server and lists every raw value with the class it maps to.
npm run fingerprint -- SOURCEPrints the hash of the field list a spec reads.
npm run accuracy -- SOURCE COUNT or -- --all COUNT [--write]The accuracy run. See how we check our work.
npm run proveAll ten sources, live. Looks up one public building in each, checks that Aavi's census total equals the city's own count, and ends with m3: pass or m3: fail.
npm run prove:live -- --base HTTPS_ORIGINThe live site. See below.

Use a public building for lookups, not a home.

Prove it on the live site

npm run prove:live -- --base https://aavi.vercel.app

Run npm ci and npm run build first. It ends with m7: pass and exit code 0, or m7: fail and exit code 1. The steps and the expected output are on the judges page. Wait a minute before running it again, because it uses one client's per-minute limits.

On a fresh deployment of your own, the cities step fails until the first census rows are in the store. That is expected.

Deploy your own

The full guide is docs/deploy.md. In short:

  1. Create a Vercel project from the repo with these settings:

    SettingValue
    Root Directoryapps/web
    Node.js Version24.x
    Install Commandnpm ci --prefix ../..
    Build Commandnpm run build --prefix ../..

    Turn on "Include source files outside of the Root Directory in the Build Step", because the site needs packages/sources.

  2. Add DATABASE_URL, KV_REST_API_URL, KV_REST_API_TOKEN and SOCRATA_APP_TOKEN, each for Production only. Leave Preview and Development unchecked.

  3. Set the Ignored Build Step in the project's Git settings so that only the production branch builds. This setting lives in Vercel, not in a file in the repo.

  4. Create the database roles. In your terminal, set DATABASE_OWNER_URL to the owner string. It must end with no query, or with exactly ?sslmode=verify-full. Then, from the repo root, run:

    node apps/web/db/setup.mjs READER_FILE WRITER_FILE

    Each file name is a new path outside the repo. The script prints created or exists, and writes the two connection strings into the files, readable by you only.

  5. Copy the reader string into DATABASE_URL in Vercel. The writer string never goes in the Vercel project. Only the Crew App's census push uses it. Delete both files when you are done.

  6. Set READER_URL and WRITER_URL in your terminal and run node apps/web/db/attack.mjs. It tries an update, a delete and a row dated in the future, and exits with code 1 if the database accepts any of them. Run it again after every schema change.

  7. After the first production build, run the proof command against your domain.

The Vercel project must never hold an owner credential, or a credential that a hosting integration created for the database, because those carry owner rights.