# Project Structure

import { Callout } from "fumadocs-ui/components/callout";
import { Accordion, Accordions } from "fumadocs-ui/components/accordion";
import { File, Folder, Files } from "fumadocs-ui/components/files";
import { Step, Steps } from "fumadocs-ui/components/steps";
import { Tabs, Tab } from "fumadocs-ui/components/tabs";
import { Badge, Card, CardContent, CardHeader, CardTitle } from "@pycolors/ui";
import {
  ArrowRight,
  ArrowUpRight,
  Boxes,
  CheckCircle,
  CreditCard,
  FolderTree,
  Layers,
  Layers3,
  LockKeyhole,
  Puzzle,
  Route,
  Table2,
  XCircle,
} from "lucide-react";
import { PreferAvoid } from "@/components/docs/prefer-avoid";
import { DocsLinks } from "@/components/docs/docs-links";
import { DocsConceptTabs } from "@/components/docs/docs-concept-tabs";

<div className="flex flex-wrap items-center gap-2">
  <Badge variant="outline">
    Starter
  </Badge>

  <Badge>
    Structure
  </Badge>
</div>

## Overview

Starter Free is structured for **clarity and long-term evolution**.

This is not a demo folder. It is a **production-shaped architecture** designed to help you extend features without turning pages into large, fragile files.

Understanding the structure early helps you:

* extend features cleanly
* keep routes readable
* wire backend progressively
* avoid refactors caused by mixed responsibilities

<Callout title="Key idea">
  You are not only learning where files live. You are learning how product
  architecture scales from a mocked SaaS surface to a real product.
</Callout>

### Mental model

> Pages define routes.
> Components define features.
> UI defines primitives.

| Layer          | Responsibility                                  |
| -------------- | ----------------------------------------------- |
| `app/`         | Routing, layouts, and product entry points      |
| `components/`  | Feature composition and interaction logic       |
| `@pycolors/ui` | Stateless UI primitives used across the product |

<Callout type="info" title="System rule">
  Keep pages thin. When interaction logic grows, move it into a feature folder.
</Callout>

### First customization points

Paths here are relative to your Starter Free checkout. In the source monorepo,
that checkout is `apps/starter-free`; do not import private monorepo packages
into the independently delivered starter.

| File                             | Start here for                                        |
| -------------------------------- | ----------------------------------------------------- |
| `app/layout.tsx`                 | App name, page metadata, and the root document        |
| `app/(app)/layout.tsx`           | App-header branding and the application shell         |
| `app/globals.css`                | Styles and semantic tokens for both themes            |
| `lib/getting-started.ts`         | The dashboard's informational guide content and links |
| `components/app/app-sidebar.tsx` | Desktop application navigation                        |

Keep the appearance bootstrap and existing theme control when changing
branding. The dashboard guide does not track completion or own project state.
Try the [first-session workflow](/docs/starter/getting-started#your-first-session)
before changing the project feature.

### Structure

<Files>
  <Folder name="app" defaultOpen>
    <File name="layout.tsx" />

    <File name="globals.css" />

    <Folder name="(auth)" defaultOpen>
      <Folder name="login">
        <File name="page.tsx" />
      </Folder>

      <Folder name="register">
        <File name="page.tsx" />
      </Folder>

      <Folder name="forgot-password">
        <File name="page.tsx" />
      </Folder>

      <File name="layout.tsx" />
    </Folder>

    <Folder name="(app)" defaultOpen>
      <Folder name="admin">
        <File name="page.tsx" />
      </Folder>

      <Folder name="billing">
        <File name="page.tsx" />
      </Folder>

      <Folder name="dashboard">
        <File name="page.tsx" />
      </Folder>

      <Folder name="projects" defaultOpen>
        <File name="layout.tsx" />

        <File name="page.tsx" />

        <Folder name="[id]">
          <File name="page.tsx" />
        </Folder>
      </Folder>

      <Folder name="settings">
        <File name="page.tsx" />
      </Folder>

      <File name="layout.tsx" />
    </Folder>
  </Folder>

  <Folder name="components" defaultOpen>
    <Folder name="projects" defaultOpen>
      <File name="project-provider.tsx" />

      <File name="project-create-dialog.tsx" />

      <File name="project-table.tsx" />

      <File name="project-row-actions.tsx" />

      <File name="project-rename-dialog.tsx" />

      <File name="project-confirm-delete-dialog.tsx" />

      <File name="project-types.ts" />
    </Folder>

    <Folder name="app">
      <File name="page-shell.tsx" />
    </Folder>
  </Folder>

  <Folder name="lib" defaultOpen>
    <File name="project-storage.ts" />

    <File name="getting-started.ts" />

    <File name="theme.ts" />
  </Folder>
</Files>

This structure is intentionally small. It separates route ownership from feature composition.

### Architecture flow

```txt title="architecture-flow.txt"
App Router pages
  ↓
Feature components
  ↓
PyColors UI primitives
```

A page should describe the product surface. Feature components should own interactions. UI primitives should stay reusable and stateless.

<DocsConceptTabs
  items={[
  {
    value: 'Route',
    title: 'Route layer',
    icon: Route,
    description: (
      <>
        <p>
          The route layer defines URLs, page structure, layout composition, and high-level orchestration.
        </p>

        <div className="mt-4 flex flex-wrap gap-2">
          <Badge variant="outline">Page structure</Badge>
          <Badge variant="outline">Layouts</Badge>
          <Badge variant="outline">Navigation</Badge>
          <Badge variant="outline">Route composition</Badge>
        </div>
      </>
    ),
  },
  {
    value: 'Feature',
    title: 'Feature layer',
    icon: Layers3,
    description: (
      <>
        <p>
          The feature layer owns product behavior, local state, dialogs, actions, and future API integration boundaries.
        </p>

        <div className="mt-4 flex flex-wrap gap-2">
          <Badge variant="outline">Dialogs</Badge>
          <Badge variant="outline">Row actions</Badge>
          <Badge variant="outline">Local state</Badge>
          <Badge variant="outline">Mock data</Badge>
          <Badge variant="outline">Server integration</Badge>
        </div>
      </>
    ),
  },
  {
    value: 'Primitive',
    title: 'UI primitive layer',
    icon: Boxes,
    description: (
      <>
        <p>
          UI primitives provide reusable building blocks that stay small, predictable, and composable.
        </p>

        <div className="mt-4 flex flex-wrap gap-2">
          <Badge variant="outline">Button</Badge>
          <Badge variant="outline">Card</Badge>
          <Badge variant="outline">Table</Badge>
          <Badge variant="outline">Dialog</Badge>
          <Badge variant="outline">Sheet</Badge>
          <Badge variant="outline">Input</Badge>
        </div>
      </>
    ),
  },

]}
/>

### App directory

The `app/` directory is the routing layer. The `(app)` route group provides the
application shell without adding `(app)` to the URL. For example,
`app/(app)/projects/page.tsx` serves `/projects`, and the nested `[id]/page.tsx`
serves a real project ID selected from the list.

`app/(app)/projects/layout.tsx` mounts `ProjectProvider` for both the list and
detail routes. Keep this shared boundary so navigation does not create a
second, disconnected project store. The dashboard remains a Server Component;
the existing Projects page and provider use a client boundary for local state.

It defines:

* auth entry points
* dashboard pages
* product routes
* settings and billing surfaces
* high-level layout composition

<Files>
  <Folder name="app" defaultOpen>
    <Folder name="(auth)" defaultOpen>
      <Folder name="login">
        <File name="page.tsx" />
      </Folder>

      <Folder name="register">
        <File name="page.tsx" />
      </Folder>

      <Folder name="forgot-password">
        <File name="page.tsx" />
      </Folder>
    </Folder>

    <Folder name="(app)" defaultOpen>
      <Folder name="dashboard">
        <File name="page.tsx" />
      </Folder>

      <Folder name="projects">
        <File name="layout.tsx" />

        <File name="page.tsx" />

        <Folder name="[id]">
          <File name="page.tsx" />
        </Folder>
      </Folder>

      <Folder name="admin">
        <File name="page.tsx" />
      </Folder>

      <Folder name="billing">
        <File name="page.tsx" />
      </Folder>

      <Folder name="settings">
        <File name="page.tsx" />
      </Folder>
    </Folder>
  </Folder>
</Files>

<br />

<Callout title="Page rule">
  A page should compose the feature. It should not become the feature itself.
</Callout>

### Components directory

The `components/` directory contains feature-level building blocks.

For example, the projects feature keeps its browser-local provider, table rendering, row actions, dialogs, and sample types together.

<Files>
  <Folder name="components" defaultOpen>
    <Folder name="projects" defaultOpen>
      <File name="project-provider.tsx" />

      <File name="project-create-dialog.tsx" />

      <File name="project-table.tsx" />

      <File name="project-row-actions.tsx" />

      <File name="project-rename-dialog.tsx" />

      <File name="project-confirm-delete-dialog.tsx" />

      <File name="project-types.ts" />
    </Folder>
  </Folder>
</Files>

A focused composition excerpt from the Projects page passes the current state
and callbacks to the table:

```tsx title="Project table composition (inside the existing Projects provider)"
"use client";

import { ProjectTable } from "@/components/projects/project-table";
import { useProjects } from "@/components/projects/project-provider";

export function ProjectList() {
  const { projects, isLoading, renameProject, deleteProject } = useProjects();

  return (
    <ProjectTable
      projects={projects}
      isLoading={isLoading}
      onRename={renameProject}
      onDelete={deleteProject}
    />
  );
}
```

This excerpt is not a replacement for the complete delivered page. Preserve its
create/reset controls, storage notice, details links, and `PageShell`. Render
such a consumer only beneath the existing `ProjectProvider`; `useProjects`
throws outside that context. Reuse the delivered dialogs and row actions
instead of replacing them with placeholder components.

## Mock data strategy

The project samples are initial/reset data, not the only source of truth after
a user edits a project. The current flow is:

```txt title="local-project-data-flow.txt"
ProjectProvider
  -> read saved browser-local projects (or initial samples)
  -> expose projects, loading, storage notice, and mutation callbacks
  -> create / rename / delete -> update state and attempt localStorage write
  -> confirmed Reset demo -> replace local projects with original samples
```

`components/projects/project-types.ts` owns the complete `Project` type and
`MOCK_PROJECTS`. Reuse that type instead of copying a reduced interface.
`components/projects/project-provider.tsx` owns React state and mutations;
`lib/project-storage.ts` owns reading/writing stored project records.

Changing `MOCK_PROJECTS` does not replace a valid saved project collection.
Use the confirmed **Reset demo** action only when you intend to discard local
changes. Invalid saved data falls back to samples with a notice. When browser
storage is unavailable, changes remain in memory for the current visit only.
This is not a shared database, authentication, or cross-device synchronization.

Later, replace this browser-local persistence boundary with your own server-side
validation, authorization, and database-backed project operations. Keep the
presentation components separate from that product-specific integration.

### PageShell pattern

Main SaaS pages use a shared shell for consistent page structure.

```tsx title="PageShell composition"
import { PageShell } from "@/components/app/page-shell";

export function ReportsPreview() {
  return (
    <PageShell title="Reports" description="Explore your report layout.">
      <p>No reports yet.</p>
    </PageShell>
  );
}
```

Use this pattern to keep:

* page spacing consistent
* headers predictable
* actions aligned
* metadata structured

Do not bypass it unless the page truly needs a different layout.

## Dialog pattern

Dialogs are isolated from the page and controlled by their parent feature.

<Files>
  <Folder name="components" defaultOpen>
    <Folder name="projects" defaultOpen>
      <File name="project-rename-dialog.tsx" />

      <File name="project-confirm-delete-dialog.tsx" />
    </Folder>
  </Folder>
</Files>

<br />

Recommended ownership:

| Concern          | Owner                    |
| ---------------- | ------------------------ |
| Open state       | Parent feature component |
| Form UI          | Dialog component         |
| API call later   | Feature/service layer    |
| Visual primitive | `@pycolors/ui` Dialog    |

This makes rename and delete flows easier to wire later without changing page structure.

## Add a new feature

Start with a static route in the existing application shell. These are new
example files to create in your checkout, not files already included in Free.
No backend or permission model is introduced by this example.

<Steps>
  <Step>
    ### Add the route

    ```bash title="From the Starter Free checkout"
    mkdir -p 'app/(app)/reports' components/reports
    ```

    Use the quoted route-group path so the new page shares the application layout.
  </Step>

  <Step>
    ### Create the feature folder

    Save this component in `components/reports/report-panel.tsx`:

    ```tsx title="components/reports/report-panel.tsx"
    export function ReportPanel() {
      return <p>No reports yet. Connect your own report data when ready.</p>;
    }
    ```
  </Step>

  <Step>
    ### Compose the page

    Save the route in `app/(app)/reports/page.tsx`:

    ```tsx title="app/(app)/reports/page.tsx"
    import { PageShell } from "@/components/app/page-shell";
    import { ReportPanel } from "@/components/reports/report-panel";

    export default function ReportsPage() {
      return (
        <PageShell title="Reports" description="Your product reports.">
          <ReportPanel />
        </PageShell>
      );
    }
    ```

    Open `/reports` in the running starter. Both files can remain Server Components;
    add a client leaf only when real interaction requires it. Run the checks in your
    checkout's package scripts before committing your customization.
  </Step>
</Steps>

### Decision guide

Use the Starter Free structure if:

* you want thin route files
* features need to evolve independently
* mock data will later become backend data
* dialogs and row actions need to stay reusable
* you want a clear path from frontend surface to production wiring

Avoid changing the structure if:

* you have not explored the full vertical slice yet
* the change only saves a few lines today
* the route would start owning too much logic
* UI primitives would start fetching data
* the mock layer would become scattered globally

<PreferAvoid
  prefer={[
  "feature-based folders",
  "thin pages",
  "mock data close to the feature",
  "isolated dialogs and row actions",
  "UI primitives that stay stateless",
]}
  avoid={[
  "putting feature logic directly in pages",
  "fetching data inside UI primitives",
  "placing all mock data in one global file",
  "duplicating dialog logic across routes",
  "deleting structure before understanding it",
]}
/>

### Backend wiring later

When you connect a backend, the structure stays familiar.

| Today                                      | Later                                               |
| ------------------------------------------ | --------------------------------------------------- |
| Browser-local project provider and storage | Your authorized, database-backed project operations |
| local dialog state                         | server action or API mutation                       |
| disabled billing portal                    | Stripe billing portal                               |
| mocked auth screens                        | real auth provider                                  |
| static members                             | organization members from backend                   |

The goal is to reuse the presentation while implementing a real product boundary,
not simply substitute a database call for local storage. Starter Pro supplies
configurable connected foundations, not automatic migration of Free projects.
Review [what is included](/docs/starter-pro/what-is-included) and the
[upgrade guide](/docs/starter/upgrade) before planning your integration.

<Callout title="Upgrade when wiring becomes the blocker">
  Starter Free validates the product surface. Starter Pro wires the business
  layer with production-shaped auth, billing, backend, and delivery foundations.
  → `/docs/starter-pro`
</Callout>

### Common questions

<Accordions type="single">
  <Accordion title="Why keep feature logic outside the app directory?">
    The `app/` directory should stay focused on routes and layout composition. Feature folders make behavior easier to reuse, test, and replace later.
  </Accordion>

  <Accordion title="Should mock data live globally?">
    Usually no. Keeping mock data near the feature makes it easier to replace with
    backend data later without searching through unrelated files.
  </Accordion>

  <Accordion title="Can I move features into a features/ directory?">
    Yes. The important rule is the boundary, not the exact folder name. Keep route files thin and feature behavior grouped.
  </Accordion>
</Accordions>

## Next steps

<DocsLinks
  variant="grid"
  items={[
  {
    title: "Authentication concept",
    href: "/docs/starter/auth-concept",
    description:
      "Understand how authentication is modeled before wiring a real provider.",
    icon: LockKeyhole,
  },
  {
    title: "Billing concept",
    href: "/docs/starter/billing-concept",
    description:
      "See how monetization surfaces are prepared before Stripe integration.",
    icon: CreditCard,
  },
  {
    title: "Upgrade to Starter Pro",
    href: "/docs/starter/upgrade",
    description:
      "Know when Starter Free stops being enough and Starter Pro becomes the faster path.",
    icon: ArrowUpRight,
    badge: "Pro",
    tone: "primary",
  },
  {
    title: "Data table pattern",
    href: "/docs/patterns/data-table",
    description:
      "Learn the production-ready pattern behind the Projects table.",
    icon: Table2,
  },
]}
/>