scaffolding-data-layer
Skill378 starsChanged 4 months agoApache-2.0View on GitHub
Reads Data_Models.md artifacts and generates the equivalent modern ORM schema or native MongoDB/Zod layer. Use when following a legacy audit artifact to scaffold out the data access layer for a Next.js app.
- Reads credentials
In this repository59 other files it gives its agents.
- codelabs/ai-toolkit-lab-2/hackathon-judge/frontend/.agents/skills/vercel-composition-patterns/AGENTS.mdAGENTS.md
- codelabs/ai-toolkit-lab-2/hackathon-judge/frontend/.agents/skills/vercel-react-best-practices/AGENTS.mdAGENTS.md
- batch-executing-test-suitesSkill
- circuit-breaker-reporterSkill
- generating-mock-imagesSkill
- making-forms-demoSkill
- multi-step-workflow-reporterSkill
- go-project-setupSkill
- latest-software-versionSkill
- video-descriptionSkill
- adk-memory-bank-initializerSkill
- agent-containerizerSkill
- cloud-run-agent-architectSkill
- gcp-agent-eval-engine-runnerSkill
- gcp-agent-eval-metric-configuratorSkill
- gcp-agent-golden-dataset-builderSkill
- gcp-agent-model-armor-shieldSkill
- gcp-agent-safety-gatekeeperSkill
- gcp-agent-sdp-template-factorySkill
- gcp-agent-shadow-deployerSkill
- gcp-agent-tool-trajectory-evaluatorSkill
- gcp-production-secret-handlerSkill
- mcp-connector-generatorSkill
- go-architectSkill
- go-backend-devSkill
- go-reviewerSkill
- go-test-expertSkill
- vercel-composition-patternsSkill
- vercel-react-best-practicesSkill
- brand-guidelinesSkill
- knowledge_catalog_governanceSkill
- banana-breadSkill
- cheese-breadSkill
- drawingsSkill
- paintingsSkill
- photographySkill
- adding-easter-eggSkill
- building-platformer-gamesSkill
- creating-a-gameSkill
- ensuring-arcade-visualsSkill
- handling-user-inputSkill
- helping-the-userSkill
- improving-game-qualitySkill
- messaging-game-overSkill
- playing-the-gameSkill
- adversarial-verificationSkill
- auditing-api-contractsSkill
- auditing-business-logicSkill
- auditing-data-modelsSkill
- auditing-paritySkill
- auditing-ui-archeologySkill
- generating-api-testsSkill
- generating-database-seederSkill
- orchestrating-greenfield-migrationSkill
- scaffolding-api-routesSkill
- scaffolding-nextjs-foundationSkill
- scaffolding-test-foundationSkill
- scaffolding-ui-and-pagesSkill
- ping_pong_pairingSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 32
Before writing code, you MUST ensure the modern schemas are compatible with the existing legacy data.
- Distinctive: line 33
Strategy: Run the new Zod validation schemas against *actual* records in the legacy database.
- Very specific: line 37
Create src/lib/db/mongodb.ts (or the appropriate client).
- Very specific: line 38
Configuration: Ensure the connection string (usually via MONGODB_URI in .env.local) points to the legacy-app's database.
- Very specific: line 53
Create src/lib/models/schema.ts (Zod) and src/lib/models/types.ts (TypeScript).
- Very specific: line 55
Type Inference: Use z.infer<typeof Schema> to generate your TypeScript types automatically.
- Very specific: line 59
Create src/lib/models/utils.ts for logic that was previously buried in the ORM (e.g., password hashing, complex queries, virtual field …
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Scaffolding the Modern Data Layer
Translate legacy data models (Mongoose, Sequelize, etc.) into a modern, type-safe data access layer using TypeScript and Zod.
Objective
Recreate the legacy data structures in a way that provides runtime validation and full TypeScript support, while accounting for Schema Evolution and potential "Dirty Data" in the legacy system.
Instructions for the Scaffold Subagent
Copy this checklist and track your progress:
Task Progress:
- [ ] Step 1: Analyze Audit Specs
- [ ] Step 2: Perform Data Integrity Audit (Draft)
- [ ] Step 3: Initialize Database Connection
- [ ] Step 4: Define Zod Schemas & TypeScript Types
- [ ] Step 5: Implement Data Access UtilitiesStep 1. Analyze Audit Specs
Locate and read docs/legacy-audit/Data_Models.md. Identify:
- Primary Entities and their relationships (One-to-Many, Many-to-Many).
- Validation Rules: Required fields, regex patterns, min/max values.
- Middleware Hooks: Legacy
pre-saveorpost-removelogic that needs to be manually ported to the service layer.
Step 2. Perform Data Integrity Audit
Before writing code, you MUST ensure the modern schemas are compatible with the existing legacy data.
- Strategy: Run the new Zod validation schemas against actual records in the legacy database.
- Outcome: Identify "Dirty Data" gaps (e.g., missing required fields in old records, inconsistent types) and use
z.optional()or.nullable()to maintain compatibility with legacy data patterns.
Step 3. Connect to Legacy Database
Create src/lib/db/mongodb.ts (or the appropriate client).
- Configuration: Ensure the connection string (usually via
MONGODB_URIin.env.local) points to the legacy-app's database. - Pattern: Export a cached client promise (Singleton pattern) to avoid opening too many connections during HMR (Hot Module Replacement) in Next.js development.
// Example: src/lib/db/mongodb.ts
import { MongoClient } from "mongodb";
if (!process.env.MONGODB_URI) {
throw new Error('Invalid/Missing environment variable: "MONGODB_URI"');
}
const uri = process.env.MONGODB_URI;
// ... (Rest of singleton implementation)Step 4. Define Zod Schemas & TypeScript Types
Create src/lib/models/schema.ts (Zod) and src/lib/models/types.ts (TypeScript).
- Zod First: Define the schema using Zod for runtime validation.
- Type Inference: Use
z.infer<typeof Schema>to generate your TypeScript types automatically. - Relationship Mapping: Convert legacy ORM relationships (e.g., Mongoose
Refs) into manual link logic usingObjectIdfrom the native driver.
Step 5. Implement Data Access Utilities
Create src/lib/models/utils.ts for logic that was previously buried in the ORM (e.g., password hashing, complex queries, virtual field calculation).
- Static Utilities: Native drivers lack "Model Methods." All logic must be extracted into pure functions that take the data object as an argument.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

