bun-tanstack-start
TanStack Start full-stack React framework with Bun runtime. Use for TanStack Router, server functions, vinxi, or encountering SSR, build, preset errors.
git clone --depth 1 https://github.com/secondsky/claude-skills /tmp/bun-tanstack-start && cp -r /tmp/bun-tanstack-start/plugins/bun/skills/bun-tanstack-start ~/.claude/skills/bun-tanstack-startSKILL.md
# Bun TanStack Start
Run TanStack Start (full-stack React framework) with Bun.
## Quick Start
```bash
# Create new TanStack Start project
bunx create-tanstack-start@latest my-app
cd my-app
# Install dependencies
bun install
# Development
bun run dev
# Build
bun run build
# Preview
bun run start
```
## Secure Installation
Scaffolding tools like `bunx create-tanstack-start` download and execute remote code. Before running, follow supply chain security best practices:
- **Block post-install scripts** — Bun disables them by default; allow specific packages via `trustedDependencies` in `package.json`
- **Cooldown period** — Configure `minimumReleaseAge` in `bunfig.toml` to wait 7 days for new versions
- **Audit before installing** — Run `socket package score npm <pkg>` or use `socket npm install <pkg>` to check packages
Load the `dependency-upgrade` skill for full security configuration including Socket CLI integration, cooldown setup, lockfile validation, and CI enforcement.
## Project Setup
### package.json
```json
{
"scripts": {
"dev": "vinxi dev",
"build": "vinxi build",
"start": "vinxi start"
},
"dependencies": {
"@tanstack/react-router": "^1.139.0",
"@tanstack/start": "^1.120.0",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"vinxi": "^0.5.10"
}
}
```
### app.config.ts
```typescript
import { defineConfig } from "@tanstack/start/config";
export default defineConfig({
server: {
preset: "bun",
},
});
```
## File-Based Routing
```
app/
├── routes/
│ ├── __root.tsx # Root layout
│ ├── index.tsx # /
│ ├── about.tsx # /about
│ ├── users/
│ │ ├── index.tsx # /users
│ │ └── $userId.tsx # /users/:userId
│ └── api/
│ └── users.ts # /api/users
└── client.tsx
```
## Route Components
### Basic Route
```tsx
// app/routes/index.tsx
import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/")({
component: Home,
});
function Home() {
return <h1>Welcome Home</h1>;
}
```
### Route with Loader
```tsx
// app/routes/users/index.tsx
import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/users/")({
loader: async () => {
const response = await fetch("/api/users");
return response.json();
},
component: Users,
});
function Users() {
const users = Route.useLoaderData();
return (
<ul>
{users.map((user) => (
<li key={user.id}>{user.name}</li>
))}
</ul>
);
}
```
### Dynamic Routes
```tsx
// app/routes/users/$userId.tsx
import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/users/$userId")({
loader: async ({ params }) => {
const response = await fetch(`/api/users/${params.userId}`);
return response.json();
},
component: UserDetail,
});
function UserDetail() {
const user = Route.useLoaderData();
const { userId } = Route.useParams();
return (
<div>
<h1>{user.name}</h1>
<p>User ID: {userId}</p>
</div>
);
}
```
## Server Functions
### Define Server Function
```tsx
// app/routes/users/index.tsx
import { createFileRoute } from "@tanstack/react-router";
import { createServerFn } from "@tanstack/start";
import { Database } from "bun:sqlite";
const getUsers = createServerFn("GET", async () => {
const db = new Database("data.sqlite");
const users = db.query("SELECT * FROM users").all();
db.close();
return users;
});
const createUser = createServerFn("POST", async (name: string) => {
const db = new Database("data.sqlite");
db.run("INSERT INTO users (name) VALUES (?)", [name]);
db.close();
return { success: true };
});
export const Route = createFileRoute("/users/")({
loader: () => getUsers(),
component: Users,
});
function Users() {
const users = Route.useLoaderData();
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const formData = new FormData(e.currentTarget);
const name = formData.get("name") as string;
await createUser(name);
// Refetch or update state
};
return (
<div>
<form onSubmit={handleSubmit}>
<input name="name" placeholder="Name" />
<button type="submit">Add User</button>
</form>
<ul>
{users.map((user) => (
<li key={user.id}>{user.name}</li>
))}
</ul>
</div>
);
}
```
### Server Function with Context
```tsx
import { createServerFn } from "@tanstack/start";
import { getWebRequest } from "@tanstack/start/server";
const getSession = createServerFn("GET", async () => {
const request = getWebRequest();
const cookies = request.headers.get("Cookie");
// Parse and validate session
return { userId: "123", role: "admin" };
});
const protectedAction = createServerFn("POST", async (data: any) => {
const session = await getSession();
if (session.role !== "admin") {
throw new Error("Unauthorized");
}
// Perform action
return { success: true };
});
```
## API Routes
```typescript
// app/routes/api/users.ts
import { createAPIFileRoute } from "@tanstack/start/api";
import { Database } from "bun:sqlite";
export const Route = createAPIFileRoute("/api/users")({
GET: async ({ request }) => {
const db = new Database("data.sqlite");
const users = db.query("SELECT * FROM users").all();
db.close();
return Response.json(users);
},
POST: async ({ request }) => {
const { name } = await request.json();
const db = new Database("data.sqlite");
db.run("INSERT INTO users (name) VALUES (?)", [name]);
db.close();
return Response.json({ success: true });
},
});
```
## Root Layout
```tsx
// app/routes/__root.tsx
import { createRootRoute, Link, Outlet } from "@tanstack/react-router";
export const Route = createRootRoute({
component: Root,
});
function Root() {
return (
<html>
<head>
<meta charSet="utf-8" />
<meta name="viewport"Role-based access control (RBAC) with permissions and policies. Use for admin dashboards, enterprise access, multi-tenant apps, fine-grained authorization, or encountering permission hierarchies, role inheritance, policy conflicts.
100+ animated React components (Aceternity UI) for Next.js with Tailwind. Use for hero sections, parallax, 3D effects, or encountering animation, shadcn CLI integration errors.
shadcn/ui AI chat components for conversational interfaces. Use for streaming chat, tool/function displays, reasoning visualization, or encountering Next.js App Router setup, Tailwind v4 integration, AI SDK v5 migration errors.
Vercel AI SDK v5 for backend AI (text generation, structured output, tools, agents). Multi-provider. Use for server-side AI or encountering AI_APICallError, AI_NoObjectGeneratedError, streaming failures.
Vercel AI SDK v5 React hooks (useChat, useCompletion, useObject) for AI chat interfaces. Use for React/Next.js AI apps or encountering parse stream errors, no response, streaming issues.
Secure API authentication with JWT, OAuth 2.0, API keys. Use for authentication systems, third-party integrations, service-to-service communication, or encountering token management, security headers, auth flow errors.
Creates comprehensive API changelogs documenting breaking changes, deprecations, and migration strategies for API consumers. Use when managing API versions, communicating breaking changes, or creating upgrade guides.
Verifies API contracts between services using consumer-driven contracts, schema validation, and tools like Pact. Use when testing microservices communication, preventing breaking changes, or validating OpenAPI specifications.