@starci/hfs 4.10.0 → 4.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/db/drift.mjs +16 -15
- package/db/image.mjs +8 -0
- package/db/postgres.mjs +1 -1
- package/package.json +1 -1
- package/runtime/knowledge/hfs/canon-pins.yaml +16 -6
- package/runtime/knowledge/hfs/rules.yaml +28 -4
- package/runtime/knowledge/hfs/slots.yaml +53 -12
- package/runtime/knowledge/patterns/be/idempotency.yaml +1 -1
- package/runtime/knowledge/patterns/be/jobs.yaml +3 -0
- package/runtime/knowledge/patterns/be/queues.yaml +12 -11
- package/runtime/knowledge/patterns/be/realtime.yaml +1 -1
- package/runtime/modules/kernel/failure-codes.yaml +11 -1
- package/runtime/modules/schemas/application-stacks.schema.yaml +1 -1
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +53 -0
- package/runtime/scripts/hfs/architecture/owners.mjs +11 -0
- package/runtime/scripts/hfs/architecture/tiers.mjs +14 -3
- package/runtime/scripts/hfs/db-baseline-verb.mjs +45 -13
- package/runtime/scripts/hfs/manifest-shape.mjs +5 -1
- package/runtime/scripts/hfs/rules/database-config.mjs +1 -1
- package/runtime/scripts/hfs/rules/stacks-lite-backing.mjs +3 -4
- package/runtime/scripts/lib/swarm-stack.mjs +4 -6
- package/scaffold/add-queue-lite.mjs +24 -5
- package/stack/build.mjs +3 -1
- package/sync/index.mjs +19 -7
- package/templates/app/db-bootstrap/db/bootstrap.sql +7 -15
- package/templates/app/db-image/db/Dockerfile +8 -0
- package/templates/app/package-scripts/db.json +2 -1
- package/templates/app/skeleton-lite/.starcistacks/application-stacks.yaml +4 -2
- package/templates/app/skeleton-lite/.starcistacks/dev/README.md +1 -1
- package/templates/app/skeleton-lite/.starcistacks/dev/infra/swarm/stack.yaml +1 -1
- package/templates/app/skeleton-lite/.starcistacks/production/README.md +1 -1
- package/templates/app/skeleton-lite/.starcistacks/production/infra/swarm/stack.yaml +1 -1
- package/templates/app/skeleton-lite/README.md +2 -2
- package/templates/be/patterns/jobs/platform/jobs.log-events.ts.tpl +2 -0
- package/templates/be/patterns/jobs/platform-lite/job-tick.service.spec.ts.tpl +65 -0
- package/templates/be/patterns/jobs/platform-lite/job-tick.service.ts.tpl +78 -0
- package/templates/be/patterns/jobs/platform-lite/job-ticks.contracts.ts.tpl +16 -0
- package/templates/be/patterns/jobs/platform-lite/jobs.module.ts.tpl +40 -0
- package/templates/be/patterns/jobs/platform-lite/jobs.sql.tpl +44 -0
- package/templates/be/skeleton-lite/src/modules/platform/database/entities.ts +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.11.0 - 2026-10-29
|
|
4
|
+
|
|
5
|
+
Breaking for lite apps (rulings lite-official-postgres-image and lite-queue-bullmq; the move is contexts/project/lite.md "Moving an app off Supabase").
|
|
6
|
+
|
|
7
|
+
- Changed: the lite db service runs the Docker Official `postgres` image. `starci app sync --write` writes the managed `db/Dockerfile` (slot `app.db.image`, templates/app/db-image): `FROM postgres:17.11@sha256:31ba9c94…b08f` (sync `DB_BASE_IMAGE`) plus `postgresql-17-pgvector=0.8.7-1.pgdg13+1` from PGDG (`PGVECTOR_PACKAGE`), nothing else. The managed db scripts gain `db:image` (`docker build --tag <project>-db:local db`) and `db:create` builds it first; the lite skeleton's stack runs `{{project}}/db` for its db component and service, deploys it as `deploy.images.db: {app: db}` (`starci app stack build` and the managed `images.yml` and `stack-deploy.yml` build `db/Dockerfile` for it, `db/image.mjs`); `starci app db drift` builds `db/Dockerfile` for its scratch database (`DB_DRIFT_NO_IMAGE` without one) instead of reading `components.db.image`. `DB_IMAGE` (supabase/postgres) is removed.
|
|
8
|
+
- Changed: `db/bootstrap.sql` keeps the NOLOGIN browser roles and the auth and storage stubs and no longer creates the `extensions` schema or the `supabase_realtime` publication; it applies green, twice, on the official image.
|
|
9
|
+
- Changed: R276 refuses every PostgreSQL or Mongo image in a lite stack (`isLiteDatabaseImage` is removed): the db component runs the app's own db image; `DB_EXTENSION_ALLOWED` (R259) defaults to pgcrypto, pg_trgm, vector, uuid-ossp, unaccent and btree_gist.
|
|
10
|
+
- Added: the lite tick scheduler (R335, BE-JOBS-6). `starci app add job` in lite writes `platform/jobs/job-ticks.contracts.ts` (`JOB_TICKS`, empty), `job-tick.service.ts` (`JobTickService`: one `CronJob` per tick in `SchedulerRegistry`; each firing takes `advisoryXactLock(tx, "tick:<name>")`, claims the tick's UTC minute through `job_tick_claim` and only then writes the queue outbox) and its spec, a lite `jobs.module.ts` composing `ScheduleModule.forRoot()`, the `job_ticks` table and `job_tick_claim` function in the jobs migration, and pins `@nestjs/schedule` and `cron` in the app's package.json; `JobsLogEvent.TickFailed`; `job_tick_claim` joins the canon `ruleParams.be.dbFunctions`. The bundled lite pattern knowledge (queues, jobs, idempotency, realtime) names the tick instead of pg_cron, and the failure-code catalog carries `BE_JOBS_SCHEDULER_OWNER`.
|
|
11
|
+
- Changed: the bundled slot manifest 3.11.0 adds the managed lite slot `app.db.image` (`db/Dockerfile`), narrows `ruleParams.db.extensions` to what the official postgres image plus pgvector carries (pgcrypto, pg_trgm, vector, uuid-ossp, unaccent, btree_gist; no pgmq, pg_cron, pg_net or supabase_vault) and gives `@nestjs/schedule` and `cron` one owner, `platform/jobs`, in `infraOwners`; the bundled rule catalog adds R335 `BE_JOBS_SCHEDULER_OWNER` and its R250 and R276 laws name the platform/jobs tick and the db image; the bundled canon pins name hfs 4.11.0, eslint-canon-be 3.8.0, eslint-canon-fe 9.5.2 and the Grammar family 0.15.13 and pin `@nestjs/schedule` 6.1.3 (CommonJS on the Nest 11 line) and `cron` 4.4.0.
|
|
12
|
+
- Fixed: `starci app db baseline` judges the archive (`db/migrations/archive/`) as frozen history (R257): an archived file needs only its leading 14-digit stamp and an underscore, so a retired chain's snake_case names, impossible times (`20261014300000`) and shared stamps no longer refuse the cutover. The active chain keeps R213 in full (`<ts14>_<kebab>.sql` with a valid UTC stamp); R213 and R332 set no upper bound, so an active stamp after now is no breach. A file both active and archived is refused by name. The new version sorts after every archived and active file, and the baseline header names the last valid stamp, the boundary R257 judges.
|
|
13
|
+
- Fixed: a refusal over the migration chain lists every offender as `<file>: <reason> (<rule>)`, all at once: a misnamed or invalid-time active file (`db baseline`, `db restamp`, `db plan`), and for `db baseline` the `--stamp` boundary file, the committed-history findings (R257), the queue and cron findings (R258) and each active migration a schema-only dump cannot rebuild. Spec: `src/hfs-database-baseline.spec.mjs`.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## 4.10.1 - 2026-10-29
|
|
17
|
+
|
|
18
|
+
- Changed: the bundled slot manifest 3.10.0 adds the lite slot `be.platform.database.entities`, the entity registry (slot fields `role: entity-registry` and `importedBy`, validated by the manifest shape); the bundled architecture machine reads it (`architecture/entity-registry.mjs`): `tier-direction` (R26 `BE_TIER_DIRECTION`) admits the registry's import of a domain or platform capability's `index.ts` that binds only that capability's `<c>Entities`, and `owner-export-bypass` (R30 `ARCH_OWNER_EXPORT_BYPASS`) admits a direct import of the registry from the files `importedBy` names (`apps/*/src/compose/*.ts`, `apps/*/src/app.module.ts`, `src/tests/world/**`); every other import of either shape stays refused, and full has no registry; the bundled canon pins name hfs 4.10.1, eslint-canon-be 3.7.1, eslint-canon-fe 9.5.1 and the Grammar family 0.15.12; the lite skeleton's `platform/database/entities.ts` names its importers (app composition and the test world).
|
|
19
|
+
- Changed: the bundled architecture machine: the owner-cycle check (R27 `ARCH_OWNER_CYCLE`) counts the entity registry as a unit of its own, not part of `platform/database`, so naming every `<c>Entities` closes no cycle among capabilities while any other platform/database file importing a domain still does; the bundled rule catalog's R26 and R30 laws name the entity registry.
|
|
20
|
+
|
|
3
21
|
## 4.10.0 - 2026-10-29
|
|
4
22
|
|
|
5
23
|
Breaking for lite apps (ruling lite-self-hosted-postgres-passport-minio; the migration note is contexts/project/lite.md "Moving an app off Supabase").
|
package/db/drift.mjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// The migrations (db/migrations/*.sql, after db/bootstrap.sql when present) are the only DDL and `synchronize` is false, so an entity only
|
|
3
3
|
// maps tables that already exist and can drift from them. The verb builds TypeORM's metadata from the app's entity list
|
|
4
4
|
// (be/src/modules/platform/database/entities.ts, compiled in-process with the app's own typescript and loaded with the app's own typeorm) through a
|
|
5
|
-
// DataSource that never connects, applies the migrations to a scratch database (a throwaway container of the image the app's
|
|
6
|
-
//
|
|
5
|
+
// DataSource that never connects, applies the migrations to a scratch database (a throwaway container of the image the app's managed
|
|
6
|
+
// db/Dockerfile builds, or the empty database named by --url-env), reads that schema from
|
|
7
7
|
// information_schema.columns and pg_catalog, and reports every entity column whose table or column is missing, whose type differs (both
|
|
8
8
|
// normalised to PostgreSQL's format_type names) or whose nullability differs, under BE_ENTITY_SCHEMA_DRIFT. Database columns no entity maps
|
|
9
9
|
// are fine. Exit 0 is green, 1 is drift (or a migration that does not apply to an empty database), 2 is a refusal: no verdict, which is
|
|
@@ -12,10 +12,11 @@ import fs from 'node:fs';
|
|
|
12
12
|
import path from 'node:path';
|
|
13
13
|
import Module, { createRequire } from 'node:module';
|
|
14
14
|
import { randomBytes } from 'node:crypto';
|
|
15
|
-
import { runVerb
|
|
15
|
+
import { runVerb } from '../release/index.mjs';
|
|
16
16
|
import { failure, refusal } from '../stack/errors.mjs';
|
|
17
17
|
import { firstLine, tool } from '../stack/context.mjs';
|
|
18
18
|
import { ENTITY_LIST, hasEntityList } from './entity-list.mjs';
|
|
19
|
+
import { DB_DOCKERFILE } from './image.mjs';
|
|
19
20
|
|
|
20
21
|
export const DRIFT_CODE = 'BE_ENTITY_SCHEMA_DRIFT';
|
|
21
22
|
export const MIGRATIONS_DIR = 'db/migrations';
|
|
@@ -141,27 +142,27 @@ export function migrationFiles(root) {
|
|
|
141
142
|
return [...(fs.existsSync(path.join(root, BOOTSTRAP_FILE)) ? [BOOTSTRAP_FILE] : []), ...migrations];
|
|
142
143
|
}
|
|
143
144
|
|
|
144
|
-
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/** Starts a throwaway container of `image` on a loopback port; returns { connection, stop }. Docker missing or failing is no verdict. */
|
|
152
|
-
function startScratch(ctx, image) {
|
|
145
|
+
/**
|
|
146
|
+
* Builds the app's db image from db/Dockerfile and starts a throwaway container of it on a loopback port; returns { connection, stop }.
|
|
147
|
+
* Docker missing or failing is no verdict; an app without db/Dockerfile is refused (sync writes it).
|
|
148
|
+
*/
|
|
149
|
+
function startScratch(ctx, root) {
|
|
150
|
+
if (!fs.existsSync(path.join(root, DB_DOCKERFILE))) throw refusal('DB_DRIFT_NO_IMAGE', `${DB_DOCKERFILE} is missing: run "npx starci app sync --write" (the scratch database runs the app's own db image) or pass --url-env`);
|
|
153
151
|
const docker = (args, env) => tool(ctx, 'docker', args, { env: { ...ctx.env, ...env } });
|
|
154
152
|
const probe = docker(['version', '--format', '{{.Server.Version}}']);
|
|
155
153
|
if (probe.error || probe.status !== 0) throw needsDatabase('Docker is not available on this host; start it, or pass --url-env naming an empty database');
|
|
154
|
+
const build = docker(['build', '--quiet', '--file', path.join(root, DB_DOCKERFILE), path.join(root, 'db')]);
|
|
155
|
+
const image = /sha256:[a-f0-9]{64}/u.exec(String(build.stdout ?? ''))?.[0];
|
|
156
|
+
if (build.status !== 0 || !image) throw needsDatabase(`docker could not build ${DB_DOCKERFILE}: ${firstLine(build.stderr)}`);
|
|
156
157
|
const password = randomBytes(18).toString('hex');
|
|
157
158
|
const name = `starci-db-drift-${randomBytes(6).toString('hex')}`;
|
|
158
159
|
const run = docker(['run', '-d', '--rm', '--name', name, '--label', 'starci.db-drift=1', '-e', 'POSTGRES_PASSWORD', '-p', '127.0.0.1::5432', image], { POSTGRES_PASSWORD: password });
|
|
159
160
|
const stop = () => { docker(['rm', '-f', name]); };
|
|
160
|
-
if (run.status !== 0) { stop(); throw needsDatabase(`docker could not start ${
|
|
161
|
+
if (run.status !== 0) { stop(); throw needsDatabase(`docker could not start the image of ${DB_DOCKERFILE}: ${firstLine(run.stderr)}`); }
|
|
161
162
|
const port = docker(['port', name, '5432/tcp']);
|
|
162
163
|
const match = /:(\d+)\s*$/mu.exec(String(port.stdout ?? '').split('\n')[0]);
|
|
163
164
|
if (port.status !== 0 || !match) { stop(); throw needsDatabase('docker published no port for the scratch database'); }
|
|
164
|
-
return { connection: { host: '127.0.0.1', port: Number(match[1]), user: 'postgres', password, database: 'postgres' }, stop, how: `scratch container of ${
|
|
165
|
+
return { connection: { host: '127.0.0.1', port: Number(match[1]), user: 'postgres', password, database: 'postgres' }, stop, how: `scratch container of the image ${DB_DOCKERFILE} builds` };
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
/** Connects with the app's pg, retrying while a fresh container is still initialising; gives up after READY_TIMEOUT_MS. */
|
|
@@ -200,7 +201,7 @@ export async function migratedSchema(ctx, appRoot, { urlEnv } = {}) {
|
|
|
200
201
|
if (typeof value !== 'string' || !/^postgres(?:ql)?:\/\//u.test(value)) throw needsDatabase(`${urlEnv} holds no postgres connection URL`);
|
|
201
202
|
secrets = [value];
|
|
202
203
|
scratch = { connection: { connectionString: value }, stop: () => {}, how: `the database ${urlEnv} names` };
|
|
203
|
-
} else scratch = startScratch(ctx,
|
|
204
|
+
} else scratch = startScratch(ctx, root);
|
|
204
205
|
const scrub = (text) => secrets.reduce((out, secret) => out.replaceAll(secret, '[value]'), String(text));
|
|
205
206
|
let client;
|
|
206
207
|
try {
|
package/db/image.mjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// image.mjs - the one name of a lite app's db image (slot app.db.image, ruling:lite-official-postgres-image): the managed db/Dockerfile
|
|
2
|
+
// builds it, `deploy.images.db` of .starcistacks/application-stacks.yaml names it as app `db`, and the stack build, the images and
|
|
3
|
+
// stack-deploy workflows, the local db container and the drift scratch database all build that one file.
|
|
4
|
+
|
|
5
|
+
/** The image app name a deploy block gives the db service. */
|
|
6
|
+
export const DB_IMAGE_APP = 'db';
|
|
7
|
+
/** The managed Dockerfile of the db image, app-relative. */
|
|
8
|
+
export const DB_DOCKERFILE = 'db/Dockerfile';
|
package/db/postgres.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { firstLine, tool } from '../stack/context.mjs';
|
|
|
6
6
|
|
|
7
7
|
/** The default environment variable that names the app's database. */
|
|
8
8
|
export const DEFAULT_DB_URL_ENV = 'DATABASE_URL';
|
|
9
|
-
/** The history table `starci app db migrate` records applied migrations in (
|
|
9
|
+
/** The history table `starci app db migrate` records applied migrations in (Supabase's layout, so a history restored from a hosted Supabase carries over; migrate creates it on an empty database). */
|
|
10
10
|
export const HISTORY_TABLE = 'supabase_migrations.schema_migrations';
|
|
11
11
|
|
|
12
12
|
const KEY = /^[A-Z][A-Z0-9_]*$/u;
|
package/package.json
CHANGED
|
@@ -31,35 +31,35 @@ pins:
|
|
|
31
31
|
source: packages/event-stream/package.json
|
|
32
32
|
why: 'the one server-sent-events client of every front end (fe-stack event-stream, owner:event-stream-package): the transport client layer (modules/api/sse/clients) creates one instance for the app with the bearer token source and the stream operations follow on it; it carries Last-Event-ID resume, the capped doubling backoff, the heartbeat timeout, the single 401 renewal and the useSWRSubscription adapter, so no app keeps a hand-written reader.'
|
|
33
33
|
'@starci/grammar':
|
|
34
|
-
version: 0.15.
|
|
34
|
+
version: 0.15.13
|
|
35
35
|
group: starci
|
|
36
36
|
install: registry
|
|
37
37
|
side: fe
|
|
38
38
|
source: packages/grammar/package.json
|
|
39
39
|
why: 'the grammar front ends read: the brand layer sets `--font-sans` and `--font-mono` and the grammar reads them; it carries the Input tel kind, the copyable and read-only Input, the IconButton disclosure props and count badge, ChatBubble, FillViewport, Textarea mentions and Enter-to-send, the leading PrimaryRailLayout rail, the plate-less Image, ListRow, the soft Alert, Progress steps, the floating primary IconButton, FlowGraph, the STATE-8 loading views and the bordered selectable TagGroup chips. The runtime source version wins for a @starci package.'
|
|
40
40
|
'@starci/eslint-canon-be':
|
|
41
|
-
version: 3.
|
|
41
|
+
version: 3.8.0
|
|
42
42
|
group: starci
|
|
43
43
|
install: registry
|
|
44
44
|
side: be
|
|
45
45
|
source: packages/eslint-canon-be/package.json
|
|
46
46
|
why: 'the back-end ESLint canon: `loadHfs(import.meta.url)` of be/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the be side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; `starciBeConfig({ hfs: loadHfs(import.meta.url) })` is the typed factory and the BE-CONVENTION laws are its rules.'
|
|
47
47
|
'@starci/eslint-canon-fe':
|
|
48
|
-
version: 9.5.
|
|
48
|
+
version: 9.5.2
|
|
49
49
|
group: starci
|
|
50
50
|
install: registry
|
|
51
51
|
side: fe
|
|
52
52
|
source: packages/eslint-canon-fe/package.json
|
|
53
53
|
why: 'the front-end ESLint canon: `loadHfs(import.meta.url)` of fe/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the fe side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; the front end has no tests (FE_NO_TESTS R97 in hfs) and no-vietnamese-in-source (R91) applies.'
|
|
54
54
|
'@starci/eslint-grammar-core':
|
|
55
|
-
version: 0.15.
|
|
55
|
+
version: 0.15.13
|
|
56
56
|
group: starci
|
|
57
57
|
install: registry
|
|
58
58
|
side: fe
|
|
59
59
|
source: packages/eslint-grammar-core/package.json
|
|
60
60
|
why: 'the StarCi Grammar component API lint, versioned with @starci/grammar; front ends compose this family package with the universal FE canon.'
|
|
61
61
|
'@starci/eslint-grammar-offset-pop':
|
|
62
|
-
version: 0.15.
|
|
62
|
+
version: 0.15.13
|
|
63
63
|
group: starci
|
|
64
64
|
install: registry
|
|
65
65
|
side: fe
|
|
@@ -106,7 +106,7 @@ pins:
|
|
|
106
106
|
source: packages/ai-router/package.json
|
|
107
107
|
why: 'the AI pool router of a back end: a NestJS module that routes OpenAI-compatible chat, stream and embeddings calls across keys, models and providers, with @starci/ai-router/testing for its specs; @starci/jest-preset compiles it as an ESM-only dependency.'
|
|
108
108
|
'@starci/hfs':
|
|
109
|
-
version: 4.
|
|
109
|
+
version: 4.11.0
|
|
110
110
|
group: starci
|
|
111
111
|
install: registry
|
|
112
112
|
side: both
|
|
@@ -600,6 +600,16 @@ pins:
|
|
|
600
600
|
group: framework
|
|
601
601
|
side: be
|
|
602
602
|
why: 'PassportStrategy of integrations/passport; 11.0.5 is CommonJS on the Nest 11 line (12.0.0 is ESM-only and breaks Nest 11 jest under the CommonJS transform of @starci/jest-preset), as nivo-lite runs it.'
|
|
603
|
+
'@nestjs/schedule':
|
|
604
|
+
version: 6.1.3
|
|
605
|
+
group: framework
|
|
606
|
+
side: be
|
|
607
|
+
why: 'the tick scheduler of platform/jobs, the one owner that imports it (R335, ruling lite-official-postgres-image); 6.1.3 is CommonJS on the Nest 11 line (12.x is ESM-only and breaks Nest 11 jest under the CommonJS transform of @starci/jest-preset).'
|
|
608
|
+
cron:
|
|
609
|
+
version: 4.4.0
|
|
610
|
+
group: framework
|
|
611
|
+
side: be
|
|
612
|
+
why: 'CronJob of the platform/jobs tick scheduler; the exact version @nestjs/schedule 6.1.3 depends on, so one cron is installed.'
|
|
603
613
|
passport:
|
|
604
614
|
version: 0.7.0
|
|
605
615
|
group: framework
|
|
@@ -474,7 +474,7 @@ rules:
|
|
|
474
474
|
witness:
|
|
475
475
|
- {path: packages/eslint/be/legacy-owner-graph.a16.spec.mjs, editions: [lite, full]}
|
|
476
476
|
templateNa: "Tier and package direction are constraints on cross-owner import graphs; no dedicated cross-owner graph scaffold is generated."
|
|
477
|
-
law: "The tier direction matrix; a shared package never imports an app. Front-end page and layout owners may import overlay entries; every other cross-owner feature-to-feature edge is forbidden, including layout-to-page and overlay-to-overlay. Components never import overlays."
|
|
477
|
+
law: "The tier direction matrix; a shared package never imports an app. Front-end page and layout owners may import overlay entries; every other cross-owner feature-to-feature edge is forbidden, including layout-to-page and overlay-to-overlay. Components never import overlays. The one platform-to-domain edge is the lite entity registry (be.platform.database.entities) importing a capability's `<c>Entities` alone from its `index.ts`."
|
|
478
478
|
kinds: [lint, design]
|
|
479
479
|
gates: [settle, land, ci]
|
|
480
480
|
failureCodes: ["BE_TIER_DIRECTION", "FE_TIER_DIRECTION", "ARCH_PACKAGE_IMPORTS_APP"]
|
|
@@ -541,7 +541,7 @@ rules:
|
|
|
541
541
|
- {path: packages/eslint/be/a16-r29-r31.spec.mjs, edition: full}
|
|
542
542
|
- id: R30
|
|
543
543
|
code: "BE_PUBLIC_SURFACE"
|
|
544
|
-
law: "Every owner has one `index.ts`; cross-owner imports use it, same-owner imports are relative and never go through it; it holds only named `export { }` lines, no `export *`, no alias re-export (`export { X as Y }`, `export const Y = X`, `export type Y = X`, `export interface Y extends X {}`: one declaration has one name), within the owner slot's `indexExports` budget (60 for domain and feature owners, 80 for `be.integrations` provider entries); cross-package imports use the package name and a declared export."
|
|
544
|
+
law: "Every owner has one `index.ts`; cross-owner imports use it, except the lite entity registry, reached by deep path only from the files its slot's `importedBy` names; same-owner imports are relative and never go through it; it holds only named `export { }` lines, no `export *`, no alias re-export (`export { X as Y }`, `export const Y = X`, `export type Y = X`, `export interface Y extends X {}`: one declaration has one name), within the owner slot's `indexExports` budget (60 for domain and feature owners, 80 for `be.integrations` provider entries); cross-package imports use the package name and a declared export."
|
|
545
545
|
kinds: [lint, codemod]
|
|
546
546
|
gates: [settle, land, ci]
|
|
547
547
|
failureCodes: ["BE_PUBLIC_SURFACE", "ARCH_OWNER_EXPORT_BYPASS", "ARCH_OWNER_EXPORT_STAR", "HFS_ALIAS_REEXPORT", "ARCH_PACKAGE_EXPORT_BYPASS"]
|
|
@@ -4176,7 +4176,7 @@ rules:
|
|
|
4176
4176
|
editions: [lite, full]
|
|
4177
4177
|
docs:
|
|
4178
4178
|
- {path: docs/application-stacks.md#r250-deploy-scan, editions: [lite, full]}
|
|
4179
|
-
law: "In lite and full apps, scheduled work belongs to the back-end queue scheduler, a
|
|
4179
|
+
law: "In lite and full apps, scheduled work belongs to the back-end queue scheduler, a platform/jobs tick (R335) that enqueues through the queue outbox or a declared replicated-job. Deployment files, scripts, workflows, compose files and Dockerfiles install no host crontab, cron.d entry, systemd timer, @reboot job or at job; a workflow does not schedule app work. Docker compose up, down and pull run only against an explicitly dev environment. Deploy shell scripts delegate to docker, starci or the app CLI, and contain no node -e, psql, inline SQL or downloaded shell logic."
|
|
4180
4180
|
kinds: [check]
|
|
4181
4181
|
gates: [settle, land, ci]
|
|
4182
4182
|
failureCodes: ["HFS_HOST_CRON", "HFS_DEPLOY_NO_LOGIC", "HFS_DEPLOY_COMPOSE_ON_VPS", "HFS_DEPLOY_SCHEDULER"]
|
|
@@ -4701,7 +4701,7 @@ rules:
|
|
|
4701
4701
|
- {path: packages/hfs/src/hfs-stacks-full-fixtures.spec.mjs, edition: full}
|
|
4702
4702
|
- id: R276
|
|
4703
4703
|
code: "STACKS_LITE_SELFHOSTED_DB"
|
|
4704
|
-
law: "Lite runs exactly one database, its db component of image
|
|
4704
|
+
law: "Lite runs exactly one database, its db component of the image its managed db/Dockerfile builds (the digest-pinned official postgres image plus pgvector, ruling:lite-official-postgres-image) for vector search too, and no other PostgreSQL, MongoDB or Qdrant backing image, even when declared (owner:lite-vector-is-pgvector, ruling:lite-self-hosted-postgres-passport-minio). A Redis image runs only when hfs.json sides.be.backing declares redis (ruling:R212/case-10), as one minimal instance; a declared Redis runs as exactly one stack service, with AOF persistence (`appendonly yes`, `appendfsync everysec` or `always`, never `no`) on a writable named volume so queue jobs survive a restart and with no maxmemory-policy but noeviction so none is evicted. A queue job Redis loses inside the at most one second `everysec` leaves unwritten is not lost work: every job is born from a Postgres outbox row, and the relay marks that row sent only after Redis confirms the job is in its append-only file (WAITAOF) and still holds it, so a job Redis did not persist leaves its row waiting and the relay adds it again (examples/lite-app queue-relay.service.spec.ts and bullmq-queue-transport.client.spec.ts). A sidecar keeps its own SQLite on a named persistent volume declared by its component and mounted in the rendered model, and never uses the app's declared Redis, which serves the back-end app services only; a sidecar requiring another database, that Redis included, is refused. Full retains its declared backing topology."
|
|
4705
4705
|
kinds: [check]
|
|
4706
4706
|
gates: ["settle","land","ci"]
|
|
4707
4707
|
failureCodes: ["STACKS_LITE_SELFHOSTED_DB", "STACKS_SIDECAR_VOLUME_UNDECLARED", "STACKS_SIDECAR_DB_UNSUPPORTED", "STACKS_LITE_REDIS_PERSISTENCE"]
|
|
@@ -5849,3 +5849,27 @@ rules:
|
|
|
5849
5849
|
source: owner
|
|
5850
5850
|
quote: "big refactor đi … không viết raw sql như thế theo starci-academy-be"
|
|
5851
5851
|
ruling: "Lite persistence moves to TypeORM entities on the EntityManager, the shape of full and starci-academy-be (ruling lite-persistence-typeorm-entities)."
|
|
5852
|
+
- id: R335
|
|
5853
|
+
code: "BE_JOBS_SCHEDULER_OWNER"
|
|
5854
|
+
law: "Recurring work is a tick of platform/jobs (ruling lite-official-postgres-image): JOB_TICKS of job-ticks.contracts.ts lists the ticks as data, and only job-tick.service.ts (JobTickService, which registers one CronJob per tick in SchedulerRegistry) and jobs.module.ts (which composes ScheduleModule.forRoot()) import @nestjs/schedule or cron; no file uses the Cron, Interval or Timeout decorator. JobTickService takes advisoryXactLock(tx, \"tick:<name>\") and claims the tick's UTC minute through callDbFunction(tx, \"job_tick_claim\", ...) in the transaction that writes the queue outbox row, so of the replicas that fire a tick exactly one enqueues it once per minute."
|
|
5855
|
+
kinds: [lint]
|
|
5856
|
+
gates: [pre-commit, settle, land, ci]
|
|
5857
|
+
failureCodes: ["BE_JOBS_SCHEDULER_OWNER"]
|
|
5858
|
+
enforcers:
|
|
5859
|
+
- {kind: eslint-be, id: jobs-scheduler-owner}
|
|
5860
|
+
editions: [lite, full]
|
|
5861
|
+
docs: [contexts/code/be/jobs.md]
|
|
5862
|
+
proves:
|
|
5863
|
+
- packages/eslint-canon-be/src/jobs-scheduler.spec.ts
|
|
5864
|
+
exemplifiedBy:
|
|
5865
|
+
- {path: packages/hfs/templates/be/patterns/jobs/platform-lite/job-tick.service.ts.tpl, edition: lite}
|
|
5866
|
+
- {path: packages/eslint-canon-be/src/jobs-scheduler.spec.ts, editions: [lite, full], codes: [BE_JOBS_SCHEDULER_OWNER]}
|
|
5867
|
+
witness:
|
|
5868
|
+
- {path: packages/eslint-canon-be/src/jobs-scheduler.spec.ts, edition: lite, codes: [BE_JOBS_SCHEDULER_OWNER]}
|
|
5869
|
+
- {path: packages/eslint-canon-be/src/jobs-scheduler.spec.ts, edition: full, codes: [BE_JOBS_SCHEDULER_OWNER]}
|
|
5870
|
+
cases:
|
|
5871
|
+
- id: case-1
|
|
5872
|
+
date: "2026-10-29"
|
|
5873
|
+
source: owner
|
|
5874
|
+
quote: "chạy postgresql thuần image chính chủ nhé ko phải supebase"
|
|
5875
|
+
ruling: "The lite db image carries no pg_cron, so recurring work moves to a Nest schedule tick of platform/jobs under an advisory lock and a minute claim (ruling lite-official-postgres-image)."
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
# catalog READ this file through scripts/hfs/slots.mjs; none of them hardcodes a path.
|
|
8
8
|
# Shape: modules/schemas/hfs-slots.schema.yaml. The repository side is hfs.json: modules/schemas/hfs-repo.schema.yaml.
|
|
9
9
|
schema: starci/hfs-slots@3
|
|
10
|
-
version: 3.
|
|
10
|
+
version: 3.11.0
|
|
11
11
|
|
|
12
12
|
versioning:
|
|
13
13
|
# MAJOR.MINOR.PATCH of this manifest. A repository pins only the MAJOR in hfs.json ("hfs": 3).
|
|
@@ -50,6 +50,11 @@ versioning:
|
|
|
50
50
|
# transport client layer), and lets fe.hooks.swr hold the SWR subscription hooks (api/sse/subscriptions/useSubscribe<X>Swr.ts, one useSWRSubscription per stream operation).
|
|
51
51
|
# 3.8.0 is a minor (urgent release, 2026-10-29): it ADDS the optional fe.dev-server-generated slot (apps/*/AGENTS.md, which `next dev` rewrites) and the
|
|
52
52
|
# slot field rewrittenBy, so the release gate's clean-tree check passes over an untracked file a declared dev server writes, and over nothing else.
|
|
53
|
+
# 3.10.0 is a minor (2026-10-29): it ADDS the lite be.platform.database.entities slot, the entity registry (slot fields role and importedBy), so the
|
|
54
|
+
# tier matrix and the public-entry rules admit exactly its <c>Entities imports and its deep importers (persistence.md BE-PERSISTENCE-3).
|
|
55
|
+
# 3.11.0 (ruling:lite-official-postgres-image, 2026-10-29) is, like 3.9.0, a change for lite only: it ADDS the managed app.db.image slot
|
|
56
|
+
# (db/Dockerfile, written by `starci app sync --write`), narrows ruleParams.db.extensions to the extensions that image carries, and gives
|
|
57
|
+
# @nestjs/schedule and cron one owner, platform/jobs (R335).
|
|
53
58
|
|
|
54
59
|
# Field meaning, per slot.
|
|
55
60
|
# id stable name, never changes meaning inside a major.
|
|
@@ -72,6 +77,10 @@ versioning:
|
|
|
72
77
|
# outcomeHome true on a file slot: the one file that declares the repository's Outcome union. A repository holds exactly one such
|
|
73
78
|
# file (modules/api/outcome.ts, the api package's outcome.ts, or modules/db/outcome.ts of a lite app),
|
|
74
79
|
# and no other file declares an Outcome union (one-outcome-union, FE_TRANSPORT_OWNER).
|
|
80
|
+
# role on a file slot: the one part it plays that a rule reads. entity-registry = the lite PRIMARY_ENTITIES list
|
|
81
|
+
# (be.platform.database.entities): the one platform file that imports capability <c>Entities, imported by deep path
|
|
82
|
+
# only from the files importedBy names (architecture/entity-registry.mjs).
|
|
83
|
+
# importedBy on a slot with a role: the side-relative path patterns of the only files that import its file by deep path.
|
|
75
84
|
# requires files or directories that must exist inside each instance; <var> is replaced by the bound name,
|
|
76
85
|
# a leading / means repository root; a trailing / means directory.
|
|
77
86
|
# requiredInstances variable -> names that must exist as instances (config, logging ... of platform).
|
|
@@ -121,8 +130,8 @@ testValues: [unit-beside, e2e, none]
|
|
|
121
130
|
# specs (unitRoles, logicRoles, 100 per file, @starci/jest-preset doubles, builders). What differs is ADAPTERS and DELIVERY
|
|
122
131
|
# (ruling:R212/case-10): schema authority in db/migrations, the queue port on BullMQ over the Redis hfs.json
|
|
123
132
|
# sides.be.backing declares (as in full, fed by the Postgres outbox), event-bus ports on pgmq-backed topics or in-process
|
|
124
|
-
# delivery, cache and locks on Postgres or the declared Redis, schedules
|
|
125
|
-
# outbox, storage on S3-compatible MinIO (integrations/object-storage) and auth through integrations/passport. Realtime uses SSE or the socket.io gateway
|
|
133
|
+
# delivery, cache and locks on Postgres or the declared Redis, schedules as platform/jobs ticks enqueueing through the queue
|
|
134
|
+
# outbox (R335), storage on S3-compatible MinIO (integrations/object-storage) and auth through integrations/passport. Realtime uses SSE or the socket.io gateway
|
|
126
135
|
# in the api process, which scales horizontally and stateless (memory hub for one replica or tests; the Redis hub and @socket.io/redis-adapter when Redis is declared, else the Postgres hub and @socket.io/postgres-adapter, for N replicas; websocket only, no sticky sessions). Integration and provider sandbox contract specs are optional;
|
|
127
136
|
# declared patterns owe their integration proofs (R284). Lite has no e2e world. Production uses declared docker-swarm under
|
|
128
137
|
# .starcistacks/production/infra/swarm/ (owner ruling 2026-10-14); lite runs its PostgreSQL as the db service of its
|
|
@@ -199,8 +208,9 @@ crossApp: apps never import each other; shared code is a packages/<pkg> slot.
|
|
|
199
208
|
ruleParams:
|
|
200
209
|
db:
|
|
201
210
|
# R259: btree_gist supplies UUID equality for the booking interval exclusion constraint.
|
|
202
|
-
# R259:
|
|
203
|
-
|
|
211
|
+
# R259: the extensions the db image carries (ruling:lite-official-postgres-image): the official postgres image's contrib set and pgvector
|
|
212
|
+
# from PGDG; unaccent serves Vietnamese-content search functions. No pg_cron, pg_net, pgmq or supabase_vault.
|
|
213
|
+
extensions: [pgcrypto, pg_trgm, vector, uuid-ossp, unaccent, btree_gist]
|
|
204
214
|
# R258 DB_CRON_OWNED: THE queue outbox of a lite schema (the relay hands its unsent rows to BullMQ, ruling:R212/case-10). A pg_cron
|
|
205
215
|
# job enqueues only by inserting one row into this table, writing only these columns, one of which is `queue`.
|
|
206
216
|
queueOutbox: {table: public.queue, columns: [queue, payload, created_at, correlation_id]}
|
|
@@ -249,7 +259,8 @@ ruleParams:
|
|
|
249
259
|
bull: [platform/queue]
|
|
250
260
|
"@nestjs/bull": [platform/queue]
|
|
251
261
|
kafkajs: [platform/event-bus] # pattern event-bus: Kafka is the only event transport
|
|
252
|
-
"@nestjs/schedule": []
|
|
262
|
+
"@nestjs/schedule": [platform/jobs] # R335: only the tick scheduler of platform/jobs (jobs.scheduler.ts); elsewhere a schedule is a BullMQ job scheduler of a queue
|
|
263
|
+
cron: [platform/jobs] # R335: CronJob of the tick scheduler
|
|
253
264
|
eventemitter2: []
|
|
254
265
|
setInterval: [platform/retry, platform/event-bus, platform/queue, platform/http, platform/realtime]
|
|
255
266
|
setTimeout: [platform/retry, platform/event-bus, platform/queue, platform/http]
|
|
@@ -432,6 +443,7 @@ ruleParams:
|
|
|
432
443
|
- {name: job_advance, reason: "platform/jobs (add job, lite): the token-guarded step write of jobs.sql"}
|
|
433
444
|
- {name: job_complete, reason: "platform/jobs (add job, lite): the token-guarded completion of jobs.sql"}
|
|
434
445
|
- {name: job_fail, reason: "platform/jobs (add job, lite): the token-guarded failure of jobs.sql"}
|
|
446
|
+
- {name: job_tick_claim, reason: "platform/jobs (add job, lite): the once-per-minute claim of a scheduler tick, jobs.sql (R335)"}
|
|
435
447
|
- {name: queue_write, reason: "platform/queue (add queue, lite): the outbox insert of queue-outbox.sql"}
|
|
436
448
|
- {name: queue_waiting, reason: "platform/queue (add queue, lite): the relay read FOR UPDATE SKIP LOCKED of queue-outbox.sql"}
|
|
437
449
|
- {name: queue_mark_sent, reason: "platform/queue (add queue, lite): the relay mark of queue-outbox.sql"}
|
|
@@ -855,7 +867,7 @@ slots:
|
|
|
855
867
|
"<env>/runtime/{config,env}/**", "<env>/runtime/env/KEYS.md", "<env>/secrets/<slug>.enc", "<env>/secrets/.gitkeep", "<env>/seeds/**"]
|
|
856
868
|
forbids: ["<env>/runtime/files/**", "**/*.enc outside <env>/secrets/", DESIGN.md, deployment.json, "k8s/ at root"]
|
|
857
869
|
# Owner ruling 2026-10-14: lite declares docker-swarm production, app runtime config, sealed custody and seed data.
|
|
858
|
-
# The db service supplies the database
|
|
870
|
+
# The db service supplies the database; schedules are platform/jobs ticks (R335); production has no Compose or host cron.
|
|
859
871
|
lite:
|
|
860
872
|
requires: [application-stacks.yaml]
|
|
861
873
|
allows: [application-stacks.yaml, "<env>/README.md", "<env>/environment.json", "<env>/infra/swarm/**", "<env>/infra/metadata.json",
|
|
@@ -919,7 +931,7 @@ slots:
|
|
|
919
931
|
rules: [HFS_PLAINTEXT_SECRET]
|
|
920
932
|
|
|
921
933
|
# ----- app root: the database of a lite app (ruling:lite-self-hosted-postgres-passport-minio): a self-hosted PostgreSQL in the app's
|
|
922
|
-
# stack (the `db` service,
|
|
934
|
+
# stack (the `db` service, built from the managed db/Dockerfile: the official postgres image plus pgvector, ruling:lite-official-postgres-image), migrated by
|
|
923
935
|
# `starci app db migrate --url-env <NAME>`. A full app keeps its TypeORM migrations under be/ and has no such folder.
|
|
924
936
|
- id: app.db
|
|
925
937
|
profiles: [app]
|
|
@@ -969,12 +981,26 @@ slots:
|
|
|
969
981
|
tier: none
|
|
970
982
|
tests: none
|
|
971
983
|
since: 3.9.0
|
|
984
|
+
- id: app.db.image
|
|
985
|
+
profiles: [app]
|
|
986
|
+
editions: [lite]
|
|
987
|
+
# The managed image of the db service (templates/app/db-image, ruling:lite-official-postgres-image): FROM the digest-pinned official
|
|
988
|
+
# postgres image plus postgresql-17-pgvector from PGDG. The stack's db service, the local db container and the scratch database
|
|
989
|
+
# of `starci app db drift` all build it.
|
|
990
|
+
path: "db/Dockerfile"
|
|
991
|
+
presence: required
|
|
992
|
+
tracked: tracked
|
|
993
|
+
managedBy: db-image
|
|
994
|
+
tier: none
|
|
995
|
+
tests: none
|
|
996
|
+
since: 3.11.0
|
|
997
|
+
rules: [HFS_MANAGED_FILE_DRIFT]
|
|
972
998
|
- id: app.db.bootstrap
|
|
973
999
|
profiles: [app]
|
|
974
1000
|
editions: [lite]
|
|
975
|
-
# The managed pre-migration bootstrap (templates/app/db-bootstrap): the auth
|
|
976
|
-
#
|
|
977
|
-
#
|
|
1001
|
+
# The managed pre-migration bootstrap (templates/app/db-bootstrap): the auth and storage schemas, auth.users with the GoTrue column
|
|
1002
|
+
# set, auth.uid/role/jwt stubs and the NOLOGIN browser roles, so migrations written for a hosted Supabase apply to the db service's
|
|
1003
|
+
# official postgres image (nothing else of Supabase: no supabase_admin, extensions schema or realtime publication). `starci app db migrate` applies it before the first migration of an empty database.
|
|
978
1004
|
path: "db/bootstrap.sql"
|
|
979
1005
|
presence: required
|
|
980
1006
|
tracked: tracked
|
|
@@ -1725,6 +1751,21 @@ slots:
|
|
|
1725
1751
|
coverage: required
|
|
1726
1752
|
budget: {indexExports: 60}
|
|
1727
1753
|
rules: [BE_TIER_DIRECTION, ARCH_OWNER_CYCLE, BE_MODULE_SHAPE]
|
|
1754
|
+
- id: be.platform.database.entities
|
|
1755
|
+
since: 3.10.0
|
|
1756
|
+
profiles: [be]
|
|
1757
|
+
editions: [lite]
|
|
1758
|
+
editionWhy: "lite registers the one PRIMARY_ENTITIES list on its single primary connection; full registers each capability's <c>Entities per connection from persistence/connection.ts."
|
|
1759
|
+
path: "src/modules/platform/database/entities.ts"
|
|
1760
|
+
presence: optional
|
|
1761
|
+
tracked: tracked
|
|
1762
|
+
tier: inherit
|
|
1763
|
+
role: entity-registry
|
|
1764
|
+
importedBy: ["apps/*/src/compose/*.ts", "apps/*/src/app.module.ts", "src/tests/world/**"]
|
|
1765
|
+
tests: none
|
|
1766
|
+
coverage: none
|
|
1767
|
+
why: "the entity registry (persistence.md BE-PERSISTENCE-3): it lists every capability's <c>Entities array by name, no glob, as PRIMARY_ENTITIES, the one list the primary connection maps, and exports nothing else. It is the one platform file that imports domain and platform capabilities, each import naming only that capability's <c>Entities from its index.ts (BE_TIER_DIRECTION, ARCH_OWNER_EXPORT_BYPASS); DatabaseModule and the platform/database index never import it, and only the files importedBy names (app composition and the test world) import it, by the deep path @modules/platform/database/entities (BE_PUBLIC_SURFACE), since database.module, this list and the capability indexes would otherwise form a cycle that fails at boot"
|
|
1768
|
+
rules: [BE_TIER_DIRECTION, BE_PUBLIC_SURFACE, BE_SCHEMA_OWNER]
|
|
1728
1769
|
- id: be.platform.logging
|
|
1729
1770
|
since: 3.5.0
|
|
1730
1771
|
profiles: [be]
|
|
@@ -1779,7 +1820,7 @@ slots:
|
|
|
1779
1820
|
the same QueueOutbox and QueueWorkerRegistry ports and full's BullMQ adapter on the declared Redis (backing: [redis]): the
|
|
1780
1821
|
relay adds each committed outbox row with the outbox id as the job id, workers retry with exponential backoff and keep a
|
|
1781
1822
|
job that exhausts its attempts as failed (the dead letter); the outbox table comes from a db migration, and a
|
|
1782
|
-
schedule is a BullMQ job scheduler or a
|
|
1823
|
+
schedule is a BullMQ job scheduler or a platform/jobs tick that writes one outbox row, R335 (knowledge/patterns/be/queues.yaml liteAdapter)
|
|
1783
1824
|
requires: [index.ts, queue.module.ts, queue.port.ts, queue.contracts.ts, queue-outbox.service.ts, queue-outbox.service.spec.ts]
|
|
1784
1825
|
tests: unit-beside
|
|
1785
1826
|
coverage: required
|
|
@@ -258,7 +258,7 @@ liteAdapter:
|
|
|
258
258
|
idempotency pattern with its required proof scenarios.
|
|
259
259
|
ports:
|
|
260
260
|
- {port: Inbox, adapter: PostgresInbox through the caller's active EntityManager transaction}
|
|
261
|
-
- {port: receipt retention, adapter: a fenced job delivered by the BullMQ queue on the declared Redis and scheduled by a
|
|
261
|
+
- {port: receipt retention, adapter: a fenced job delivered by the BullMQ queue on the declared Redis and scheduled by a platform/jobs tick (R335) that enqueues through the queue outbox}
|
|
262
262
|
proof: >-
|
|
263
263
|
The same inbox and fingerprint unit specs apply; declaring idempotency requires both client receipt scenarios in
|
|
264
264
|
lite's local db integration lane.
|
|
@@ -287,8 +287,11 @@ liteAdapter:
|
|
|
287
287
|
ports:
|
|
288
288
|
- {port: job claim (platform/jobs), adapter: "the claim and guarded writes as the job_claim, job_advance, job_complete and job_fail functions of the jobs migration in db/migrations, called through callDbFunction of platform/database (R334)"}
|
|
289
289
|
- {port: processor delivery, adapter: "full's BullMQ worker (attempts and exponential backoff from the queue policy, failed jobs kept as the dead letter)"}
|
|
290
|
+
- {port: tick scheduler (platform/jobs), adapter: "JOB_TICKS of job-ticks.contracts.ts as data and JobTickService (job-tick.service.ts, composed with ScheduleModule.forRoot() by the lite jobs.module.ts): one CronJob per tick in SchedulerRegistry, each firing taking advisoryXactLock and claiming the tick's UTC minute through the job_tick_claim function of the jobs migration before it writes the queue outbox (R335, contexts/code/be/jobs.md BE-JOBS-6)"}
|
|
290
291
|
proof: >-
|
|
291
292
|
Unit specs as full (job-claim.service.spec.ts); declaring fenced-job requires integration specs titled
|
|
292
293
|
`fenced-job/<scenario>: ...` for every declared scenario on the local db service (R284, which runs no container of its
|
|
293
294
|
own): the claim, the fencing token and the guarded writes are Postgres facts, driven there by the real runner without BullMQ.
|
|
295
|
+
The tick scheduler's unit spec (job-tick.service.spec.ts) proves the lock, the minute claim and that a replica that comes
|
|
296
|
+
second enqueues nothing.
|
|
294
297
|
see: [knowledge/patterns/be/queues.yaml]
|
|
@@ -78,18 +78,19 @@ rules:
|
|
|
78
78
|
manual: []
|
|
79
79
|
relatedExamples: [queue]
|
|
80
80
|
- id: BE-QUEUES-3
|
|
81
|
-
title: A schedule is a BullMQ job scheduler declared with its queue, or a
|
|
81
|
+
title: A schedule is a BullMQ job scheduler declared with its queue, or a platform/jobs tick that writes the outbox
|
|
82
82
|
kind: mandatory
|
|
83
|
-
hfsRules: [R90,
|
|
83
|
+
hfsRules: [R90, R335]
|
|
84
84
|
requirement: |-
|
|
85
85
|
A recurring task is a job scheduler (`upsertJobScheduler`) that the queue module declares in its `schedulers` list and
|
|
86
|
-
`platform/queue` registers at boot, or, in a lite app, a
|
|
87
|
-
|
|
88
|
-
`
|
|
89
|
-
|
|
90
|
-
`
|
|
86
|
+
`platform/queue` registers at boot, or, in a lite app, a tick of `platform/jobs` (BE-JOBS-6, R335): `JOB_TICKS` of
|
|
87
|
+
`job-ticks.contracts.ts` lists it as data and `JobTickService` fires it on every replica, where each firing takes
|
|
88
|
+
`advisoryXactLock(tx, "tick:<name>")`, claims the tick's UTC minute through `job_tick_claim` and only then writes one row of
|
|
89
|
+
the tick's queue into the queue outbox, which the relay hands to BullMQ. Its job is processed by the same
|
|
90
|
+
`features/jobs/<job>/<job>.processor.ts` as any enqueued job. `@nestjs/schedule` and `cron` are imported only by that
|
|
91
|
+
scheduler, and `@Cron`, `@Interval`, `@Timeout` and `setInterval` for work are not used anywhere.
|
|
91
92
|
rationale: |-
|
|
92
|
-
One scheduler in Redis, or one
|
|
93
|
+
One scheduler in Redis, or one minute claim in the database, fires once for the whole deployment, where cron in a replicated
|
|
93
94
|
process fires once per replica.
|
|
94
95
|
cases:
|
|
95
96
|
- id: case-1
|
|
@@ -283,12 +284,12 @@ liteAdapter:
|
|
|
283
284
|
- {port: queue transport (queue-transport.port.ts), adapter: "full's bullmq-queue-transport.client.ts over the declared Redis (host, port, db and the password read from its sealed secret file), plus persist(jobs): WAITAOF 1 0 on each queue's connection, then each job's state, refusing with QUEUE_NOT_PERSISTED or QUEUE_JOB_LOST (errors/queue.error.ts)"}
|
|
284
285
|
- {port: outbox relay (queue-relay.service.ts), adapter: "full's relay, which calls persist after the adds and before it marks the rows sent, so a refusal rolls the mark back and the next pass adds the rows again"}
|
|
285
286
|
- {port: QueueWorkerRegistry (platform/queue), adapter: "full's BullMQ worker per queue: attempts and exponential backoff from queue.policy.ts, failed jobs kept as the dead letter"}
|
|
286
|
-
- {port: schedulers, adapter: "a BullMQ job scheduler declared with its queue, as full, or a
|
|
287
|
-
forbids: [kafkajs
|
|
287
|
+
- {port: schedulers, adapter: "a BullMQ job scheduler declared with its queue, as full, or a platform/jobs tick (JobTickService, R335) that writes one row of the tick's queue into the queue outbox under its lock and minute claim"}
|
|
288
|
+
forbids: [kafkajs]
|
|
288
289
|
proof: >-
|
|
289
290
|
Unit specs as full (queue-outbox, relay and worker services, the BullMQ client against a mocked factory); declaring queue
|
|
290
291
|
requires integration specs titled `queue/<scenario>: ...` for every declared scenario on the local db service (R284,
|
|
291
|
-
which runs no container of its own): the outbox, its commit boundary, the relay identity and the
|
|
292
|
+
which runs no container of its own): the outbox, its commit boundary, the relay identity and the tick's minute claim are Postgres
|
|
292
293
|
facts proved there with the real outbox writer and relay, and the queue transport records what the relay hands to BullMQ
|
|
293
294
|
(the job id is the outbox id). BullMQ itself is covered by the unit spec of the BullMQ client, which also proves the
|
|
294
295
|
persist refusals; the relay's unit spec proves a refused persist leaves the rows waiting.
|
|
@@ -670,7 +670,7 @@ files:
|
|
|
670
670
|
optional: true
|
|
671
671
|
- path: db/migrations/<timestamp>_realtime-events.sql
|
|
672
672
|
slot: repo.side-root-forbidden
|
|
673
|
-
role: Lite edition migration (created with `npm run db:new`) of the same two tables, forced row level security for app_be
|
|
673
|
+
role: Lite edition migration (created with `npm run db:new`) of the same two tables, forced row level security for app_be; the retention queue is fired by a platform/jobs tick (R335).
|
|
674
674
|
optional: true
|
|
675
675
|
- path: src/features/reactors/<name>/transport/message/<event>.consumer.ts
|
|
676
676
|
slot: be.transport.message
|
|
@@ -3732,7 +3732,7 @@ HFS_HOST_CRON:
|
|
|
3732
3732
|
meaning_vi: "Tệp triển khai hoặc script tại <path> khai báo crontab, cron.d, systemd timer, @reboot hoặc at; lịch chạy phải do ứng dụng sở hữu."
|
|
3733
3733
|
causes_vi:
|
|
3734
3734
|
- "Vi phạm R250: cài lịch chạy ngoài scheduler của ứng dụng hoặc replicated-job đã khai báo."
|
|
3735
|
-
nextStep_vi: "Chuyển tác vụ sang scheduler hàng đợi của back end, một tick
|
|
3735
|
+
nextStep_vi: "Chuyển tác vụ sang scheduler hàng đợi của back end, một tick của platform/jobs (R335) enqueue qua outbox hàng đợi hoặc replicated-job đã khai báo và gọi lệnh CLI của ứng dụng."
|
|
3736
3736
|
owner: op-retry
|
|
3737
3737
|
kind: check-finding
|
|
3738
3738
|
|
|
@@ -5600,3 +5600,13 @@ BE_PERSISTENCE_NO_RAW_SQL:
|
|
|
5600
5600
|
nextStep_vi: "Khai entity ở persistence/entities/<table>.entity.ts và đọc/ghi bằng EntityManager hoặc createQueryBuilder với tham số có tên; hàm pg/SECURITY DEFINER không diễn đạt được thì khai vào rawSqlFunctions kèm lý do."
|
|
5601
5601
|
owner: op-retry
|
|
5602
5602
|
kind: check-finding
|
|
5603
|
+
|
|
5604
|
+
BE_JOBS_SCHEDULER_OWNER:
|
|
5605
|
+
title: "A schedule outside the platform/jobs tick scheduler"
|
|
5606
|
+
title_vi: "Lịch chạy định kỳ nằm ngoài bộ lập lịch tick của platform/jobs"
|
|
5607
|
+
meaning_vi: "File `<path>` import @nestjs/schedule hoặc cron ngoài job-tick.service.ts và jobs.module.ts của platform/jobs, dùng decorator Cron/Interval/Timeout, hoặc JobTickService không giữ advisoryXactLock và job_tick_claim trước khi ghi outbox."
|
|
5608
|
+
causes_vi:
|
|
5609
|
+
- "Vi phạm R335: việc định kỳ là tick của platform/jobs (JOB_TICKS), mỗi phút chỉ một replica enqueue nhờ khoá advisory và claim phút trong DB."
|
|
5610
|
+
nextStep_vi: "Khai tick vào JOB_TICKS của platform/jobs/job-ticks.contracts.ts (name, cron, timeZone UTC, queue, payload) và xoá lịch tự viết; giữ advisoryXactLock và job_tick_claim trong JobTickService."
|
|
5611
|
+
owner: op-retry
|
|
5612
|
+
kind: check-finding
|
|
@@ -85,7 +85,7 @@ properties:
|
|
|
85
85
|
command: {type: string, minLength: 1}
|
|
86
86
|
backing:
|
|
87
87
|
description: >-
|
|
88
|
-
The self-hosted database of a lite app: its db component (image
|
|
88
|
+
The self-hosted database of a lite app: its db component (the image its managed db/Dockerfile builds), a Docker container in
|
|
89
89
|
development and a Swarm service in production. Every other dependency is a Docker component too.
|
|
90
90
|
type: object
|
|
91
91
|
additionalProperties:
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { braceVariants, globExpression } from '../../lib/glob.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The entity registry (persistence.md BE-PERSISTENCE-3): the one file whose slot plays `role: entity-registry`
|
|
5
|
+
* (`be.platform.database.entities`, lite's `src/modules/platform/database/entities.ts`). It lists every capability's `<c>Entities`
|
|
6
|
+
* array as `PRIMARY_ENTITIES`, so it is the one platform file that imports domain and platform capability barrels, and only for
|
|
7
|
+
* that name; and it is imported by deep path only from the files its slot's `importedBy` names (app composition and the test world).
|
|
8
|
+
* The tier matrix (tiers.mjs), the public-entry check (owners.mjs) and the lint rule `import-owner-entry` read it here.
|
|
9
|
+
*/
|
|
10
|
+
export const ENTITY_REGISTRY_ROLE = 'entity-registry';
|
|
11
|
+
|
|
12
|
+
/** The tiers whose capabilities contribute an entity list to the registry. */
|
|
13
|
+
const CONTRIBUTING_TIERS = new Set(['domain', 'platform']);
|
|
14
|
+
|
|
15
|
+
/** The entity list a capability exports: `<c>Entities`, `<c>` its folder name in camelCase. */
|
|
16
|
+
export const entityListName = capability => `${capability.replace(/-([a-z0-9])/g, (_, next) => next.toUpperCase())}Entities`;
|
|
17
|
+
|
|
18
|
+
/** The slot of `file` (side-relative or absolute) when it plays the entity-registry role, else null. */
|
|
19
|
+
export function registrySlot(resolver, file) {
|
|
20
|
+
const slot = resolver?.slotOf?.(file);
|
|
21
|
+
return slot?.role === ENTITY_REGISTRY_ROLE ? slot : null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Whether `file` is one of the importers the registry slot admits by deep path (`importedBy`, side-relative patterns); an app-wide
|
|
26
|
+
* resolver answers for a side-prefixed path (`be/apps/...`), which is read without its side folder.
|
|
27
|
+
*/
|
|
28
|
+
export function registryImporter(resolver, slot, file) {
|
|
29
|
+
const side = resolver?.sideOf?.(file);
|
|
30
|
+
const rel = side ? file.slice(side.length + 1) : file;
|
|
31
|
+
return (slot.importedBy ?? []).some(pattern => braceVariants(pattern).some(variant => globExpression(variant).test(rel)));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The names an import declaration binds by name; null for a default, namespace or side-effect import and for any re-export. */
|
|
35
|
+
function namedImports(declaration) {
|
|
36
|
+
const clause = declaration?.importClause;
|
|
37
|
+
if (!clause || clause.name || !Array.isArray(clause.namedBindings?.elements) || !clause.namedBindings.elements.length) return null;
|
|
38
|
+
return clause.namedBindings.elements.map(element => (element.propertyName ?? element.name).text);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Whether an owner-graph edge (side-relative `from` and `to`, `edge.declaration` the TypeScript statement) is the registry naming a
|
|
43
|
+
* capability's entity list: it leaves the registry, imports the public entry (`index.ts`) of a domain or platform capability, and
|
|
44
|
+
* binds that capability's `<c>Entities` and nothing else.
|
|
45
|
+
*/
|
|
46
|
+
export function registryListImport(resolver, edge) {
|
|
47
|
+
if (!registrySlot(resolver, edge.from)) return false;
|
|
48
|
+
const owner = resolver.ownerOf(edge.to);
|
|
49
|
+
if (!owner || !CONTRIBUTING_TIERS.has(resolver.slot(owner.slot)?.tier) || edge.to !== `${owner.root}/index.ts`) return false;
|
|
50
|
+
const names = namedImports(edge.edge?.declaration ?? edge.declaration);
|
|
51
|
+
const listName = entityListName(owner.root.split('/').at(-1));
|
|
52
|
+
return names !== null && names.every(name => name === listName);
|
|
53
|
+
}
|