Priority: High · Area: Persistence / architecture · Est. effort: 12–16 h
📌 Problem
package.json lists exactly three runtime dependencies:
compression, cors, express
There is no database driver, no ORM, no migration tool. Every repository under src/repositories/ — anchorRepository.ts, liquidityRepository.ts, settlementRepository.ts — is backed by inMemoryRepository.ts, and settlementRepository.ts:13 keeps its secondary index as private readonly anchorIndex: Map<string, Set<number>> = new Map().
Consequences:
- Every restart wipes all state. A deploy, crash, or scale event destroys the settlement history, the registered anchors and all liquidity records.
- Horizontal scaling is impossible. Two replicas hold two disjoint datasets; which one answers a request decides what the client sees.
- Unbounded growth. Nothing evicts, so the process grows until it is restarted — which is also the only thing that clears it.
Settlements are financial records. A service that forgets them on restart cannot be operated.
🎯 Design decision required
Post your proposed schema and approach in a comment on this issue before writing code, and wait for maintainer agreement. This is too large to land unsolicited. State and defend:
- Store choice. Postgres is the conventional answer for relational financial records; argue it against the alternatives rather than assuming it.
- Migration tooling and how migrations run in CI, in development, and on deploy.
- Interface preservation. The repository classes have method signatures that
src/services/*.ts depend on. Keeping them stable means no service code changes — confirm that is achievable, and list any signature you must change.
- Sequencing. All three repositories in one PR, or one at a time behind the existing interfaces? Argue which is reviewable.
- Testing without a live database. The suite currently runs with no external dependency. How do you preserve that — an in-memory implementation retained for tests behind the same interface, or a containerised database in CI?
🧩 Requirements and context
src/services/anchorService.ts, liquidityService.ts, settlementService.ts and quoteService.ts should require no changes. If one does, justify it.
- Schema must include the indexes the current code relies on —
settlementRepository.ts's anchor index is the obvious one; find the rest by reading the query methods.
- Concurrency matters: two simultaneous settlements against the same liquidity must not both succeed if only one can be funded. State how your schema and transactions prevent that.
- All 42 existing test files must pass.
- Do not change API response shapes.
- Configuration must fail fast with a clear message when the database is unreachable —
src/config.ts is the place.
🛠️ Suggested execution
- Post the schema and approach; wait for agreement.
- Add the driver and migration tooling; write migrations.
- Implement one repository behind its existing interface; keep the in-memory one for tests if that is your choice.
- Prove services are untouched.
- Add a concurrency test for the double-spend case.
✅ Acceptance criteria
🚫 Out of scope
- Changing the public API surface.
- Migrating all three repositories, if you argued for sequencing.
- Adding caching.
🧪 Verification
npm ci
npm run lint
npm run build
npm test
📤 What your PR must include
- A link to the agreed schema comment.
- Your store, tooling, sequencing and test-strategy decisions with reasoning.
- The concurrency test.
- Confirmation services are unchanged.
Closes #<n> or Part of #<n>.
🔒 Security notes
Settlement records are the audit trail for value movement. Storing them only in process memory means there is no durable record of what the system did — a restart erases the evidence of every settlement executed before it. Beyond availability, that is an integrity and accountability failure: no reconstruction, no dispute resolution, and no way to detect after the fact that something went wrong.
📋 Guidelines
- Minimum 95% test coverage on changed lines
- Clear documentation
- Timeframe: 96 hours from assignment
- One logical change per commit; no merge commits
💬 Join our community
Working on this, or want to sanity-check your approach before you start? Come and ask — the maintainers are there and happy to help.
Telegram: https://t.me/Grainlify
Priority: High · Area: Persistence / architecture · Est. effort: 12–16 h
📌 Problem
package.jsonlists exactly three runtime dependencies:There is no database driver, no ORM, no migration tool. Every repository under
src/repositories/—anchorRepository.ts,liquidityRepository.ts,settlementRepository.ts— is backed byinMemoryRepository.ts, andsettlementRepository.ts:13keeps its secondary index asprivate readonly anchorIndex: Map<string, Set<number>> = new Map().Consequences:
Settlements are financial records. A service that forgets them on restart cannot be operated.
🎯 Design decision required
Post your proposed schema and approach in a comment on this issue before writing code, and wait for maintainer agreement. This is too large to land unsolicited. State and defend:
src/services/*.tsdepend on. Keeping them stable means no service code changes — confirm that is achievable, and list any signature you must change.🧩 Requirements and context
src/services/anchorService.ts,liquidityService.ts,settlementService.tsandquoteService.tsshould require no changes. If one does, justify it.settlementRepository.ts's anchor index is the obvious one; find the rest by reading the query methods.src/config.tsis the place.🛠️ Suggested execution
✅ Acceptance criteria
src/services/changed, or every change is justified.🚫 Out of scope
🧪 Verification
npm ci npm run lint npm run build npm test📤 What your PR must include
Closes #<n>orPart of #<n>.🔒 Security notes
Settlement records are the audit trail for value movement. Storing them only in process memory means there is no durable record of what the system did — a restart erases the evidence of every settlement executed before it. Beyond availability, that is an integrity and accountability failure: no reconstruction, no dispute resolution, and no way to detect after the fact that something went wrong.
📋 Guidelines
💬 Join our community
Working on this, or want to sanity-check your approach before you start? Come and ask — the maintainers are there and happy to help.
Telegram: https://t.me/Grainlify