.claude/skills/fullstack-workflow/SKILL.md
Complete fullstack workflow combining GET API routes, server actions, SWR data fetching, and form handling. Use when building features that need both data fetching and mutations from API to UI.
npx skillsauth add elie222/inbox-zero fullstack-workflowInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Complete guide for building features from API to UI, combining GET API routes, data fetching, form handling, and server actions.
When building a new feature, follow this pattern:
For fetching data. Always wrap with withAuth or withEmailAccount:
// apps/web/app/api/user/example/route.ts
import { NextResponse } from "next/server";
import prisma from "@/utils/prisma";
import { withEmailAccount } from "@/utils/middleware";
// Auto-generate response type for client use
export type GetExampleResponse = Awaited<ReturnType<typeof getData>>;
export const GET = withEmailAccount(async (request) => {
const { emailAccountId } = request.auth;
const result = await getData({ emailAccountId });
return NextResponse.json(result);
});
// We make this its own function so we can infer the return type for a type-safe response on the client
async function getData({ emailAccountId }: { emailAccountId: string }) {
const items = await prisma.example.findMany({
where: { emailAccountId },
});
return { items };
}
For mutations. Use next-safe-action with proper validation.
Action clients (defined in apps/web/utils/actions/safe-action.ts):
| Client | Context | Use when |
|--------|---------|----------|
| actionClientUser | ctx.userId | Only need authenticated user |
| actionClient | ctx.emailAccountId, ctx.userId | Need user + email account (most mutations) |
| adminActionClient | ctx.logger | Admin-only actions (no userId in ctx) |
Always use .metadata({ name: "actionName" }) for Sentry instrumentation. Use SafeError for expected errors.
Validation Schema (apps/web/utils/actions/example.validation.ts):
import { z } from "zod";
export const createExampleBody = z.object({
name: z.string().min(1, "Name is required"),
email: z.string().email("Invalid email"),
description: z.string().optional(),
});
export type CreateExampleBody = z.infer<typeof createExampleBody>;
export const updateExampleBody = z.object({
id: z.string(),
name: z.string().optional(),
email: z.string().email().optional(),
description: z.string().optional(),
});
export type UpdateExampleBody = z.infer<typeof updateExampleBody>;
Server Action (apps/web/utils/actions/example.ts):
"use server";
import { actionClient } from "@/utils/actions/safe-action";
import { createExampleBody, updateExampleBody } from "@/utils/actions/example.validation";
import prisma from "@/utils/prisma";
export const createExampleAction = actionClient
.metadata({ name: "createExample" })
.inputSchema(createExampleBody)
.action(async ({
ctx: { emailAccountId },
parsedInput: { name, email, description }
}) => {
const example = await prisma.example.create({
data: {
name,
email,
description,
emailAccountId,
},
});
return example;
});
export const updateExampleAction = actionClient
.metadata({ name: "updateExample" })
.inputSchema(updateExampleBody)
.action(async ({
ctx: { emailAccountId },
parsedInput: { id, name, email, description }
}) => {
const example = await prisma.example.update({
where: { id, emailAccountId },
data: { name, email, description },
});
return example;
});
Use SWR for client-side data fetching:
import useSWR from "swr";
import { GetExampleResponse } from "@/app/api/user/example/route";
export function useExamples() {
return useSWR<GetExampleResponse>("/api/user/example");
}
Use React Hook Form with useAction from next-safe-action/hooks:
import { useCallback } from "react";
import { useForm, type SubmitHandler } from "react-hook-form";
import { useAction } from "next-safe-action/hooks";
import { zodResolver } from "@hookform/resolvers/zod";
import { Input } from "@/components/Input";
import { Button } from "@/components/ui/button";
import { toastSuccess, toastError } from "@/components/Toast";
import { getActionErrorMessage } from "@/utils/error";
import { createExampleAction } from "@/utils/actions/example";
import { createExampleBody, type CreateExampleBody } from "@/utils/actions/example.validation";
export function ExampleForm({ onSuccess }: { onSuccess?: () => void }) {
const {
register,
handleSubmit,
formState: { errors },
reset,
} = useForm<CreateExampleBody>({
resolver: zodResolver(createExampleBody),
});
const { execute, isExecuting } = useAction(createExampleAction, {
onSuccess: () => {
toastSuccess({ description: "Example created!" });
reset();
onSuccess?.();
},
onError: (error) => {
toastError({
description: getActionErrorMessage(error.error),
});
},
});
return (
<form className="space-y-4" onSubmit={handleSubmit(execute)}>
<Input
type="text"
name="name"
label="Name"
registerProps={register("name")}
error={errors.name}
/>
<Input
type="email"
name="email"
label="Email"
registerProps={register("email")}
error={errors.email}
/>
<Input
type="text"
name="description"
label="Description"
registerProps={register("description")}
error={errors.description}
/>
<Button type="submit" loading={isExecuting}>
Create Example
</Button>
</form>
);
}
'use client';
import { useExamples } from "@/hooks/useExamples";
import { Button } from "@/components/ui/button";
import { LoadingContent } from "@/components/LoadingContent";
export function Examples() {
const { data, isLoading, error } = useExamples();
return (
<LoadingContent loading={isLoading} error={error}>
<div className="grid gap-4">
{data?.examples.map((example) => (
<div key={example.id} className="border p-4 rounded">
<h3 className="font-semibold">{example.name}</h3>
<p className="text-gray-600">{example.email}</p>
{example.description && (
<p className="text-sm text-gray-500">{example.description}</p>
)}
</div>
))}
</div>
</LoadingContent>
);
}
withAuth for user-level operationswithEmailAccount for email-account-level operationsuseAction hook with onSuccess and onError callbacksgetActionErrorMessage(error.error) from @/utils/error to extract user-friendly messagesgetActionErrorMessage(error.error, { prefix: "Failed to save" })next-safe-action provides centralized error handling with flattened validation errorsLoadingContent component to handle loading and error states consistentlyloading, error, and children props to LoadingContentmutate() after successful mutations to refresh dataapps/web/
├── app/api/user/example/route.ts # GET API route
├── utils/actions/example.validation.ts # Zod schemas
├── utils/actions/example.ts # Server actions
├── hooks/useExamples.ts # SWR hook
└── components/ExampleForm.tsx # Form component
tools
Use the Inbox Zero API CLI to inspect the live API schema, list and manage automation rules, and read inbox analytics through the public API. Use this when a task involves Inbox Zero rules, stats, or API-driven automation and can be solved through the CLI instead of browser interaction.
tools
Write focused unit tests for backend and utility logic
testing
Pause execution for a user-specified duration
testing
Update workspace packages while respecting the repo's pinned package list in .ncurc.cjs. Use when the user asks to update dependencies or refresh package versions.