project-structure について
Turborepo と pnpm workspaces を使う Next.js アプリの開発者向け構成ガイドです。ディレクトリ配置、命名規則、ページやコンポーネント、ユーティリティの整理方法を説明します。
主な機能
- 01アプリとパッケージの構成案内
- 02ページとコンポーネントの配置説明
- 03ファイル命名規則の提示
- 04ユーティリティの整理とインポート方法
活用シーン
- 01メインアプリや共有パッケージのコード検索
- 02規約に沿ったページの新規作成
- 03再利用可能なユーティリティの整理
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ elie222/ inbox-zero --skill project-structureインストール後、Claude Code で/project-structureを入力して読み込まれたか確認します。
詳細
プロジェクト構成
主な構成
- Turborepo と pnpm ワークスペースを使用しています
- メインアプリは
apps/webにあります - パッケージは
packagesフォルダーにあります - サーバーアクションは
apps/web/utils/actionsフォルダーにあります
.
├── apps
│ ├── web/ # Main Next.js application
│ │ ├── app/ # Next.js App Router
│ │ │ ├── (app)/ # Main application pages
│ │ │ │ ├── assistant/ # AI assistant feature
│ │ │ │ ├── reply-zero/ # Reply Zero feature
│ │ │ │ ├── settings/ # User settings
│ │ │ │ ├── setup/ # Main onboarding
│ │ │ │ ├── clean/ # Bulk email cleanup
│ │ │ │ ├── smart-categories/ # Smart sender categorization
│ │ │ │ ├── bulk-unsubscribe/ # Bulk unsubscribe
│ │ │ │ ├── stats/ # Email analytics
│ │ │ │ ├── mail/ # Email client (in beta)
│ │ │ │ └── ... (other app routes)
│ │ │ ├── api/ # API Routes
│ │ │ │ ├── knowledge/ # Knowledge base API
│ │ │ │ ├── reply-tracker/ # Reply tracking
│ │ │ │ ├── clean/ # Cleanup API
│ │ │ │ ├── ai/ # AI features API
│ │ │ │ ├── user/ # User management
│ │ │ │ ├── google/ # Google integration
│ │ │ │ ├── auth/ # Authentication
│ │ │ │ └── ... (other APIs)
│ │ │ ├── (landing)/ # Marketing/landing pages
│ │ │ ├── blog/ # Blog pages
│ │ │ ├── layout.tsx # Root layout
│ │ │ └── ... (other app files)
│ │ ├── utils/ # Utility functions and helpers
│ │ │ ├── actions/ # Server actions
│ │ │ ├── ai/ # AI-related utilities
│ │ │ ├── llms/ # Language model utilities
│ │ │ ├── gmail/ # Gmail integration utilities
│ │ │ ├── redis/ # Redis utilities
│ │ │ ├── user/ # User-related utilities
│ │ │ ├── parse/ # Parsing utilities
│ │ │ ├── queue/ # Queue management
│ │ │ ├── error-messages/ # Error handling
│ │ │ └── *.ts # Other utility files (auth, email, etc.)
│ │ ├── public/ # Static assets (images, fonts)
│ │ ├── prisma/ # Prisma schema and client
│ │ ├── styles/ # Global CSS styles
│ │ ├── providers/ # React Context providers
│ │ ├── hooks/ # Custom React hooks
│ │ ├── sanity/ # Sanity CMS integration
│ │ ├── __tests__/ # AI test files (Vitest)
│ │ ├── scripts/ # Utility scripts
│ │ ├── store/ # State management
│ │ ├── types/ # TypeScript type definitions
│ │ ├── next.config.mjs
│ │ ├── package.json
│ │ └── ... (config files)
├── packages
├── tinybird/
├── loops/
├── resend/
├── tinybird-ai-analytics/
└── tsconfig/
ファイルの命名と整理
- ルートディレクトリにはケバブケースを使用します(例:
api/hello-world/route) - コンポーネントにはパスカルケースを使用します(例:
components/Button.tsx) - Shadcn コンポーネントは
components/uiにあります - その他すべてのコンポーネントは
components/にあります - アプリ全体で使用できる場合を除き、ファイルは使用するフォルダー内にまとめます
- コンポーネントを多くの場所で使用できる場合は、
componentsフォルダーに配置します
新しいページ
- 新しいページは
apps/web/app/(app)/PAGE_NAME/page.tsxに作成します - ページ用のコンポーネントは、
page.tsxまたはapps/web/app/(app)/PAGE_NAMEフォルダーに配置します - ページは、データを直接読み込むためのサーバーコンポーネントです
- 深くネストされたコンポーネントでのデータ取得には
swrを使用します onClickを持つコンポーネントは、use clientディレクティブを指定したクライアントコンポーネントにする必要があります- サーバーアクションのファイルは
use serverで始める必要があります
ユーティリティ関数
- 再利用可能なロジック用のユーティリティ関数は
utils/フォルダーに作成します - 一般的な操作(配列、オブジェクト、文字列)には lodash のユーティリティを使用します
- バンドルサイズを最小限に抑えるため、lodash の関数を個別にインポートします:
import groupBy from "lodash/groupBy";
コメント
Markdown 対応