create-knit 0.0.0-stage → 0.3.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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +17 -2
  3. package/index.mjs +248 -0
  4. package/package.json +32 -3
  5. package/template/base/.claude/skills/knit-add-api/SKILL.md +41 -0
  6. package/template/base/.claude/skills/knit-add-model/SKILL.md +31 -0
  7. package/template/base/.cursor/mcp.json +24 -0
  8. package/template/base/.mcp.json +25 -0
  9. package/template/base/.vscode/mcp.json +25 -0
  10. package/template/base/AGENTS.md +76 -0
  11. package/template/base/CLAUDE.md +9 -0
  12. package/template/base/_gitignore +13 -0
  13. package/template/base/apps/web/.env.example +124 -0
  14. package/template/base/apps/web/app/app.vue +7 -0
  15. package/template/base/apps/web/app/pages/index.vue +20 -0
  16. package/template/base/apps/web/tsconfig.json +9 -0
  17. package/template/base/docker/.env.production.example +21 -0
  18. package/template/base/docker/Dockerfile +64 -0
  19. package/template/base/docker/Dockerfile.dockerignore +16 -0
  20. package/template/base/docker/dev.Dockerfile +10 -0
  21. package/template/base/docker/dev.Dockerfile.dockerignore +2 -0
  22. package/template/base/docker/docker-compose.prod.yml +44 -0
  23. package/template/base/docker-compose.yml +71 -0
  24. package/template/examples/apps/web/app/pages/platform.vue +94 -0
  25. package/template/examples/apps/web/server/api/demo/flash.post.ts +5 -0
  26. package/template/examples/layers/example-blog/admin.ts +126 -0
  27. package/template/examples/layers/example-blog/app/pages/blog/[slug].vue +169 -0
  28. package/template/examples/layers/example-blog/app/pages/blog/index.vue +73 -0
  29. package/template/examples/layers/example-blog/app/pages/blog/stats.vue +33 -0
  30. package/template/examples/layers/example-blog/commands/publishpost.ts +23 -0
  31. package/template/examples/layers/example-blog/i18n/locales/de.json +140 -0
  32. package/template/examples/layers/example-blog/i18n/locales/en.json +33 -0
  33. package/template/examples/layers/example-blog/i18n/locales/es.json +140 -0
  34. package/template/examples/layers/example-blog/nuxt.config.ts +9 -0
  35. package/template/examples/layers/example-blog/package.json +18 -0
  36. package/template/examples/layers/example-blog/server/api/blog/posts/[slug].get.ts +15 -0
  37. package/template/examples/layers/example-blog/server/api/blog/posts.get.ts +14 -0
  38. package/template/examples/layers/example-blog/server/api/blog/word-count.post.ts +23 -0
  39. package/template/examples/layers/example-blog/server/channels/comments.ts +39 -0
  40. package/template/examples/layers/example-blog/server/database/schema.ts +160 -0
  41. package/template/examples/layers/example-blog/server/database/seed.ts +24 -0
  42. package/template/examples/layers/example-blog/server/feeds/blog.ts +26 -0
  43. package/template/examples/layers/example-blog/server/resources/comments.ts +78 -0
  44. package/template/examples/layers/example-blog/server/resources/posts.ts +25 -0
  45. package/template/examples/layers/example-blog/server/routes/blog/atom.xml.ts +4 -0
  46. package/template/examples/layers/example-blog/server/routes/blog/feed.xml.ts +4 -0
  47. package/template/examples/layers/example-blog/server/sitemaps/blog.ts +14 -0
  48. package/template/examples/layers/example-blog/server/tasks/blog.ts +49 -0
  49. package/template/examples/layers/example-blog/test/blog.test.ts +46 -0
  50. package/template/examples/layers/example-blog/test/i18n.test.ts +27 -0
  51. package/template/examples/layers/example-blog/tsconfig.json +9 -0
  52. package/template/examples/layers/example-dashboard/app/pages/dashboard.vue +67 -0
  53. package/template/examples/layers/example-dashboard/i18n/locales/de.json +12 -0
  54. package/template/examples/layers/example-dashboard/i18n/locales/en.json +12 -0
  55. package/template/examples/layers/example-dashboard/i18n/locales/es.json +12 -0
  56. package/template/examples/layers/example-dashboard/nuxt.config.ts +12 -0
  57. package/template/examples/layers/example-dashboard/package.json +16 -0
  58. package/template/examples/layers/example-dashboard/tsconfig.json +9 -0
  59. package/template/versions.json +13 -0
@@ -0,0 +1,124 @@
1
+ # Copy to .env (`cp .env.example .env`). Every variable is optional in development.
2
+
3
+ # Required in production: at least 32 random characters.
4
+ # Generate one with: openssl rand -base64 32
5
+ NUXT_BETTER_AUTH_SECRET=
6
+
7
+ # Public base URL of the site in production, e.g. https://example.com
8
+ NUXT_BETTER_AUTH_URL=
9
+
10
+ # Use a Postgres server instead of the embedded PGlite database (app + `pnpm manage`).
11
+ # DATABASE_URL=postgres://user:password@localhost:5432/knit
12
+
13
+ # PGlite data directory (relative to apps/web, or to the folder holding a deployed .output). Default: .data/pglite
14
+ # NUXT_FRAMEWORK_DATA_DIR=.data/pglite
15
+
16
+ # Apply pending migrations at startup: dev (default) | always | never
17
+ # NUXT_FRAMEWORK_AUTO_MIGRATE=dev
18
+
19
+ # First-admin setup wizard at /admin/setup: dev (default) | always | never
20
+ # NUXT_FRAMEWORK_ALLOW_SETUP=dev
21
+
22
+ # Site name used in auth emails. Default: Knit
23
+ # NUXT_BETTER_AUTH_APP_NAME=Knit
24
+
25
+ # Block sign-in until the email address is verified: false (default) | true
26
+ # NUXT_BETTER_AUTH_REQUIRE_EMAIL_VERIFICATION=false
27
+
28
+ # BetterAuth rate limiting (100 req/min, stricter on credential routes): true (default) | false
29
+ # NUXT_BETTER_AUTH_RATE_LIMIT=true
30
+ # Behind a reverse proxy, read the client IP from X-Forwarded-For: false (default) | true
31
+ # NUXT_BETTER_AUTH_TRUST_PROXY=false
32
+
33
+ # Email. Mailer: console (dev default, prints to the terminal) | smtp | memory (in-process outbox)
34
+ # Empty mailer = smtp when NUXT_MAIL_URL is set, otherwise console.
35
+ # NUXT_MAIL_MAILER=
36
+ # SMTP connection URL, e.g. smtp://user:pass@smtp.example.com:587 or smtps://user:pass@host:465
37
+ # NUXT_MAIL_URL=
38
+ # Default sender (Django: DEFAULT_FROM_EMAIL)
39
+ # NUXT_MAIL_FROM=Knit <webmaster@localhost>
40
+
41
+ # Used by `pnpm manage createsuperuser --noinput`
42
+ # FRAMEWORK_SUPERUSER_PASSWORD=
43
+
44
+ # Used by `pnpm manage changepassword <email> --noinput`
45
+ # FRAMEWORK_NEW_PASSWORD=
46
+ # ── Logging (LogLayer) ─────────────────────────────────────────────────────────
47
+ # trace | debug | info | warn | error | fatal (default: debug in dev, info in production)
48
+ # NUXT_KNIT_LOG_LEVEL=info
49
+ # pretty (colourful, dev default) | json (one object per line, production default)
50
+ # NUXT_KNIT_LOG_FORMAT=json
51
+ # One line per request: method, path, status, duration (default true)
52
+ # NUXT_KNIT_LOG_REQUESTS=true
53
+ # Extra keys to redact, comma-separated (passwords, tokens, cookies… are always redacted)
54
+ # NUXT_KNIT_LOG_REDACT=ssn,card.number
55
+
56
+ # ── Site ────────────────────────────────────────────────────────────────────────
57
+ # Public base URL for sitemaps and feeds (default: NUXT_BETTER_AUTH_URL, then the request)
58
+ # NUXT_KNIT_SITE_URL=https://example.com
59
+
60
+ # ── Security (headers, CSRF, CSP) ───────────────────────────────────────────────
61
+ # Origin-based CSRF guard for cookie-authenticated POST/PUT/PATCH/DELETE to /api/** (default true)
62
+ # NUXT_KNIT_SECURITY_CSRF=true
63
+ # Extra origins allowed to make state-changing requests, comma-separated
64
+ # NUXT_KNIT_SECURITY_TRUSTED_ORIGINS=https://app.example.com
65
+ # Path prefixes exempt from the CSRF guard (webhooks), comma-separated
66
+ # NUXT_KNIT_SECURITY_CSRF_EXEMPT=/api/webhooks/
67
+ # Content-Security-Policy with per-request nonces (default true); report-only mode
68
+ # NUXT_KNIT_SECURITY_CSP=true
69
+ # NUXT_KNIT_SECURITY_CSP_REPORT_ONLY=false
70
+ # Extra CSP sources, merged into the defaults
71
+ # NUXT_KNIT_SECURITY_CSP_EXTRA=img-src https://cdn.example.com; connect-src https://api.example.com
72
+ # DENY (default; SAMEORIGIN in dev) | SAMEORIGIN | empty to disable
73
+ # NUXT_KNIT_SECURITY_FRAME_OPTIONS=DENY
74
+ # NUXT_KNIT_SECURITY_REFERRER_POLICY=same-origin
75
+ # NUXT_KNIT_SECURITY_CROSS_ORIGIN_OPENER_POLICY=same-origin
76
+ # HSTS on HTTPS responses in production (0 disables)
77
+ # NUXT_KNIT_SECURITY_HSTS_SECONDS=31536000
78
+ # NUXT_KNIT_SECURITY_HSTS_INCLUDE_SUBDOMAINS=true
79
+ # NUXT_KNIT_SECURITY_HSTS_PRELOAD=false
80
+ # Behind a TLS-terminating reverse proxy: trust X-Forwarded-Proto/Host
81
+ # NUXT_KNIT_SECURITY_TRUST_PROXY=false
82
+
83
+ # ── Tasks ───────────────────────────────────────────────────────────────────────
84
+ # immediate (default: run in-process on enqueue) | database (knit_task queue)
85
+ # NUXT_KNIT_TASKS_BACKEND=immediate
86
+ # Let the server process the database queue itself: always (default) | dev | never
87
+ # NUXT_KNIT_TASKS_SERVER_WORKER=always
88
+ # NUXT_KNIT_TASKS_POLL_INTERVAL=1000
89
+ # NUXT_KNIT_TASKS_MAX_ATTEMPTS=3
90
+ # NUXT_KNIT_TASKS_RETRY_DELAY=10
91
+
92
+ # ── Realtime (SSE + WebSocket channels) ─────────────────────────────────────────
93
+ # memory (default, one process) | postgres (LISTEN/NOTIFY on DATABASE_URL: several
94
+ # instances, or a `pnpm manage worker` that publishes)
95
+ # NUXT_KNIT_REALTIME_BACKEND=memory
96
+ # Seconds between keep-alive pings (keep below proxy idle timeouts)
97
+ # NUXT_KNIT_REALTIME_HEARTBEAT=25
98
+ # Messages kept per process for SSE Last-Event-ID replay
99
+ # NUXT_KNIT_REALTIME_HISTORY=200
100
+ # Largest message in bytes, and channels per connection
101
+ # NUXT_KNIT_REALTIME_MAX_PAYLOAD=65536
102
+ # NUXT_KNIT_REALTIME_MAX_CHANNELS=20
103
+
104
+ # ── Cache ───────────────────────────────────────────────────────────────────────
105
+ # memory (default) | fs | redis
106
+ # NUXT_KNIT_CACHE_DRIVER=memory
107
+ # fs directory (absolute; default apps/web/.data/cache)
108
+ # NUXT_KNIT_CACHE_BASE=
109
+ # NUXT_KNIT_CACHE_URL=redis://localhost:6379/0
110
+ # Default TTL in seconds
111
+ # NUXT_KNIT_CACHE_TTL=300
112
+
113
+ # ── File storage ────────────────────────────────────────────────────────────────
114
+ # fs (default, apps/web/.data/uploads) | s3 (any S3-compatible bucket)
115
+ # NUXT_KNIT_STORAGE_DRIVER=fs
116
+ # NUXT_KNIT_STORAGE_DIR=
117
+ # Upload limit in bytes (default 10 MiB) and allowed MIME types (type/* wildcards work)
118
+ # NUXT_KNIT_STORAGE_MAX_SIZE=10485760
119
+ # NUXT_KNIT_STORAGE_ALLOWED_TYPES=image/png,image/jpeg,image/gif,image/webp,image/avif,application/pdf,text/plain,text/csv,application/zip
120
+ # NUXT_KNIT_STORAGE_S3_ENDPOINT=https://s3.eu-central-1.amazonaws.com
121
+ # NUXT_KNIT_STORAGE_S3_REGION=eu-central-1
122
+ # NUXT_KNIT_STORAGE_S3_BUCKET=
123
+ # NUXT_KNIT_STORAGE_S3_ACCESS_KEY_ID=
124
+ # NUXT_KNIT_STORAGE_S3_SECRET_ACCESS_KEY=
@@ -0,0 +1,7 @@
1
+ <template>
2
+ <UApp>
3
+ <NuxtLayout>
4
+ <NuxtPage />
5
+ </NuxtLayout>
6
+ </UApp>
7
+ </template>
@@ -0,0 +1,20 @@
1
+ <script setup lang="ts">
2
+ const { data: health } = await useFetch('/api/_framework/health')
3
+ const { user, isAdmin, fetchSession } = useAuth()
4
+ await fetchSession()
5
+ </script>
6
+
7
+ <template>
8
+ <UContainer class="py-12 space-y-6">
9
+ <div class="flex items-center justify-between">
10
+ <h1 class="text-3xl font-bold">Knit Framework</h1>
11
+ <UButton to="/admin" icon="i-lucide-shield-check" :label="isAdmin ? 'Admin' : 'Admin login'" />
12
+ </div>
13
+ <UCard>
14
+ <template #header>Kernel</template>
15
+ <pre class="text-sm">{{ health }}</pre>
16
+ </UCard>
17
+ <p v-if="user">Signed in as {{ user.email }}</p>
18
+ <p v-else class="text-muted">Not signed in.</p>
19
+ </UContainer>
20
+ </template>
@@ -0,0 +1,9 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ { "path": "./.nuxt/tsconfig.app.json" },
5
+ { "path": "./.nuxt/tsconfig.server.json" },
6
+ { "path": "./.nuxt/tsconfig.shared.json" },
7
+ { "path": "./.nuxt/tsconfig.node.json" }
8
+ ]
9
+ }
@@ -0,0 +1,21 @@
1
+ # Production settings for docker/docker-compose.prod.yml. Copy to docker/.env.production (never commit it).
2
+ # Every variable is documented in docs/configuration.md and apps/web/.env.example.
3
+
4
+ # Database password for the bundled Postgres (any long random string).
5
+ POSTGRES_PASSWORD=
6
+
7
+ # Required: at least 32 random characters, e.g. `openssl rand -base64 32`.
8
+ NUXT_BETTER_AUTH_SECRET=
9
+ # The public HTTPS URL of the site.
10
+ NUXT_BETTER_AUTH_URL=https://example.com
11
+
12
+ # Email (password resets, verification).
13
+ NUXT_MAIL_URL=smtp://user:password@smtp.example.com:587
14
+ NUXT_MAIL_FROM=Example <noreply@example.com>
15
+
16
+ # Behind a TLS-terminating proxy (Caddy, nginx, Traefik…).
17
+ NUXT_KNIT_SECURITY_TRUST_PROXY=true
18
+ NUXT_BETTER_AUTH_TRUST_PROXY=true
19
+
20
+ # Background tasks with retries and cron, processed by the server.
21
+ NUXT_KNIT_TASKS_BACKEND=database
@@ -0,0 +1,64 @@
1
+ # syntax=docker/dockerfile:1
2
+ # Production image for Knit.
3
+ #
4
+ # Build from the repository root (the build context):
5
+ # docker build -f docker/Dockerfile -t knit . # the app (default target: runtime)
6
+ # docker build -f docker/Dockerfile -t knit-tools --target tools . # one-off `pnpm manage …` commands
7
+ #
8
+ # See docs/deployment.md.
9
+
10
+ ARG NODE_VERSION=24
11
+
12
+ # ── base: Node + pnpm ─────────────────────────────────────────────────────────
13
+ FROM node:${NODE_VERSION}-slim AS base
14
+ ENV PNPM_HOME=/pnpm PATH=/pnpm:$PATH NUXT_TELEMETRY_DISABLED=1
15
+ RUN corepack enable
16
+ WORKDIR /app
17
+
18
+ # ── deps: install from the lockfile (cached until a manifest changes) ─────────
19
+ FROM base AS deps
20
+ COPY pnpm-lock.yaml pnpm-workspace.yaml package.json ./
21
+ COPY apps/web/package.json apps/web/
22
+ COPY layers/ layers/
23
+ # Keep only the layer manifests at this stage (sources come later, so code changes don't bust the cache).
24
+ RUN find layers -mindepth 2 -not -name package.json -not -type d -delete
25
+ RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
26
+ pnpm install --frozen-lockfile --ignore-scripts
27
+
28
+ # ── build: generate types and build the Nitro server ──────────────────────────
29
+ FROM deps AS build
30
+ COPY . .
31
+ # Install scripts were skipped above (sources weren't there yet): run dependency build scripts,
32
+ # then every workspace package's postinstall (each layer generates its .nuxt with `nuxt prepare`)
33
+ # and the root's (core's types).
34
+ RUN pnpm rebuild && pnpm -r run postinstall && pnpm run --if-present postinstall
35
+ RUN pnpm build
36
+
37
+ # ── tools: the full workspace, for `pnpm manage` against the production database ──
38
+ # docker run --rm -it -e DATABASE_URL=… knit-tools pnpm manage createsuperuser
39
+ FROM build AS tools
40
+ ENV NODE_ENV=production
41
+ CMD ["pnpm", "manage", "--help"]
42
+
43
+ # ── runtime: just the self-contained server ───────────────────────────────────
44
+ FROM node:${NODE_VERSION}-slim AS runtime
45
+ ENV NODE_ENV=production \
46
+ NUXT_TELEMETRY_DISABLED=1 \
47
+ HOST=0.0.0.0 \
48
+ PORT=3000 \
49
+ # Apply pending migrations on start (set to `never` to run them as a separate release step).
50
+ NUXT_FRAMEWORK_AUTO_MIGRATE=always \
51
+ # Persistent data when using the embedded PGlite database and local file storage.
52
+ NUXT_FRAMEWORK_DATA_DIR=/data/pglite \
53
+ NUXT_KNIT_STORAGE_DIR=/data/uploads \
54
+ NUXT_KNIT_CACHE_BASE=/data/cache
55
+ WORKDIR /app
56
+ # Self-contained: the migrations are bundled into .output.
57
+ COPY --from=build --chown=node:node /app/apps/web/.output apps/web/.output
58
+ RUN mkdir -p /data && chown node:node /data
59
+ USER node
60
+ VOLUME ["/data"]
61
+ EXPOSE 3000
62
+ HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
63
+ CMD node -e "fetch('http://127.0.0.1:'+(process.env.PORT||3000)+'/api/_framework/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
64
+ CMD ["node", "apps/web/.output/server/index.mjs"]
@@ -0,0 +1,16 @@
1
+ # Keep the build context small and host-specific files out of the image.
2
+ **/node_modules
3
+ **/.nuxt
4
+ **/.output
5
+ **/.data
6
+ **/.framework
7
+ **/.inspectdb
8
+ .git
9
+ .github
10
+ .claude
11
+ .cursor
12
+ .vscode
13
+ .env
14
+ **/.env
15
+ docs/screenshots
16
+ *.log
@@ -0,0 +1,10 @@
1
+ # Development image for `docker compose --profile app up`: Node + pnpm (via corepack),
2
+ # with the repository bind-mounted at /app.
3
+ FROM node:24-slim
4
+ RUN corepack enable
5
+ WORKDIR /app
6
+ ENV PNPM_HOME=/pnpm \
7
+ PATH=/pnpm:$PATH \
8
+ NUXT_TELEMETRY_DISABLED=1
9
+ EXPOSE 3000
10
+ CMD ["sh", "-c", "pnpm install --frozen-lockfile && pnpm dev --host 0.0.0.0"]
@@ -0,0 +1,2 @@
1
+ # The dev image copies nothing (the repository is bind-mounted), so send no build context.
2
+ *
@@ -0,0 +1,44 @@
1
+ # Single-server production example: Knit + Postgres.
2
+ #
3
+ # cp docker/.env.production.example docker/.env.production # then fill in the secrets
4
+ # docker compose -f docker/docker-compose.prod.yml --env-file docker/.env.production up -d --build
5
+ #
6
+ # See docs/deployment.md. Put a TLS-terminating proxy (Caddy, nginx, Traefik…) in front.
7
+
8
+ name: knit-prod
9
+
10
+ services:
11
+ app:
12
+ build:
13
+ context: ..
14
+ dockerfile: docker/Dockerfile
15
+ restart: unless-stopped
16
+ env_file: .env.production
17
+ environment:
18
+ DATABASE_URL: postgres://knit:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}@postgres:5432/knit
19
+ ports:
20
+ - "${KNIT_APP_PORT:-3000}:3000"
21
+ volumes:
22
+ - app-data:/data
23
+ depends_on:
24
+ postgres:
25
+ condition: service_healthy
26
+
27
+ postgres:
28
+ image: postgres:17-alpine
29
+ restart: unless-stopped
30
+ environment:
31
+ POSTGRES_USER: knit
32
+ POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}
33
+ POSTGRES_DB: knit
34
+ volumes:
35
+ - postgres-data:/var/lib/postgresql/data
36
+ healthcheck:
37
+ test: ["CMD-SHELL", "pg_isready -U knit -d knit"]
38
+ interval: 5s
39
+ timeout: 3s
40
+ retries: 20
41
+
42
+ volumes:
43
+ app-data:
44
+ postgres-data:
@@ -0,0 +1,71 @@
1
+ # Local services for Knit development. See docs/development.md.
2
+ #
3
+ # docker compose up -d # Postgres + Mailpit; run the app natively with `pnpm dev`
4
+ # docker compose --profile app up # …and the app itself in a container
5
+ #
6
+ # With the app running natively, point it at these services in apps/web/.env:
7
+ # DATABASE_URL=postgres://knit:knit@localhost:5432/knit
8
+ # NUXT_MAIL_URL=smtp://localhost:1025
9
+ #
10
+ # Ports already taken by another project? Override them, e.g. in a root .env file:
11
+ # KNIT_POSTGRES_PORT=55432 KNIT_SMTP_PORT=51025 KNIT_MAIL_UI_PORT=58025 KNIT_APP_PORT=53000
12
+
13
+ name: knit
14
+
15
+ services:
16
+ postgres:
17
+ image: postgres:17-alpine
18
+ environment:
19
+ POSTGRES_USER: knit
20
+ POSTGRES_PASSWORD: knit
21
+ POSTGRES_DB: knit
22
+ ports:
23
+ - "${KNIT_POSTGRES_PORT:-5432}:5432"
24
+ volumes:
25
+ - postgres-data:/var/lib/postgresql/data
26
+ healthcheck:
27
+ test: ["CMD-SHELL", "pg_isready -U knit -d knit"]
28
+ interval: 2s
29
+ timeout: 3s
30
+ retries: 30
31
+
32
+ # Catches every email the app sends (password resets, verification…). Inbox: http://localhost:8025
33
+ mailpit:
34
+ image: axllent/mailpit:latest
35
+ ports:
36
+ - "${KNIT_SMTP_PORT:-1025}:1025"
37
+ - "${KNIT_MAIL_UI_PORT:-8025}:8025"
38
+
39
+ # The whole dev environment in a container: `docker compose --profile app up`.
40
+ app:
41
+ profiles: ["app"]
42
+ build:
43
+ context: .
44
+ dockerfile: docker/dev.Dockerfile
45
+ environment:
46
+ DATABASE_URL: postgres://knit:knit@postgres:5432/knit
47
+ NUXT_MAIL_URL: smtp://mailpit:1025
48
+ # Polling keeps file watching reliable on Docker Desktop bind mounts.
49
+ CHOKIDAR_USEPOLLING: "true"
50
+ ports:
51
+ - "${KNIT_APP_PORT:-3000}:3000"
52
+ volumes:
53
+ - .:/app
54
+ # Container-only dependencies and build output: Linux binaries must not replace your host's.
55
+ # Add a line here for each new layer (`pnpm manage startapp` creates layers/<name>).
56
+ - /app/node_modules
57
+ - /app/apps/web/node_modules
58
+ - /app/apps/web/.nuxt
59
+ - /app/apps/web/.data
60
+ - /app/layers/example-blog/node_modules
61
+ - /app/layers/example-blog/.nuxt
62
+ - /app/layers/example-dashboard/node_modules
63
+ - /app/layers/example-dashboard/.nuxt
64
+ depends_on:
65
+ postgres:
66
+ condition: service_healthy
67
+ mailpit:
68
+ condition: service_started
69
+
70
+ volumes:
71
+ postgres-data:
@@ -0,0 +1,94 @@
1
+ <script setup lang="ts">
2
+ import { fileUrl, type StoredFile } from '#framework/files-types'
3
+
4
+ useHead({ title: 'Platform services' })
5
+
6
+ const { loggedIn, fetchSession } = useAuth()
7
+ await fetchSession()
8
+
9
+ const file = ref<StoredFile | null>(null)
10
+
11
+ async function flashAndReload(): Promise<void> {
12
+ await $fetch('/api/demo/flash', { method: 'POST' })
13
+ // A full reload: the toast comes from the cookie during SSR.
14
+ window.location.reload()
15
+ }
16
+
17
+ const now = new Date('2026-11-30T12:00:00Z')
18
+ const samples = [
19
+ ['naturaltime(5 minutes ago)', naturaltime(new Date(now.getTime() - 5 * 60_000), now)],
20
+ ['naturaltime(26 hours ago)', naturaltime(new Date(now.getTime() - 26 * 3600_000), now)],
21
+ ['naturalday(yesterday)', naturalday(new Date(now.getTime() - 24 * 3600_000), now)],
22
+ ['intcomma(1234567)', intcomma(1234567)],
23
+ ['intword(1200000000)', intword(1200000000)],
24
+ ['filesizeformat(4300000)', filesizeformat(4300000)],
25
+ ['`vote${pluralize(2)}`', `vote${pluralize(2)}`],
26
+ ['truncatewords(…, 3)', truncatewords('Knit is a batteries-included framework', 3)],
27
+ ['ordinal(22)', ordinal(22)],
28
+ ] as const
29
+ </script>
30
+
31
+ <template>
32
+ <UContainer class="space-y-6 py-12">
33
+ <div class="flex items-center justify-between">
34
+ <h1 class="text-3xl font-bold text-highlighted">
35
+ Platform services
36
+ </h1>
37
+ <UButton to="/" color="neutral" variant="link" icon="i-lucide-arrow-left" label="Home" />
38
+ </div>
39
+
40
+ <UCard>
41
+ <template #header>
42
+ Messages
43
+ </template>
44
+ <div class="flex flex-wrap gap-2">
45
+ <UButton icon="i-lucide-bell" label="Flash from the server and reload" @click="flashAndReload" />
46
+ <UButton color="neutral" variant="outline" label="Client-side toast" @click="useFlash().show({ type: 'info', title: 'Hello from useFlash()' })" />
47
+ </div>
48
+ </UCard>
49
+
50
+ <UCard>
51
+ <template #header>
52
+ File upload
53
+ </template>
54
+ <div v-if="loggedIn" class="space-y-3">
55
+ <KnitFileInput v-model="file" accept="image/*,application/pdf,text/plain" description="PNG, JPG, PDF or text, up to 10 MB" />
56
+ <pre v-if="file" class="overflow-x-auto rounded bg-elevated p-3 text-xs">{{ file }}</pre>
57
+ <ULink v-if="file" :to="fileUrl(file)" external target="_blank" class="text-sm">
58
+ Open {{ file.name }}
59
+ </ULink>
60
+ </div>
61
+ <p v-else class="text-muted">
62
+ <ULink to="/admin/login" class="text-primary">Sign in</ULink> to upload files.
63
+ </p>
64
+ </UCard>
65
+
66
+ <UCard>
67
+ <template #header>
68
+ Humanize
69
+ </template>
70
+ <dl class="grid gap-x-6 gap-y-1 text-sm sm:grid-cols-2">
71
+ <template v-for="[label, value] in samples" :key="label">
72
+ <dt class="font-mono text-muted">
73
+ {{ label }}
74
+ </dt>
75
+ <dd class="text-highlighted">
76
+ {{ value }}
77
+ </dd>
78
+ </template>
79
+ </dl>
80
+ </UCard>
81
+
82
+ <UCard>
83
+ <template #header>
84
+ Sitemaps &amp; feeds
85
+ </template>
86
+ <div class="flex flex-wrap gap-2">
87
+ <UButton to="/sitemap.xml" external target="_blank" color="neutral" variant="outline" icon="i-lucide-map" label="sitemap.xml" />
88
+ <UButton to="/blog/feed.xml" external target="_blank" color="neutral" variant="outline" icon="i-lucide-rss" label="RSS" />
89
+ <UButton to="/blog/atom.xml" external target="_blank" color="neutral" variant="outline" icon="i-lucide-rss" label="Atom" />
90
+ <UButton to="/blog" color="neutral" variant="outline" icon="i-lucide-newspaper" label="Blog" />
91
+ </div>
92
+ </UCard>
93
+ </UContainer>
94
+ </template>
@@ -0,0 +1,5 @@
1
+ /** Demo for the messages framework: queues a flash message, shown as a toast on the next page load. */
2
+ export default defineEventHandler((event) => {
3
+ flash(event, { type: 'success', title: 'Saved', description: `Flashed by the server at ${new Date().toLocaleTimeString('en-US')}` })
4
+ return { ok: true }
5
+ })
@@ -0,0 +1,126 @@
1
+ import { inArray, sql } from 'drizzle-orm'
2
+ import { manyToMany, registerAdminModel, tabularInline } from '@knit-framework/core/admin'
3
+ import { useModel, type ModelDatabase } from '@knit-framework/core/models'
4
+ import { category, comment, post, postTag, tag } from './server/database/schema'
5
+
6
+ registerAdminModel(category, {
7
+ icon: 'i-lucide-folder',
8
+ label: 'Category',
9
+ labelPlural: 'Categories',
10
+ listDisplay: ['name', 'slug', 'createdAt'],
11
+ listEditable: ['slug'],
12
+ searchFields: ['name', 'slug'],
13
+ ordering: ['name'],
14
+ displayField: 'name',
15
+ readonlyFields: ['createdAt'],
16
+ prepopulatedFields: { slug: 'name' },
17
+ help: {
18
+ slug: 'URL-friendly identifier. Filled in from the name while creating.',
19
+ description: 'Optional. Shown on the category page.',
20
+ },
21
+ // Django TabularInline: edit the category's posts on its change form.
22
+ inlines: [
23
+ tabularInline(post, { fkField: 'categoryId', fields: ['title', 'slug', 'published', 'publishedAt'], extra: 1 }),
24
+ ],
25
+ })
26
+
27
+ registerAdminModel(post, {
28
+ icon: 'i-lucide-file-text',
29
+ listDisplay: ['title', 'published', 'categoryId', 'publishedAt', 'updatedAt'],
30
+ listEditable: ['published'],
31
+ listFilter: ['published', 'categoryId', 'authorId', 'publishedAt'],
32
+ dateHierarchy: 'publishedAt',
33
+ searchFields: ['title', 'slug', 'body'],
34
+ ordering: ['-createdAt'],
35
+ displayField: 'title',
36
+ readonlyFields: ['createdAt', 'updatedAt'],
37
+ prepopulatedFields: { slug: 'title' },
38
+ rawIdFields: ['authorId'],
39
+ fieldsets: [
40
+ { title: 'Content', fields: ['title', 'slug', 'body', 'cover'] },
41
+ { title: 'Publishing', description: 'Controls when and where the post appears.', fields: ['published', 'publishedAt', 'categoryId'] },
42
+ { title: 'Advanced', fields: ['authorId'], collapsible: true, collapsed: true },
43
+ ],
44
+ help: {
45
+ slug: 'Used in the post URL. Filled in from the title while creating.',
46
+ cover: 'PNG, JPEG, WebP or AVIF; shown at the top of the post.',
47
+ published: 'Only published posts appear on the site.',
48
+ publishedAt: 'Shown as the post date. Leave empty to hide it.',
49
+ authorId: 'User id of the author. Use the search button to look one up.',
50
+ },
51
+ manyToMany: [
52
+ manyToMany(postTag, { sourceField: 'postId', targetField: 'tagId', target: tag, label: 'Tags', help: 'Pick any number of tags.' }),
53
+ ],
54
+ viewOnSite: row => (row.published ? `/blog/${row.slug}` : null),
55
+ actions: [
56
+ {
57
+ name: 'publish',
58
+ label: 'Publish selected',
59
+ icon: 'i-lucide-send',
60
+ color: 'success',
61
+ async handler({ ids, db }) {
62
+ const rows = await db
63
+ .update(post)
64
+ .set({ published: true, publishedAt: sql`coalesce(${post.publishedAt}, now())` })
65
+ .where(inArray(post.id, ids.map(Number)))
66
+ .returning({ id: post.id })
67
+ return { message: `Published ${rows.length} post${rows.length === 1 ? '' : 's'}` }
68
+ },
69
+ },
70
+ {
71
+ name: 'unpublish',
72
+ label: 'Unpublish selected',
73
+ icon: 'i-lucide-eye-off',
74
+ color: 'warning',
75
+ confirm: 'Hide the selected posts from the site?',
76
+ async handler({ ids, db }) {
77
+ const rows = await db.update(post).set({ published: false }).where(inArray(post.id, ids.map(Number))).returning({ id: post.id })
78
+ return { message: `Unpublished ${rows.length} post${rows.length === 1 ? '' : 's'}` }
79
+ },
80
+ },
81
+ ],
82
+ })
83
+
84
+ registerAdminModel(tag, {
85
+ icon: 'i-lucide-tag',
86
+ listDisplay: ['name'],
87
+ searchFields: ['name'],
88
+ ordering: ['name'],
89
+ displayField: 'name',
90
+ })
91
+
92
+ registerAdminModel(comment, {
93
+ icon: 'i-lucide-message-square',
94
+ listDisplay: ['body', 'postId', 'authorId', 'approved', 'createdAt'],
95
+ listFilter: ['approved', 'postId', 'createdAt'],
96
+ listEditable: ['approved'],
97
+ searchFields: ['body'],
98
+ ordering: ['-createdAt'],
99
+ displayField: 'body',
100
+ readonlyFields: ['createdAt', 'updatedAt'],
101
+ rawIdFields: ['authorId'],
102
+ help: {
103
+ approved: 'Only approved comments are shown to visitors.',
104
+ authorId: 'Set automatically for comments posted on the site.',
105
+ },
106
+ actions: [
107
+ {
108
+ name: 'approve',
109
+ label: 'Approve selected',
110
+ icon: 'i-lucide-check',
111
+ color: 'success',
112
+ // Through useModel, so comment validators and signals run as for any other write.
113
+ async handler({ ids, db }) {
114
+ const comments = useModel(comment, { db: db as unknown as ModelDatabase })
115
+ let approved = 0
116
+ for (const id of ids.map(Number)) {
117
+ const row = await comments.get(id)
118
+ if (row.approved) continue
119
+ await comments.update(id, { approved: true })
120
+ approved++
121
+ }
122
+ return { message: `Approved ${approved} comment${approved === 1 ? '' : 's'}` }
123
+ },
124
+ },
125
+ ],
126
+ })