next-data-layout

Organizes Next.js App Router code into route sidecars and shared domain primitives.

Updated Jan 12, 2026
One-click install
npx skills add https://github.com/brandonarbini/arbini.family --skill next-data-layout-brandonarbini
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: next-data-layout
Source: https://github.com/brandonarbini/arbini.family/tree/main/.agents/skills/next-data-layout
Command: npx skills add https://github.com/brandonarbini/arbini.family --skill next-data-layout-brandonarbini

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Deciding where new code should live in a Next.js App Router project is a recurring source of inconsistency: queries end up inline in pages, routes import from sibling routes, and shared logic gets copy-pasted. This Skill prescribes a two-layer structure — route sidecars under /app/<route>/ and shared domain primitives under /lib/<domain>/ — so every file has a defined home. ## Core Features & Use Cases - Placement decision table: Maps each kind of code (reads, mutations, schemas, cache tags, pure logic) to its correct file, such as data.ts, actions.ts, service.ts, or validations.ts. - Promotion triggers: Defines exactly when code moves from a route sidecar into /lib/<domain>/ — shared cache tags, queries used by 2+ routes, non-trivial domain logic, and write-path business logic. - Structural rules: Enforces pure data.ts files with tenant-key filtering, server-only imports, no /lib to /app imports, and no cross-route imports. - Use Case: When asked to build a new admin page for discount codes, the Skill scaffolds /app/system/discount-codes/ with page.tsx, data.ts, actions.ts, and validations.ts, while placing shared queries, the write service, and cache tags in /lib/discounts/. ## Quick Start Ask the assistant to scaffold a new route or domain in your Next.js app, for example: create a dashboard route that lists orders with a form to create new ones.

Frequently Asked Questions about next-data-layout

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Where should data fetching code live in a Next.js App Router project?▼

Read queries live in a data.ts file — either a route-private ./data.ts sidecar or a shared /lib/<domain>/data.ts when used by multiple routes. Pages and API routes import from data.ts rather than querying directly, keeping one source of truth per query.

How do I share code between routes in Next.js App Router?▼

Shared code is promoted to /lib/<domain>/ instead of importing across sibling routes in /app. Queries go to data.ts, write-path logic to service.ts, shared cache tags to cache.ts, and pure domain logic to operation-named files like calculator.ts.

Should Server Actions go in /lib or /app in Next.js?▼

Server Actions stay in /app/<route>/actions.ts and are never promoted to /lib, so the "use server" boundary and auth check remain adjacent. The underlying business logic lives in /lib/<domain>/service.ts, which the action calls after auth and validation.

When should code be promoted from a route folder to a shared lib folder?▼

Promote when a cache tag is invalidated from multiple places, a query is needed by two or more routes or non-route callers, domain logic has branching worth testing, or write-path business logic exists. One-off formatters and route-specific queries stay in the route.

Does this structure work with src directories or monorepos?▼

Yes, the paths are logical. With a src directory, /app and /lib map to src/app and src/lib, and in a monorepo /lib/<domain>/ may itself be a shared package. The layering rules remain identical.