Description
docs/ARCHITECTURE.md describes a "Settlement Service" and a settlement data flow, but no such service exists in src/services/ (only transactionService.ts, accrualService.ts, eventIngestionService.ts, webhookDeliveryService.ts, and auditService.ts), and the accrual formula plus the outbound webhook delivery lifecycle are documented only as inline code comments. This leaves contributors without an authoritative description of how accrual, webhook delivery, and settlement actually behave today. This issue adds accurate, code-grounded documentation for these three areas.
Requirements and context
- Document the accrual formula exactly as implemented in
src/services/accrualService.ts: accrued = ratePerSecond * max(0, min(now, endTime) - lastSettledAt), the non-active short-circuit to 0, and the 9-decimal toFixed(9) precision (tied to the decimal(20, 9) columns in src/db/schema.ts).
- Document the outbound webhook delivery lifecycle using
src/services/webhookDeliveryService.ts and the webhook_deliveries table (pending/success/failed status, attempts, nextAttemptAt backoff, lastHttpStatus/lastError).
- Document the indexer ingestion semantics from
src/routes/webhooks/indexer.ts: 200 for first-time events, 202 for duplicates, and the 401/400/500 failure mapping.
- Reconcile
docs/ARCHITECTURE.md with reality: clearly mark the Settlement Service as planned/not-yet-implemented (or link to the settlement issue), so the diagram is not mistaken for current behavior.
- Non-functional: documentation only; no source changes; all file paths and symbol names cited must match the repo.
Acceptance criteria
Suggested execution
1. Fork the repo and create a branch — git checkout -b docs/settlement-accrual-webhook-semantics.
2. Implement changes — update docs/ARCHITECTURE.md and add/extend a docs page (e.g. docs/accrual-and-settlement.md) covering the three areas; cross-link from README.md.
3. Write/extend tests — this repo uses Jest + Supertest. No new tests are required for docs-only changes; verify nothing breaks by running the suite.
4. Test and commit —
npm run lint -- --max-warnings 0
npm run build
npm test
Example commit message
docs: document accrual, webhook delivery, and settlement semantics
Guidelines
No coverage change expected (documentation only). Ensure every code reference is verifiable against the current tree; keep diagrams consistent with implemented behavior. Timeframe: 96 hours.
Description
docs/ARCHITECTURE.mddescribes a "Settlement Service" and a settlement data flow, but no such service exists insrc/services/(onlytransactionService.ts,accrualService.ts,eventIngestionService.ts,webhookDeliveryService.ts, andauditService.ts), and the accrual formula plus the outbound webhook delivery lifecycle are documented only as inline code comments. This leaves contributors without an authoritative description of how accrual, webhook delivery, and settlement actually behave today. This issue adds accurate, code-grounded documentation for these three areas.Requirements and context
src/services/accrualService.ts:accrued = ratePerSecond * max(0, min(now, endTime) - lastSettledAt), the non-active short-circuit to0, and the 9-decimaltoFixed(9)precision (tied to thedecimal(20, 9)columns insrc/db/schema.ts).src/services/webhookDeliveryService.tsand thewebhook_deliveriestable (pending/success/failedstatus,attempts,nextAttemptAtbackoff,lastHttpStatus/lastError).src/routes/webhooks/indexer.ts:200for first-time events,202for duplicates, and the401/400/500failure mapping.docs/ARCHITECTURE.mdwith reality: clearly mark the Settlement Service as planned/not-yet-implemented (or link to the settlement issue), so the diagram is not mistaken for current behavior.Acceptance criteria
accrualService.ts.webhook_deliveries.docs/ARCHITECTURE.mdno longer implies a Settlement Service exists in code when it does not.npm run buildstill passes (no code touched).Suggested execution
1. Fork the repo and create a branch —
git checkout -b docs/settlement-accrual-webhook-semantics.2. Implement changes — update
docs/ARCHITECTURE.mdand add/extend a docs page (e.g.docs/accrual-and-settlement.md) covering the three areas; cross-link fromREADME.md.3. Write/extend tests — this repo uses Jest + Supertest. No new tests are required for docs-only changes; verify nothing breaks by running the suite.
4. Test and commit —
npm run lint -- --max-warnings 0 npm run build npm testExample commit message
Guidelines
No coverage change expected (documentation only). Ensure every code reference is verifiable against the current tree; keep diagrams consistent with implemented behavior. Timeframe: 96 hours.