Analyze routes and recommend whether to use Server Actions or API routes based on use case patterns including authentication, revalidation, external API calls, and client requirements. Use this skill when deciding between Server Actions and API routes, optimizing Next.js data fetching, refactoring routes, analyzing route architecture, or choosing the right data mutation pattern. Trigger terms include Server Actions, API routes, route handler, data mutation, revalidation, authentication flow, external API, client-side fetch, route optimization, Next.js patterns.
Analyzes your Next.js routes and recommends Server Actions vs API routes based on authentication, revalidation, and external API usage. Use when deciding between data mutation patterns, optimizing routes, or refactoring existing code.
/plugin marketplace add hopeoverture/worldbuilding-app-skills/plugin install server-actions-vs-api-optimizer@worldbuilding-app-skillsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/decision_matrix.mdscripts/analyze_routes.pyAnalyze existing routes and recommend whether to use Server Actions or traditional API routes based on specific use case patterns, including authentication flows, data revalidation, external API calls, and client requirements.
To analyze current route architecture:
scripts/analyze_routes.py for automated analysisBased on analysis, provide recommendations using the decision matrix from references/decision_matrix.md:
When refactoring is recommended:
Prefer Server Actions for:
revalidatePath() or revalidateTag()Benefits:
Prefer API routes for:
Benefits:
Use the analysis script to scan your codebase:
python scripts/analyze_routes.py --path /path/to/app --output analysis-report.md
The script identifies:
Consult references/decision_matrix.md for detailed decision criteria:
For each route, determine:
For routes requiring changes:
Current: API route with fetch from client Recommended: Server Action Reason: Simpler, built-in CSRF protection, progressive enhancement
// Before (API Route)
// app/api/entities/route.ts
export async function POST(request: Request) {
const data = await request.json();
await db.entity.create(data);
return Response.json({ success: true });
}
// After (Server Action)
// app/actions.ts
'use server';
export async function createEntity(formData: FormData) {
await db.entity.create(Object.fromEntries(formData));
revalidatePath('/entities');
}
Current: Client-side fetch to external API (exposes keys) Recommended: API route Reason: Hide API keys, rate limiting, response transformation
// Recommended: API Route
// app/api/external-service/route.ts
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const query = searchParams.get('query');
const response = await fetch(`https://api.external.com?key=${process.env.API_KEY}&q=${query}`);
const data = await response.json();
return Response.json(data);
}
Current: None (new feature) Recommended: API route Reason: External service calls, needs public URL
// Recommended: API Route
// app/api/webhooks/stripe/route.ts
export async function POST(request: Request) {
const signature = request.headers.get('stripe-signature');
const body = await request.text();
// Verify webhook signature
// Process webhook event
return Response.json({ received: true });
}
Current: API route with manual cache invalidation Recommended: Server Action Reason: Built-in revalidation, simpler code
// Before (API Route)
// app/api/entities/[id]/route.ts
export async function PATCH(request: Request, { params }) {
const data = await request.json();
await db.entity.update({ where: { id: params.id }, data });
revalidatePath('/entities');
return Response.json({ success: true });
}
// After (Server Action)
// app/actions.ts
'use server';
export async function updateEntity(id: string, data: any) {
await db.entity.update({ where: { id }, data });
revalidatePath('/entities');
revalidateTag(`entity-${id}`);
}
Current: API middleware Recommended: Server Action for mutations, API route for public endpoints Reason: Simpler auth in Server Components
// Server Action (for mutations)
'use server';
export async function protectedAction() {
const session = await auth();
if (!session) throw new Error('Unauthorized');
// Perform action
}
// API Route (for public/external access)
export async function POST(request: Request) {
const token = request.headers.get('authorization');
if (!validateToken(token)) {
return Response.json({ error: 'Unauthorized' }, { status: 401 });
}
// Process request
}
Automated route analysis tool that scans your Next.js app directory to identify route patterns, Server Actions, authentication usage, revalidation calls, and external API integrations. Generates a detailed report with recommendations.
Comprehensive decision matrix with detailed criteria for choosing between Server Actions and API routes. Includes use case patterns, trade-offs, performance considerations, security implications, and real-world examples.
Common patterns in worldbuilding applications:
Consult references/decision_matrix.md for detailed analysis of each pattern.
Use when working with Payload CMS projects (payload.config.ts, collections, fields, hooks, access control, Payload API). Use when debugging validation errors, security issues, relationship queries, transactions, or hook behavior.
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.