Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Astroの使用感とディレクトリ設計についての考察

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.
Avatar for Saku Saku
September 17, 2025

 Astroの使用感とディレクトリ設計についての考察

Avatar for Saku

Saku

September 17, 2025
Tweet

More Decks by Saku

Other Decks in Programming

Transcript

  1. ⽬次 1. 感想 今後導⼊していけそうか‧⾏きたいか 2. 困ったこと‧便利なこと 実際に使ってみた経験 3. 使う時はどこに注意すべきか ポイントと留意点

    4. どんな案件に向いてそうか 適⽤シーン AstroをFeature-basedなディレクトリ構成で使⽤する 5. ディレクトリ設計について考える
  2. なぜディレクトリ設計を考えるのか? 拡張性の担保 機能追加‧差し替え時の“波及”が局所化。リグレッションやレビュー⼯数の抑制につながる。 オンボーディングが速い どの機能がどこにあるかが予測可能 → 新メンバーの探索時間が短縮。 テストしやすい / 再利⽤しやすい

    責務が分離され、単体テストなどを当てやすく、コンポーネントやロジックの再利⽤率が上がる。 ビルド最適化に効く 共同作業での変更衝突‧不要再ビルドを減らし、tree-shaking/コード分割(code-splitting)が⽣き る。 設計判断の基準になる どこに置くか‧どこから参照するかの⼀貫性が、⽇々の意思決定コストを下げる。
  3. Directory Structure src/ ├── pages/ # 必須 ├── layouts/ #

    レイアウト ├── components/ # コンポーネント ├── content/ # コンテンツ └── styles/ # スタイル Key Points Astroにおいて pages/ のみが必須 柔軟な構成が可能 規模に応じて拡張
  4. Atomic Design との違い Atomic Design Feature-based 分割基準 UIの粒度‧階層 ビジネス機能 構造

    atoms → molecules → organisms features/ └── 各機能/ 焦点 再利⽤性‧⼀貫性 独⽴性‧凝集性 適⽤範囲 UIコンポーネント アプリ全体
  5. Type-based vs Feature-based Type-based (Standard) src/ ├── components/ │ ├──

    Button.tsx │ └── Card.tsx ├── hooks/ │ └── useAuth.ts └── pages/ └── blog.tsx 技術的な役割で分類 ‧コンポーネントはcomponents/ ‧フックはhooks/ ‧ページはpages/ Feature-based features/ └── blog/ ├── components/ │ └── PostCard.tsx ├── hooks/ │ └── usePosts.ts └── pages/ └── BlogPage.tsx 機能単位で分類 ‧blog機能の全ては features/blog/ ‧関連コードが1箇所に集約
  6. 有名な実装例 Bulletproof React src/ ├── features/ │ └── awesome-feature/ │

    │ ├── api/ │ │ ├── components/ │ │ ├── hooks/ │ │ ├── routes/ │ │ ├── stores/ │ │ ├── types/ │ │ └── utils/ ├── components/ # 共通UI ├── hooks/ # 共通hooks └── utils/ # 共通utils その他の実装例 Angular Style Guide 公式推奨の feature modules Domain-Driven Design ドメインごとの モジュール分割 Nx Monorepo libs/features/ での管理
  7. Astro での Feature-based 実装 src/ ├── features/ │ ├── blog/

    │ │ ├── components/ │ │ └── layouts/ │ └── auth/ │ └── components/ ├── shared/ └── pages/ Benefits 機能の独⽴性 保守性の向上 スケーラブル チーム開発対応
  8. Layout Patterns Type-based (Standard) src/ ├── layouts/ │ ├── Base

    │ └── Blog └── pages/ Feature-based features/ ├── blog/ │ └── layouts/ └── shared/ └── layouts/ Flat src/ ├── BaseLayout ├── components/ └── pages/
  9. Content Collections src/content/ ├── blog/ # 記事 │ ├── 2024-01-post.md

    │ └── config.ts # Zodスキーマ定義 ├── authors/ # 著者情報 │ └── john-doe.json └── config.ts # グローバル設定 型安全 Zodスキーマ TypeScript MDX対応 コンポーネント インポート // 使用例: import { getCollection } from 'astro:content'; const posts = await getCollection('blog');
  10. API Routes 設計 Type-based pages/api/ ├── auth.ts ├── posts.ts ├──

    users.ts └── comments.ts Feature-based features/ ├── auth/ │ └── api/ └── blog/ └── api/ RESTful エンドポイント 設計 凝集性 機能単位の API配置 GraphQL 対応可能な 構造
  11. Assets/Public の管理戦略 public/ 直接配信 public/ ├── favicon.ico ├── robots.txt └──

    og-image.jpg src/assets/ 最適化対象 src/assets/ ├── images/ ├── fonts/ └── icons/ 配置戦略の⽐較 public/: 変換なし‧直接配信‧キャッシュ制御可能 src/assets/: 画像最適化‧インポート型安全‧ビルド時処理
  12. Testing ディレクトリ構造 コロケーション features/blog/ ├── BlogPost.tsx ├── BlogPost.test.tsx ├── BlogList.tsx

    └── BlogList.test.tsx 別階層 tests/ ├── unit/ │ └── components/ ├── integration/ └── e2e/ メリット⽐較 コロケーション: 近接性‧保守性向上‧変更時の影響範囲明確 別階層: テストの⼀元管理‧CI/CD設定の簡潔性‧テスト種別の明確化
  13. Key Takeaways Feature-based構成で⼤規模開発に対応 Content Collections で型安全なコンテンツ管理 API Routes は機能ごとに凝集配置 Assets

    の最適化戦略を意識した配置 Testing はコロケーションで保守性向上 段階的な移⾏でリスクを最⼩化 Build faster websites with Astro
  14. 参照資料 - CSSとスタイル | Astro公式ドキュメント - スクリプトとイベントハンドリング | Astro公式ドキュメント -

    オンデマンドレンダリング | Astro公式ドキュメント - Bulletproof-react - 【React】フォルダ構成の考え⽅