Skip to content

Commit 311e2eb

Browse files
aXenDeveloperclaude
andcommitted
refactor: extract @vitnode/api and migrate API scaffolding
Move the VitNode backend out of @vitnode/core into a new publishable workspace package, packages/api (@vitnode/api), with one dependency direction: core depends on api, never the reverse. - api owns src/api (flattened), the database schema and drizzle.config, content/server and the server halves of access/approvals/containers, emails, API locales, WebSocket/Cloudflare runtimes, the page-cache store/protocol and the vitnode CLI (bin), plus the browser-safe contracts both sides read (content definitions, staff permissions, fetcher contract/registry, plugin manifest, widget schemas). - Split mixed modules: VitNodeApiConfig/buildApiConfig move to @vitnode/api/vitnode.config; widgets split into API schemas (defineWidgetSchema) and core renderers (defineWidget) with separate default registries; i18n sources, editable pages and dashboard widget types split along the same line. - The CLI loads frontend route checks from core's `frontendCliIntegration` export when the project has core, and skips them otherwise; an older core without the export is reported, not mistaken for an API-only project. - The built-in plugin keeps the logical id @vitnode/core: endpoints, fetcher calls, permissions, events and database rows are unchanged. Drizzle discovers built-in tables in @vitnode/api; checkPluginId and the update feed map the built-in id to the package that ships it (one API_PACKAGE constant beside CORE_PLUGIN_ID). - Migrate apps, plugins, adapters, create-vitnode-app modes and templates, plugin registration, turbo.json, the publish workflow, version manager, update-manifest publisher, docs and AGENTS.md. - Trim dependencies: `shadcn` to core devDependencies; drop `@hono/zod-validator`, core's leftover `drizzle-kit`/`jsdom`/`tsx`, duplicate `jiti`/`motion` entries and the `@hono/zod-openapi` peer; declare `sonner`/`lucide-react` peers and optional `tailwindcss`/ `tw-animate-css` peers. - Remove every `sql.raw` call: keyset and thread cursors cast their text back with `cursorTextCast`, the comparison picks `>`/`<` with tagged templates, and the search vector CASE and SSO CHECK lists use `sql` fragments with `.inlineParams()`. Generated SQL and DDL are unchanged. - Upgrade pnpm to 12.21.0 across workflows and docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent aac93e1 commit 311e2eb

2,318 files changed

Lines changed: 12485 additions & 9292 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/actions/setup/action.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ runs:
77
- uses: pnpm/action-setup@v6.1.0
88
name: Install pnpm
99
with:
10-
version: 12.18.0
10+
version: 12.21.0
1111

1212
- name: Install Node.js
1313
uses: actions/setup-node@v7.0.0

‎.github/workflows/bump_publish.yml‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ on:
3535
env:
3636
# Every package this workflow publishes. The publish steps and the update
3737
# manifest both read it, so the manifest never names a package npm did not get.
38-
PUBLISHED_PACKAGES: "create-vitnode-app @vitnode/core @vitnode/config @vitnode/blog @vitnode/nodemailer @vitnode/resend @vitnode/node-cron"
38+
PUBLISHED_PACKAGES: "create-vitnode-app @vitnode/api @vitnode/core @vitnode/config @vitnode/blog @vitnode/nodemailer @vitnode/resend @vitnode/node-cron"
39+
# Published last, and only once everything else is on npm: a new app depends
40+
# on `@vitnode/api` and `@vitnode/core` at exactly this version.
41+
SCAFFOLD_PACKAGE: "create-vitnode-app"
3942

4043
jobs:
4144
bump-version:
@@ -59,7 +62,7 @@ jobs:
5962
- uses: pnpm/action-setup@v6.1.0
6063
name: Install pnpm
6164
with:
62-
version: 12.18.0
65+
version: 12.21.0
6366

6467
- name: Install Node.js
6568
uses: actions/setup-node@v7.0.0
@@ -90,21 +93,36 @@ jobs:
9093

9194
- name: Publish canary
9295
if: ${{ (github.event.inputs.mode == 'bump_and_publish' || github.event.inputs.mode == 'publish') && github.event.inputs.release == 'canary' }}
93-
run: pnpm publish $(printf -- "--filter %s " $PUBLISHED_PACKAGES) --tag canary --no-git-checks --access public
96+
# pnpm publishes the filtered packages in dependency order, so
97+
# `@vitnode/api` goes out before `@vitnode/core`; the scaffold follows
98+
# only if all of them succeeded.
99+
run: |
100+
pnpm publish $(printf -- "--filter %s " $(echo $PUBLISHED_PACKAGES | tr ' ' '\n' | grep -vx "$SCAFFOLD_PACKAGE")) --tag canary --no-git-checks --access public
101+
pnpm publish --filter "$SCAFFOLD_PACKAGE" --tag canary --no-git-checks --access public
94102
env:
95103
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
96104
NPM_CONFIG_PROVENANCE: true
97105

98106
- name: Publish release candidate
99107
if: ${{ (github.event.inputs.mode == 'bump_and_publish' || github.event.inputs.mode == 'publish') && github.event.inputs.release == 'release-candidate' }}
100-
run: pnpm publish $(printf -- "--filter %s " $PUBLISHED_PACKAGES) --tag rc --no-git-checks --access public
108+
# pnpm publishes the filtered packages in dependency order, so
109+
# `@vitnode/api` goes out before `@vitnode/core`; the scaffold follows
110+
# only if all of them succeeded.
111+
run: |
112+
pnpm publish $(printf -- "--filter %s " $(echo $PUBLISHED_PACKAGES | tr ' ' '\n' | grep -vx "$SCAFFOLD_PACKAGE")) --tag rc --no-git-checks --access public
113+
pnpm publish --filter "$SCAFFOLD_PACKAGE" --tag rc --no-git-checks --access public
101114
env:
102115
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
103116
NPM_CONFIG_PROVENANCE: true
104117

105118
- name: Publish stable
106119
if: ${{ (github.event.inputs.mode == 'bump_and_publish' || github.event.inputs.mode == 'publish') && github.event.inputs.release == 'stable' }}
107-
run: pnpm publish $(printf -- "--filter %s " $PUBLISHED_PACKAGES) --tag latest --no-git-checks --access public
120+
# pnpm publishes the filtered packages in dependency order, so
121+
# `@vitnode/api` goes out before `@vitnode/core`; the scaffold follows
122+
# only if all of them succeeded.
123+
run: |
124+
pnpm publish $(printf -- "--filter %s " $(echo $PUBLISHED_PACKAGES | tr ' ' '\n' | grep -vx "$SCAFFOLD_PACKAGE")) --tag latest --no-git-checks --access public
125+
pnpm publish --filter "$SCAFFOLD_PACKAGE" --tag latest --no-git-checks --access public
108126
env:
109127
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
110128
NPM_CONFIG_PROVENANCE: true
@@ -148,7 +166,7 @@ jobs:
148166
- uses: pnpm/action-setup@v6.1.0
149167
name: Install pnpm
150168
with:
151-
version: 12.18.0
169+
version: 12.21.0
152170

153171
- name: Install Node.js
154172
uses: actions/setup-node@v7.0.0

‎.github/workflows/publish-security-updates.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- uses: pnpm/action-setup@v6.1.0
3030
name: Install pnpm
3131
with:
32-
version: 12.18.0
32+
version: 12.21.0
3333

3434
- name: Install Node.js
3535
uses: actions/setup-node@v7.0.0

‎AGENTS.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Pick the error view by what failed:
8585

8686
- `fetcher` from `@vitnode/core/tanstack/fetcher` is universal - one call, SSR and browser. Never hand-write `createIsomorphicFn().server(...).client(...)` for a fetch.
8787
- A call names the plugin, never an API module: `fetcher({ plugin: "@vitnode/core", method: "get", module: "users", path: "/devices" })`. `plugin`, `module` (any nesting depth, `admin/advanced/cron`), `path`, `method`, `args` and the response are all inferred from the plugin API registry; an invalid combination is a compile error at the offending property.
88-
- The registry is `ApiPluginRegistry` in `@vitnode/core/lib/fetcher/registry`. Core registers itself; an app's `src/api-registry.gen.ts` registers every configured plugin that exports `config.api`, with type-only imports; `vitnode build`/`vitnode dev` write a plugin's own entry to its `types/api-registry.gen.d.ts` (kept out of the published package) so its pages can call it. Never import a plugin API factory as a value outside `vitnode.api.config.ts`.
88+
- The registry is `ApiPluginRegistry` in `@vitnode/api/lib/fetcher/registry` (`@vitnode/core/lib/fetcher/registry` re-exports it). Core registers itself; an app's `src/api-registry.gen.ts` registers every configured plugin that exports `config.api`, with type-only imports; `vitnode build`/`vitnode dev` write a plugin's own entry to its `types/api-registry.gen.d.ts` (kept out of the published package) so its pages can call it. Never import a plugin API factory as a value outside `vitnode.api.config.ts`.
8989
- `@vitnode/core/tanstack/fetcher/server` is for work that is genuinely server-only: server functions, `allowSaveCookies` cookie relay, cron/jobs, upstream secrets or a different `origin`. Same call shape, more options.
9090
- Shared `views/*` query modules call `fetcher` directly - no injected transport, no browser-only twin. `@vitnode/core/lib/fetcher-client` is the framework-neutral browser primitive the universal fetcher is built on, for code that never renders on a server.
9191
- Write the route inline at the call site - never build a request object elsewhere and pass it in.
@@ -101,6 +101,12 @@ Pick the error view by what failed:
101101
- Content Engine tag builders live in `content/cache.ts` (`contentPublicListTag` and friends) - pure strings, used to expire a content type's cached reads.
102102
- A background mutation cannot expire a front end's cache by calling a function. `dispatchContentRevalidation` posts to the origins an install opts into via `content.revalidateOrigins`.
103103

104+
# Packages
105+
106+
- `@vitnode/api` (`packages/api`) owns the backend: Hono API, database schema, Content Engine server, emails, WebSocket/Cloudflare runtime and the `vitnode` CLI. `@vitnode/core` (`packages/vitnode`) owns React, the AdminCP, TanStack Start and the Vite plugin, and depends on `@vitnode/api` - never the other way round, not even for types.
107+
- Server code imports from `@vitnode/api/...` (`@vitnode/api/lib/plugin`, `@vitnode/api/database/*`, `@vitnode/api/content/server`, `buildApiConfig` from `@vitnode/api/vitnode.config`). Contracts both sides read (content definitions, staff permissions, widget schemas) live in browser-safe `@vitnode/api` subpaths; core imports them directly, not through its own re-export stubs.
108+
- The built-in plugin keeps the logical id `@vitnode/core` in endpoints, `fetcher({ plugin: "@vitnode/core" })`, permissions, events and database rows. Never replace that id with the package name.
109+
104110
# Coding Guidelines
105111

106112
- Always implement best practices for performance, security, and accessibility.
@@ -188,7 +194,7 @@ npm i x
188194
### Speed
189195

190196
- The file name picks the environment: `*.test.tsx` runs in happy-dom (project `dom`), `*.test.ts` runs in node (project `unit`). Never add a `// @vitest-environment` pragma.
191-
- `unit` shares one module graph per worker (`isolate: false`). A test that asserts process-wide state ("nothing registered yet") goes in `ISOLATED` in `packages/vitnode/vitest.config.ts`.
197+
- `unit` shares one module graph per worker (`isolate: false`). A test that asserts process-wide state ("nothing registered yet") goes in `ISOLATED` in the package's `vitest.config.ts` (`packages/vitnode` or `packages/api`).
192198
- Real builds, watchers and child processes go in `INTEGRATION` there. `pnpm test` runs everything; `pnpm test:unit` skips them.
193199
- Never wait out a real delay - use `vi.useFakeTimers()` and advance the clock.
194200
- Build a Hono app or a fixture once per file when the tests only read from it.

‎apps/api/drizzle.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineVitNodeDrizzleConfig } from "@vitnode/core/drizzle.config";
1+
import { defineVitNodeDrizzleConfig } from "@vitnode/api/drizzle.config";
22

33
import { POSTGRES_URL, vitNodeApiConfig } from "./src/vitnode.api.config";
44

‎apps/api/global.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="use-intl" />
22

3-
import core from "@vitnode/core/locales/api/en.json" with { type: "json" };
3+
import core from "@vitnode/api/locales/en.json" with { type: "json" };
44

55
declare module "use-intl" {
66
interface AppConfig {

‎apps/api/package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
"@ai-sdk/anthropic": "^4.0.98",
2424
"@ai-sdk/google": "^4.0.113",
2525
"@hono/zod-openapi": "^1.6.3",
26-
"@hono/zod-validator": "^0.9.1",
27-
"@vitnode/core": "workspace:*",
26+
"@vitnode/api": "workspace:*",
2827
"@vitnode/node-cron": "workspace:*",
2928
"@vitnode/stripe": "workspace:*",
3029
"@vitnode/supabase-storage": "workspace:*",

‎apps/api/src/i18n.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { VitNodeI18nConfig } from "@vitnode/core/lib/i18n/types";
1+
import type { VitNodeI18nConfig } from "@vitnode/api/lib/i18n/types";
22

33
export const i18n = {
44
defaultLocale: "en",

‎apps/api/src/index.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type { StorageStaticConfig } from "@vitnode/core/api/models/storage";
1+
import type { StorageStaticConfig } from "@vitnode/api/models/storage";
22

33
import { serve, upgradeWebSocket } from "@hono/node-server";
44
import { serveStatic } from "@hono/node-server/serve-static";
55
import { OpenAPIHono } from "@hono/zod-openapi";
6-
import { VitNodeAPI } from "@vitnode/core/api/config";
7-
import { storageStaticHeadersMiddleware } from "@vitnode/core/api/middlewares/storage-static.middleware";
8-
import { websocketOriginMiddleware } from "@vitnode/core/api/middlewares/websocket-origin.middleware";
9-
import { handleVitNodeWebSocket } from "@vitnode/core/ws/handle";
6+
import { VitNodeAPI } from "@vitnode/api/config";
7+
import { storageStaticHeadersMiddleware } from "@vitnode/api/middlewares/storage-static.middleware";
8+
import { websocketOriginMiddleware } from "@vitnode/api/middlewares/websocket-origin.middleware";
9+
import { handleVitNodeWebSocket } from "@vitnode/api/ws/handle";
1010
import { compress } from "hono/compress";
1111
import { mkdirSync } from "node:fs";
1212
import { type WebSocket, WebSocketServer } from "ws";

‎apps/api/src/vitnode.api.config.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { google } from "@ai-sdk/google";
2+
import { DiscordSSOApiPlugin } from "@vitnode/api/adapters/sso/discord";
3+
import { FacebookSSOApiPlugin } from "@vitnode/api/adapters/sso/facebook";
4+
import { GoogleSSOApiPlugin } from "@vitnode/api/adapters/sso/google";
5+
import { coreRelations } from "@vitnode/api/database/relations";
6+
// import { LocalStorageAdapter } from "@vitnode/api/adapters/storage/local";
7+
import { buildApiConfig } from "@vitnode/api/vitnode.config";
28
import { blogApiPlugin } from "@vitnode/blog/config.api";
3-
import { DiscordSSOApiPlugin } from "@vitnode/core/api/adapters/sso/discord";
4-
import { FacebookSSOApiPlugin } from "@vitnode/core/api/adapters/sso/facebook";
5-
import { GoogleSSOApiPlugin } from "@vitnode/core/api/adapters/sso/google";
6-
import { coreRelations } from "@vitnode/core/database/relations";
7-
// import { LocalStorageAdapter } from "@vitnode/core/api/adapters/storage/local";
8-
import { buildApiConfig } from "@vitnode/core/vitnode.config";
99
import { forumApiPlugin } from "@vitnode/forum/config.api";
1010
import { NodeCronAdapter } from "@vitnode/node-cron";
1111
import { NodemailerEmailAdapter } from "@vitnode/nodemailer";
@@ -141,7 +141,7 @@ export const vitNodeApiConfig = buildApiConfig({
141141
clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
142142
}),
143143
// More built-in providers, opt-in: import the factory from
144-
// `@vitnode/core/api/adapters/sso/{providerId}`, uncomment its line and
144+
// `@vitnode/api/adapters/sso/{providerId}`, uncomment its line and
145145
// set its variables in `.env`. A button without credentials still shows
146146
// up and fails on click, so only add the ones you configure. Apple,
147147
// PayPal and TikTok need a public HTTPS `VITNODE_WEB_URL`.

0 commit comments

Comments
 (0)