Files
Copilot 14014cb784 Production hardening: Remove deprecations, optimize chain queries, enforce explicit configuration (#134)
* Initial plan

* Fix onLimitReached deprecation in rate-limit middleware

- Replace deprecated onLimitReached callback with inline logging in handler
- Update tests to verify logging happens in the rate limit handler
- Remove onLimitReached from exports as it's no longer a separate function

Co-authored-by: onnwee <211922112+onnwee@users.noreply.github.com>

* Fix fromBlock: 0 in event queries for better performance

- Replace fromBlock: 0 with smart default (last 1M blocks)
- Add REGISTRY_START_BLOCK env var for configurable starting block
- Update make-proof.ts, verification-jobs.routes.ts, and verification-queue.service.ts
- Document new env variable in .env.example

Co-authored-by: onnwee <211922112+onnwee@users.noreply.github.com>

* Remove hardcoded testnet RPC fallback for production safety

- Replace testnet fallbacks with proper error handling when RPC_URL is not configured
- Update registry.service.ts, blockchain.service.ts to throw errors if RPC_URL missing
- Update CLI scripts (verify.ts, register.ts, make-proof.ts) to fail fast without RPC_URL
- Update API routes to return 503 error when RPC_URL is not configured
- Update .env.example to emphasize RPC_URL is required

Co-authored-by: onnwee <211922112+onnwee@users.noreply.github.com>

* Add documentation for dual Prisma generators and pin Redis version

- Add comprehensive comments in schema.prisma explaining dual generator setup
- Document why both generators are needed (API vs Next.js web app)
- Pin Redis version to 7.2-alpine in all docker-compose files for reproducibility
- Update docker-compose.yml, docker-compose.production.yml, and docker-compose.staging.yml

Co-authored-by: onnwee <211922112+onnwee@users.noreply.github.com>

* Address code review feedback - add validation for REGISTRY_START_BLOCK

- Add proper validation for parseInt to handle NaN cases
- Ensure REGISTRY_START_BLOCK is validated before use
- Add comment explaining intentional empty catch block
- Prevents invalid block numbers from breaking event queries

Co-authored-by: onnwee <211922112+onnwee@users.noreply.github.com>

* Refactor block range validation into shared utility function

- Create block-range.util.ts with getStartBlock helper
- Extract duplicated validation logic from make-proof.ts, verification-jobs.routes.ts, and verification-queue.service.ts
- Improves code maintainability and ensures consistent validation
- Add comprehensive JSDoc documentation

Co-authored-by: onnwee <211922112+onnwee@users.noreply.github.com>

* Add comprehensive test coverage for block-range utility

- Create test/utils/block-range.util.test.ts following existing test patterns
- Test valid REGISTRY_START_BLOCK values (positive, zero, large numbers)
- Test invalid inputs (NaN, negative, empty string, whitespace)
- Test default fallback behavior (current block - 1M)
- Test edge cases (low block numbers, decimals, provider errors)
- 15 test cases covering all code paths and validation logic

Co-authored-by: PatrickFanella <61631520+PatrickFanella@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: onnwee <211922112+onnwee@users.noreply.github.com>
Co-authored-by: PatrickFanella <61631520+PatrickFanella@users.noreply.github.com>
2026-02-16 19:25:50 -06:00
..

Prisma Schema - Single Source of Truth

⚠️ IMPORTANT: This is the ONLY Prisma schema file in the repository.

Schema Location

  • Single source: prisma/schema.prisma (this directory)
  • Do NOT duplicate: Never create web/prisma/schema.prisma or any other schema copies

How It Works

The single schema.prisma file generates two Prisma Clients:

  1. API/Scripts Client (root project)

    • Generator: client
    • Output: ./node_modules/@prisma/client
    • Used by: Express API, CLI scripts
  2. Web App Client (Next.js)

    • Generator: client-web
    • Output: ../web/node_modules/.prisma/client (relative to schema location)
    • Used by: Next.js web application

Note: The output path is relative to the schema file location (prisma/schema.prisma). This is a standard Prisma pattern for monorepos and ensures both clients are generated correctly regardless of which directory you run commands from.

Commands

Generate Both Clients

# From root directory
npm run db:generate

# Or directly
prisma generate

Generate Only Web Client

# From web directory
npm run prisma:generate

# Or directly
prisma generate --schema ../prisma/schema.prisma --generator client-web

Migrations

# From root directory
npm run db:migrate

# Or directly
prisma migrate dev --name <migration_name>

Why Single Schema?

  • No Drift: Schema changes are automatically reflected everywhere
  • No Duplication: One file to maintain and version
  • Safer Migrations: Single migration history prevents conflicts
  • Better DX: Update once, generate twice

Safeguards

If you accidentally create a duplicate schema:

  1. Delete the duplicate immediately
  2. Run npm run db:generate from root to regenerate clients
  3. Verify both clients work with your imports