Project Structure

Understanding the monorepo structure and organization.

Note: This is mock/placeholder content for demonstration purposes.

Learn how the codebase is organized and where to find things.

Monorepo Overview

This project uses Turborepo to manage a monorepo with multiple apps and packages.

project-root/
ā”œā”€ā”€ apps/                    # Applications
│   ā”œā”€ā”€ web/                # Main Next.js app
│   ā”œā”€ā”€ e2e/                # Playwright E2E tests
│   └── dev-tool/           # Development utilities
ā”œā”€ā”€ packages/               # Shared packages
│   ā”œā”€ā”€ features/          # Feature packages
│   ā”œā”€ā”€ ui/                # UI components
│   ā”œā”€ā”€ supabase/          # Supabase utilities
│   └── billing/           # Billing integrations
ā”œā”€ā”€ tooling/               # Development tools
ā”œā”€ā”€ supabase/              # Database schema & migrations
└── docs/                  # Documentation

Main Application (apps/web)

The primary Next.js application:

apps/web/
ā”œā”€ā”€ app/                    # Next.js App Router
│   ā”œā”€ā”€ (marketing)/       # Public pages
│   ā”œā”€ā”€ (auth)/            # Authentication
│   ā”œā”€ā”€ home/              # Main application
│   │   ā”œā”€ā”€ (user)/        # Personal account
│   │   └── [account]/     # Team accounts
│   ā”œā”€ā”€ admin/             # Admin panel
│   └── api/               # API routes
ā”œā”€ā”€ components/            # Shared components
ā”œā”€ā”€ config/                # Configuration files
ā”œā”€ā”€ lib/                   # Utility functions
ā”œā”€ā”€ public/                # Static assets
└── supabase/              # Supabase setup

Route Structure

Marketing Routes ((marketing))

Public-facing pages:

app/(marketing)/
ā”œā”€ā”€ page.tsx               # Landing page
ā”œā”€ā”€ pricing/               # Pricing page
ā”œā”€ā”€ blog/                  # Blog
└── docs/                  # Documentation

Auth Routes ((auth))

Authentication pages:

app/(auth)/
ā”œā”€ā”€ sign-in/
ā”œā”€ā”€ sign-up/
ā”œā”€ā”€ password-reset/
└── verify/

Application Routes (home)

Main application:

app/home/
ā”œā”€ā”€ (user)/                # Personal account context
│   ā”œā”€ā”€ page.tsx          # Personal dashboard
│   ā”œā”€ā”€ settings/         # User settings
│   └── projects/         # Personal projects
└── [account]/            # Team account context
    ā”œā”€ā”€ page.tsx          # Team dashboard
    ā”œā”€ā”€ settings/         # Team settings
    ā”œā”€ā”€ projects/         # Team projects
    └── members/          # Team members

Packages Structure

Feature Packages (packages/features/)

Modular features:

packages/features/
ā”œā”€ā”€ accounts/              # Account management
ā”œā”€ā”€ auth/                  # Authentication
ā”œā”€ā”€ team-accounts/         # Team features
ā”œā”€ā”€ billing/               # Billing & subscriptions
ā”œā”€ā”€ admin/                 # Admin features
└── notifications/         # Notification system

UI Package (packages/ui/)

Shared UI components:

packages/ui/
└── src/
    ā”œā”€ā”€ components/        # Shadcn UI components
    │   ā”œā”€ā”€ button.tsx
    │   ā”œā”€ā”€ input.tsx
    │   ā”œā”€ā”€ dialog.tsx
    │   └── ...
    └── utils/             # UI utilities

Supabase Package (packages/supabase/)

Database utilities:

packages/supabase/
ā”œā”€ā”€ schema/                # Declarative schemas
│   ā”œā”€ā”€ accounts.schema.ts
│   ā”œā”€ā”€ auth.schema.ts
│   └── ...
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ clients/          # Supabase clients
│   ā”œā”€ā”€ hooks/            # React hooks
│   └── middleware/       # Auth middleware
└── migrations/           # SQL migrations

Configuration Files

Root Level

project-root/
ā”œā”€ā”€ package.json           # Root package.json
ā”œā”€ā”€ turbo.json             # Turborepo config
ā”œā”€ā”€ pnpm-workspace.yaml    # PNPM workspace
└── tsconfig.json          # Base TypeScript config

Application Level

apps/web/
ā”œā”€ā”€ next.config.js         # Next.js configuration
ā”œā”€ā”€ tailwind.config.ts     # Tailwind CSS
ā”œā”€ā”€ tsconfig.json          # TypeScript config
└── .env.local             # Environment variables

Feature Configuration

apps/web/config/
ā”œā”€ā”€ paths.config.ts        # Route paths
ā”œā”€ā”€ billing.config.ts      # Billing settings
ā”œā”€ā”€ feature-flags.config.ts # Feature flags
ā”œā”€ā”€ personal-account-navigation.config.tsx
└── team-account-navigation.config.tsx

Naming Conventions

Files

  • Pages: page.tsx (Next.js convention)
  • Layouts: layout.tsx
  • Components: kebab-case.tsx
  • Utilities: kebab-case.ts
  • Types: types.ts or component-name.types.ts

Directories

  • Route segments: [param] for dynamic
  • Route groups: (group) for organization
  • Private folders: _components, _lib
  • Parallel routes: @folder

Code Organization

feature/
ā”œā”€ā”€ page.tsx               # Route page
ā”œā”€ā”€ layout.tsx             # Route layout
ā”œā”€ā”€ loading.tsx            # Loading state
ā”œā”€ā”€ error.tsx              # Error boundary
ā”œā”€ā”€ _components/           # Private components
│   ā”œā”€ā”€ feature-list.tsx
│   └── feature-form.tsx
└── _lib/                  # Private utilities
    ā”œā”€ā”€ server/            # Server-side code
    │   ā”œā”€ā”€ loaders.ts
    │   └── actions.ts
    └── schemas/           # Validation schemas
        └── feature.schema.ts

Import Paths

Use TypeScript path aliases:

// Absolute imports from packages
import { Button } from '@kit/ui/button';
import { createClient } from '@kit/supabase/server-client';

// Relative imports within app
import { FeatureList } from './_components/feature-list';
import { loadData } from './_lib/server/loaders';

Best Practices

  1. Keep route-specific code private - Use _components and _lib
  2. Share reusable code - Extract to packages
  3. Collocate related files - Keep files near where they're used
  4. Use consistent naming - Follow established patterns
  5. Organize by feature - Not by file type

Finding Your Way

Looking for...Location
UI Componentspackages/ui/src/components/
Database Schemapackages/supabase/schema/
API Routesapps/web/app/api/
Auth Logicpackages/features/auth/
Billing Codepackages/features/billing/
Team Featurespackages/features/team-accounts/
Config Filesapps/web/config/
Types*.types.ts files throughout