> ## Documentation Index
> Fetch the complete documentation index at: https://mint-tsdocs.saulo.engineer/llms.txt
> Use this file to discover all available pages before exploring further.

# FileTree

> Display hierarchical file structures with visual icons and descriptions

export const Preview = ({children, title = "Preview", className}) => {
  const outerClasses = ["code-block mt-5 mb-8 not-prose rounded-2xl relative group", "text-gray-950 bg-gray-50 dark:bg-white/5 dark:text-gray-50", "border border-gray-950/10 dark:border-white/10", "p-0.5", className].filter(Boolean).join(" ");
  return <div className={outerClasses} data-component="tsdocs-preview">
      {}
      <div className="flex text-gray-400 text-xs rounded-t-[14px] leading-6 font-medium pl-4 pr-2.5 py-1">
        <div className="flex-none flex items-center gap-1.5 text-gray-700 dark:text-gray-300">
          {title}
        </div>
      </div>

      {}
      <div className="prose prose-sm dark:prose-invert w-0 min-w-full max-w-full py-3.5 px-4 rounded-b-2xl bg-white dark:bg-codeblock overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25">
        {children}
      </div>
    </div>;
};

export const FileTree = ({structure, item, title, level = 0, maxDepth = 10, showIcons = true}) => {
  const getFileIcon = (fileName, hasChildren) => {
    if (hasChildren) {
      return 'folder-open';
    }
    return 'file';
  };
  if (structure !== undefined) {
    return <div data-component="tsdocs-filetree" className="code-block mt-5 mb-8 not-prose rounded-2xl relative group
                   text-gray-950 bg-gray-50 dark:bg-white/5 dark:text-gray-50
                   border border-gray-950/10 dark:border-white/10
                   p-0.5">
        {title && <div className="flex text-gray-400 text-xs rounded-t-[14px] leading-6 font-medium pl-4 pr-2.5 py-1">
            <div className="flex-none flex items-center gap-1.5 text-gray-700 dark:text-gray-300">
              {title}
            </div>
          </div>}
        <div className={`prose prose-sm dark:prose-invert w-0 min-w-full max-w-full py-3.5 px-4 bg-white dark:bg-codeblock overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 rounded-xt`} style={{
      fontFamily: 'ui-monospace, SFMono-Regular, monospace',
      fontSize: '0.875rem'
    }}>
          {structure.map((fileItem, index) => {
      if (!fileItem || !fileItem.name) return null;
      return <FileTree key={index} item={fileItem} level={0} maxDepth={maxDepth} showIcons={showIcons} />;
    })}
        </div>
      </div>;
  }
  if (!item) {
    return null;
  }
  if (level >= maxDepth) {
    return <div style={{
      paddingLeft: `${level * 20}px`,
      paddingTop: '4px',
      paddingBottom: '4px',
      color: '#6b7280',
      fontStyle: 'italic'
    }}>
        {showIcons && <Icon icon="AlertTriangle" />} (max depth reached)
      </div>;
  }
  const hasChildren = item.children != null && item.children.length > 0;
  const indent = level * 20;
  if (hasChildren) {
    return <div style={{
      position: 'relative',
      paddingLeft: `${indent}px`
    }}>
        {}
        {level > 0 && <div style={{
      position: 'absolute',
      left: `${indent - 12}px`,
      top: '20px',
      bottom: '0',
      width: '1px',
      backgroundColor: 'rgba(156, 163, 175, 0.2)',
      borderLeft: '1px solid rgba(156, 163, 175, 0.1)'
    }} />}
        <div style={{
      display: 'flex',
      alignItems: 'center',
      gap: '8px',
      paddingTop: '4px',
      paddingBottom: '4px'
    }}>
          {showIcons && <Icon icon={getFileIcon(item.name, true)} />}
          <span style={{
      fontWeight: 500
    }}>
            {item.name}
          </span>
          {item.description && <span style={{
      fontSize: '0.75rem',
      color: '#94a3b8',
      marginLeft: '8px'
    }}>
              {item.description}
            </span>}
          {item.badge && <Badge color={item.badge.color || 'blue'}>
              {item.badge.text}
            </Badge>}
        </div>
        {}
        {item.children && item.children.map((child, i) => {
      const key = child.name ? `${child.name}-${i}` : `child-${i}`;
      return <FileTree key={key} item={child} level={level + 1} maxDepth={maxDepth} showIcons={showIcons} />;
    })}
      </div>;
  }
  return <div style={{
    position: 'relative',
    paddingLeft: `${indent}px`,
    display: 'flex',
    alignItems: 'center',
    gap: '8px',
    paddingTop: '4px',
    paddingBottom: '4px'
  }}>
      {}
      {level > 0 && <div style={{
    position: 'absolute',
    left: `${indent - 12}px`,
    top: '0',
    bottom: '0',
    width: '1px',
    backgroundColor: 'rgba(156, 163, 175, 0.2)',
    borderLeft: '1px solid rgba(156, 163, 175, 0.1)'
  }} />}
      {showIcons && <Icon icon={getFileIcon(item.name, false)} />}
      <span>
        {item.name}
      </span>
      {item.description && <span style={{
    fontSize: '0.75rem',
    color: '#94a3b8',
    marginLeft: '8px'
  }}>
          {item.description}
        </span>}
      {item.badge && <Badge color={item.badge.color || 'blue'}>
          {item.badge.text}
        </Badge>}
    </div>;
};

The `FileTree` component provides a beautiful way to display project file structures, directory hierarchies, and file organization in your documentation. It renders a static tree view with Lucide icons, optional descriptions, and badges in a clean code-block styled interface.

## Basic Usage

Import the component and pass it a hierarchical structure of files and directories.

```jsx FileTree usage theme={null}
import { FileTree } from "/snippets/tsdocs/FileTree.jsx"

const fileStructure = [
  {
    name: "src/",
    description: "Source code directory",
    children: [
      {
        name: "index.ts",
        description: "Main entry point"
      },
      {
        name: "components/",
        children: [
          { name: "Button.tsx", description: "Button component" },
          { name: "Card.tsx", description: "Card component" }
        ]
      }
    ]
  },
  {
    name: "package.json",
    description: "Package configuration",
    badge: { text: "Config", color: "blue" }
  }
];

<FileTree title="Project Structure" structure={fileStructure} />
```

export const basicStructure = [{
  name: "src/",
  description: "Source code directory",
  children: [{
    name: "index.ts",
    description: "Main entry point"
  }, {
    name: "components/",
    children: [{
      name: "Button.tsx",
      description: "Button component"
    }, {
      name: "Card.tsx",
      description: "Card component"
    }]
  }]
}, {
  name: "package.json",
  description: "Package configuration",
  badge: {
    text: "Config",
    color: "blue"
  }
}];

<Preview title="Basic FileTree Example">
  <FileTree title="Project Structure" structure={basicStructure} />
</Preview>

## Features

### Visual Design

* **Code block styling** with rounded corners and syntax highlighting appearance
* **Dark mode support** with automatic theme switching
* **Vertical guide lines** for nested directory structures
* **Consistent spacing** and typography for optimal readability

### File Icons

* **Folder icons** for directories (📁)
* **File icons** for individual files (📄)
* **Icon customization** via the `getFileIcon` function (extensible for different file types)

### Metadata Support

* **Descriptions** provide context for files and directories
* **Badges** highlight important files with customizable colors
* **Hierarchical structure** supports unlimited nesting depth

## Advanced Example

Here's a comprehensive example showing a typical project structure with various file types and metadata:

<Preview
  code={`<FileTree
title="OpenDocs Project Structure"
structure={[
{
  name: "docs/",
  description: "Documentation source files",
  children: [
    {
      name: "components/",
      description: "Reusable MDX components",
      children: [
        { name: "type-tree.mdx", description: "TypeTree component docs" },
        { name: "file-tree.mdx", description: "FileTree component docs" },
        { name: "preview.mdx", description: "Preview component docs" }
      ]
    },
    {
      name: "docs.json",
      description: "Mintlify navigation configuration",
      badge: { text: "Config", color: "blue" }
    }
  ]
},
{
  name: "src/",
  description: "Source code",
  children: [
    {
      name: "cli/",
      description: "Command-line interface",
      children: [
        { name: "InitAction.ts", description: "Initialize command" },
        { name: "GenerateAction.ts", description: "Generate command" }
      ]
    },
    {
      name: "components/",
      description: "React components",
      badge: { text: "React", color: "green" },
      children: [
        { name: "FileTree.jsx", description: "File tree component" },
        { name: "JsonTree.jsx", description: "JSON tree component" },
        { name: "TypeTree.jsx", description: "Type tree component" }
      ]
    }
  ]
},
{
  name: "package.json",
  description: "Package manifest",
  badge: { text: "Package", color: "purple" }
},
{
  name: "tsconfig.json",
  description: "TypeScript configuration",
  badge: { text: "Config", color: "blue" }
}
]}
/>`}
>
  <FileTree
    title="OpenDocs Project Structure"
    structure={[
  {
    name: "docs/",
    description: "Documentation source files",
    children: [
      {
        name: "components/",
        description: "Reusable MDX components",
        children: [
          { name: "type-tree.mdx", description: "TypeTree component docs" },
          { name: "file-tree.mdx", description: "FileTree component docs" },
          { name: "preview.mdx", description: "Preview component docs" }
        ]
      },
      {
        name: "docs.json",
        description: "Mintlify navigation configuration",
        badge: { text: "Config", color: "blue" }
      }
    ]
  },
  {
    name: "src/",
    description: "Source code",
    children: [
      {
        name: "cli/",
        description: "Command-line interface",
        children: [
          { name: "InitAction.ts", description: "Initialize command" },
          { name: "GenerateAction.ts", description: "Generate command" }
        ]
      },
      {
        name: "components/",
        description: "React components",
        badge: { text: "React", color: "green" },
        children: [
          { name: "FileTree.jsx", description: "File tree component" },
          { name: "JsonTree.jsx", description: "JSON tree component" },
          { name: "TypeTree.jsx", description: "Type tree component" }
        ]
      }
    ]
  },
  {
    name: "package.json",
    description: "Package manifest",
    badge: { text: "Package", color: "purple" }
  },
  {
    name: "tsconfig.json",
    description: "TypeScript configuration",
    badge: { text: "Config", color: "blue" }
  }
]}
  />
</Preview>

## Properties

<ResponseField name="structure" type="FileTreeItem[]" required>
  Hierarchical array of files and directories to display. Each item should have a `name` property.
</ResponseField>

<ResponseField name="title" type="string">
  Optional title displayed at the top of the file tree component
</ResponseField>

<ResponseField name="maxDepth" type="number" default="10">
  Maximum nesting depth to prevent infinite recursion in deeply nested structures
</ResponseField>

<ResponseField name="showIcons" type="boolean" default="true">
  Whether to display file and folder icons next to items
</ResponseField>

## FileTreeItem Interface

Each item in the `structure` array should follow this interface:

```typescript theme={null}
interface FileTreeItem {
  name: string;           // File or directory name
  description?: string;   // Optional description shown next to the name
  badge?: FileTreeBadge; // Optional badge configuration
  children?: FileTreeItem[]; // Child items for directories
}

interface FileTreeBadge {
  text: string;          // Badge text content
  color?: string;        // Badge color (Mintlify Badge color prop)
}
```

## FileTreeGroup

Use `FileTreeGroup` to organize multiple related file trees:

<Preview
  code={`<FileTreeGroup title="Project Structures">
<FileTree
title="Frontend Structure"
structure={[
  { name: "src/", children: [
    { name: "components/", children: [
      { name: "Header.tsx", description: "Header component" },
      { name: "Footer.tsx", description: "Footer component" }
    ]},
    { name: "pages/", children: [
      { name: "Home.tsx", description: "Home page" },
      { name: "About.tsx", description: "About page" }
    ]}
  ]}
]}
/>
<FileTree
title="Backend Structure"
structure={[
  { name: "api/", children: [
    { name: "routes/", children: [
      { name: "users.ts", description: "User routes" },
      { name: "posts.ts", description: "Post routes" }
    ]},
    { name: "middleware/", children: [
      { name: "auth.ts", description: "Authentication middleware" },
      { name: "validation.ts", description: "Validation middleware" }
    ]}
  ]}
]}
/>
</FileTreeGroup>`}
>
  <FileTreeGroup title="Project Structures">
    <FileTree
      title="Frontend Structure"
      structure={[
    { name: "src/", children: [
      { name: "components/", children: [
        { name: "Header.tsx", description: "Header component" },
        { name: "Footer.tsx", description: "Footer component" }
      ]},
      { name: "pages/", children: [
        { name: "Home.tsx", description: "Home page" },
        { name: "About.tsx", description: "About page" }
      ]}
    ]}
  ]}
    />

    <FileTree
      title="Backend Structure"
      structure={[
    { name: "api/", children: [
      { name: "routes/", children: [
        { name: "users.ts", description: "User routes" },
        { name: "posts.ts", description: "Post routes" }
      ]},
      { name: "middleware/", children: [
        { name: "auth.ts", description: "Authentication middleware" },
        { name: "validation.ts", description: "Validation middleware" }
      ]}
    ]}
  ]}
    />
  </FileTreeGroup>
</Preview>

## Best Practices

<AccordionGroup>
  <Accordion title="Use Descriptive Names" icon="message">
    Choose clear, descriptive names for files and directories that immediately convey their purpose.

    ```jsx theme={null}
    // ✅ Good
    { name: "user-authentication.ts", description: "Handles user login/logout logic" }

    // ❌ Avoid
    { name: "util.ts", description: "Utility functions" }
    ```
  </Accordion>

  <Accordion title="Add Context with Descriptions" icon="info">
    Use descriptions to provide additional context that helps users understand the purpose and contents of files/directories.

    ```jsx theme={null}
    <FileTree
      title="API Structure"
      structure={[
        {
          name: "controllers/",
          description: "Request handlers that process incoming API calls"
        },
        {
          name: "models/",
          description: "Data models defining database schema structure"
        },
        {
          name: "middleware/",
          description: "Cross-cutting concerns like authentication and validation"
        }
      ]}
    />
    ```
  </Accordion>

  <Accordion title="Use Badges Strategically" icon="tag">
    Apply badges to highlight important files, configuration files, or items that need special attention.

    ```jsx theme={null}
    <FileTree
      structure={[
        { name: "package.json", badge: { text: "Config", color: "blue" } },
        { name: "Dockerfile", badge: { text: "Docker", color: "green" } },
        { name: "README.md", badge: { text: "Docs", color: "purple" } },
        { name: "LICENSE", badge: { text: "Legal", color: "red" } }
      ]}
    />
    ```
  </Accordion>

  <Accordion title="Group Related Items" icon="layer-group">
    Organize file structures logically, grouping related functionality together and using FileTreeGroup for multiple related structures.

    ```jsx theme={null}
    <FileTreeGroup title="Monorepo Structure">
      <FileTree title="Shared Packages" structure={sharedPackages} />
      <FileTree title="Frontend Apps" structure={frontendApps} />
      <FileTree title="Backend Services" structure={backendServices} />
    </FileTreeGroup>
    ```
  </Accordion>

  <Accordion title="Keep Depth Reasonable" icon="sitemap">
    While FileTree supports unlimited nesting, limit depth to 4-5 levels for readability. Consider breaking very deep structures into separate documentation sections.
  </Accordion>
</AccordionGroup>

## Styling and Theming

FileTree automatically adapts to Mintlify's light and dark themes:

* **Light mode**: Light gray backgrounds with dark text
* **Dark mode**: Dark backgrounds with light text
* **Code block styling**: Consistent with other code elements in your documentation
* **Vertical guide lines**: Subtle visual indicators for nested structures
* **Hover states**: Clean interaction feedback
* **Typography**: Monospace font for file names, proportional font for descriptions

## Troubleshooting

<AccordionGroup>
  <Accordion title="Component not found" icon="triangle-exclamation">
    If you see `Cannot find module "/snippets/FileTree.jsx"`:

    1. Ensure FileTree.jsx exists in your `docs/snippets/` folder
    2. Run `mint-tsdocs` to auto-install the component
    3. Check that the import path is correct (should start with `/snippets/`)
  </Accordion>

  <Accordion title="Icons not displaying" icon="image">
    If file/folder icons are not showing:

    1. Verify that Mintlify's Icon component is available
    2. Check browser console for JavaScript errors
    3. Ensure `showIcons` prop is not set to `false`
  </Accordion>

  <Accordion title="Structure not rendering" icon="code">
    If the file tree doesn't display correctly:

    1. Verify that each item has a `name` property
    2. Check that the `structure` prop is a valid array
    3. Ensure proper JSON formatting in your MDX file
  </Accordion>

  <Accordion title="Styling issues" icon="paintbrush">
    If the component doesn't look right:

    1. Ensure Tailwind CSS is properly loaded in your Mintlify site
    2. Check that you're using an up-to-date version of the component
    3. Try refreshing the page to reload styles
  </Accordion>
</AccordionGroup>

## Version History

<CardGroup cols={2}>
  <Card title="v3.0.0" icon="rocket">
    Initial release with hierarchical file structure visualization, Lucide icons, and code block styling
  </Card>

  <Card title="Future" icon="sparkles">
    * File type detection with specific icons for different extensions
    * Expandable/collapsible directories
    * File size and modification date display
    * Copy file paths functionality
  </Card>
</CardGroup>

## Related Components

<CardGroup cols={3}>
  <Card title="JsonTree" icon="code" href="/components/jsontree">
    Display JSON data structures with beautiful formatting
  </Card>

  <Card title="TypeTree" icon="network" href="/components/type-tree">
    Display recursive type structures with expandable properties
  </Card>

  <Card title="Preview" icon="eye" href="/components/preview">
    Styled wrapper for component examples
  </Card>
</CardGroup>
