You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 766f5f1
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: AGENTS.md
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,7 +85,7 @@ Pick the error view by what failed:
85
85
86
86
-`fetcher` from `@vitnode/core/tanstack/fetcher` is universal - one call, SSR and browser. Never hand-write `createIsomorphicFn().server(...).client(...)` for a fetch.
87
87
- 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`.
89
89
-`@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.
90
90
- 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.
91
91
- 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:
101
101
- Content Engine tag builders live in `content/cache.ts` (`contentPublicListTag` and friends) - pure strings, used to expire a content type's cached reads.
102
102
- 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`.
103
103
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
+
104
110
# Coding Guidelines
105
111
106
112
- Always implement best practices for performance, security, and accessibility.
@@ -188,7 +194,7 @@ npm i x
188
194
### Speed
189
195
190
196
- 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`).
192
198
- Real builds, watchers and child processes go in `INTEGRATION` there. `pnpm test` runs everything; `pnpm test:unit` skips them.
193
199
- Never wait out a real delay - use `vi.useFakeTimers()` and advance the clock.
194
200
- Build a Hono app or a fixture once per file when the tests only read from it.
0 commit comments