app-dev-practices
Skill9 starsChanged 27 days agoMITView on GitHub
Practical guide for building Fusebase Apps apps. Use when: (1) Creating a new app, (2) Setting up project structure, Vite config, or authentication, (3) Building or registering apps, (4) Configuring permissions or public access, (5) Navigating between apps, (6) Fetching user details, (7) Troubleshooting build issues.
- Reads credentials
- Installs packages
In this repository119 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/fusebase-flow-always.mdcCursor rule
- .cursor/rules/fusebase-flow-implementation.mdcCursor rule
- .cursor/rules/fusebase-flow-security.mdcCursor rule
- .cursor/rules/fusebase-flow-specs.mdcCursor rule
- .cursor/rules/fusebase-flow-validation.mdcCursor rule
- api-explorationSkill
- app-api-contract-testingSkill
- app-backendSkill
- app-business-docsSkill
- app-e2e-testsSkill
- app-quality-patternsSkill
- app-routingSkill
- app-secretsSkill
- app-sidecarSkill
- app-ui-designSkill
- business-logic-guardianSkill
- client-vs-internalSkill
- code-reviewSkill
- comment-policySkill
- communicationSkill
- design-discovery-ideationSkill
- dev-debug-logsSkill
- documentation-budgetSkill
- file-uploadSkill
- find-wasted-codeSkill
- find-wasted-effortSkill
- fusebase-cliSkill
- fusebase-dashboardsSkill
- fusebase-flow-health-checkSkill
- fusebase-gateSkill
- fusebase-portal-specific-appsSkill
- git-history-diagnosticSkill
- git-workflowSkill
- handling-authentication-errorsSkill
- handoffSkill
- implementation-planningSkill
- invite-with-passwordSkill
- lightweight-laneSkill
- liveness-disciplineSkill
- managed-integrationsSkill
- mcp-gate-debugSkill
- module-size-disciplineSkill
- north-starSkill
- phase-auditSkill
- product-apps-decompositionSkill
- product-docs-firstSkill
- product-ownerSkill
- project-onboardingSkill
- release-deploy-reportingSkill
- remote-logsSkill
- repo-onboarding-context-mapSkill
- requirements-specificationSkill
- role-disciplineSkill
- security-permissions-reviewSkill
- skill-authoringSkill
- smoke-testingSkill
- task-delegationSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
24 rules. About 0 are common, 8 are distinctive, and 16 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
16
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
Run fusebase scaffold --template spa --dir apps/<name> before writing any app files.
- Distinctive: line 20
When integrating third-party APIs with OAuth, each user must go through their own auth flow and get their own tokens
- Very specific: line 22
Stable partition keys only: when storing per-user rows, the partition key must come from a stable identity (userId, orgUserId, email if …
- Very specific: line 43
Use existing apps in apps/ as reference when building new ones.
- Very specific: line 65
Do NOT add a css.postcss block in vite.config.ts.
- Distinctive: line 95
If your app needs to integrate with another Fusebase app in the same organization, do not treat that app as an external opaque service by …
- Very specific: line 105
Use callAppApi or direct runtime probing only if behavior still needs live verification.
- Distinctive: line 107
Avoid these dead ends as a first move:
- Distinctive: line 113
If a published app API exists, it is the primary cross-app integration surface.
- Very specific: line 119
Do not use built-in Gate permissions such as isolated_store.read for app-to-app operation authorization.
- Very specific: line 134
Read app token on app load from window.FBS_FEATURE_TOKEN first.
- Very specific: line 136
Read app token on app load: check fbsfeaturetoken cookie first, fall back to window.FBS_FEATURE_TOKEN if the cookie is absent <% } %>
- Very specific: line 146
If the app has a backend and the SPA boots auth from GET /api/account/me (or similar) with credentials: 'include':
- Very specific: line 152
Do not conflate this with platform fbsfeaturetoken expiry (AppTokenValidationError modal) — they are separate layers.
- Distinctive: line 229
This is a UX hint, not an authorization fact: Use it to choose what to render.
- Very specific: line 257
Only show a "Session Expired" modal for actual AppTokenValidationError flows
- Distinctive: line 263
Use standard browser navigation (React Router, etc.) since apps run as the main window.
- Distinctive: line 267
Use shadcn/ui. For design and UX guidance (layout, tokens, components, accessibility), see skill app-ui-design.
- Very specific: line 278
If npm run build fails because vite/typescript are not found, npm may be running in production mode (NODE_ENV=production — common in VS …
- Very specific: line 290
After creating an app, register it via fusebase app create from the project root:
- Distinctive: line 297
Execute this command automatically: after writing the app code — do not ask the user to run it manually.
- Very specific: line 301
Use --access to control who can access the app.
- Very specific: line 318
Use --permissions with fusebase app create when the app is first registered.
- Very specific: line 332
Use standard browser navigation (<a>, window.location) with full app URLs obtained from fusebase app list.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
App Dev Practices
Always Scaffold First
Run fusebase scaffold --template spa --dir apps/<name> before writing any app files. This generates the canonical React + Vite + Tailwind v4 + shadcn/ui project structure. For apps needing a backend, also run fusebase scaffold --template backend --dir apps/<name>. Customize from there — never recreate boilerplate by hand.
Multi-User by Default
Every app is multi-user. Multiple users access the same deployed app simultaneously, each with their own identity (app token). Never design for a single user.
Rules:
- Per-user state (OAuth tokens, preferences, selections) must be stored per-user — use httpOnly cookies (set by the server, scoped to the user's browser) or dashboard rows keyed by user ID
- Shared env vars / Fusebase secrets are global — they are the same for all users. Never use them for per-user credentials or settings
- In-memory backend variables are shared across all requests from all users — never store per-user data in module-level variables
- When integrating third-party APIs with OAuth, each user must go through their own auth flow and get their own tokens
- Stable partition keys only: when storing per-user rows, the partition key must come from a stable identity (
userId,orgUserId, email if immutable), not from session/token artifacts. - Never use token-derived keys (e.g.
ft:*, JWT fragments, rotating session IDs) as persistentuser_key/partition keys — they change between sessions and split one user's data into multiple buckets. - Recommended format: normalize once in backend (
user:<userId>) and reuse the same key for both read and write paths.
Ask yourself: "If two users open this app at the same time, will they interfere with each other?" If yes, the design is wrong.
Project Structure
Apps are React/Vite apps in apps/:
apps/
my-app/
package.json
vite.config.ts
src/
App.tsx
main.tsxUse existing apps in apps/ as reference when building new ones.
Vite Config: Ignore Logs Directory
fusebase dev start writes debug logs to <app-dir>/logs/. Tell Vite's file watcher to ignore this directory so it doesn't trigger unnecessary reloads:
// vite.config.ts
export default defineConfig({
server: {
watch: {
ignored: ['**/logs/**'],
},
},
// ...rest of config
});Always include this in every app's vite.config.ts.
Vite Config: Do NOT add inline css.postcss
Do NOT add a css.postcss block in vite.config.ts. An inline css config — even with an empty plugins array — overrides the external postcss.config.js entirely, silently disabling Tailwind and all other PostCSS plugins.
// ❌ BROKEN — overrides postcss.config.js, Tailwind never runs
export default defineConfig({
css: {
postcss: {
plugins: [],
},
},
});// ✅ CORRECT — no css.postcss block; Vite picks up postcss.config.js automatically
export default defineConfig({
plugins: [react()],
// ...rest of config
});PostCSS plugins (@tailwindcss/postcss, autoprefixer) belong in postcss.config.js only.
Backend (Optional)
Apps may optionally include a backend/ subfolder for a backend API (REST + WebSockets). Do not add a backend unless the app genuinely needs backend logic — most apps work fine with the Dashboard SDK alone. See skill app-backend for when and how to add one. The backend is served at /api.
<!-- CUSTOM:SKILL:BEGIN -->Consuming Another Fusebase App's API
If your app needs to integrate with another Fusebase app in the same organization, do not treat that app as an external opaque service by default.
Use this workflow:
- Discover the target app's published API through Gate:
searchAppApiOperationslistAppApiOperationsgetAppApiOperation
- Inventory the relevant operations and their request or response shapes.
- Build the integration against that published contract.
- Use
callAppApior direct runtime probing only if behavior still needs live verification.
Avoid these dead ends as a first move:
- searching for the target app's source code in the current repo
- asking for raw OpenAPI export or manual endpoint lists
- spelunking dashboard tables or storage schemas instead of using the published app API
If a published app API exists, it is the primary cross-app integration surface.
For security-sensitive operations, prefer contract-level app API policy:
x-fusebase-allowed-callersrestricts the caller identity: a caller id is the calling project'sproductId, e.g.client:<productId>, not an app id — sibling apps of one project share it.x-fusebase-required-permissionsrestricts caller capability and must use the app API namespaceapp_api.<namespace>.<capability>.<action>, e.g.app_api.client_portal.provision.write.- Do not use built-in Gate permissions such as
isolated_store.readfor app-to-app operation authorization. - Enforcement arrives per environment. Both extensions are published to the registry and read by
callAppApi, but enforcement is switched on per environment by the platform. Declare them now and grant the matching capability to caller apps withfusebase app update <callerAppId> --permissions "app_api.<namespace>.<capability>.<action>", so the grants are in place when enforcement reaches yours. Never rely on them as your only authorization check today.
<!-- CUSTOM:SKILL:END -->Authentication
<% if (it.flags?.includes("portal-specific-apps")) { %>
Apps run as the main window. The platform provides an app token via window.FBS_FEATURE_TOKEN (with fbsfeaturetoken cookie fallback when needed).
<% } else { %>
Apps run as the main window. The platform sets a fbsfeaturetoken cookie automatically.
<% } %>
Startup flow:
<% if (it.flags?.includes("portal-specific-apps")) { %>
- Read app token on app load from
window.FBS_FEATURE_TOKENfirst; if missing, fall back tofbsfeaturetokencookie <% } else { %> - Read app token on app load: check
fbsfeaturetokencookie first, fall back towindow.FBS_FEATURE_TOKENif the cookie is absent <% } %> - Render app once token is available (show loading state until then)
- Pass token via
x-app-feature-tokenfor direct SDK / Fusebase proxy calls - For calls to the app's own backend (
/api/*), rely on the same-origin cookie and make backend handlers readx-app-feature-tokenor fallback tofbsfeaturetoken
All apps MUST handle token expiration (AppTokenValidationError / 401). See skill handling-authentication-errors for the implementation pattern.
Backend session apps (httpOnly cookie)
If the app has a backend and the SPA boots auth from GET /api/account/me (or similar) with credentials: 'include':
- Load handling-authentication-errors § session probe invariant before writing auth bootstrap code.
- 401 only → login screen. 502/5xx/network → retry with deploy tolerance, then transient error — never
setState('anon')on proxy errors. fusebase deployrestarts the backend — session probe must survive the rollout window (see skill for retry delays).
Do not conflate this with platform fbsfeaturetoken expiry (AppTokenValidationError modal) — they are separate layers.
User Details
<% if (it.flags?.includes("portal-specific-apps")) { %> Fetch auth context:
type AuthContextResponse = {
user?: {
id: number
email: string
}
org?: {
globalId: string
}
// Portal context. Optional in the type because it is absent outside a portal;
// see "Portal context contract" below for exactly when it is present.
// `portalId` and `workspaceId` are always set together, or both absent.
runtimeContext?: {
portalId?: string
workspaceId?: string
}
}
const response = await fetch('https://app-api.{FUSEBASE_HOST}/v4/api/auth/context', {
headers: { 'x-app-feature-token': appToken },
})
const authContext: AuthContextResponse = response.ok ? await response.json() : {}
const user = authContext.user ?? null
// authenticated: { id: 4124, email: "testemail@gmail.com" }
// anonymous visitor on a public app: null (user field is missing)
const insidePortal = Boolean(authContext.runtimeContext?.portalId)Portal context contract
portalId and workspaceId are always set together, or both absent. Where they come from: the
portal app block stores a portal context token, the portal appends it to the app's iframe URL, and
the platform stamps its portalId / workspaceId into the x-app-feature-token minted when the
app opens. The token is stored on the block, not derived from the viewer's session.
Present — app opened from a portal embed whose block carries a portal context token. Because the token is a property of the block, this does not depend on who is looking: it is present for every portal role (client, manager, anonymous visitor) and every portal access mode. Role and access mode never cause it to go missing.
Absent — the exhaustive list:
- The app is opened directly by its own URL, outside any portal.
- Local
fusebase dev start— there is no portal embed locally, same as case 1. - Legacy portal blocks. App blocks added to a portal before the platform started storing the portal context token (April 2026) carry no token, so the fields are absent even though the app is embedded in a portal — for every viewer. Fixable per block, see below.
Possibly stale — if the block was copied from another portal, the stored token still carries
the source portal's id, so portalId can name a different portal than the one the app is
currently displayed in. All of these copy the block verbatim, and nothing re-mints the token:
- block copy-paste,
- duplicating a page or folder from another portal ("Create from another portal"),
- duplicating a whole portal, or creating a portal from a template — every app block in the new portal carries the source/template portal's id,
- synced-copy propagation into a page that lives in another portal.
Fixing a block (cases 3 and stale) — in the portal customizer, the block's app selection has to actually change for a token to be minted: pick a different app in that block, then the intended one again. Re-picking the same app is a no-op — the App picker ignores an unchanged value and no token is minted. If the product has only one app, delete the app block and add it again.
What this means in practice. Boolean(runtimeContext?.portalId) is a good instant UX signal and
is correct for every portal embed created normally today. Absence almost always means "not in a
portal" — but because of case 3, do not make it an unrecoverable dead end: prefer degrading to the
standalone UI, or offer a way forward, rather than a hard "open me from a portal" wall that leaves a
user on a legacy embed stuck.
This is a UX hint, not an authorization fact. Use it to choose what to render. Anything that
grants access to portal data must still be authorized server-side by verifying the
portalFeatureContextToken — which is also what protects you from the stale-token case above. Do
not derive permissions from runtimeContext.
Important for public apps:
- A visitor app token may be valid even when
/auth/contextreturns nouser - Missing
usermeans "not authenticated", not "session expired" /auth/contextshould not throw just because the visitor is anonymous <% } else { %> Fetch current user:
const response = await fetch('https://app-api.{FUSEBASE_HOST}/v4/api/users/me', {
headers: { 'x-app-feature-token': appToken },
})
const user = response.ok ? await response.json() : null
// authenticated: { id: 4124, email: "testemail@gmail.com" }
// anonymous visitor on a public app: nullImportant for public apps:
- A visitor app token may be valid even when
/users/mereturns 401 - In that case, treat the result as
user: null, not as "session expired" <% } %> - Show the login/auth form for anonymous visitors
- Only show a "Session Expired" modal for actual
AppTokenValidationErrorflows
See skill handling-authentication-errors for the exact 401 handling rules.
Navigation
Use standard browser navigation (React Router, etc.) since apps run as the main window. For routing setup, see skill app-routing.
UI Framework
Use shadcn/ui. For design and UX guidance (layout, tokens, components, accessibility), see skill app-ui-design.
Building Apps
cd apps/my-app
npm run builddevDependencies Missing
If npm run build fails because vite/typescript are not found, npm may be running in production mode (NODE_ENV=production — common in VS Code / Claude Code). Fix:
npm install --include=devTypecheck at project root
From the repo root, npm run typecheck runs tsc for each app (see root package.json). It catches strict TypeScript issues that ESLint does not, including the same failures as tsc inside fusebase deploy’s build. Claude Code Stop hooks run it after lint.
Registering Apps
After creating an app, register it via fusebase app create from the project root:
fusebase app create --name <name> --subdomain <subdomain> --path <path> --dev-command <command> --build-command <command> --output-dir <dir>Execute this command automatically after writing the app code — do not ask the user to run it manually.
Access Principals
Use --access to control who can access the app. Principals are comma-separated:
# Public (visitor) access
fusebase app create --name <name> --access=visitor
fusebase app update <appId> --access=visitor
# Org role access (guest, client, member, manager, owner)
fusebase app update <appId> --access=orgRole:member
fusebase app update <appId> --access=orgRole:member,orgRole:client
# Combine visitor and org roles
fusebase app update <appId> --access=visitor,orgRole:memberPermissions
Use --permissions with fusebase app create when the app is first registered. Only use fusebase app update --permissions when changing permissions on an already-registered app. Use MCP to discover dashboard/view IDs. See skill fusebase-cli for permission format and examples.
Getting App URLs
fusebase app listLists all apps with their deployed URLs. Use this to get actual URLs — do NOT hardcode or guess them.
Always use the full subdomain URL (read FUSEBASE_APP_HOST from .env, e.g. https://my-app.{FUSEBASE_APP_HOST}/), never relative paths. Each app is served from its own subdomain root — see skill app-routing.
Cross-App Navigation
Use standard browser navigation (<a>, window.location) with full app URLs obtained from fusebase app list.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

