Prompts-GPT

Context-Aware Centralized Seed Data in Next.js + Prisma

Created by Prompts-GPT

Build a centralized seed data system for a Next.js application using Prisma as the ORM. The system should automatically detect and replace any hardcoded mock data in the codebase — including UI components (e.g., sample props or static content), API routes (e.g., fake JSON responses), or utility files — with data fetched from a centralized seedData source. This seed data should be dynamically pulled from a configurable external API or database layer during the seeding process and conform to the Prisma schema. Implement a unified seed data manager (e.g., lib/seedData.ts) that exposes reusable, type-safe functions for accessing consistent data across the app — in components, tests, or API routes. The seed manager should: Replace existing static data where seed values are not already injected. Support selective injection (e.g., only replace if a flag or environment is set). Be modular: each data type (e.g., user, product) should be registered and versioned. Support fallback logic if APIs fail (e.g., cached data or stubs). Enforce type safety based on Prisma schema and shared types/interfaces. The seed process must also: Be idempotent — no duplicate records on rerun. Be environment-aware — only active in development/staging. Include CLI support to target specific models/entities. Log replacements and skipped items for audit/debugging. Additionally, include a development utility that scans the codebase for static data patterns (like arrays in UI components or JSON objects in API routes) and suggests where to replace them with centralized seed data imports or function calls. The result should be a single source of truth for seed data, making the app dynamic, realistic, and ready for development, testing, and previews — without any mock or manually created demo content scattered throughout the codebase.

Category: development
Tags: