@akanjs/cli 3.0.0-alpha.4 → 3.0.0-alpha.40
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/.build-stamp +1 -1
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/{abstractCompactor-rk6twzvj.js → abstractCompactor-20e0cwbs.js} +3 -3
- package/{agent.command-jfz8yfwy.js → agent.command-e835fjem.js} +9 -8
- package/{application.command-mxyqtd6p.js → application.command-sjtbk6tr.js} +7 -6
- package/{applicationBuildRunner-cwk52sb7.js → applicationBuildRunner-7gnfz7ww.js} +7 -8
- package/{applicationReleasePackager-yrrhbkv3.js → applicationReleasePackager-93nzdfsy.js} +2 -2
- package/buildBatch.proc.js +6 -5
- package/{capacitorApp-j357ak1g.js → capacitorApp-qv7g3dp2.js} +29 -28
- package/{cloud.command-f87dwe52.js → cloud.command-y0e4eyqz.js} +11 -10
- package/{context.command-z5bf8bn7.js → context.command-vn87jb08.js} +17 -16
- package/{dependencyScanner-f6grrep3.js → dependencyScanner-rbs2407b.js} +1 -1
- package/getDirname-ka11hm7e.js +8 -0
- package/{guideline.command-1m1ctar3.js → guideline.command-s4hn2bsy.js} +7 -6
- package/guidelines/conventions/conventions.generate.json +25 -0
- package/guidelines/conventions/conventions.instruction.md +1173 -0
- package/guidelines/cssRule/cssRule.instruction.md +7 -0
- package/guidelines/framework/framework.instruction.md +1 -0
- package/guidelines/ssrRule/ssrRule.generate.json +31 -0
- package/guidelines/ssrRule/ssrRule.instruction.md +108 -0
- package/guidelines/workspaceOnboarding/workspaceOnboarding.generate.json +24 -0
- package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +972 -0
- package/incrementalBuilder.proc.js +7 -6
- package/{index-1s71fwrq.js → index-0h212yqe.js} +13 -13
- package/index-1577bej2.js +7 -0
- package/{index-e3qskyt2.js → index-33zce8gt.js} +8 -4
- package/{index-csqk9z5j.js → index-3dp7x6rc.js} +3 -3
- package/{index-cn24dcqn.js → index-73rnbwgg.js} +15 -7
- package/{index-tq1y56tp.js → index-8d2sv6pw.js} +39 -16
- package/{index-jtm86byd.js → index-8vkkm7v0.js} +125 -66
- package/{index-r4w8cry5.js → index-9jsnb4vw.js} +4 -4
- package/{index-ybybkec0.js → index-becx1t0k.js} +6 -6
- package/{index-4yp06pn1.js → index-g9e2fhw2.js} +49 -32
- package/{index-cap2k2ch.js → index-hg0qvhmx.js} +152 -241
- package/{index-xwgm94zr.js → index-j37qq1f2.js} +1 -1
- package/{index-n0z3f2xg.js → index-k6fvbcj1.js} +37 -6
- package/{index-6pz1j0zj.js → index-mxvakhsm.js} +6 -2
- package/{index-vhv3xnjz.js → index-mykmf6wd.js} +8 -8
- package/{index-y0k42k04.js → index-mz5jtaq7.js} +1 -1
- package/{index-jk9q6pse.js → index-n706txcv.js} +5 -3
- package/{index-hjzr8ja1.js → index-qc0tnhs2.js} +1 -1
- package/{index-rh16j3c7.js → index-qnv0aqmm.js} +12 -8
- package/{index-3pgtw35d.js → index-sh01r3pm.js} +2 -2
- package/{index-xj8bks3p.js → index-t71zvmt9.js} +9 -11
- package/{index-4zgs8g1w.js → index-tsmjxph2.js} +1 -1
- package/{index-fmgbwsr5.js → index-x33gnap3.js} +4 -4
- package/{index-b978vs2e.js → index-xyrb7pk5.js} +3 -3
- package/index.js +21 -20
- package/{library.command-pwfx8dx2.js → library.command-v5cyaw9t.js} +6 -5
- package/{localRegistry.command-r4zjx5py.js → localRegistry.command-53t758pt.js} +10 -9
- package/{module.command-0t3ewata.js → module.command-pq6w84xg.js} +10 -9
- package/{package.command-7hmkxvpa.js → package.command-qkcs60ts.js} +6 -5
- package/package.json +3 -4
- package/{page.command-st6r4s0q.js → page.command-qj5bfnh9.js} +6 -5
- package/{primitive.command-1qkxpzsn.js → primitive.command-bw0nes6x.js} +11 -10
- package/{quality.command-hy5vt1bh.js → quality.command-g1s2wt8b.js} +532 -87
- package/{recipeScanner-tghkzrrt.js → recipeScanner-zrzev25x.js} +3 -3
- package/{repair.command-nakkq2zp.js → repair.command-mzwtejpk.js} +8 -7
- package/{routeSourceValidator-cncd92fv.js → routeSourceValidator-7fycdqyv.js} +3 -39
- package/{scalar.command-fjq272gs.js → scalar.command-rm6k3c65.js} +9 -8
- package/templates/app/env/env.server.debug.ts.template +1 -5
- package/templates/app/env/env.server.develop.ts.template +1 -5
- package/templates/app/env/env.server.local.ts.template +1 -5
- package/templates/app/env/env.server.main.ts.template +1 -5
- package/templates/app/page/styles.css.template +3 -3
- package/templates/appSample/srvkit/AuthGuard.ts +9 -5
- package/templates/appSample/srvkit/SessionInternalArg.ts +4 -3
- package/templates/crudPages/[__model__Id]/edit/page.tsx +1 -1
- package/templates/crudPages/new/page.tsx +1 -1
- package/templates/crudSinglePage/page.tsx +1 -1
- package/templates/env/_env.server.type.ts +7 -5
- package/templates/lib/db.ts +4 -2
- package/templates/lib/dict.ts +1 -1
- package/templates/lib/sig.ts +1 -1
- package/templates/lib/srv.ts +6 -2
- package/templates/lib/useClient.ts +9 -3
- package/templates/module/__Model__.Util.tsx +1 -1
- package/templates/module/__Model__.Zone.tsx +3 -5
- package/templates/workspaceRoot/AGENTS.md.template +0 -831
- package/templates/workspaceRoot/CLAUDE.md.template +19 -0
- package/templates/workspaceRoot/biome.json.template +4 -217
- package/{typeChecker-kravn7ns.js → typeChecker-g6bh0xfv.js} +1 -1
- package/typecheck.proc.js +1 -1
- package/{workflow.command-jswbgk90.js → workflow.command-g2cgcgxn.js} +16 -15
- package/{workspace.command-h9wwcjpt.js → workspace.command-f7jerqb2.js} +70 -52
- package/templates/libRoot/base/baseLogic.ts +0 -14
- package/templates/libRoot/base/index.ts +0 -8
- package/templates/workspaceRoot/.cursor/rules/akan-page-routing.mdc.template +0 -43
- package/templates/workspaceRoot/.cursor/rules/akan-sync-conventions.mdc.template +0 -33
- package/templates/workspaceRoot/.cursor/rules/application-test-commands.mdc.template +0 -16
- package/templates/workspaceRoot/.cursor/rules/change-scope.mdc.template +0 -12
- package/templates/workspaceRoot/.cursor/rules/client-server-boundaries.mdc.template +0 -17
- package/templates/workspaceRoot/.cursor/rules/coding-comments.mdc.template +0 -25
- package/templates/workspaceRoot/.cursor/rules/coding-style.mdc.template +0 -44
- package/templates/workspaceRoot/.cursor/rules/domain-module-conventions.mdc.template +0 -17
- package/templates/workspaceRoot/.cursor/rules/format-lint.mdc.template +0 -12
- package/templates/workspaceRoot/.cursor/rules/lint-enforced-rules.mdc.template +0 -18
- package/templates/workspaceRoot/.cursor/rules/module-file-playbook.mdc.template +0 -61
- package/templates/workspaceRoot/.cursor/rules/naming-conventions.mdc.template +0 -15
- package/templates/workspaceRoot/.cursor/rules/react-component-style.mdc.template +0 -21
- package/templates/workspaceRoot/.cursor/rules/repo-overview.mdc.template +0 -17
- package/templates/workspaceRoot/.cursor/rules/scalar-modeling.mdc.template +0 -58
- package/templates/workspaceRoot/.cursor/rules/secrets-and-env.mdc.template +0 -13
- package/templates/workspaceRoot/.cursor/rules/service-signal-conventions.mdc.template +0 -83
- package/templates/workspaceRoot/.cursor/rules/srvkit-adapters-and-guards.mdc.template +0 -50
- package/templates/workspaceRoot/.cursor/rules/typescript-imports.mdc.template +0 -16
- /package/{index-r24hmh0q.js → index-yb2wsc7f.js} +0 -0
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: sync-enforced Akan app/lib layout and generated index conventions
|
|
3
|
-
globs: apps/**/*,libs/**/*
|
|
4
|
-
alwaysApply: false
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Akan Sync Conventions
|
|
8
|
-
|
|
9
|
-
- `apps/<appName>` root may only contain these files: `akan.app.json`, `akan.config.ts`, `capacitor.config.ts`, `client.ts`, `main.ts`, `package.json`, `server.ts`, `tsconfig.json`.
|
|
10
|
-
- `apps/<appName>` root may only contain these folders: `.akan`, `android`, `common`, `env`, `ios`, `lib`, `page`, `private`, `public`, `script`, `srvkit`, `ui`, `webkit`.
|
|
11
|
-
- Do not add `apps/*/base`; place shared app utilities under `apps/*/common`.
|
|
12
|
-
- `apps/*/lib` and `libs/*/lib` root files are limited to generated/support files: `cnst.ts`, `db.ts`, `dict.ts`, `option.ts`, `sig.ts`, `srv.ts`, `st.ts`, `useClient.ts`, `useServer.ts`.
|
|
13
|
-
- Domain module folders are `lib/<model>` for database modules, `lib/_<service>` for service modules, and `lib/__scalar/<scalar>` for scalar modules.
|
|
14
|
-
- Database module UI files are limited to `<Model>.Template.tsx`, `<Model>.Unit.tsx`, `<Model>.Util.tsx`, `<Model>.View.tsx`, and `<Model>.Zone.tsx`.
|
|
15
|
-
- Service module UI files are limited to `<Service>.Util.tsx` and `<Service>.Zone.tsx`.
|
|
16
|
-
- Scalar module UI files are limited to `<Scalar>.Template.tsx` and `<Scalar>.Unit.tsx`.
|
|
17
|
-
- Module `*.test.ts`, `*.test.tsx`, `*.spec.ts`, and `*.spec.tsx` files are allowed.
|
|
18
|
-
- `ui/index.ts`, `webkit/index.ts`, `srvkit/index.ts`, `common/index.ts`, and module `lib/**/index.ts` files are generated by `akan sync`; do not hand-edit or track them.
|
|
19
|
-
- Generated facet indexes export only 1-depth files/folders with `export * from "./name";`.
|
|
20
|
-
|
|
21
|
-
## Layer Placement
|
|
22
|
-
|
|
23
|
-
| Folder | Admission test | Naming |
|
|
24
|
-
|---|---|---|
|
|
25
|
-
| `common/` | pure, isomorphic, zero-dependency; may import only sibling `common/*` and `akanjs/base`. Cannot import `Err`, so keep throwing code out of it. | camelCase file, filename equals the single export |
|
|
26
|
-
| `webkit/` | touches `window` / `navigator` / Capacitor, or is a React hook | `use<Thing>.tsx` — `.tsx` even with no JSX |
|
|
27
|
-
| `srvkit/` | touches `node:*`, `Bun`, `process.env`, a secret, or a server SDK | camelCase file, PascalCase class |
|
|
28
|
-
| `ui/` | renders JSX and is not bound to one model | PascalCase component, camelCase sidecar (`swipeCard.util.ts`) |
|
|
29
|
-
|
|
30
|
-
- Hooks return a named object of async closures, never a tuple.
|
|
31
|
-
- Only layer-root `index.ts` barrels are generated. A `ui/<Folder>/index.tsx` that builds a namespace is hand-written source; the distinguishing test is that a generated barrel contains nothing but `export * from "./X";` lines.
|
|
32
|
-
- `ui/<Folder>/index_.tsx` (trailing underscore) is the `"use client"` + `lazy()` boundary, with a server-safe `index.tsx` beside it. Collapsing the pair into one file breaks RSC.
|
|
33
|
-
- Never add a sibling helper file inside `lib/<model>/`; helpers belong in one of the folders above.
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Application test commands after source changes
|
|
3
|
-
alwaysApply: true
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Application Test Commands
|
|
7
|
-
|
|
8
|
-
- After changing application source code, test the app with `bun run akan start <appName>`.
|
|
9
|
-
- Test production build generation with `bun run akan build <appName>`.
|
|
10
|
-
- To test a built artifact locally, run it from the generated app directory with the required Akan runtime environment variables.
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
cd dist/apps/<appName> && USE_AKANJS_PKGS=true AKAN_PUBLIC_REPO_NAME=akansoft AKAN_PUBLIC_SERVE_DOMAIN="akanjs.com" AKAN_PUBLIC_APP_NAME=seon AKAN_PUBLIC_ENV=local AKAN_PUBLIC_OPERATION_MODE=local SERVER_MODE=federation AKAN_PUBLIC_BASE_PATHS=operator,office,homepage bun main.js
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
- Adjust `<appName>`, `AKAN_PUBLIC_APP_NAME`, and `AKAN_PUBLIC_BASE_PATHS` to match the app being tested.
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Keep edits scoped and avoid unrelated churn
|
|
3
|
-
alwaysApply: true
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Change Scope
|
|
7
|
-
|
|
8
|
-
- Keep edits scoped to the requested task and the directly related files.
|
|
9
|
-
- Do not reformat unrelated files or rewrite nearby code just for style.
|
|
10
|
-
- Do not revert or overwrite unrelated user changes in a dirty working tree.
|
|
11
|
-
- Prefer established nearby patterns over introducing a new abstraction.
|
|
12
|
-
- Add new abstractions only when they remove real duplication or match an existing project pattern.
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Client/server boundary conventions for Akan apps
|
|
3
|
-
globs: apps/**/*.{ts,tsx},libs/**/*.{ts,tsx},pkgs/akanjs/**/*.{ts,tsx}
|
|
4
|
-
alwaysApply: false
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Client Server Boundaries
|
|
8
|
-
|
|
9
|
-
- Use `"use client";` at the top of client component files.
|
|
10
|
-
- Be careful when importing client-only code from page or layout modules.
|
|
11
|
-
- Keep page props serializable unless the existing route pattern clearly allows otherwise.
|
|
12
|
-
- Let server page/layout files own route-level concerns: `usePage`, headers, static layout, and `akanjs/ui` `Tab` composition.
|
|
13
|
-
- Keep interactive loading, submit/import actions, local form inputs, and `router.push` inside client `Util`, `Template`, or `Zone` components.
|
|
14
|
-
- Prefer server-rendered `Tab` shells for static mode selection; put one client component inside each `Tab.Panel` instead of managing the selected mode with extra `useState`.
|
|
15
|
-
- In domain UI the boundary is mechanical, not a judgment call: `Template`, `Zone`, and `Util` are always client components with `"use client"` on line 1; `Unit` and `View` are always server components and never carry the directive. `usePage()` is still legal in server files.
|
|
16
|
-
- Preserve established domain file roles such as `.document.ts`, `.service.ts`, `.store.ts`, `.constant.ts`, and `.client.ts`.
|
|
17
|
-
- When unsure, inspect nearby files in the same app or package before introducing a new boundary pattern.
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Do not narrate code; document only what the code cannot say
|
|
3
|
-
alwaysApply: true
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Comments
|
|
7
|
-
|
|
8
|
-
Do not narrate code. Do document the thing the code cannot say. Both halves are the rule.
|
|
9
|
-
|
|
10
|
-
- Never add a comment that restates the identifier, the signature, or the control flow.
|
|
11
|
-
- Prefer clear names and structure so ordinary logic needs no explanation.
|
|
12
|
-
- Do not add JSDoc, section banners, or "why/how" comments for ordinary logic.
|
|
13
|
-
- Comment density tracks the layer, not the author: pages carry none, product `lib/` and `ui/` code stays under 1 %, and `srvkit/` adapters and `guards.ts` carry as much as the external constraints require.
|
|
14
|
-
- A comment is warranted for: a vendor spec or protocol quirk; an infrastructure constraint; a third-party library gotcha; security reasoning; why a rule that looks arbitrary is correct; a math derivation; a domain field's business meaning; a state transition above a document chain method; why an obvious alternative was rejected.
|
|
15
|
-
- In-code markers:
|
|
16
|
-
1. `TODO` — unfinished work that must be tracked in-code
|
|
17
|
-
2. `FIXME` — known broken or incorrect behavior that must be fixed
|
|
18
|
-
3. `XXX` — dangerous / surprising hazard that a reader must not miss
|
|
19
|
-
4. `//!` — disabled or must-fix code
|
|
20
|
-
5. `//?` — an explanatory aside
|
|
21
|
-
6. `//*` — a design note
|
|
22
|
-
7. Deletion caution — warn why removing a line or block would break something non-obvious
|
|
23
|
-
- Keep allowed comments one short line when possible.
|
|
24
|
-
- Every suppression carries a reason: `// biome-ignore lint/<rule>: <why>`. Never a bare disable block.
|
|
25
|
-
- Match nearby file style: if the surrounding code has few comments, keep it that way.
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Coding style conventions for classes, functions, files, and types
|
|
3
|
-
globs: **/*.{ts,tsx}
|
|
4
|
-
alwaysApply: false
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Coding Style
|
|
8
|
-
|
|
9
|
-
- For large units of work, prefer declaring a class and running the flow through an instance instead of scattering many standalone functions.
|
|
10
|
-
- Prefer class methods or `static` methods over unrelated top-level helper functions when the logic belongs to a class-level workflow.
|
|
11
|
-
- Prefer ECMAScript `#private` fields and methods over TypeScript `private`, except in the four suffixes where `#private` is lint-banned (`*.constant.ts`, `*.document.ts`, `*.service.ts`, `*.store.ts`) — those use TypeScript `private`. `#private` is the house style under `srvkit/`, including `adapt()` classes.
|
|
12
|
-
- In files that declare a class, avoid top-level functions or variables when they can reasonably live inside the class.
|
|
13
|
-
- Prefer `const` function expressions over `function` declarations unless hoisting, overloads, generators, or framework conventions make `function` the better fit.
|
|
14
|
-
- Prefer declaring only one class per file; split the file when two or more class declarations are needed.
|
|
15
|
-
- For class-centered modules, prefer noun-style filenames that match the primary class name, such as `RouteClientBuilder.ts`, instead of verb-style wrapper filenames like `buildRouteClient.ts`.
|
|
16
|
-
- Avoid keeping exported functions that only instantiate a class and immediately call one method. Prefer migrating callers to instantiate the class directly.
|
|
17
|
-
- Except for React component files or convention files, TypeScript filenames should use camelCase.
|
|
18
|
-
- In React components, keep one-off `className` strings inline. Only extract class name constants when the class is reused, conditionally composed, or too large to read comfortably in JSX.
|
|
19
|
-
|
|
20
|
-
# File Size And Duplication
|
|
21
|
-
|
|
22
|
-
- Keep files small. The house median is well under 50 lines; split a component before it reaches ~150 lines rather than adding section comments.
|
|
23
|
-
- Ship every scaffold file even when it is empty — `export class XInternal extends internal(srv.x, () => ({})) {}`, empty dictionary stages, the `// state` / `// action` markers in an empty store. They mark where things go.
|
|
24
|
-
- Never add a sibling helper file inside `lib/<model>/`. Helpers go to `common/`, `webkit/`, `srvkit/`, or `ui/`.
|
|
25
|
-
- Prefer duplication to premature abstraction at the leaf. Near-identical sibling modules and per-vendor pages are deliberately copied, not parameterised. Copy the file and change the literals; share enums by import only.
|
|
26
|
-
|
|
27
|
-
# TypeScript Shape
|
|
28
|
-
|
|
29
|
-
- Use `interface` for object shapes and `type` only for unions and aliases.
|
|
30
|
-
- Declare `interface <ComponentName>Props` immediately above the component with no blank line between, and put `className?: string` first. Name it for the component (`CardProps`, `WorldProps`), never for the model. Do not export it unless a sibling imports it.
|
|
31
|
-
- Never use a non-null assertion. Narrow with `?.`, an early return, or a type predicate such as `.filter((id): id is string => !!id)`.
|
|
32
|
-
- Escape with `as unknown as T`. Never `as any`.
|
|
33
|
-
- Never annotate a component's return type. Annotate a helper only when the return is a union, a tuple, or a type predicate.
|
|
34
|
-
- Use `as const` on every `enumOf(...)` array, every `via(Model, [...] as const, …)` Light tuple, and every module-scope lookup map. Never use the TypeScript `enum` keyword.
|
|
35
|
-
- Async functions carry no `Async` suffix.
|
|
36
|
-
|
|
37
|
-
# Test Code
|
|
38
|
-
|
|
39
|
-
- Write TypeScript tests with Bun's test runner and import `describe`, `expect`, and `test` from `bun:test`.
|
|
40
|
-
- Keep tests colocated with the source they cover using `*.test.ts` or `*.spec.ts`, following the existing nearby pattern.
|
|
41
|
-
- Prefer focused behavior tests for public contracts and edge cases over implementation-detail assertions.
|
|
42
|
-
- Split signal tests in two. `<model>.signal.spec.ts` holds reusable fixtures built on `sampleOf(cnst.XInput)` with explicit `Promise<cnst.X>` return types and **no assertions**. `<model>.signal.test.ts` holds the assertions: `describe("<Model> Signal")`, `let` fixtures at describe scope, one `beforeAll`, story-ordered `it`s, and negatives via `await expect(p).rejects.toThrow()`.
|
|
43
|
-
- `lib/user/user.signal.spec.ts` is the one place agent types are re-exported and re-typed; import `UserAgent` / `AdminAgent` from there rather than from the shared lib directly.
|
|
44
|
-
- A placeholder `it` with a descriptive title is an acceptable floor. Write a real suite when the behaviour is security-relevant.
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Akan domain module file roles and naming conventions
|
|
3
|
-
globs: apps/**/lib/**/*.{ts,tsx},libs/**/lib/**/*.{ts,tsx}
|
|
4
|
-
alwaysApply: false
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Domain Module Conventions
|
|
8
|
-
|
|
9
|
-
- Organize business concepts as domain folders under `lib/`; keep related schema, service, signal, store, and UI files together.
|
|
10
|
-
- Use lowercase logic files such as `<model>.constant.ts`, `<model>.document.ts`, `<model>.service.ts`, `<model>.signal.ts`, `<model>.dictionary.ts`, and `<model>.store.ts`.
|
|
11
|
-
- Use PascalCase React component files such as `<Model>.Template.tsx`, `<Model>.Unit.tsx`, `<Model>.View.tsx`, `<Model>.Zone.tsx`, and `<Model>.Util.tsx`.
|
|
12
|
-
- Treat `constant.ts`, `dictionary.ts`, and `signal.ts` as shared contract files that should avoid platform-specific dependencies.
|
|
13
|
-
- Keep backend persistence/query logic in `.document.ts` and domain business orchestration in `.service.ts`.
|
|
14
|
-
- Keep frontend state in `.store.ts`; use `Template` for forms, `Unit` for list/card items, `View` for details, `Zone` for composed page sections, and `Util` for domain-specific UI helpers.
|
|
15
|
-
- Move reusable workflow state and actions from client UI into `<model>.store.ts` when they span loading state, selected lists, messages, or multi-step actions; consume them as `st.use.someState()` and `st.do.someAction()`.
|
|
16
|
-
- Keep `Util` components thin when a store action exists: render controls, call `st.do.*`, read `st.use.*`, and leave orchestration in the store.
|
|
17
|
-
- When adding or formalizing a public workflow such as importing an existing project, update the module `*.abstract.md` with the invariant or behavior change.
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Formatting and linting conventions
|
|
3
|
-
alwaysApply: true
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Formatting And Linting
|
|
7
|
-
|
|
8
|
-
- Use Biome as the formatter and linter.
|
|
9
|
-
- Format with `bun run akan lint <appName>` from the repo root.
|
|
10
|
-
- Keep formatting consistent with `biome.json`: 2-space indentation, 120 line width, and double quotes for JS/TS.
|
|
11
|
-
- Avoid adding new `console` usage except accepted methods such as `console.error`, `console.info`, and `console.warn`.
|
|
12
|
-
- Do not make broad formatting-only changes in unrelated files.
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Lint rules that break the build, including several whose correct output looks wrong
|
|
3
|
-
alwaysApply: true
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Lint-Enforced Rules (These Break The Build)
|
|
7
|
-
|
|
8
|
-
Enforced by `biome.json` and the Akan grit plugins registered in `biome.json`. Several of them produce output that looks wrong; do not "fix" it back.
|
|
9
|
-
|
|
10
|
-
- **Never hand-order Tailwind classes.** `nursery/useSortedClasses` is an error and also sorts the string arguments to `clsx()` and `cva()`. Sorter output such as `font-bold text-2xl text-base-content` or `border-base-content/5 border-t` is correct. Write the classes in any order, run the formatter, leave the result.
|
|
11
|
-
- **Never `throw new Error`.** Throw `new Err("<module>.error.<key>")` and register the key as `[en, ko]` in that module's dictionary `.error({})`. Import `Err` from `"../dict"` on the server and from `"@libs/<lib>/client"` or `"@apps/<app>/client"` in UI. `no-throw-raw-error.grit` exempts `*.test.ts`, `*.spec.ts`, `*.constant.ts`, and `common/**` — `common/` has no legal `Err` import path, so keep throwing code out of it.
|
|
12
|
-
- **Never import a third-party package** from `page/**`, from any barrel, or from any `*.{constant,dictionary,document,service,signal,store}.ts` / `*.{Template,Unit,Util,View,Zone}.tsx` (`no-import-external-library.grit`). Re-export the symbol through a lib first. One-line re-export shims such as `libs/<lib>/base/<pkg>.ts` and `libs/<lib>/webkit/<hook>.ts` exist for exactly this reason — they are load-bearing, not cruft. Do not delete them.
|
|
13
|
-
- **`#private` is banned in exactly four file suffixes:** `*.constant.ts`, `*.document.ts`, `*.service.ts`, and `*.store.ts` (`no-js-private-class-method.grit`). The rule is scoped by file path, not by class shape, so `#private` remains the house style everywhere under `srvkit/`, including `adapt()` adapter classes.
|
|
14
|
-
- **No `console.log` / `console.debug`.** Only `assert`, `error`, `info`, and `warn` are allowed. Server code uses the injected `this.logger.*` or `new Logger("ClassName")`.
|
|
15
|
-
- **Never redeclare a generated CRUD endpoint name** in `*.signal.ts` (`no-redeclare-predefined-endpoint.grit`).
|
|
16
|
-
- **No deep imports past a barrel** (`no-deep-internal-import.grit`). Cross-module constant references such as `../map/map.constant` are the sanctioned exception.
|
|
17
|
-
- **Server-component discipline** is enforced on `page/**`, `*.Unit.tsx`, and `*.View.tsx` (`no-import-client-functions.grit`, `no-use-client-in-server.grit`, `non-scalar-props-restricted.grit`).
|
|
18
|
-
- `noArrayIndexKey` and `useExhaustiveDependencies` are **off** on purpose: `key={idx}` for embedded scalars and short dependency arrays are intentional, not oversights.
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Per-file shape for constant, document, service, signal, store, dictionary, and abstract files
|
|
3
|
-
globs: apps/**/lib/**/*.{ts,tsx,md},libs/**/lib/**/*.{ts,tsx,md}
|
|
4
|
-
alwaysApply: false
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Module File Playbook
|
|
8
|
-
|
|
9
|
-
## `<model>.constant.ts`
|
|
10
|
-
|
|
11
|
-
Five classes in order with one blank line between them and `enumOf("camelName", [...] as const)` classes above: `XInput → XObject → LightX → X → XInsight`. Write `XInsight` even when it is empty.
|
|
12
|
-
|
|
13
|
-
- Put display and predicate logic on `LightX` (`isNew()`, `canWrite(user?)`, `formatTimes()`, `isCancellable()`) — the Light class is the one both server and client hold, so shared logic belongs there instead of in a util module. This is the most commonly missed rule in the codebase.
|
|
14
|
-
- Collection-level helpers go `static` on the full model.
|
|
15
|
-
- Defaults are a literal for scalars and a thunk for anything constructed. Arrays are `field([T])`; optional is the postfix `.optional()`.
|
|
16
|
-
- Give any field whose business meaning is not obvious a short trailing comment.
|
|
17
|
-
|
|
18
|
-
## `<model>.document.ts`
|
|
19
|
-
|
|
20
|
-
Fixed order: `XFilter extends from(...)` → `X extends by(...)` → `XModel extends into(...)`, with `sort: {}` always present.
|
|
21
|
-
|
|
22
|
-
- Chain methods validate → mutate → `return this`, and never `save()`; the caller saves, so chains compose (`org.removeUser(id).removeInvite(id).save()`).
|
|
23
|
-
- Put a one-line comment above each chain method stating the transition.
|
|
24
|
-
- Atomic counters live on the Model class with the updater-callback form, returning `!!modifiedCount`.
|
|
25
|
-
- Indexes and derived totals go in `static override _onSchema`, not in the service.
|
|
26
|
-
|
|
27
|
-
## `<model>.service.ts`
|
|
28
|
-
|
|
29
|
-
- Keep methods to a few lines: load → chain → `return await ….save()`. Write `return await` explicitly in tail position; do not "optimize" it away.
|
|
30
|
-
- Side effects belong in `override async _preUpdate` / `_postCreate`, not inline.
|
|
31
|
-
- Fire-and-forget is explicitly `void`-ed.
|
|
32
|
-
- Order deliberately: load every referenced document, then save, then notify.
|
|
33
|
-
- Return `null` / `false` for "not allowed" or "not found" and let the signal decide whether that is an error.
|
|
34
|
-
|
|
35
|
-
## `<model>.signal.ts`
|
|
36
|
-
|
|
37
|
-
- `XInternal` → `XSlice` → `XEndpoint`, all three declared even when empty. `exec` is a one-liner delegating to the service.
|
|
38
|
-
- Every `slice()` takes an explicit `{ guards: {…} }` second argument, and `root:` is always `Admin`.
|
|
39
|
-
- Every custom `mutation` / `query` / `message` names its own `guards: [...]` array. `Public` belongs on a slice `get:`, never on a mutation.
|
|
40
|
-
- The acting user arrives via `.with(Self)` / `.with(CurrentUserId)` / `.with(Me)`. Never trust a client-supplied id.
|
|
41
|
-
|
|
42
|
-
## `<model>.store.ts`
|
|
43
|
-
|
|
44
|
-
- Write a custom action only for a toast, an optimistic update, or a multi-field write; most stores need none, because state and CRUD actions are generated.
|
|
45
|
-
- The body is three lines: `await fetch.X` → `this.setX(...)` → toast. The optimistic shape is mutate the client model, `void fetch.*`, then commit.
|
|
46
|
-
- Use `this.pick(...)` when the value must exist, `this.get()` when it may not, and `this.set({...})` to write.
|
|
47
|
-
- Mutate lists through the collection API (`this.set({ xList: xList.set(x).save() })`), not array spread.
|
|
48
|
-
- **Never `import type { RootStore } from "../st"`** — it crashes `akan build` with a Bun SSR segfault.
|
|
49
|
-
- Store actions do not `try/catch`; let the framework toast the `Err`.
|
|
50
|
-
|
|
51
|
-
## `<model>.dictionary.ts`
|
|
52
|
-
|
|
53
|
-
Fixed chain, with empty stages still written: `.of() → .model() → .insight() → .query() → .sort() → .enum() → .slice() → .endpoint() → .error() → .translate()`.
|
|
54
|
-
|
|
55
|
-
- Every label is `t(["English", "한국어"])`, and nearly every one also carries `.desc([en, ko])`.
|
|
56
|
-
- Name every argument in `.arg()`, including framework-supplied `skip` / `limit` / `sort`.
|
|
57
|
-
- Use `modelDictionary`, `scalarDictionary`, or `serviceDictionary` to match the module kind.
|
|
58
|
-
|
|
59
|
-
## `<module>.abstract.md`
|
|
60
|
-
|
|
61
|
-
A title line, one declarative sentence naming what the module owns, a `## Rules` list of two to five invariants the code cannot show, and an optional workflow arrow chain (`draft -> signed -> active -> completed`). Never restate field lists or types. Update it whenever an invariant or workflow changes.
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Naming conventions for components, methods, slices, booleans, and language choice
|
|
3
|
-
alwaysApply: true
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Naming And Language
|
|
7
|
-
|
|
8
|
-
- Component exports are role names — `Card`, `Sticker`, `General`, `Preview`, `Admin`, `World`, `Mesh`, `Remove`. The model comes from the namespace (`<Floor.Unit.Card>`), so never write `FloorCard`. `Util` exports are the endpoint verb minus the model noun (`Serve`, `Refund`, `Complete`, `Terminate`).
|
|
9
|
-
- Layer the verbs: the document chain method drops the model (`sign()`, `approve()`), the service keeps the bare verb, and the signal, store, and dictionary re-add it (`signScContract`). This keeps custom endpoints clear of generated CRUD and makes `st.do.X` read the same as `fetch.X`.
|
|
10
|
-
- Slice and filter names are prepositional: `inOrg`, `inProject`, `inPeriod`, `byStatuses`, `ofPortfolio`. Never `getXInY`, never `listX`.
|
|
11
|
-
- Handlers are `onX` props taking inline arrows. Do not extract a `handleX`.
|
|
12
|
-
- Booleans are `is*` / `has*` / `can*` / `show*` / `disable*`. Counters are `*Num`, indices are `idx`, collections are `*List` or plural. `SCREAMING_SNAKE` is unused; module-scope tables are camelCase + `as const`.
|
|
13
|
-
- Keep existing domain vocabulary and its typos. Transliterated domain terms and misspelled identifiers already in use are load-bearing — renaming them silently breaks callers that match on the name.
|
|
14
|
-
- Identifiers, type names, endpoint names, and log messages are **English, always**. Everything a user reads goes through `l("model.field")` or `l.trans({ en, ko })` — never a hard-coded string in JSX, never `window.alert`.
|
|
15
|
-
- Dictionary entries are `[en, ko]` pairs, and nearly every label also carries a `.desc([en, ko])` even when it repeats the label. English labels are Title Case, Korean is the plain domain term, and `.error()` Korean ends in `다.`.
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: React component, form, and Tailwind/daisyUI styling conventions
|
|
3
|
-
globs: **/*.tsx
|
|
4
|
-
alwaysApply: false
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# React Components And Styling
|
|
8
|
-
|
|
9
|
-
- Components are `export const X = ({ … }: XProps) => { return (…); };` — arrow const with a block body. `export default` is reserved for pages, layouts, and `lazy()` targets.
|
|
10
|
-
- Never `React.FC`, never `defaultProps`, never `PropsWithChildren`. Defaults go in the destructuring (`prefix = ""`); children are typed `children: ReactNode`.
|
|
11
|
-
- `"use client"` on line 1 above the imports is mechanical by file role: every `.Zone.tsx`, `.Template.tsx`, and `.Util.tsx` has it; no `.Unit.tsx` or `.View.tsx` ever does. `usePage()` is legal in server files.
|
|
12
|
-
- Conditional render is `cond ? <X/> : null`. Never `{cond && <X/>}` — in a `className` context it renders the literal string `"false"`. Early `return null` is for guard clauses only.
|
|
13
|
-
- Never hand-roll loading, empty, or list states. Use `Load.Units` / `Load.View` / `Load.Edit` with `renderItem`, `renderList`, `renderView`, and `renderEmpty`; `<Empty />` for a bare placeholder; and `Model.New` / `Model.Edit` / `Model.SureToRemove` for CRUD modals.
|
|
14
|
-
- Avoid hooks. `useState` is for modal-open, tab, draft-input, and drag state only — never for server data. `useEffect` must be a genuine effect such as subscribe-with-cleanup or one-shot init. Prefer `Tab` over a `useState` mode switch. `.Template.tsx` files contain zero `useState`.
|
|
15
|
-
- Forms are entirely store-driven: `value={xForm.field}` with `onChange={st.do.setFieldOnX}`, the setter passed by reference. Always use `Field.*`, never a bare `<input>` for a model field. Nested rows use `st.do.writeOnX("payments.3.name", v)` plus the generated `add<Field>OnX` / `sub<Field>OnX`.
|
|
16
|
-
- Read with `st.use.*` and write with `st.do.*`. Client components do not call `fetch.*`.
|
|
17
|
-
- Static class strings stay plain strings. Reach for `clsx` only for a conditional or to merge an incoming `className`, and merge the caller last: `clsx("base classes", conditional, className)`. `clsx` comes from `akanjs/client`. No `twMerge`, no `cn()`.
|
|
18
|
-
- Multi-slot components take extra named props (`wrapperClassName`, `bodyClassName`), never a `classNames` object.
|
|
19
|
-
- Use daisyUI semantic tokens with opacity modifiers (`text-base-content/60`, `border-base-content/10`, `bg-base-100/70`, `bg-primary/10`). Never use `dark:` — theming is the daisyUI theme block in `page/*/styles.css`. Raw hex belongs only in marketing surfaces; match the neighbouring files.
|
|
20
|
-
- Hoist enum→class lookups to a module-scope `as const` map typed `{ [key in cnst.XStatus["value"]]: string }`. Do not use `Record<...>`. Escalate the map to `webkit/` when a second module needs it.
|
|
21
|
-
- Use `<Link>` from `akanjs/ui` for internal navigation; `<a>` only for `mailto:` and external links.
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Akan.js monorepo structure and ownership conventions
|
|
3
|
-
alwaysApply: true
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Repo Overview
|
|
7
|
-
|
|
8
|
-
- Akan.js is a full-stack TypeScript framework for building all-stack applications at once.
|
|
9
|
-
- Write one line and deploy across web, app, server, database, and infrastructure.
|
|
10
|
-
- Akan prioritizes actual business code by abstracting technical implementation details as much as possible.
|
|
11
|
-
- The goal is minimal code, high performance, and type-safe services that can deploy to web, mobile, server, and DB infrastructure together.
|
|
12
|
-
- This is a Bun-first Akan.js monorepo.
|
|
13
|
-
- Main top-level areas are `apps/`, `libs/`, `pkgs/`, and `infra/`.
|
|
14
|
-
- `apps/<app>` contains app-level pages, domain code, UI, env files, and `akan.config.ts`.
|
|
15
|
-
- `libs/*` contains shared domain and utility libraries.
|
|
16
|
-
- `pkgs/akanjs/*` contains framework, runtime, and tooling facets published through the single `akanjs` package. Prefer extending existing Akan facets before adding new framework-level patterns.
|
|
17
|
-
- `infra/` contains Helm, deployment templates, edge configs, and Jenkins env/secret scripts.
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Akan scalar and constant model conventions
|
|
3
|
-
globs: **/*.constant.ts
|
|
4
|
-
alwaysApply: false
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Scalar Modeling
|
|
8
|
-
|
|
9
|
-
- Define Akan models in `.constant.ts` files with `via` from `akanjs/constant`.
|
|
10
|
-
- Use `Int` for whole-number counts and quantities; use `Float` only for values that need decimals.
|
|
11
|
-
- Use `ID` for document references and prefer explicit structured fields over `Any` unless the content is genuinely flexible.
|
|
12
|
-
- For date defaults, prefer a function such as `default: () => dayjs()` so the value is created at runtime.
|
|
13
|
-
- Follow the established model layering pattern in this order: `Input`, `Object`, `Light<Model>`, full `<Model>`, and `<Model>Insight`. Write all five, and write `<Model>Insight` even when it is empty.
|
|
14
|
-
- Put display and predicate logic on the `Light<Model>` class (`isNew()`, `canWrite(user?)`, `formatTimes()`) rather than in a util module — the Light class is the one both server and client hold. Collection-level helpers go `static` on the full model.
|
|
15
|
-
- Defaults are a literal for scalars and a thunk for anything constructed. Arrays are `field([T])`; optional is the postfix `.optional()`.
|
|
16
|
-
- Give any field whose business meaning is not obvious a short trailing comment.
|
|
17
|
-
|
|
18
|
-
## Scalar & Field Type Reference
|
|
19
|
-
|
|
20
|
-
- **Import from `akanjs/base`** (real classes/helpers, not globals): `Int`, `Float`, `ID`, `Any`, `Upload`, `enumOf`, and the `dayjs` factory. There is **no `JSON` scalar** — use `Any` for open/flexible payloads.
|
|
21
|
-
- **Use the JS globals directly (no import needed)**: `String`, `Boolean`, `Date`. They are monkey-patched to behave like scalars, so `field(String)` typechecks.
|
|
22
|
-
- **`Number` is not a valid field/body type.** `NumberConstructor` is intentionally not augmented, so `field(Number)` / `.body("x", Number)` fails to typecheck. Use `Int` or `Float` instead.
|
|
23
|
-
- Runtime resolution of every scalar (globals included) goes through `PrimitiveRegistry` by `refName` (`pkgs/akanjs/base/primitiveRegistry.ts`).
|
|
24
|
-
|
|
25
|
-
## Text Search Fields — the `text` role
|
|
26
|
-
|
|
27
|
-
- A field joins the full-text index by declaring one of five roles: `field(String, { text: "title" })`, and likewise
|
|
28
|
-
`"desc"`, `"tag"`, `"thumb"`, `"filter"`. Nothing else opts a field in, and there is no per-model switch.
|
|
29
|
-
- Pick the role by what the value *is*, because `bm25` weights them positionally (`title` 10, `tag` 3, `desc` 1,
|
|
30
|
-
`filter` 0): `title` is the one line a human scans for, `desc` is prose, `tag` is a keyword list, `filter` is a
|
|
31
|
-
scoping value (status, owner, role) that must be matchable but must never outrank a real title hit.
|
|
32
|
-
- `thumb` is mirrored for rendering a hit and is **not** indexed — never expect it to match.
|
|
33
|
-
- **A `secret`, `hidden`, or `resolve()` field with `text` throws at class-build time**, not at query time. That is
|
|
34
|
-
deliberate: the mirror is plaintext, so an indexed secret would leak through search. Do not work around it. The
|
|
35
|
-
same throw covers a `text` field *underneath* one of those — a scalar's own field is reachable through its parent,
|
|
36
|
-
so `f.secret(Noti)` where `Noti.label` carries a role is rejected at the parent, not silently indexed.
|
|
37
|
-
- The role works on a relation too (`image: field(File, { text: "thumb" })`) and on an array (`playing: field([String],
|
|
38
|
-
{ text: "tag" })`); an array of objects indexes by leaf key, including an array leaf (`works[*].tags`). A field
|
|
39
|
-
inside a `Map` indexes nothing: there is no fixed path to extract it from.
|
|
40
|
-
- Declaring roles is all the wiring there is. Mirror rows are maintained by SQL triggers — not document hooks —
|
|
41
|
-
because `updateOneByQuery` and friends fire no hooks, and most searchable-field mutations go through exactly that
|
|
42
|
-
path.
|
|
43
|
-
- Search runs on sqlite/libsql only. `q.search()` against Postgres throws, loudly, rather than returning every row.
|
|
44
|
-
- `AKAN_SEARCH_ENABLED=0` switches the index off process-wide; unset means on. It never deletes mirror data, and
|
|
45
|
-
re-enabling reconciles every ref. **Give every process the same value** — a process cannot drop triggers for models
|
|
46
|
-
it does not mount, so a mixed fleet leaves stale triggers behind.
|
|
47
|
-
- The tokenizer is `AKAN_SEARCH_TOKENIZER` (or `database.search.tokenizer`, which wins), defaulting to
|
|
48
|
-
`unicode61 remove_diacritics 2`. Changing it rebuilds the index from the mirror on the next boot — the model
|
|
49
|
-
tables are never re-read — so it is a safe knob, unlike a `text` role change, which re-reads every row. The
|
|
50
|
-
rebuild takes no cross-process claim, so a fleet restarted at once repeats it in every process; stagger the
|
|
51
|
-
restart when the mirror is large.
|
|
52
|
-
|
|
53
|
-
## Image & File Fields
|
|
54
|
-
|
|
55
|
-
- **Do not declare `Upload` as a model field.** `Upload` is a signal-body-only primitive. Models reference the `File` model instead.
|
|
56
|
-
- Declare an image/file field as a relation to `File`: `image: field(File).optional()` for one, `images: field([File])` for many (see `libs/shared/lib/user/user.constant.ts`, `libs/shared/lib/banner/banner.constant.ts`).
|
|
57
|
-
- The store then auto-generates an `upload<Field>On<Model>(fileList)` action that calls the framework upload mutation and polls file status until it leaves `"uploading"` (`pkgs/akanjs/store/action.ts`).
|
|
58
|
-
- Storage is wired through the `StorageAdaptor` DI role (default `BlobStorage`, `pkgs/akanjs/service/predefinedAdaptor/storage.adaptor.ts`); the reference implementation is the `file` lib (`libs/shared/lib/file/*`). Do not hand-roll data-URL fallbacks.
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Secret and environment file safety conventions
|
|
3
|
-
globs: .env,**/.env,**/*.env,infra/**/*,**/*secret*,**/*Secret*,**/*credential*,**/*Credential*
|
|
4
|
-
alwaysApply: false
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Secrets And Env Safety
|
|
8
|
-
|
|
9
|
-
- Never print, summarize, commit, or expose real secret values, credentials, tokens, private keys, or `.env` contents.
|
|
10
|
-
- If env keys are needed for documentation, list only key names and example placeholders, not live values.
|
|
11
|
-
- Preserve the existing env/secret flow through root scripts such as `bun run downloadEnv`, `bun run uploadEnv`, `bun run downloadSecret`, and `bun run uploadSecret`.
|
|
12
|
-
- When editing infra env or secret scripts, keep Jenkins and deployment assumptions intact unless the task explicitly asks to change them.
|
|
13
|
-
- Treat generated env/secret artifacts as sensitive even when they are not named `.env`.
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: Akan service, signal, and adapter conventions
|
|
3
|
-
globs: apps/**/lib/**/*.{service,signal}.ts,libs/**/lib/**/*.{service,signal}.ts,apps/**/server/**/*.ts,libs/**/server/**/*.ts
|
|
4
|
-
alwaysApply: false
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Service And Signal Conventions
|
|
8
|
-
|
|
9
|
-
- Keep domain business operations in `.service.ts` classes built with `serve(...)`.
|
|
10
|
-
- Keep execution contracts and triggers in `.signal.ts` classes built with `internal(...)`, `slice(...)`, and `endpoint(...)`.
|
|
11
|
-
- Use `Internal` for internal triggers such as init, interval, cron, or queue jobs.
|
|
12
|
-
- Use `Slice` for typed data views that feed client stores and zones; keep each slice focused on one purpose.
|
|
13
|
-
- Use `Endpoint` for query and mutation contracts exposed to callers.
|
|
14
|
-
- Connect external APIs or infrastructure through adapters, usually under `srvkit/`, and inject them into services instead of importing vendor clients directly into domain logic.
|
|
15
|
-
|
|
16
|
-
## Guards And Transports
|
|
17
|
-
|
|
18
|
-
- Guards run on both HTTP and websocket calls. Read the caller with `context.get<T>("account")` (`pkgs/akanjs/signal/signalContext.ts`) instead of branching on `getHttpContext()` / `getWebSocketContext()`.
|
|
19
|
-
- Slice-level `guards` only reach the generated query/mutation endpoints. A `pubsub`/`message` endpoint is unguarded unless it declares its own `guards` in its signal option.
|
|
20
|
-
- A pubsub room is authorized once, at subscribe. When a socket's credential changes the framework re-runs each room's guards and unsubscribes the ones that now fail (`SignalResolver.revalidateWsRooms`), so guards must stay side-effect free and safe to re-run.
|
|
21
|
-
- A websocket carries its credential in the handshake snapshot on `ws.data` (`AppWsData`); clients that hold the token in memory send it with `fetch.setJwt(...)`, which forwards an auth frame over the socket.
|
|
22
|
-
|
|
23
|
-
## Authorization Defaults
|
|
24
|
-
|
|
25
|
-
- **Every `slice()` takes an explicit `{ guards: {…} }` second argument, and `root:` is always `Admin`.**
|
|
26
|
-
- **Every custom `mutation` / `query` / `message` names its own `guards: [...]` array.** Never rely on the slice default. `Public` belongs on a slice `get:`, never on a mutation.
|
|
27
|
-
- The acting user arrives via `.with(Self)` / `.with(CurrentUserId)` / `.with(Me)`. Never trust a client-supplied id.
|
|
28
|
-
- Services re-check ownership even when a guard already gated the call — two independent gates.
|
|
29
|
-
- Guard class shape, fail-closed rules, and the `static name = "User"` requirement live in the srvkit adapters and guards rule.
|
|
30
|
-
|
|
31
|
-
## Service Method Shape
|
|
32
|
-
|
|
33
|
-
- Keep methods to a few lines: load → chain → `return await ….save()`. Write `return await` explicitly in tail position; do not "optimize" it away.
|
|
34
|
-
- Side effects belong in `override async _preUpdate` / `_postCreate`, not inline. Fire-and-forget is explicitly `void`-ed.
|
|
35
|
-
- Order deliberately: load every referenced document, then save, then notify.
|
|
36
|
-
- Return `null` / `false` for "not allowed" or "not found" and let the signal decide whether that is an error.
|
|
37
|
-
- `XInternal` → `XSlice` → `XEndpoint` are all declared even when empty, and `exec` is a one-liner delegating to the service.
|
|
38
|
-
|
|
39
|
-
## Signal Body Types
|
|
40
|
-
|
|
41
|
-
- `.body(...)` / `.param(...)` args accept `ConstantFieldTypeInput` only: scalars, model refs, or `enumOf(...)`.
|
|
42
|
-
- Numbers must use `Int` or `Float` — `Number` is rejected (`pkgs/akanjs/signal/endpointInfo.ts`).
|
|
43
|
-
- `Upload` is valid only inside a mutation flagged for file upload: `mutation([cnst.File], { fileUpload: true }).body("files", [Upload])` (see `libs/shared/lib/file/file.signal.ts`). It is not a model field type.
|
|
44
|
-
|
|
45
|
-
## Reserved Endpoint Names
|
|
46
|
-
|
|
47
|
-
- Auto-generated CRUD endpoints (e.g. `create<Model>`, `update<Model>`, `remove<Model>`) already exist for every model. Do not declare an `Endpoint`/`Slice` with a name that collides with them.
|
|
48
|
-
- The service layer surfaces such a collision as a typecheck error, but the signal layer can pass sync/typecheck/build and fail only at runtime — so treat name collisions as errors regardless of whether the build is green.
|
|
49
|
-
|
|
50
|
-
## Slices, Queries, and Hydration
|
|
51
|
-
|
|
52
|
-
- A slice's `exec` returns a `QueryOf` (an opaque query descriptor, `pkgs/akanjs/constant/types.ts`); you **cannot** chain `.sort()`/`.limit()` on it.
|
|
53
|
-
- Apply ordering/paging via the store `init` fetch option instead: `initX(..., { sort, page, limit })` (`pkgs/akanjs/fetch/fetchType/sliceFetch.type.ts`).
|
|
54
|
-
- Generated list accessors like `listBy(...)` return `Promise<Doc[]>`. For a chainable builder (`.sort().skip().limit().select()`) use the model facade's `findMany`/`findOne` (`FindManyChain`, `pkgs/akanjs/document/into.ts`).
|
|
55
|
-
- **Hydrated vs raw:** server queries return hydrated `cnst.<Model>` instances (with `set`/`save`/`refresh`); client fetch results are raw `GetStateObject` plain data (functions stripped, `pkgs/akanjs/base/types.ts`).
|
|
56
|
-
|
|
57
|
-
## Text Search In A Filter — `q.search()`
|
|
58
|
-
|
|
59
|
-
- Text search is a filter query node like any other: `bySearch: filter().arg("text", String).query((text, q) =>
|
|
60
|
-
q.search(text, { prefix: true }))`. The generated `listBySearch` / `countBySearch` / `queryBySearch` /
|
|
61
|
-
`insightBySearch` come for free — you do **not** need a slice to make search usable.
|
|
62
|
-
- **Only add a search slice when the model's data is safe to enumerate.** A filter is server-side; a slice is a
|
|
63
|
-
client-callable endpoint, so on a model whose slice `get:` is `Public` a search slice hands anyone a way to walk the
|
|
64
|
-
table. Leave that decision to the mounting app.
|
|
65
|
-
- `q.search()` compiles to a JOIN, not a WHERE fragment, so it **must sit at an AND position**. Nesting it under
|
|
66
|
-
`q.any()` or `q.not()` throws, and it is rejected in `updateOneByQuery` / `updateManyByQuery` — a query-level write
|
|
67
|
-
takes no join, so ignoring the node would silently widen the write to every other matching row.
|
|
68
|
-
- Blank or whitespace-only input matches **nothing**. Never "fix" that into a passthrough: a passthrough turns a
|
|
69
|
-
search endpoint into a full listing.
|
|
70
|
-
- Order by relevance with the built-in `relevance` sort key. It is an empty sort map, which the store reads as
|
|
71
|
-
"unspecified": score order when a search join is present, `createdAt` descending otherwise. That fallback is the
|
|
72
|
-
compiler's own, not a model-defined default — redefining `latest` on the model does not change it.
|
|
73
|
-
- **A slice endpoint never reaches "unspecified".** The resolver fills `latest` before the query is built, so a
|
|
74
|
-
client asking for the score order has to name `relevance`; leaving `sort` off gets `latest`, not relevance.
|
|
75
|
-
- Scope a search with `columns` (`q.search(text, { columns: ["title"] })`) and re-weight with `weights`, a tuple of
|
|
76
|
-
finite numbers positional over `["title", "desc", "tag", "filter"]`.
|
|
77
|
-
|
|
78
|
-
## Service / Signal Injection
|
|
79
|
-
|
|
80
|
-
- Injected dependencies resolve by field-name convention: a field named `<refName>Service` resolves to the service registered under `<refName>`, and `<refName>Signal` likewise (`pkgs/akanjs/service/injectInfo.ts`).
|
|
81
|
-
- The `Service`/`Signal` suffix is required — the injector strips it to derive the registry lookup key. Name the field after the target refName plus the suffix, not arbitrarily.
|
|
82
|
-
- Preference order inside a service: `service<srv.XService>()` for another module's service · `plug(AdapterClass)` or `plug(StorageAdaptorRole)` for an adapter · `use<T>()` only to reach an `option.ts`-registered legacy singleton · `env(...)` for config.
|
|
83
|
-
- New adapters are `adapt("name" as const, ({ use, env, plug, memory }) => ({…}))` classes in `srvkit/` that self-register — do not add them to `lib/option.ts`. See the srvkit adapters and guards rule.
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: srvkit adapter (adapt/plug), guard, and error-handling conventions
|
|
3
|
-
globs: apps/**/srvkit/**/*.ts,libs/**/srvkit/**/*.ts
|
|
4
|
-
alwaysApply: false
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Adapters — `adapt()` And `plug()`
|
|
8
|
-
|
|
9
|
-
An injected singleton is an `adapt()` class in `srvkit/`. Write new adapters this way.
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
export class AdminNoti extends adapt("adminNoti" as const, ({ use, env, plug, memory }) => ({
|
|
13
|
-
discordApi: use<DiscordApi>(),
|
|
14
|
-
workspaceRoot: env(() => `~/build/${getEnv().environment}`),
|
|
15
|
-
masterHost: plug(MasterHost),
|
|
16
|
-
tokenMap: memory(Map, { of: String }),
|
|
17
|
-
})) {}
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
- Inject it with `plug(TheClass)` from a service or from another adapter. Destructure only the injectors you use, and write the registration key `as const`.
|
|
21
|
-
- **Do not register an `adapt()` class in `lib/option.ts`.** It self-registers, and `plug(Class)` uses the class itself as the token. `option.ts` is now only for legacy constructor-style adapters and for widening the options type.
|
|
22
|
-
- `this.logger` is provided; never construct a `Logger` inside an `adapt()` class. Lifecycle work goes in `override async onInit()`.
|
|
23
|
-
- `#private` is the house style here — the `#private` lint ban covers only `*.constant.ts`, `*.document.ts`, `*.service.ts`, and `*.store.ts`.
|
|
24
|
-
- **`adapt()` is for singletons only.** A per-use value object stays a plain class you `new` at the call site. Ask whether there is exactly one per process that a service needs injected; if not, it is a plain class.
|
|
25
|
-
- **Legacy shape — recognise it, do not copy it.** Plain classes with `constructor(options: XOptions)`, registered in `lib/option.ts` as `options.x ? new XApi(options.x) : null` and injected with `use<T>()`, still work. Migrate one to `adapt()` only when you are already changing it.
|
|
26
|
-
- Preference order inside a service: `service<srv.XService>()` for another module's service · `plug(AdapterClass)` or `plug(StorageAdaptorRole)` for an adapter · `use<T>()` only to reach an `option.ts`-registered legacy singleton · `env(...)` for config.
|
|
27
|
-
|
|
28
|
-
Conventions that hold for both shapes:
|
|
29
|
-
|
|
30
|
-
- Route every remote call through one private `#api<T>(path, init?)` with `signal: AbortSignal.timeout(20_000)`.
|
|
31
|
-
- Paginate with `for (let page = 1; ; page += 1)` broken by `if (pageItems.length < 100) break;`.
|
|
32
|
-
- Resolve secrets as `process.env.X ?? options.x ?? deterministicGenerator(...)` **inside a function**, never at module scope.
|
|
33
|
-
- Extend a function by appending an optional trailing parameter with a default, never by changing arity.
|
|
34
|
-
- Parameters: up to three required primitives positional; optional flags in a trailing `{ … } = {}`; four or more parameters, or any two same-typed strings, in one named destructured object.
|
|
35
|
-
- Release locks in `finally`. Load heavy optional dependencies through a module-level memoized promise (`sharpLoad ??= import("sharp")`).
|
|
36
|
-
|
|
37
|
-
# Guards (`srvkit/guards.ts`)
|
|
38
|
-
|
|
39
|
-
- Resource guards are `Can<Verb><Model>` classes that `implements Guard` with an `async canPass(context)`.
|
|
40
|
-
- They **fail closed**: no resource named ⇒ `false`; a load that throws ⇒ `logger.warn` then `false`. Admin bypass goes first.
|
|
41
|
-
- Keep `static name = "User";` on guard classes. `fetch` serializes guard names and the API explorer filters on them; it looks like dead code, and deleting it breaks the UI. Comment it so the next reader knows.
|
|
42
|
-
- Guards ship with the library that owns the model and are imported by its own signals through the package path, so a mounting app inherits authorization and cannot forget it.
|
|
43
|
-
- Services re-check ownership even when a guard already gated the call — two independent gates.
|
|
44
|
-
- This file earns real comments: explain what would leak without each guard.
|
|
45
|
-
|
|
46
|
-
# Error Placement
|
|
47
|
-
|
|
48
|
-
- State-machine preconditions throw in `document.ts`; cross-document rules throw in `service.ts`; request-level policy belongs in signal guards.
|
|
49
|
-
- Best-effort code returns a sentinel (`null`, `undefined`, `[0, 0]`, `{}`). There are no Result/Either wrappers.
|
|
50
|
-
- `try/catch` is rare and always converts an exception into a decision, never swallows one. Guards catch → `logger.warn` → `return false`; adapters catch → `logger.error` → `return null`; UI uses `try/finally` to reset a spinner. A bodyless `catch {}` is acceptable only with a one-line reason.
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: TypeScript and import conventions
|
|
3
|
-
globs: **/*.{ts,tsx}
|
|
4
|
-
alwaysApply: false
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# TypeScript And Imports
|
|
8
|
-
|
|
9
|
-
- Use Bun and ESM assumptions from the root `tsconfig.json`.
|
|
10
|
-
- Prefer path aliases over deep relative imports when crossing package boundaries.
|
|
11
|
-
- Use `akanjs/*` for framework facets, `@apps/*` for apps, `@libs/*` for shared libs, and `@contract/*` for contract code.
|
|
12
|
-
- Respect existing client/server entrypoints such as `@libs/shared/client`, `@libs/shared/server`, `@apps/myapp/client`, and `@apps/myapp/server`.
|
|
13
|
-
- Let Biome organize imports instead of manually reshuffling unrelated imports.
|
|
14
|
-
- Namespace the generated barrels in backend `.ts` files: `import * as cnst from "../cnst"`, `* as db`, `* as srv`. Use `import type * as srv` in services so the runtime graph stays lazy, and a value import in signals.
|
|
15
|
-
- In `.tsx` files use one flat named import from the package client path (`import { cnst, fetch, st, Task, usePage } from "@apps/myapp/client"`) — never a relative `../` import.
|
|
16
|
-
- Never import a third-party package from a page, a barrel, or a module file; re-export it through a one-line shim in `base/`, `webkit/`, or `ui/` first.
|
|
File without changes
|