project-architecture
Skill0 starsChanged 13 days agoMITView on GitHub
Canonical folder and file architecture for Payload CMS 3 + Next.js App Router projects, with code conventions and a refactor-first playbook. Use when creating any new file, deciding where code belongs, reviewing structure, or before adding a backend to a frontend built by another agent or tool (Next.js, Vite, Create React App, Lovable). Refactors to the standard with zero visual change before any backend work.
9 other projects use a version of this.
Adopted by
Most recently taken up by
- maurodesouza/skillstheir own version, first seen Nov 22, 2026
- luigi-dv/react-ts-vitetheir own version, first seen Oct 20, 2026
- BidingCC/BuildingAItheir own version, first seen Oct 8, 2026
- marwan562/agents-skillstheir own version, first seen Sep 19, 2026
- sebas8824/sdd-harnesstheir own version, first seen Aug 24, 2026
- Jithnkn/project-architecturetheir own version, first seen Aug 20, 2026
Other versions9 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 9
- BidingCC/BuildingAI★ 1.9ksame name
- extra-org/extra★ 121same name
- Jithnkn/project-architecture★ 8same name
- marwan562/agents-skills★ 8same name
- fqmyysjjd/agent-feed★ 4same name
- luigi-dv/react-ts-vite★ 1same name
- maurodesouza/skills★ 1same name
- sebas8824/sdd-harness★ 1same name
- thetruong1099/android-mvi-base-code★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- agent-guardrailsSkill
- creative-frontendSkill
- figma-handoffSkill
- payload-admin-brandingSkill
- payload-auth-rbacSkill
- payload-bookings-paymentsSkill
- payload-bootstrapSkill
- payload-deploy-vercelSkill
- payload-forms-crmSkill
- payload-integrationsSkill
- payload-legal-trustSkill
- payload-live-previewSkill
- payload-localizationSkill
- payload-mcpSkill
- payload-mediaSkill
- payload-performanceSkill
- payload-project-kickoffSkill
- payload-seo-geoSkill
- payload-testingSkill
The file
We split this skill into the rules it gives an agent
7 rules. 0 are common, 2 are distinctive, and 5 are very specific to this project.
0
Common
Most of the 8 edited versions we read keep these.
2
Distinctive
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
- Very specific: line 57
Run once after payload-bootstrap creates the project, before writing features.
- Distinctive: line 60
Search the project for these strings and update each match:
- Very specific: line 64
Run pnpm generate:importmap, then pnpm tsc --noEmit.
- Very specific: line 68
Leave the rest of the template where it is (src/heros, src/blocks, src/components/ui).
- Distinctive: line 72
When another agent or tool built the frontend, restructure it before adding Payload.
- Very specific: line 81
Only then run payload-bootstrap in "add to existing app" mode.
- Very specific: line 93
No barrel files (index.ts that re-exports everything).
“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Project architecture
One layout for every project, so any model finds any file without searching. The layout extends the official Payload website template instead of inventing a new one.
When to use
| Situation | Action |
| Creating a file | Place it using the table in Step 1 |
| New project from the template | Apply Step 2 once, right after bootstrap |
| Existing frontend without Payload | Run the refactor-first playbook (Step 3) before any backend work |
| Vite, Create React App, or Lovable export | Run the migration section of the playbook first |
Step 1: Where code goes
Full tree with examples: references/folder-structure.md.
| Code | Location |
| Public routes | src/app/(frontend)/ (or src/app/(frontend)/[locale]/ when localized) |
| Payload admin and REST routes | src/app/(payload)/ (generated; only custom.scss is edited) |
| Preview routes | src/app/(frontend)/next/preview/route.ts, next/exit-preview/route.ts |
| Machine-readable routes | src/app/llms.txt/route.ts, src/app/llms-full.txt/route.ts; sitemaps stay in the template's src/app/(frontend)/(sitemaps)/ |
| Collections | src/collections/<Name>.ts; becomes src/collections/<Name>/index.ts with hooks/ and access/ once it has hooks |
| Globals | src/globals/<Name>/config.ts with Component.tsx and hooks/ beside it |
| Layout blocks | src/blocks/<Name>/config.ts + Component.tsx |
| Reusable fields | src/fields/<fieldName>.ts |
| Shared access functions | src/access/<rule>.ts |
| Business features | src/features/<feature>/ (booking, payments, leads) |
| Design system primitives | src/components/ui/ |
| Page sections | src/components/sections/ |
| Admin custom components | src/components/admin/ |
| Server-only clients (Payload, Google, email, storage) | src/lib/ |
| Pure helpers | src/utilities/ |
| Translations and routing | src/i18n/ |
| Request proxy (Next.js 16) | src/proxy.ts |
| Tests | tests/e2e/, tests/int/ |
Rules:
- One component per file. File name matches the export (
BookingForm.tsxexportsBookingForm). - Collection and global folders use PascalCase (
Posts,SiteSettings). Slugs are kebab-case (site-settings). - A feature folder owns everything specific to it:
schema.ts(Zod),actions.ts(server actions),queries.ts(TanStack Query hooks),components/,server/(server-only code). - Code used by two or more features moves to
src/components,src/lib, orsrc/utilities. - Server-only modules start with
import 'server-only'.
Step 2: Normalize a fresh template
Run once after payload-bootstrap creates the project, before writing features.
- Move
src/Headertosrc/globals/Headerandsrc/Footertosrc/globals/Footer. - Search the project for these strings and update each match:
@/Header/becomes@/globals/Header/@/Footer/becomes@/globals/Footer/- relative imports of
./Headeror./Footerinsrc/payload.config.ts
- Run
pnpm generate:importmap, thenpnpm tsc --noEmit. Both must pass. - Open
/admin, then open the Header global. It must render without an import map error. - Commit:
refactor: move globals into src/globals.
Leave the rest of the template where it is (src/heros, src/blocks, src/components/ui). The template's components/ui primitives may stay for template blocks; new UI follows the project design system, not shadcn/ui.
Step 3: Refactor-first playbook
When another agent or tool built the frontend, restructure it before adding Payload. The goal is the layout above with zero visual or behavioral change.
Summary (full procedure: references/refactor-playbook.md):
- Inventory: list routes, components, data sources, and hardcoded content. Write the list into
PROJECT.md. - Baseline: capture a screenshot of every route at 375 px and 1440 px widths with Playwright, and save them under
tests/e2e/__baseline__/. - Move files into the canonical layout in small commits. Change imports only. No styling or logic edits.
- Extract hardcoded content into typed constants in the component's folder, ready to be replaced by CMS data.
- Compare: re-capture screenshots and diff them against the baseline. Any visible difference blocks the next step.
- Only then run
payload-bootstrapin "add to existing app" mode.
For Vite, Create React App, or Lovable exports, migrate to the Next.js App Router first, following the migration section of the playbook.
Step 4: Code conventions
Apply references/code-conventions.md to every file. The essentials:
- Server Components by default. Add
'use client'only for state, effects, or browser APIs, and keep client components small. - Data reads in Server Components use the Payload Local API through
src/lib/payload.ts. - Client-side data uses TanStack Query with query keys from a
queryKeysobject in the feature folder. - Forms use React Hook Form + Zod. One Zod schema per form in
schema.ts, shared by the client form and the server action. - No barrel files (
index.tsthat re-exports everything); import from the file directly. - Imports at the top of the file. No inline or dynamic imports except
next/dynamicfor heavy client components. switchon a union type ends with anevercheck so new variants fail at compile time.
Done when
- Every new file is in the location given by Step 1
- Globals live in
src/globals/and the admin renders them - For refactors: baseline and post-refactor screenshots match for every route
pnpm tsc --noEmitandpnpm lintpass
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.

