Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ The data layer for MGPL Diagnostics: one domain model on **MongoDB (Mongoose)**
(Sequelize)** behind the same repository interface, Tally-style double-entry accounting, a Redis cache
toolkit, and Fastify / Express decorators.

> **Pending move:** `src/graphql/` belongs in the backend repo. Read
> [docs/MOVE-GRAPHQL-TO-BACKEND.md](docs/MOVE-GRAPHQL-TO-BACKEND.md) before touching GraphQL code.
> **No GraphQL here.** The API lives in [mgpl-diagnostics/api](https://github.com/mgpl-diagnostics/api); the old
> `src/graphql` module was removed in 2.0.0 (see [docs/MOVE-GRAPHQL-TO-BACKEND.md](docs/MOVE-GRAPHQL-TO-BACKEND.md)).

## Map

Expand All @@ -17,7 +17,6 @@ src/pg/ Sequelize models + repositories (row locks, retry on 40001/40P01
src/cache/ cache-aside, single-flight, stampede lock, SWR, negative, tags, namespaces,
two-tier L1+L2, rate limiters, distributed lock, cached repositories
src/adapters/ fastify (decorates app.db), express (attachDb, dbErrorHandler)
src/graphql/ TO BE MOVED (see the handoff doc)
scripts/test.ts one contract suite on real MongoDB + real PostgreSQL (in-process), plus cache and adapters
```

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ Errors carry `statusCode`:
| `…/mongo` · `…/pg` | `createMongoRepositories` · `createPgRepositories`, schemas / models |
| `…/cache` | the cache toolkit |
| `…/fastify` · `…/express` | adapters |
| `…/graphql` | **moving to the backend repo.** See [docs/MOVE-GRAPHQL-TO-BACKEND.md](docs/MOVE-GRAPHQL-TO-BACKEND.md) |

Peer dependencies are all optional: install only the ones you use (`mongoose`, or `sequelize` + `pg`
+ `pg-hstore`; `ioredis`; `fastify`).
Expand Down
2 changes: 1 addition & 1 deletion docs/FINANCE-STORAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const db = await createDb({ backend: "pg", pg: { url }, posting: financePosting
```

Spreading `{ ...repos, posting }` does **not** reach the `tx` repositories; use the option.
When the accounting engine moves to its own kit (tally-kit), that kit implements this hook and
When the accounting engine moves to its own kit (ledger-kit), that kit implements this hook and
db-kit no longer imports the engine.

## Upgrading an existing database
Expand Down
3 changes: 3 additions & 0 deletions docs/MOVE-GRAPHQL-TO-BACKEND.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Handoff: move the GraphQL layer from db-kit to the backend repo

> **Done.** The GraphQL layer now lives in [mgpl-diagnostics/api](https://github.com/mgpl-diagnostics/api).
> db-kit 2.0.0 removed `src/graphql`, the `./graphql` export and the graphql peer dependencies. This page is kept as history.

**Audience:** the AI agent (or developer) doing the move. Follow the checklist top to bottom.
**Status (2026-10-13):** not started. Everything below currently lives in db-kit and passes its tests
(`npm test`: 194 checks; 38 of them are the GraphQL suite).
Expand Down
1,013 changes: 12 additions & 1,001 deletions llms-full.txt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions llms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Key facts for agents:
- Reports: trialBalance, ledgerStatement, cashBook, dayBook, profitAndLoss, balanceSheet, outstandingReceivables, gstSummary.
- Errors carry statusCode: NotFoundError 404, ConflictError 409, ValidationError 400, UnbalancedVoucherError 422; MongoDB without a replica set → TransactionsUnsupportedError.
- Change a repository in both src/mongo and src/pg; `npm test` runs one contract suite on real MongoDB and PostgreSQL.
- src/graphql is moving to the backend repo: see docs/MOVE-GRAPHQL-TO-BACKEND.md.
- No GraphQL here (removed in 2.0.0): the API is mgpl-diagnostics/api.

## Docs

- [README](README.md): overview, workflows, books, ACID, cache, entry points
- [AGENTS.md](AGENTS.md): map and rules
- [docs/FINANCE-STORAGE.md](docs/FINANCE-STORAGE.md): storage for finance-kit, lock dates, posting hook, upgrading a database
- [docs/MOVE-GRAPHQL-TO-BACKEND.md](docs/MOVE-GRAPHQL-TO-BACKEND.md): handoff for the GraphQL move
- [docs/MOVE-GRAPHQL-TO-BACKEND.md](docs/MOVE-GRAPHQL-TO-BACKEND.md): the completed GraphQL move (history)
- [llms-full.txt](llms-full.txt): every doc and source file in one document

## Source
Expand Down
20 changes: 2 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@mgpl-diagnostics/db-kit",
"version": "1.1.0",
"description": "MGPL Diagnostics data layer: patients, bookings, samples, reports, invoices, payments, users, roles and audit — on MongoDB (Mongoose) or PostgreSQL (Sequelize) behind one repository API, with Tally-style double-entry accounting, storage for finance-kit (customers, partners, settlements, cash, bank, lock dates, tax rules, credit notes), a GraphQL module, a Redis cache toolkit, sessions, RBAC, and Fastify / Express adapters.",
"version": "2.0.0",
"description": "MGPL Diagnostics data layer: patients, bookings, samples, reports, invoices, payments, users, roles and audit \u2014 on MongoDB (Mongoose) or PostgreSQL (Sequelize) behind one repository API, with Tally-style double-entry accounting, storage for finance-kit (customers, partners, settlements, cash, bank, lock dates, tax rules, credit notes), a Redis cache toolkit, sessions, RBAC, and Fastify / Express adapters.",
"type": "module",
"license": "SEE LICENSE IN LICENSE",
"repository": "github:mgpl-diagnostics/db-kit",
Expand Down Expand Up @@ -33,10 +33,6 @@
"types": "./dist/express.d.ts",
"import": "./dist/express.js"
},
"./graphql": {
"types": "./dist/graphql.d.ts",
"import": "./dist/graphql.js"
},
"./package.json": "./package.json"
},
"files": [
Expand All @@ -59,25 +55,17 @@
"llms": "node scripts/llms-full.mjs @mgpl-diagnostics/db-kit README.md AGENTS.md llms.txt docs package.json src scripts"
},
"peerDependencies": {
"@graphql-tools/schema": ">=10",
"fastify": ">=4",
"graphql": ">=16.10",
"ioredis": ">=5",
"mongoose": ">=8",
"pg": ">=8",
"pg-hstore": ">=2",
"sequelize": ">=6"
},
"peerDependenciesMeta": {
"@graphql-tools/schema": {
"optional": true
},
"fastify": {
"optional": true
},
"graphql": {
"optional": true
},
"ioredis": {
"optional": true
},
Expand All @@ -95,13 +83,9 @@
}
},
"devDependencies": {
"@graphql-tools/schema": "^10.1.4",
"@types/node": "^22.20.5",
"dataloader": "^2.2.3",
"embedded-postgres": "^18.4.0-beta.17",
"fastify": "^5.12.7",
"graphql": "^17.0.2",
"graphql-yoga": "^5.24.4",
"ioredis": "^5.11.1",
"ioredis-mock": "^8.13.1",
"mongodb-memory-server": "^11.3.0",
Expand Down
128 changes: 0 additions & 128 deletions scripts/graphql-suite.ts

This file was deleted.

3 changes: 0 additions & 3 deletions scripts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { createMongoRepositories, TransactionsUnsupportedError } from "../src/mo
import { createPgRepositories } from "../src/pg/index";
import { mgplDb } from "../src/adapters/fastify";
import { attachDb, dbErrorHandler } from "../src/adapters/express";
import { graphqlSuite } from "./graphql-suite";

let failed = 0;
let passed = 0;
Expand Down Expand Up @@ -403,7 +402,6 @@ async function main() {
const mongo = await createDb({ backend: "mongo", mongo: { uri: rs.getUri("mgpl_test") } });
const m = await contract(mongo);
await financeStorage(mongo, m.org, m.branch, (posting) => createMongoRepositories({ uri: rs.getUri("mgpl_test"), posting }));
await graphqlSuite(mongo, ok);

// a standalone server refuses multi-document work instead of silently losing atomicity
const standalone = await MongoMemoryServer.create();
Expand All @@ -423,7 +421,6 @@ async function main() {
const pgdb = await createDb({ backend: "pg", pg: { url: pgUrl } });
const p = await contract(pgdb);
await financeStorage(pgdb, p.org, p.branch, (posting) => createPgRepositories({ url: pgUrl, posting }));
await graphqlSuite(pgdb, ok);

const { redis, cache } = await cacheSuite();

Expand Down
2 changes: 1 addition & 1 deletion src/core/ports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export interface PeriodLockRepo extends Repo<PeriodLock> {

/**
* Called by the billing workflows, inside their transaction, to post the books. The default posts
* with this package's accounting; an accounting kit (finance-kit today, tally-kit later) supplies its own.
* with this package's accounting; an accounting kit (finance-kit today, ledger-kit later) supplies its own.
*/
export interface PostingHook {
invoiceIssued(tx: Repositories, invoice: Invoice, actorId?: string): Promise<void>;
Expand Down
Loading
Loading