スキル一覧に戻る
cr8297408

nextjs-data-flow

by cr8297408

0🍴 0📅 2026年1月19日
GitHubで見るManusで実行

SKILL.md


name: nextjs-data-flow description: > Expert guidance on data handling in Next.js 16+, focusing on Server Actions, robust data fetching, and the Data Access Layer (DAL) pattern. Enforces type safety, server-only constraints, and secure mutation patterns. Trigger: "Create Server Action", "Fetch data Next.js", "Handle form submission", "Database query Next.js". version: 1.0.0 author: github.com/cr8297408 license: Apache-2.0 tags:

  • nextjs
  • data-fetching
  • server-actions
  • typescript allowed_tools:
  • write_to_file
  • view_file

Next.js Data Flow Expert

1. Overview

This skill handles the implementation of secure and efficient data flows in Next.js applications. It champions the Server Actions model for mutations and direct Server Component fetching for reads. It enforces the separation of database logic into a Data Access Layer (DAL) and necessitates strictly typed inputs using Zod.

2. Prerequisites & Context

  • Required Tools:
    • write_to_file: To generate action files and DAL utilities.
  • Environment: Next.js App Router (Server Actions enabled).
  • Input:
    • Data model (e.g., User, Product).
    • Desired operation (Create, Read, Update, Delete).

3. Workflow

  1. Define Schema: Create a Zod schema to validate the input data (form data or API payload).
  2. Create DAL Function: Write a reusable, server-only function to interact with the database (e.g., createUserInDb).
  3. Implement Server Action:
    • Mark with 'use server'.
    • Validate input against Schema.
    • Call the DAL function.
    • Handle errors gracefully.
    • Revalidate cache (revalidatePath) and Redirect (redirect).
  4. Connect UI: Use the action in a form or event handler (inside a Client Component if needed).

4. Detailed Instructions & Rules

Critical Rules

  • Rule 1: Always use 'use server' at the top of action files.
  • Rule 2: Always import server-only in DAL files and actions to prevent leakage to the client.
  • Rule 3: Always validate inputs using Zod (or similar) before processing any mutation.
  • Rule 4: Never expose raw database errors to the client; catch them and return user-friendly messages.
  • Rule 5: Use redirect outside of try-catch blocks (as it throws an error internally).

Standard Action Pattern

'use server'
import 'server-only'
import { z } from 'zod'
import { redirect } from 'next/navigation'
import { revalidatePath } from 'next/cache'

export async function myAction(prevState: any, formData: FormData) {
  // Logic here
}

5. Examples

Example 1: Simple Form Submission

See examples/simple-form.md.

Example 2: Secure Data Fetching (DAL)

See examples/secure-fetching.md.

スコア

総合スコア

35/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

0/5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です