# Layout Organization

Mountaineer supports flexible layout organization patterns inspired by Next.js. This guide explains how to structure your layouts for different scenarios.

## Default Layout Structure

By default, Mountaineer uses a cascading layout system where layouts apply to all pages in their directory and subdirectories:

```
views/
└── app/
    ├── layout.tsx         # Root layout (applies to all pages)
    ├── home/
    │   └── page.tsx       # Uses root layout
    └── dashboard/
        ├── layout.tsx     # Dashboard layout (applies to all dashboard pages)
        ├── home/
        │   └── page.tsx   # Uses both root and dashboard layouts
        └── settings/
            └── page.tsx   # Uses both root and dashboard layouts
```

In this structure, when rendering `dashboard/home/page.tsx`, the page will be wrapped by both the `dashboard/layout.tsx` and the root `app/layout.tsx`.

## Optional Layout Structure with (root) Folder

For more granular control over which layouts apply to which pages, you can use the optional (root) folder pattern. This allows you to isolate layouts to specific sections of your application:

```
views/
└── app/
    ├── (root)/            # Root group
    │   ├── layout.tsx     # Layout only applies within this group
    │   └── home/
    │       └── page.tsx   # Uses the (root) layout
    └── dashboard/         # Separate section not using the (root) layout
        └── page.tsx       # Doesn't use any layout
```

In this structure:
- The layout in `(root)/layout.tsx` only applies to pages within the `(root)` directory
- Pages outside the `(root)` directory (like `dashboard/page.tsx`) don't inherit the root layout

This pattern is useful when:
- You want different sections of your app to have completely different layouts
- You need to isolate layout changes to prevent them from affecting other parts of your application
- You're building a multi-tenant application where each tenant needs its own layout

## Nested Layout Groups

You can also nest these layout groups for even more control:

```
views/
└── app/
    ├── (root)/
    │   ├── layout.tsx
    │   ├── home/
    │   │   └── page.tsx   # Uses only the (root) layout
    │   └── (admin)/
    │       ├── layout.tsx # Admin layout
    │       └── dashboard/
    │           └── page.tsx # Uses both (root) and (admin) layouts
    └── auth/
        └── page.tsx       # Doesn't use any layout
```

## Implementation Details

When Mountaineer encounters a folder name wrapped in parentheses like `(root)`, it treats it as a layout group. The parentheses in the folder name are just a convention to indicate that this folder is used for layout organization and doesn't affect the actual URL routing.

This approach gives you the flexibility to organize your layouts in a way that matches your application's structure while maintaining clean separation between different sections. 