Claude-skill-registry codebase-structure
Provides a high-level overview of the Next.js application's file structure and directory organization. Use when deciding where to place new files, components, server actions, database schemas, or when understanding the overall architecture of the codebase. Essential for maintaining consistent file organization and knowing where different types of code belong.
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/codebase-structure" ~/.claude/skills/majiayu000-claude-skill-registry-codebase-structure && rm -rf "$T"
skills/data/codebase-structure/SKILL.mdCodebase Structure
Overview
Understand the file structure and directory organization to maintain consistency when adding new features, components, or functionality.
Directory Structure
create-reodor-app/ ├── app/ # Next.js App Router - Pages and routes ├── components/ # React components ├── docs/ # Project documentation ├── hooks/ # Custom React hooks ├── lib/ # External service configurations and utilities ├── providers/ # React context providers ├── public/ # Static assets (images, logos, manifests) ├── schemas/ # Generated Zod schemas (auto-generated) ├── scripts/ # Utility scripts (deployment, setup) ├── seed/ # Database seeding configuration ├── server/ # Server actions for data mutations ├── stores/ # Zustand state management stores ├── supabase/ # Supabase configuration and database ├── transactional/ # React Email templates ├── types/ # TypeScript type definitions └── middleware.ts # Next.js middleware (auth, route protection)
Where to Place New Code
Pages & Routes (app/
)
app/Structure: Next.js App Router with file-based routing
Place here:
- Page components (
)page.tsx - Layouts (
)layout.tsx - Error boundaries (
,error.tsx
)global-error.tsx - Not found pages (
)not-found.tsx - API routes (
)api/*/route.ts - Route-specific loading states (
)loading.tsx - SEO metadata (
,robots.ts
,sitemap.ts
)opengraph-image.png - Favicons and app icons
Examples:
- Todos feature pageapp/oppgaver/page.tsx
- Sign in pageapp/auth/sign-in/page.tsx
- Cron job endpointsapp/api/cron/*/route.ts
- Root layout with providersapp/layout.tsx
Components (components/
)
components/Structure: Feature-based organization + shared components
Place here:
- Feature directories (
) - Feature-specific componentscomponents/[feature]/- Example:
,components/todos/
,components/auth/components/admin/
- Example:
- Shared components - Components used across features
- Example:
,navbar.tsx
,footer.tsxerror-boundary.tsx
- Example:
- UI library (
) - shadcn/ui componentscomponents/ui/ - Specialized UI (
) - Kibo UI componentscomponents/kibo-ui/ - Magic UI (
) - Magic UI componentscomponents/magicui/
Naming: Use kebab-case for directories, PascalCase for component files
Examples:
- Todo form componentcomponents/todos/todo-form.tsx
- Todo dialog wrappercomponents/todos/todo-dialog.tsx
- Authentication formcomponents/auth/auth-form.tsx
- shadcn/ui button componentcomponents/ui/button.tsx
Server Actions (server/
)
server/Purpose: Type-safe server-side data operations with authentication
Place here:
- Database CRUD operations
- Authenticated data mutations
- Server-side business logic
Naming:
[feature].actions.ts
Examples:
- Todo CRUD operationsserver/todo.actions.ts
- Profile managementserver/profile.actions.ts
- Admin operationsserver/admin.actions.ts
Pattern: Individual exported async functions, not default exports
Custom Hooks (hooks/
)
hooks/Purpose: Reusable React hooks for client-side logic
Place here:
- Data fetching hooks (TanStack Query)
- File upload hooks
- Authentication hooks
- Form state management hooks
- UI state hooks (media queries, scroll position, etc.)
Naming:
use-[hook-name].ts
Examples:
- Authentication statehooks/use-auth.ts
- File upload logichooks/use-upload-todo-attachments.ts
- Responsive breakpoint detectionhooks/use-media-query.ts
State Management (stores/
)
stores/Purpose: Global state with Zustand
Place here:
- Application-wide state
- Persisted state (localStorage, sessionStorage)
- Shared UI state
Naming:
[feature]-store.ts or use-[feature]-store.ts
Examples:
- Setup wizard statestores/setup-steps-store.ts
Database (supabase/
)
supabase/Structure:
supabase/ ├── schemas/ # Declarative SQL schemas (source of truth) ├── migrations/ # Generated SQL migrations (auto-generated) └── functions/ # Edge functions (Deno runtime)
Place here:
- schemas/ - Declarative database schemas, RLS policies, triggers
- Tables, enums, indexes01-schema.sql
- Row Level Security policies02-policies.sql
- Database triggers03-triggers.sql
- migrations/ - Generated from schemas (DO NOT edit manually)
- functions/ - Supabase Edge Functions for serverless operations
Workflow:
- Edit schema in
schemas/ - Run
to generate migrationbun db:diff <name> - Review generated migration in
migrations/ - Run
to applybun migrate:up
Type Definitions (types/
)
types/Purpose: TypeScript types and interfaces
Place here:
- database.types.ts - Generated from Supabase (auto-generated, DO NOT edit)
- index.ts - Custom types, shared filter types, runtime-agnostic types
- Feature-specific type definitions
Examples:
- Auto-generated Supabase typestypes/database.types.ts
- Custom types liketypes/index.ts
,BookingFiltersServiceFilters
Schemas (schemas/
)
schemas/Purpose: Auto-generated Zod validation schemas
Content:
- Generated from Supabase types (DO NOT edit manually)database.schema.ts
Usage: Import schemas for validation in server actions and forms
Generation: Run
bun gen:types to regenerate
External Services (lib/
)
lib/Purpose: Service configurations and utilities
Place here:
- Service clients (
,resend.ts
)lib/supabase/client.ts - Service utilities (
,resend-utils.ts
)lib/supabase/storage.ts - Configuration (
,brand.ts
,navigation.ts
)permissions.ts - Helper functions (
- cn(), formatting, etc.)utils.ts
Structure:
lib/ ├── supabase/ # Supabase configuration │ ├── client.ts # Browser client │ ├── server.ts # Server client │ └── storage.ts # Storage utilities ├── brand.ts # Brand configuration ├── navigation.ts # Navigation structure ├── utils.ts # Shared utilities └── [service].ts # External service configs
React Providers (providers/
)
providers/Purpose: React Context providers for app-wide state
Place here:
- TanStack Query provider
- Theme providers
- Authentication providers
- Any context providers
Examples:
providers/tanstack-query-provider.tsx
Email Templates (transactional/emails
)
transactional/emailsPurpose: React Email templates for transactional emails
Place here:
- Email components built with React Email
- Email-specific utilities
Examples:
transactional/emails/welcome.tsxtransactional/emails/password-reset.tsx
Documentation (docs/
)
docs/Structure:
docs/ ├── business/ # Business features and workflows └── technical/ # Technical implementation details
Place here:
- business/ - Feature docs, user workflows, business logic
- technical/ - Architecture, API docs, deployment guides
Examples:
docs/technical/google-auth-setup.mddocs/technical/railway-deployment.md
Static Assets (public/
)
public/Purpose: Static files served at root path
Place here:
- Logos and brand assets
- Web app manifest images
- Static images referenced by absolute paths
- Files that need specific public URLs
Structure:
public/ ├── logos/ # Logo variations ├── web-app-manifest-192x192.png # PWA icons └── web-app-manifest-512x512.png
Note: Favicons and app icons go in
app/ directory, not public/
Utility Scripts (scripts/
)
scripts/Purpose: Development and deployment automation
Place here:
- Deployment scripts
- Setup scripts
- Database utilities
- Build automation
Examples:
scripts/railway-setup.shscripts/ensure-transactional-deps-installed.sh
Database Seeding (seed/
)
seed/Purpose: Snaplet configuration for database seeding
Place here:
- Snaplet configuration
- Seed data scripts
Root-Level Files
- middleware.ts - Next.js middleware for auth and route protection
- next.config.ts - Next.js configuration
- tailwind.config.ts - Tailwind CSS configuration
- seed.config.ts - Database seeding configuration
- next-env.d.ts - Next.js TypeScript declarations (auto-generated)
Key Principles
- Feature-based organization - Group related files by feature (e.g.,
,components/todos/
)server/todo.actions.ts - Separation of concerns - Keep server logic (
) separate from client components (server/
)components/ - Generated files - Never edit auto-generated files (
,types/database.types.ts
,schemas/database.schema.ts
)migrations/ - Naming conventions - Use kebab-case for files, PascalCase for components, camelCase for functions
Common Workflows
Adding a New Feature
- Database: Update
with new database schema state. Refer tosupabase/schemas/01-schema.sql
for guidance.skills/database-schema-extension/SKILL.md - Server Actions: Create
server/[feature].actions.ts - Components: Create
directorycomponents/[feature]/ - Hooks: Add custom hooks to
if needed.hooks/use-[feature].ts - Page: Create
. It can be nested as needed.app/[path-to-feature]/page.tsx - Types: Custom types go in
types/index.ts
Adding a New UI Component
- Shared component:
components/[name].tsx - Feature component:
components/[feature]/[name].tsx - shadcn/ui: Run
(auto-adds tobunx --bun shadcn@latest add [component]
)components/ui/
Adding Authentication
- Server action: Add to
server/auth.actions.ts - Middleware: Update route protection in
middleware.ts - Components: Add to
components/auth/ - Hooks: Update
hooks/use-auth.ts
Quick Reference
| Type | Location | Example |
|---|---|---|
| Page | | |
| Server Action | | |
| Component | | |
| Hook | | |
| Store | | |
| Database Schema | | Table definitions |
| Email Template | | |
| Util Function | or | |
| Type | | Custom types |
| API Route | | |