An open-sourced backend service for Resell.
- Runtime: Node 20, Express (
routing-controllers+ TypeORM 0.2) - Database: Neon PostgreSQL 18 (pooled URL for the app, direct URL for migrations)
- Hosting: Vercel (Fluid Express). Docker Swarm / DigitalOcean are retired.
Semantic similarity (similar posts, request matching, search vectors) uses OpenAI embeddings (text-embedding-3-small) stored as float[], with exact cosine KNN in TypeScript. Set OPENAI_API_KEY in your .env. Without it, embeddings stay null and those features degrade gracefully. No pgvector extension is required.
-
Install Node 20 (
nvm install 20 && nvm use 20). -
From the repo root:
npm install -
Configure Neon for your editor (once per machine):
npx neon@latest init
Select Cursor, VS Code, and Claude CLI (Space to toggle). For Zed:
npx add-mcp https://mcp.neon.tech/mcp -a zed -g
-
Link env vars to the Neon project (writes
DATABASE_URL/DATABASE_URL_UNPOOLEDinto.env):npx neon@latest env pull
Or copy
.env_templateto.envand fill values manually. -
For authenticated local testing, follow Local testing with Firebase emulators. For deployments, configure
FIREBASE_SERVICE_ACCOUNT_JSON(preferred on Vercel) orFIREBASE_SERVICE_ACCOUNT_PATH. -
Apply schema:
npm run db:migrate
Neon branches used by this project:
| Neon branch | Use |
|---|---|
production |
Vercel Production |
staging |
Vercel Preview / main deploys |
dev |
Local development (optional personal branches later) |
Project context is stored in .neon (safe to commit; no secrets).
The backend verifies Firebase ID tokens and looks up the signed-in user by Firebase UID. The Auth emulator issues tokens for local test accounts. The Firestore emulator stores the availability document created during Resell registration. Both emulators and the local API listen on loopback.
-
Install the Firebase CLI and Java 21 or newer. Check with
firebase --versionandjava -version. The emulator configuration in this repo uses the demo projectdemo-resell-localand works without a Firebase login or service-account key. Firebase emulator setup -
Follow the Node and database setup above. Use a development database with the Resell schema applied. Set
DATABASE_URLandDATABASE_URL_UNPOOLEDin.envto the development database. If the database still needs the historicalAuthorizationRefactormigration, use an already-migrated development branch as your starting point. That migration has its own Firebase requirements. -
Add
EMAIL_WHITELIST=resell-test@example.comto.env. If the variable already has entries, append the test address to the comma-separated list. LeaveIS_PRODunset or set it tofalse. -
Start both processes using the commands below (
npm run dev:emulatorsandnpm run dev:local). In the Emulator Suite UI, add an Authentication user with the emailresell-test@example.comand a password used only for local testing. -
Sign in using the command below and authorize in Swagger. Run POST /user/create once to create the Resell profile in the development database. Use the email you signed in with and choose unique profile identifiers if you share the database. This is a sample request body.
{ "username": "resell-local-test", "netid": "resell-local-test", "givenName": "Local", "familyName": "Tester", "photoUrl": "", "venmoHandle": "", "email": "resell-test@example.com", "googleId": "resell-test@example.com", "bio": "", "fcmToken": "local-test-placeholder" }
-
From the repo root, run
npm run dev:emulatorsin one terminal. Wait for the Auth, Firestore, and Emulator UI addresses to appear. -
In another terminal, run
npm run dev:local. Check the API and database at localhost:3000/health. -
Sign in to the Auth emulator. Run the below command in another terminal, replacing
YOUR_TEST_PASSWORDwith your local test password and copyidTokenfrom the JSON response. Run this again when the token expires. Firebase Auth REST APIcurl --fail-with-body -sS \ 'http://127.0.0.1:9099/identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=fake-api-key' \ -H 'Content-Type: application/json' \ --data '{"email":"resell-test@example.com","password":"YOUR_TEST_PASSWORD","returnSecureToken":true}'
-
In Swagger, click Authorize and paste the ID token itself. Try GET /post for an authenticated request as a regular user. For curl, use the
Authorization: Bearer <idToken>header. -
Stop both processes with Ctrl+C. The emulator command saves Auth users and Firestore documents in the ignored
.firebase/localdirectory on clean shutdown and imports them on the next run. Keeping that state preserves the UID linked to your Resell profile.
If the API says User not found, register the signed-in account through POST /user/create. If you reset emulator data, recreating a test account can assign it a new UID. Use a new test email and unique profile identifiers, or start with a fresh development database.
The legacy GET /api/authToken/ and POST /api/authToken/create/ routes have been removed. The backend rejects emulator settings on Vercel and outside local development. Keep FIREBASE_AUTH_EMULATOR_HOST and FIRESTORE_EMULATOR_HOST out of Production and Preview settings. Firebase Auth Emulator token behavior
Set DATABASE_URL and OPENAI_API_KEY in .env. The command targets that
database (shell variables take precedence), prints its host/name without credentials,
and includes archived and sold posts that have no embedding.
npm run embeddings:backfill -- --dry-run
npm run embeddings:backfill -- --limit 5
npm run embeddings:backfillThe dry run only counts missing embeddings; it makes no OpenAI requests or writes.
The backfill sends each post's title and description to the existing OpenAI embedding
service and saves its 512-dimensional vector in Post.embedding. It reads 25 posts
at a time, processes requests sequentially, and retries failed generation up to three
times. Successful writes are saved immediately, so rerunning skips completed posts.
Failed posts remain missing and produce a nonzero exit status. Concurrently changed
posts are skipped to avoid saving stale embeddings. Similar-item caches for updated
posts are cleared and populated lazily by similar-item requests. Existing populated
embeddings are never overwritten. API usage is billed to the configured key.
npm run db:migrateCI runs migrations via .github/workflows/migrate-neon.yml using GitHub secrets:
DATABASE_URL_UNPOOLED_PRODUCTIONDATABASE_URL_UNPOOLED_STAGINGDATABASE_URL_UNPOOLED_DEV
Push to release migrates production; push to main migrates staging. App deploy is handled by Vercel Git integration (not Docker).
- Import the GitHub repo in Vercel.
- Set env vars for Production / Preview to match Neon branch URLs, plus Firebase JSON,
OPENAI_API_KEY, upload settings,IS_PROD, andCRON_SECRET. - Entry is
src/app.ts(default export for Fluid Express;app.listenonly when not on Vercel). - Cron:
vercel.jsonhitsGET /api/cron/transaction-confirmationswithAuthorization: Bearer ${CRON_SECRET}. The transaction confirmation job body is still disabled until product re-enables it.
npm run db:seedSeeding is skipped when IS_PROD=true.
- Local Homebrew / Docker Postgres install (use Neon
devinstead) - DigitalOcean dump/import scripts (one-time migration only if needed)
Dockerfile/docker-compose.ymland the disabled Swarm workflows under.github/workflows/deploy-*.yml