@20baht/cli 0.0.0-stage → 0.1.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.
Files changed (140) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +214 -2
  3. package/dist/application/create.js +72 -0
  4. package/dist/application/generate.js +239 -0
  5. package/dist/application/ports.js +1 -0
  6. package/dist/args.js +49 -0
  7. package/dist/cli.js +207 -0
  8. package/dist/domain/blueprint.js +6 -0
  9. package/dist/domain/create-plan.js +59 -0
  10. package/dist/domain/deploy-plan.js +82 -0
  11. package/dist/domain/form-dsl.js +120 -0
  12. package/dist/domain/generate-plan.js +60 -0
  13. package/dist/domain/naming.js +18 -0
  14. package/dist/domain/remote-plan.js +153 -0
  15. package/dist/domain/template-path.js +19 -0
  16. package/dist/infrastructure/fs-reader.js +19 -0
  17. package/dist/infrastructure/fs-writer.js +27 -0
  18. package/dist/infrastructure/shell-runner.js +32 -0
  19. package/dist/infrastructure/spawn-plan.js +35 -0
  20. package/dist/infrastructure/template-renderer.js +16 -0
  21. package/dist/infrastructure/template-source.js +28 -0
  22. package/package.json +53 -4
  23. package/templates/angular/README.md.hbs +46 -0
  24. package/templates/angular/_dependency-cruiser.mjs +51 -0
  25. package/templates/angular/apps/server/package.json +30 -0
  26. package/templates/angular/apps/server/src/app.ts +14 -0
  27. package/templates/angular/apps/server/src/index.ts +8 -0
  28. package/templates/angular/apps/server/test/app.test.ts +12 -0
  29. package/templates/angular/apps/server/tsconfig.json +7 -0
  30. package/templates/angular/apps/server/tsconfig.types.json +12 -0
  31. package/templates/angular/apps/shell/_editorconfig +17 -0
  32. package/templates/angular/apps/shell/angular.json +115 -0
  33. package/templates/angular/apps/shell/federation.config.mjs +44 -0
  34. package/templates/angular/apps/shell/package.json +43 -0
  35. package/templates/angular/apps/shell/public/federation.manifest.json +1 -0
  36. package/templates/angular/apps/shell/src/app/app.config.ts +20 -0
  37. package/templates/angular/apps/shell/src/app/app.css +4 -0
  38. package/templates/angular/apps/shell/src/app/app.html.hbs +16 -0
  39. package/templates/angular/apps/shell/src/app/app.routes.ts.hbs +39 -0
  40. package/templates/angular/apps/shell/src/app/app.ts +57 -0
  41. package/templates/angular/apps/shell/src/app/core/federation/load-remote.ts +31 -0
  42. package/templates/angular/apps/shell/src/app/core/federation/manifest.spec.ts +46 -0
  43. package/templates/angular/apps/shell/src/app/core/federation/manifest.ts +37 -0
  44. package/templates/angular/apps/shell/src/app/core/federation/remote-loader.ts +20 -0
  45. package/templates/angular/apps/shell/src/app/core/federation/timeout.ts +17 -0
  46. package/templates/angular/apps/shell/src/app/modules/home/home.component.ts.hbs +46 -0
  47. package/templates/angular/apps/shell/src/app/modules/unavailable/unavailable.component.ts +39 -0
  48. package/templates/angular/apps/shell/src/bootstrap.ts +25 -0
  49. package/templates/angular/apps/shell/src/environments/environment.development.ts +10 -0
  50. package/templates/angular/apps/shell/src/environments/environment.ts +10 -0
  51. package/templates/angular/apps/shell/src/index.html.hbs +12 -0
  52. package/templates/angular/apps/shell/src/main.ts +43 -0
  53. package/templates/angular/apps/shell/src/styles.css +19 -0
  54. package/templates/angular/apps/shell/tsconfig.app.json +10 -0
  55. package/templates/angular/apps/shell/tsconfig.federation.json +4 -0
  56. package/templates/angular/apps/shell/tsconfig.json.hbs +39 -0
  57. package/templates/angular/apps/shell/tsconfig.spec.json +9 -0
  58. package/templates/angular/bahtui.json +6 -0
  59. package/templates/angular/eslint.config.ts.hbs +28 -0
  60. package/templates/angular/knip.ts +30 -0
  61. package/templates/angular/package.json.hbs +52 -0
  62. package/templates/angular/packages/kit/package.json.hbs +27 -0
  63. package/templates/angular/packages/kit/src/api.ts +21 -0
  64. package/templates/angular/packages/kit/src/errors.ts +28 -0
  65. package/templates/angular/packages/kit/src/index.ts +2 -0
  66. package/templates/angular/packages/kit/test/errors.test.ts +28 -0
  67. package/templates/angular/packages/kit/tsconfig.json +9 -0
  68. package/templates/create/README.md.hbs +32 -0
  69. package/templates/create/_github/workflows/ci.yml +56 -0
  70. package/templates/create/_gitignore +6 -0
  71. package/templates/create/_husky/pre-commit +3 -0
  72. package/templates/create/_prettierignore +3 -0
  73. package/templates/create/_prettierrc.json +4 -0
  74. package/templates/create/apps/api/package.json.hbs +21 -0
  75. package/templates/create/apps/api/src/index.test.ts.hbs +10 -0
  76. package/templates/create/apps/api/src/index.ts.hbs +14 -0
  77. package/templates/create/apps/api/tsconfig.json +7 -0
  78. package/templates/create/apps/web/index.html.hbs +20 -0
  79. package/templates/create/apps/web/package.json.hbs +24 -0
  80. package/templates/create/apps/web/src/App.tsx.hbs +31 -0
  81. package/templates/create/apps/web/src/app.css +27 -0
  82. package/templates/create/apps/web/src/health.test.ts.hbs +28 -0
  83. package/templates/create/apps/web/src/health.ts.hbs +14 -0
  84. package/templates/create/apps/web/src/main.tsx.hbs +20 -0
  85. package/templates/create/apps/web/src/vite-env.d.ts.hbs +1 -0
  86. package/templates/create/apps/web/tsconfig.json +8 -0
  87. package/templates/create/apps/web/vite.config.ts.hbs +6 -0
  88. package/templates/create/bahtui.json.hbs +7 -0
  89. package/templates/create/eslint.config.js +30 -0
  90. package/templates/create/knip.json +9 -0
  91. package/templates/create/libs/shared/eden/index.ts.hbs +9 -0
  92. package/templates/create/libs/shared/eden/package.json.hbs +15 -0
  93. package/templates/create/libs/shared/eden/tsconfig.json +4 -0
  94. package/templates/create/package.json.hbs +47 -0
  95. package/templates/create/tsconfig.base.json +17 -0
  96. package/templates/deploy/deploy/__project__.service.hbs +23 -0
  97. package/templates/deploy/deploy/env.example.hbs +4 -0
  98. package/templates/deploy/deploy/install.sh.hbs +58 -0
  99. package/templates/deploy/deploy/nginx.conf.hbs +67 -0
  100. package/templates/deploy/scripts/deploy.ts.hbs +33 -0
  101. package/templates/deploy/scripts/preview.ts.hbs +57 -0
  102. package/templates/deploy/scripts/release.ts.hbs +48 -0
  103. package/templates/new/CLAUDE.md +3 -0
  104. package/templates/new/README.md.hbs +38 -0
  105. package/templates/new/_dependency-cruiser.mjs +9 -0
  106. package/templates/new/_github/actions/setup/action.yml +15 -0
  107. package/templates/new/_github/workflows/ci.yml +122 -0
  108. package/templates/new/_gitignore +12 -0
  109. package/templates/new/_gitleaks.toml +6 -0
  110. package/templates/new/_husky/commit-msg +1 -0
  111. package/templates/new/_husky/pre-commit +8 -0
  112. package/templates/new/_husky/pre-push +1 -0
  113. package/templates/new/_jscpd.json +20 -0
  114. package/templates/new/_mcp.json +9 -0
  115. package/templates/new/_prettierignore +5 -0
  116. package/templates/new/apps/_gitkeep +0 -0
  117. package/templates/new/commitlint.config.js +1 -0
  118. package/templates/new/eslint.config.ts.hbs +7 -0
  119. package/templates/new/knip.ts +7 -0
  120. package/templates/new/lint-staged.config.js +1 -0
  121. package/templates/new/package.json.hbs +51 -0
  122. package/templates/new/packages/_gitkeep +0 -0
  123. package/templates/new/renovate.json +23 -0
  124. package/templates/new/scripts/dev.ts +54 -0
  125. package/templates/new/scripts/each.ts +29 -0
  126. package/templates/new/scripts/workspaces.ts +24 -0
  127. package/templates/new/tsconfig.base.json +3 -0
  128. package/templates/new/tsconfig.json +7 -0
  129. package/templates/remote/_editorconfig +17 -0
  130. package/templates/remote/angular.json.hbs +95 -0
  131. package/templates/remote/federation.config.mjs.hbs +48 -0
  132. package/templates/remote/package.json.hbs +38 -0
  133. package/templates/remote/src/app/__name__.routes.ts.hbs +12 -0
  134. package/templates/remote/src/app/modules/__name__/__name__.component.ts.hbs +37 -0
  135. package/templates/remote/src/app/services/__name__.service.ts.hbs +14 -0
  136. package/templates/remote/src/index.html.hbs +11 -0
  137. package/templates/remote/src/main.ts.hbs +3 -0
  138. package/templates/remote/tsconfig.app.json +10 -0
  139. package/templates/remote/tsconfig.federation.json +4 -0
  140. package/templates/remote/tsconfig.json.hbs +36 -0
@@ -0,0 +1,43 @@
1
+ import { initFederation, type NativeFederationResult } from '@angular-architects/native-federation'
2
+ import { parseManifest, type Manifest } from './app/core/federation/manifest'
3
+ import { withTimeout } from './app/core/federation/timeout'
4
+ import { federation, federationFallback } from './environments/environment'
5
+
6
+ /** How long the shell waits for the manifest, then for the remotes, before booting without them. */
7
+ const BOOT_TIMEOUT_MS = 8_000
8
+
9
+ // Only federation starts here: shared packages (@angular/*, @20baht/ui) resolve through the
10
+ // import map once initFederation is done, so everything else loads from ./bootstrap. A failed or
11
+ // slow start still boots the shell; the remotes' pages then show the fallback.
12
+ const manifest = async (): Promise<Manifest> => {
13
+ if (typeof federation !== 'string') return federation
14
+ try {
15
+ const res = await fetch(federation, { signal: AbortSignal.timeout(BOOT_TIMEOUT_MS) })
16
+ if (!res.ok) throw new Error(`federation manifest: HTTP ${String(res.status)}`)
17
+ const parsed = parseManifest(await res.json())
18
+ if (parsed === null) throw new Error('federation manifest: an entry has the wrong shape')
19
+ return parsed
20
+ } catch (err) {
21
+ console.error('federation manifest failed to load, using the built-in one', err)
22
+ return federationFallback
23
+ }
24
+ }
25
+
26
+ const start = async () => {
27
+ const remotes = await manifest()
28
+ const entries = Object.fromEntries(
29
+ Object.entries(remotes).map(([name, remote]) => [name, remote.entry]),
30
+ )
31
+ let nf: NativeFederationResult | null = null
32
+ try {
33
+ nf = await withTimeout(initFederation(entries), BOOT_TIMEOUT_MS)
34
+ } catch (err) {
35
+ console.error(err)
36
+ }
37
+ const { bootstrap } = await import('./bootstrap')
38
+ await bootstrap(nf?.loadRemoteModule ?? null, remotes)
39
+ }
40
+
41
+ start().catch((err: unknown) => {
42
+ console.error(err)
43
+ })
@@ -0,0 +1,19 @@
1
+ /* @20baht/ui's tokens.css comes first (angular.json); this file only sets the page up. */
2
+ html,
3
+ body {
4
+ margin: 0;
5
+ min-height: 100dvh;
6
+ background: var(--baht-color-bg);
7
+ color: var(--baht-color-text);
8
+ font-family: var(--baht-font-family);
9
+ }
10
+
11
+ /* The width every routed page keeps to inside the shell. */
12
+ .app-page {
13
+ display: flex;
14
+ flex-direction: column;
15
+ gap: var(--baht-space-5);
16
+ box-sizing: border-box;
17
+ max-width: 1200px;
18
+ padding: var(--baht-space-5);
19
+ }
@@ -0,0 +1,10 @@
1
+ /* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2
+ /* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
3
+ {
4
+ "extends": "./tsconfig.json",
5
+ "compilerOptions": {
6
+ "types": []
7
+ },
8
+ "include": ["src/**/*.ts"],
9
+ "exclude": ["src/**/*.spec.ts"]
10
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.app.json",
3
+ "include": ["src/**/*.d.ts"]
4
+ }
@@ -0,0 +1,39 @@
1
+ /* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2
+ /* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
3
+ {
4
+ "compileOnSave": false,
5
+ "compilerOptions": {
6
+ "strict": true,
7
+ "noUncheckedIndexedAccess": true,
8
+ "exactOptionalPropertyTypes": true,
9
+ "verbatimModuleSyntax": true,
10
+ "noImplicitOverride": true,
11
+ "noPropertyAccessFromIndexSignature": true,
12
+ "noImplicitReturns": true,
13
+ "noFallthroughCasesInSwitch": true,
14
+ "skipLibCheck": true,
15
+ "isolatedModules": true,
16
+ "experimentalDecorators": true,
17
+ "importHelpers": true,
18
+ "target": "ES2022",
19
+ "module": "preserve",
20
+ "paths": {
21
+ "@{{name}}/kit": ["../../packages/kit/src/index.ts"]
22
+ }
23
+ },
24
+ "angularCompilerOptions": {
25
+ "enableI18nLegacyMessageIdFormat": false,
26
+ "strictInjectionParameters": true,
27
+ "strictTemplates": true,
28
+ "strictInputAccessModifiers": true
29
+ },
30
+ "files": [],
31
+ "references": [
32
+ {
33
+ "path": "./tsconfig.app.json"
34
+ },
35
+ {
36
+ "path": "./tsconfig.spec.json"
37
+ }
38
+ ]
39
+ }
@@ -0,0 +1,9 @@
1
+ /* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
2
+ /* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
3
+ {
4
+ "extends": "./tsconfig.json",
5
+ "compilerOptions": {
6
+ "types": ["vitest/globals"]
7
+ },
8
+ "include": ["src/**/*.d.ts", "src/**/*.spec.ts"]
9
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "apps": { "web": "apps/shell", "api": "apps/server" },
3
+ "libsDir": "packages",
4
+ "frontend": "angular",
5
+ "backend": "elysia"
6
+ }
@@ -0,0 +1,28 @@
1
+ import { defineConfig } from 'eslint/config'
2
+
3
+ import { angular, bahtui, base } from '@20baht/strict/eslint'
4
+
5
+ /** The host, its remotes, and the kit they all compile in. `bahtui g remote` adds a line. */
6
+ const WEB = [
7
+ 'apps/shell/src/**',
8
+ 'packages/kit/src/**',
9
+ // bahtui:remotes
10
+ ]
11
+
12
+ // Every rule is an error. Add app overrides below, each with a reason:
13
+ // // eslint-disable-next-line <rule> -- <why>
14
+ export default defineConfig([
15
+ ...base,
16
+ ...angular({
17
+ files: WEB,
18
+ restrictedImports: [
19
+ {
20
+ name: 'server',
21
+ allowTypeImports: true,
22
+ message:
23
+ 'The web apps share the server only as types (the eden App type); no server runtime code in a bundle.',
24
+ },
25
+ ],
26
+ }),
27
+ ...bahtui({ files: WEB, tokenFiles: ['apps/shell/src/styles.css'] }),
28
+ ])
@@ -0,0 +1,30 @@
1
+ import { knip } from '@20baht/strict/knip'
2
+
3
+ const SRC = ['src/**/*.ts']
4
+
5
+ /** A Native Federation remote: its entry is the routes module federation.config.mjs exposes. */
6
+ const remote = (name: string) => ({ entry: [`src/app/${name}.routes.ts`], project: SRC })
7
+
8
+ /** A workspace tested with `bun test`: the tests are its entries. */
9
+ const tested = { entry: ['test/**/*.test.ts'], project: [...SRC, 'test/**/*.ts'] }
10
+
11
+ export default knip({
12
+ ignoreDependencies: [
13
+ // The runtime loader behind @angular-architects/native-federation; nothing imports it directly.
14
+ '@softarc/native-federation-orchestrator',
15
+ // Reached through the kit; listed in each app so federation shares it as one singleton.
16
+ '@20baht/ngx-eden',
17
+ // Imported by name from @20baht/ui's own bundles; listed in each app so federation
18
+ // shares it (unlisted, the import map has no entry for it and the elements do not load).
19
+ '@20baht/engine',
20
+ // Angular's compiler emits tslib helpers (importHelpers).
21
+ 'tslib',
22
+ ],
23
+ workspaces: {
24
+ '.': { entry: ['scripts/*.ts'], project: ['scripts/**/*.ts'] },
25
+ 'apps/server': tested,
26
+ 'apps/shell': { project: SRC },
27
+ 'packages/kit': tested,
28
+ // bahtui:remotes
29
+ },
30
+ })
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "{{name}}",
3
+ "private": true,
4
+ "type": "module",
5
+ "workspaces": [
6
+ "apps/*",
7
+ "packages/*"
8
+ ],
9
+ "scripts": {
10
+ "dev": "bun run scripts/dev.ts",
11
+ "build": "bun run scripts/each.ts build",
12
+ "typecheck": "tsc -p tsconfig.json && bun run scripts/each.ts typecheck",
13
+ "lint": "eslint .",
14
+ "lint:fix": "eslint . --fix",
15
+ "format": "prettier --write .",
16
+ "format:check": "prettier --check .",
17
+ "knip": "knip",
18
+ "madge": "madge --circular --extensions ts,tsx --exclude '(^|/)(dist|node_modules|\\.angular)/' apps packages scripts",
19
+ "deps": "depcruise apps packages scripts --config .dependency-cruiser.mjs",
20
+ "dup": "jscpd",
21
+ "audit": "bun audit --audit-level=high",
22
+ "secrets": "gitleaks git --redact --no-banner",
23
+ "test": "bun run scripts/each.ts test:coverage",
24
+ "check:fast": "bun run lint && bun run format:check && bun run typecheck && bun run madge && bun run deps",
25
+ "check": "bun run check:fast && bun run knip && bun run dup && bun run build && bun run test",
26
+ "prepare": "husky"
27
+ },
28
+ "prettier": "@20baht/strict/prettier",
29
+ "packageManager": "bun@1.3.14",
30
+ "devDependencies": {
31
+ "@commitlint/cli": "^21.2.2",
32
+ "@commitlint/config-conventional": "^21.2.2",
33
+ "@eslint/css": "^2.0.0",
34
+ "@eslint/js": "^10.0.1",
35
+ "@types/bun": "^1.3.0",
36
+ "angular-eslint": "22.5.0",
37
+ "@20baht/strict": "0.1.0",
38
+ "dependency-cruiser": "^18.3.1",
39
+ "eslint": "^10.10.0",
40
+ "eslint-config-prettier": "^10.1.8",
41
+ "eslint-plugin-sonarjs": "^4.2.1",
42
+ "husky": "^9.1.7",
43
+ "jiti": "^2.6.1",
44
+ "jscpd": "^5.3.0",
45
+ "knip": "^6.35.1",
46
+ "lint-staged": "^17.5.1",
47
+ "madge": "^8.0.0",
48
+ "prettier": "^3.9.6",
49
+ "typescript": "^5.9.3",
50
+ "typescript-eslint": "^8.70.0"
51
+ }
52
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "{{name}}-kit",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "description": "What the host and its remotes share: the typed API client and error text. Imported as @{{name}}/kit through a tsconfig path, so each app compiles its own copy.",
7
+ "exports": {
8
+ ".": "./src/index.ts"
9
+ },
10
+ "scripts": {
11
+ "typecheck": "tsc --noEmit",
12
+ "pretypecheck": "bun run --filter server build:types",
13
+ "test": "bun test",
14
+ "test:coverage": "bun test --coverage"
15
+ },
16
+ "dependencies": {
17
+ "@angular/core": "^22.2.0",
18
+ "@20baht/ngx-eden": "^0.1.0",
19
+ "rxjs": "~7.8.0",
20
+ "tslib": "^2.3.0"
21
+ },
22
+ "devDependencies": {
23
+ "@types/bun": "^1.3.0",
24
+ "server": "workspace:*",
25
+ "typescript": "~6.0.2"
26
+ }
27
+ }
@@ -0,0 +1,21 @@
1
+ import { Injectable, InjectionToken, inject, isDevMode } from '@angular/core'
2
+ import { createEden } from '@20baht/ngx-eden'
3
+ import type { App } from 'server'
4
+
5
+ /**
6
+ * Where the API lives. In dev the Angular servers run on :4200 and up and Elysia on :3001;
7
+ * deployed, one web server serves the apps and proxies `/api` on the same origin.
8
+ */
9
+ export const API_BASE = new InjectionToken<string>('API_BASE', {
10
+ providedIn: 'root',
11
+ factory: () => (isDevMode() ? 'http://localhost:3001' : globalThis.location.origin),
12
+ })
13
+
14
+ /**
15
+ * The typed client of the Elysia server: `inject(Api).client.api.hello.get()`.
16
+ * Types come from `apps/server/dist/types` (`bun run --filter server build:types`).
17
+ */
18
+ @Injectable({ providedIn: 'root' })
19
+ export class Api {
20
+ readonly client = createEden<App>({ baseUrl: inject(API_BASE) })
21
+ }
@@ -0,0 +1,28 @@
1
+ const FALLBACK = 'Something went wrong. Try again.'
2
+
3
+ const isRecord = (value: unknown): value is Record<string, unknown> =>
4
+ typeof value === 'object' && value !== null
5
+
6
+ /** Where the response body sits: `value` from `unwrap()`, `error` on an `HttpErrorResponse`. */
7
+ const bodyOf = (error: Record<string, unknown>): Record<string, unknown> => {
8
+ for (const key of ['value', 'error']) {
9
+ const body = error[key]
10
+ if (isRecord(body)) return body
11
+ }
12
+ return error
13
+ }
14
+
15
+ /**
16
+ * The sentence to show for a failed API call: the server's `{ message }` or Elysia's validator
17
+ * `{ summary }`, as ngx-eden's `unwrap()` or a resource's `error()` carries it.
18
+ */
19
+ export const describeError = (error: unknown): string => {
20
+ if (!isRecord(error)) return FALLBACK
21
+ if (error['status'] === 0) return 'The server cannot be reached.'
22
+ const body = bodyOf(error)
23
+ for (const key of ['message', 'summary']) {
24
+ const text = body[key]
25
+ if (typeof text === 'string' && text !== '') return text
26
+ }
27
+ return FALLBACK
28
+ }
@@ -0,0 +1,2 @@
1
+ export { API_BASE, Api } from './api'
2
+ export { describeError } from './errors'
@@ -0,0 +1,28 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+
3
+ import { describeError } from '../src/errors'
4
+
5
+ describe('describeError', () => {
6
+ test('reads the body ngx-eden wraps', () => {
7
+ expect(describeError({ status: 404, value: { message: 'Not found' } })).toBe('Not found')
8
+ expect(describeError({ status: 422, value: { summary: 'Expected string' } })).toBe(
9
+ 'Expected string',
10
+ )
11
+ })
12
+
13
+ test('reads the body of an HttpErrorResponse', () => {
14
+ expect(
15
+ describeError({ status: 404, error: { message: 'Gone' }, message: 'Http failure' }),
16
+ ).toBe('Gone')
17
+ expect(describeError({ status: 0, message: 'Http failure response: 0 Unknown Error' })).toBe(
18
+ 'The server cannot be reached.',
19
+ )
20
+ })
21
+
22
+ test('reads a plain Error and falls back', () => {
23
+ expect(describeError(new Error('boom'))).toBe('boom')
24
+ expect(describeError({ status: 0 })).toBe('The server cannot be reached.')
25
+ expect(describeError({ status: 500, value: 'oops' })).toBe('Something went wrong. Try again.')
26
+ expect(describeError(null)).toBe('Something went wrong. Try again.')
27
+ })
28
+ })
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "lib": ["ES2022", "DOM"],
5
+ "types": ["bun"],
6
+ "experimentalDecorators": true
7
+ },
8
+ "include": ["src", "test"]
9
+ }
@@ -0,0 +1,32 @@
1
+ # {{name}}
2
+
3
+ Bun-workspace monorepo scaffolded by [`@20baht/cli`](https://github.com/bank20baht/20baht) —
4
+ React + Elysia wired end-to-end with Eden (type-safe client, zero codegen).
5
+
6
+ ## Quickstart
7
+
8
+ ```sh
9
+ bun install
10
+ bun run dev # web on :5173, api on :3001
11
+ ```
12
+
13
+ ## Layout (DDD taxonomy)
14
+
15
+ ```
16
+ apps/web React 19 + Vite on @20baht/ui (import each <baht-*> you use in src/main.tsx)
17
+ apps/api Elysia — exports `type App`, the Eden type anchor
18
+ libs/shared/eden treaty<App> — the ONE typed http client
19
+ libs/domain/<d>/model (later) entities + form JSON, framework-free
20
+ libs/domain/<d>/api (later) Elysia plugin for the domain
21
+ libs/domain/<d>/feature-*(later) React feature slices
22
+ ```
23
+
24
+ Dependency direction: features and api libs depend on `model`; `model` depends
25
+ on nothing; the frontend never imports server code — types travel through Eden.
26
+
27
+ ## Toolchain
28
+
29
+ - `bun run lint` / `format:check` / `knip` / `deps:circular` — also run by CI
30
+ and by the pre-commit hook (lint-staged → knip → madge).
31
+ - `bun run test` — bun test in every app.
32
+ - `bun run build` — typecheck + vite build.
@@ -0,0 +1,56 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ concurrency:
9
+ group: ci-${{ github.ref }}
10
+ cancel-in-progress: true
11
+
12
+ permissions:
13
+ contents: read
14
+
15
+ jobs:
16
+ lint:
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v5
20
+ - uses: oven-sh/setup-bun@v2
21
+ with:
22
+ bun-version: latest
23
+ - name: Install deps
24
+ run: bun install --frozen-lockfile
25
+ - name: ESLint
26
+ run: bun run lint
27
+ - name: Prettier
28
+ run: bun run format:check
29
+ - name: Knip (dead code)
30
+ run: bun run knip
31
+ - name: Circular dependencies (madge)
32
+ run: bun run deps:circular
33
+
34
+ test:
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - uses: actions/checkout@v5
38
+ - uses: oven-sh/setup-bun@v2
39
+ with:
40
+ bun-version: latest
41
+ - name: Install deps
42
+ run: bun install --frozen-lockfile
43
+ - name: Test
44
+ run: bun run test
45
+
46
+ build:
47
+ runs-on: ubuntu-latest
48
+ steps:
49
+ - uses: actions/checkout@v5
50
+ - uses: oven-sh/setup-bun@v2
51
+ with:
52
+ bun-version: latest
53
+ - name: Install deps
54
+ run: bun install --frozen-lockfile
55
+ - name: Build
56
+ run: bun run build
@@ -0,0 +1,6 @@
1
+ node_modules/
2
+ dist/
3
+ coverage/
4
+ *.local
5
+ *.tsbuildinfo
6
+ .DS_Store
@@ -0,0 +1,3 @@
1
+ bunx lint-staged
2
+ bun run knip
3
+ bun run deps:circular
@@ -0,0 +1,3 @@
1
+ dist/
2
+ *.tsbuildinfo
3
+ bun.lock
@@ -0,0 +1,4 @@
1
+ {
2
+ "singleQuote": true,
3
+ "printWidth": 100
4
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@{{name}}/api",
3
+ "private": true,
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./src/index.ts"
7
+ },
8
+ "scripts": {
9
+ "dev": "bun run --watch src/index.ts",
10
+ "test": "bun test",
11
+ "build": "tsc --noEmit"
12
+ },
13
+ "dependencies": {
14
+ "@elysiajs/cors": "^1.3.0",
15
+ "elysia": "^1.3.0"
16
+ },
17
+ "devDependencies": {
18
+ "@types/bun": "^1.2.0",
19
+ "typescript": "^5.8.3"
20
+ }
21
+ }
@@ -0,0 +1,10 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import { app } from './index';
3
+
4
+ describe('GET /health', () => {
5
+ it('reports the service as ok', async () => {
6
+ const res = await app.handle(new Request('http://localhost/health'));
7
+ expect(res.status).toBe(200);
8
+ expect(await res.json()).toEqual({ status: 'ok', service: '{{name}}-api' });
9
+ });
10
+ });
@@ -0,0 +1,14 @@
1
+ import { Elysia } from 'elysia';
2
+ import { cors } from '@elysiajs/cors';
3
+
4
+ export const app = new Elysia()
5
+ .use(cors())
6
+ .get('/health', () => ({ status: 'ok', service: '{{name}}-api' }));
7
+
8
+ /** Eden anchor — the whole API's type surface, consumed by libs/shared/eden. */
9
+ export type App = typeof app;
10
+
11
+ if (import.meta.main) {
12
+ app.listen(3001);
13
+ console.log(`{{name}}-api listening on http://localhost:${app.server?.port}`);
14
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "types": ["bun"]
5
+ },
6
+ "include": ["src"]
7
+ }
@@ -0,0 +1,20 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>{{name}}</title>
7
+ <script>
8
+ // apply the saved <baht-theme-toggle> choice before paint (no flash)
9
+ try {
10
+ var t = localStorage.getItem('baht-theme');
11
+ if (t === 'light' || t === 'dark')
12
+ document.documentElement.setAttribute('data-baht-theme', t);
13
+ } catch (e) {}
14
+ </script>
15
+ </head>
16
+ <body>
17
+ <div id="root"></div>
18
+ <script type="module" src="/src/main.tsx"></script>
19
+ </body>
20
+ </html>
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@{{name}}/web",
3
+ "private": true,
4
+ "type": "module",
5
+ "scripts": {
6
+ "dev": "vite",
7
+ "test": "bun test",
8
+ "build": "tsc --noEmit && vite build"
9
+ },
10
+ "dependencies": {
11
+ "@{{name}}/eden": "workspace:*",
12
+ "@20baht/ui": "^0.1.0",
13
+ "react": "^19.1.0",
14
+ "react-dom": "^19.1.0"
15
+ },
16
+ "devDependencies": {
17
+ "@types/bun": "^1.2.0",
18
+ "@types/react": "^19.1.0",
19
+ "@types/react-dom": "^19.1.0",
20
+ "@vitejs/plugin-react": "^5.0.0",
21
+ "typescript": "^5.8.3",
22
+ "vite": "^7.0.0"
23
+ }
24
+ }
@@ -0,0 +1,31 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { api } from '@{{name}}/eden';
3
+ import { describeHealth, healthTone, type HealthTone } from './health';
4
+
5
+ type Status = { label: string; tone: HealthTone | 'neutral' };
6
+
7
+ export default function App() {
8
+ const [status, setStatus] = useState<Status>({ label: 'checking api…', tone: 'neutral' });
9
+
10
+ useEffect(() => {
11
+ void api.health.get().then(({ data, error }) => {
12
+ setStatus(
13
+ error
14
+ ? { label: 'api unreachable (start it: bun run dev)', tone: 'danger' }
15
+ : { label: describeHealth(data), tone: healthTone(data) },
16
+ );
17
+ });
18
+ }, []);
19
+
20
+ return (
21
+ <main className="app">
22
+ <header className="app-bar">
23
+ <h1>{{name}}</h1>
24
+ <baht-theme-toggle />
25
+ </header>
26
+ <baht-card heading="API" subtitle="apps/api via libs/shared/eden">
27
+ <baht-badge tone={status.tone} label={status.label} />
28
+ </baht-card>
29
+ </main>
30
+ );
31
+ }
@@ -0,0 +1,27 @@
1
+ /* Page chrome only. Components style themselves from the --baht-* tokens. */
2
+ body {
3
+ margin: 0;
4
+ background: var(--baht-color-bg);
5
+ color: var(--baht-color-text);
6
+ font-family: var(--baht-font-family);
7
+ }
8
+
9
+ .app {
10
+ max-width: 720px;
11
+ margin: 0 auto;
12
+ padding: var(--baht-space-8) var(--baht-space-4);
13
+ display: grid;
14
+ gap: var(--baht-space-4);
15
+ }
16
+
17
+ .app-bar {
18
+ display: flex;
19
+ align-items: center;
20
+ justify-content: space-between;
21
+ }
22
+
23
+ .app-bar h1 {
24
+ margin: 0;
25
+ font-family: var(--baht-font-display);
26
+ font-size: 1.5rem;
27
+ }