AGENTS
- Use Node 18+; install deps with
npm ciin root,backend/,web/,admin/before CI-like runs. - Backend dev/prod:
cd backend && npm run devfor local API,npm run build && npm startfor production. - Backend tests:
cd backend && npm test; single test:npx vitest run src/<path>/<file>.test.ts -t "test name". - Web/admin (Vite React):
cd web|admin && npm run dev|build|test|lint|typecheckas needed. - Block reward bot:
cd block-reward-bot && npm start(runstsx index.ts). - Lint/typecheck/format backend:
cd backend && npm run lint && npm run typecheck && npm run format(CI mirrors this in.github/workflows/ci.yml). - Formatting: Prettier (
.prettierrc.json) with 100-char width, single quotes, semicolons, no trailing commas; run format before large diffs. - TypeScript style: prefer
strict-friendly code, avoidany, and give explicit return types for exported functions and shared utilities. - Imports: group as Node builtins, external libs, then internal modules; use relative paths within each package (avoid cross-package imports without a clear reason).
- Naming:
camelCasefor variables/functions,PascalCasefor types/classes,SCREAMING_SNAKE_CASEfor env-style constants and config keys. - Error handling: never swallow errors; centralize with Express middleware where possible, return sanitized messages, and log full details server-side only.
- HTTP/Express layout: keep middleware in
backend/src/middleware, routes inbackend/src/routes, and keep each route file cohesive and minimal. - Tests: colocate Vitest files as
*.test.tsundersrc; prefer HTTP-level tests via supertest plus focused unit tests for utilities and services. - When touching mining reward, withdrawal, or pool-like logic, always review and update related tests and architecture docs under
docs/. - For "pool" / "VIDDHANA pool" work, first read
contracts/pools/,contracts/rewards/,contracts/oracles/,contracts/risk/and relevantdocs/to understand current design and risks. - For significant pool changes, sketch a brief blueprint (overview, asset flow, reward model, oracle updates, risk/circuit breaker, upgrade path) before coding large refactors.
- Pool-related tests must at least cover deposit/withdraw happy paths, reward/APY calculation, emergency stop/pause, basic reentrancy attempts, and bad/stale oracle data using the repo's test framework.
- When editing Solidity/contract-like code (e.g., under
contracts/), keep changes small and audited-style, target Solidity 0.8.x, prefer OpenZeppelin over custom primitives, and document key invariants/assumptions in comments. - Security: treat all external input (HTTP, env, RPC, DB, oracle data) as untrusted; validate/parse minimally but explicitly, and respect existing auth, rate limiting, and circuit breaker mechanisms.
- Repo hygiene/tooling: avoid large refactors or deletions without explicit user approval, summarize diffs by area (backend/web/admin/contracts/infra), and update this file if Cursor or Copilot instruction files are added.