Expert guidance for building full-stack apps with RedwoodSDK, Cloudflare Workers, D1, Drizzle ORM, and React Server Components. Includes database migrations, authentication, and session management patterns.
Expert guidance for working with RedwoodSDK applications built on Cloudflare Workers infrastructure.
This skill provides comprehensive development patterns for full-stack applications using:
When working with RedwoodSDK projects, understand these core architectural patterns:
```bash
pnpm dev
```
This starts the Vite dev server with Cloudflare Workers compatibility. Hot module reloading is enabled for both server and client code.
**For local development (uses local SQLite):**
```bash
npm run local:db:generate # Generate migration files
npm run local:db:migrate # Apply migrations
npm run migrate:dev # Generate + migrate in one step
npm run local:db:push
npm run local:db:studio # Opens Drizzle Studio on localhost
```
**For production (uses Cloudflare D1):**
```bash
npm run db:generate # Generate migration files
npm run db:migrate # Apply to D1 via Cloudflare API
npm run db:push # Direct schema push
npm run db:studio
```
**Authentication schema updates:**
```bash
npm run auth:db:migrate # Regenerates auth schema and migrates
```
**Server Components (default behavior):**
```typescript
// src/app/components/MyComponent.tsx
import { db } from '~/db'
export default async function MyComponent({ ctx }) {
// Can directly await database queries
const users = await db.select().from(schema.users)
return (
<div>
{users.map(user => <div key={user.id}>{user.name}</div>)}
</div>
)
}
```
**Client Components (for interactivity):**
```typescript
// src/app/components/Counter.tsx
"use client";
import { useState } from 'react'
export default function Counter() {
const [count, setCount] = useState(0)
return (
<button onClick={() => setCount(count + 1)}>
Count: {count}
</button>
)
}
```
**Key rules:**
**In Server Components:**
```typescript
// Async component - no useEffect needed
export default async function UserList({ ctx }) {
const users = await db.query.users.findMany({
with: { posts: true }
})
return <ul>{users.map(u => <li>{u.name}</li>)}</ul>
}
```
**In Client Components:**
```typescript
"use client";
import { useEffect, useState } from 'react'
export default function ClientData() {
const [data, setData] = useState(null)
useEffect(() => {
fetch('/api/data').then(r => r.json()).then(setData)
}, [])
return <div>{data && JSON.stringify(data)}</div>
}
```
Access session via the context object:
```typescript
// In a route handler or server component
export default async function ProtectedPage({ ctx }) {
const session = await ctx.session.get()
if (!session.user) {
return <Redirect to="/login" />
}
return <div>Welcome {session.user.name}</div>
}
```
Session operations:
```bash
pnpm types # Run TypeScript type checker
pnpm check # Generate types + type check
```
Run `pnpm check` after schema changes to regenerate database types.
```bash
pnpm build # Build for production (outputs to dist/)
npm run release # Full release: clean + generate + build + deploy
```
The `release` script:
1. Cleans previous build artifacts
2. Generates latest migrations
3. Builds optimized Worker bundle
4. Deploys to Cloudflare via Wrangler
1. Edit `src/db/schema.ts`:
```typescript
export const posts = sqliteTable('posts', {
id: integer('id').primaryKey({ autoIncrement: true }),
title: text('title').notNull(),
authorId: integer('author_id').references(() => users.id),
createdAt: integer('created_at', { mode: 'timestamp' })
})
```
2. Generate and apply migration:
```bash
npm run migrate:dev # For local
npm run db:migrate # For production
```
3. Regenerate types:
```bash
pnpm check
```
1. Define route in `src/worker.tsx`:
```typescript
app.get('/api/auth/status', async (ctx) => {
const session = await ctx.session.get()
return ctx.json({ user: session.user || null })
})
```
2. Use Better Auth helpers from `src/app/lib/auth.client.ts` and `auth.ts`
Configure in `wrangler.jsonc`:
```jsonc
{
"vars": {
"ENVIRONMENT": "development"
},
"d1_databases": [
{
"binding": "DB",
"database_name": "my-app-db",
"database_id": "..."
}
]
}
```
Access in code: `ctx.env.ENVIRONMENT`
Use this skill when:
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/redwoodsdk-cloudflare-workers-development/raw