Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
フロントエンド_最強ディレクトリ構成
Search
hatsune
December 07, 2022
Programming
5.3k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
フロントエンド_最強ディレクトリ構成
hatsune
December 07, 2022
More Decks by hatsune
See All by hatsune
Vue_CLIプロジェクトにViteを導入検討してみた
kitsuneeee
1
8.1k
Vue.js + TypeScriptによる 新規サービス開発の振り返り/frontend-looking-back
kitsuneeee
4
2.2k
コンポーネント間のデータやりとりを色々試してみた.pdf
kitsuneeee
0
520
Other Decks in Programming
See All in Programming
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.5k
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
14
6.4k
ふつうのFeature Flag実践入門
irof
8
4.2k
Oxlintのカスタムルールの現況
syumai
6
1.2k
Agentic UI
manfredsteyer
PRO
0
200
Vite+ Unified Toolchain for the Web
naokihaba
0
360
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
220
AIで効率化できた業務・日常
ochtum
0
150
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
130
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
130
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
410
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
My Coaching Mixtape
mlcsv
0
160
Art, The Web, and Tiny UX
lynnandtonic
304
22k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
370
Build your cross-platform service in a week with App Engine
jlugia
234
18k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
260
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
400
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
Transcript
フロントエンド 最強ディレクトリ構成 株式会社ラクス 勤怠開発2課 北嶋初音
index • 発表経緯 • 開発フェーズによる特徴 • 利用技術 • ディレクトリ構成見直し •
まとめ
発表経緯 • 楽楽勤怠のリリースから約2年 • 開発も運用フェーズへと移行しつつある • ディレクトリ設計の見直しもたびたび必要があった • 設計方針がある程度固まってきたので共有 •
経緯や具体的な移行内容をまとめておく
開発フェーズによる特徴 初期 開発スピード重視 • 共通化 ◦ 1箇所直したらで全部直って欲 しい • 機能要件が満たせればOK
現在 品質(保守性)重視 • 責務の分割 ◦ デグレを防止したい ◦ 修正の影響箇所を絞りたい • テストコードも書きたい
利用技術 • Vue.js(2系) • Vuex • TypeScript • Axios •
Jest • Testing Library • Storybook ※今回分かっておけば良い部分のみ記載
ディレクトリ構成見直し:導入 src/ ├── app/ │ ├── components/ │ │ ├──
base/ │ │ ├── pages/ │ │ └── parts/ │ ├── repositories/ │ ├── stores/ │ └── types/ ├── stories/ └── tests/
ディレクトリ構成見直し:導入 src/ ├── app/ │ ├── components/ │ │ ├──
base/ → 複数画面で利用される 共通コンポーネント(.vue) │ │ ├── pages/ → 各画面のルートとなる 画面コンポーネント(.vue) │ │ └── parts/ → 各画面で利用される 部品コンポーネント(.vue) │ ├── repositories/ │ ├── stores/ │ └── types/ ├── stories/ └── tests/
ディレクトリ構成見直し:導入 src/ ├── app/ │ ├── components/ │ │ ├──
base/ │ │ ├── pages/ │ │ └── parts/ │ ├── repositories/ → API通信を行う関数をまとめたファイル( .repo.ts) │ ├── stores/ │ └── types/ ├── stories/ └── tests/
ディレクトリ構成見直し:導入 src/ ├── app/ │ ├── components/ │ │ ├──
base/ │ │ ├── pages/ │ │ └── parts/ │ ├── repositories/ │ ├── stores/ → API通信の結果など状態を保持しておく Vuexファイル(.store.ts) │ └── types/ ├── stories/ └── tests/
ディレクトリ構成見直し:導入 src/ ├── app/ │ ├── components/ │ │ ├──
base/ │ │ ├── pages/ │ │ └── parts/ │ ├── repositories/ │ ├── stores/ │ └── types/ → TypeScriptの型情報を記載しておくファイル( .type.ts) ├── stories/ └── tests/
ディレクトリ構成見直し:導入 src/ ├── app/ │ ├── components/ │ │ ├──
base/ │ │ ├── pages/ │ │ └── parts/ │ ├── repositories/ │ ├── stores/ │ └── types/ ├── stories/ → storybookによるコンポーネントカタログのファイル( .stories.ts) └── tests/
ディレクトリ構成見直し:導入 src/ ├── app/ │ ├── components/ │ │ ├──
base/ │ │ ├── pages/ │ │ └── parts/ │ ├── repositories/ │ ├── stores/ │ └── types/ ├── stories/ └── tests/ → Jest, Testing Library によるテストコードのファイル( .spec.ts)
ディレクトリ構成見直し:導入 page part base store repository logic test sotires logic
test component test
ディレクトリ構成見直し:問題点① src/ ├── app/ │ ├── components/ │ │ ├──
base/ │ │ ├── pages/ │ │ └── parts/ → どの画面で使われてるのか分かりにくい。。 │ ├── repositories/ │ ├── stores/ → どの画面で状態が変更されるのか追いにくい。。 │ └── types/ ├── stories/ └── tests/
ディレクトリ構成見直し:問題点① src/ ├── app/ │ ├── components/ │ │ ├──
base/ │ │ ├── pages/ │ │ └── parts/ │ ├── repositories/ │ ├── stores/ │ └── types/ ├── stories/ → どのコンポーネントに対して実装済みか分かりにくい。。 └── tests/ → どのコンポーネントに対して実装済みか分かりにくい。。
ディレクトリ構成見直し:問題点① src/ ├── app/ │ ├── components/ │ │ ├──
base/ │ │ ├── pages/ │ │ └── parts/ │ ├── repositories/ │ ├── stores/ │ └── types/ ├── stories/ └── tests/ どの画面・どのコンポーネント に所属しているのかが分かれば良さそう ↓ pageコンポーネント中心に集めてみる
ディレクトリ構成見直し:partsファイル components/ ├── pages/ │ └── pc/ │ └── admin/
│ └── department-list/ │ └── AdminDepartmentListPc.vue └── parts/ └── pc/ └── admin/ └── department-list/ └── admin-department-form/ └── AdminDepartmentForm.vue components/ └── pages/ └── pc/ └── admin/ └── department-list/ ├── AdminDepartmentListPc.vue └── parts/ └── department-form/ └── DepartmentForm.vue before after
ディレクトリ構成見直し:partsファイル components/ ├── pages/ │ └── pc/ │ └── admin/
│ └── department-list/ │ └── AdminDepartmentListPc.vue └── parts/ └── pc/ └── admin/ └── admin-department-form/ └── AdminDepartmentForm.vue components/ └── pages/ └── pc/ └── admin/ └── department-list/ ├── AdminDepartmentListPc.vue └── parts/ └── department-form/ └── DepartmentForm.vue before after • 利用される画面が分かりや すくなった • フォルダ名やファイル名が シンプルになった • 階層を合わせる必要もなく なった
ディレクトリ構成見直し:storeファイル app/ ├── components/ │ └── pages/ │ └── pc/
│ └── admin/ │ └── department-list/ │ └── AdminDepartmentListPc.vue └── stores/ └── Department.ts components/ └── pages/ └── pc/ └── admin/ └── department-list/ ├── AdminDepartmentListPc.vue └── store/ └── AdminDepartmentListPc.store.ts before after
ディレクトリ構成見直し:storeファイル app/ ├── components/ │ └── pages/ │ └── pc/
│ └── admin/ │ └── department-list/ │ └── AdminDepartmentListPc.vue └── stores/ └── Department.ts components/ └── pages/ └── pc/ └── admin/ └── department-list/ ├── AdminDepartmentListPc.vue └── store/ └── AdminDepartmentListPc.store.ts before after • 更新される画面が分かりや すくなった • グローバルなStoreから画 面専用のStoreになったの で、他画面の影響を受けな くなった
ディレクトリ構成見直し:typeファイル app/ ├── components/ │ └── pages/ │ └── pc/
│ └── admin/ │ └── department-list/ │ └── AdminDepartmentListPc.vue └── types/ └── department.type.ts components/ └── pages/ └── pc/ └── admin/ └── department-list/ ├── AdminDepartmentListPc.vue └── AdminDepartmentListPc.type.ts before after
ディレクトリ構成見直し:specファイル src/ ├── app/ │ └── components/ │ └── pages/
│ └── pc/ │ └── admin/ │ └── department-list/ │ └── AdminDepartmentListPc.vue └── tests/ └── app/ 〜 省略 〜 └── AdminDepartmentListPc.it.spec.ts components/ └── pages/ └── pc/ └── admin/ └── department-list/ ├── AdminDepartmentListPc.vue └── AdminDepartmentListPc.it.spec.ts before after
ディレクトリ構成見直し:stories src/ ├── app/ │ └── components/ │ └── pages/
│ └── pc/ │ └── admin/ │ └── department-list/ │ └── AdminDepartmentListPc.vue └── stories/ └── app/ 〜 省略 〜 └── AdminDepartmentListPc.stories.ts components/ └── pages/ └── pc/ └── admin/ └── department-list/ ├── AdminDepartmentListPc.vue └── AdminDepartmentListPc.stories.ts before after
ディレクトリ構成見直し:まとめ① components/ └── pages/ └── pc/ └── admin/ └── department-list
├── AdminDepartmentListPc.vue ├── AdminDepartmentListPc.type.ts ├── AdminDepartmentListPc.it.spec.ts ├── AdminDepartmentListPc.stories.ts ├── parts │ └── department-form │ └── DepartmentForm.vue └── store └── AdminDepartmentListPc.store.ts after pageコンポーネント中心に集めて 各ファイルの利用箇所が分かりや すくやった (責務の分離もできた)
ディレクトリ構成見直し:問題点② page part base store repository logic test sotires logic
test component test ビジネスロジックが 多くなりがち テストが書きにくい ビジネスロジックが 多くなりがち テストが書きにくい
ディレクトリ構成見直し:問題点② page part base store repository logic test sotires logic
test component test modules modules • ビジネスロジックを抜き出す階層を作成 • export/importでテストも書くやすくする
ディレクトリ構成見直し:modules components/ └── pages/ └── pc/ └── admin/ └── department-list
├── AdminDepartmentListPc.vue ├── AdminDepartmentListPc.type.ts ├── AdminDepartmentListPc.it.spec.ts ├── AdminDepartmentListPc.stories.ts ├── parts │ └── department-form │ └── DepartmentForm.vue └── store └── AdminDepartmentListPc.store.ts components/ └── pages/ └── pc/ └── admin/ └── department-list ├── AdminDepartmentListPc.vue ├── AdminDepartmentListPc.type.ts ├── AdminDepartmentListPc.it.spec.ts ├── AdminDepartmentListPc.stories.ts ├── AdminDepartmentListPc.modules.ts ├── AdminDepartmentListPc.modules.spec.ts ├── parts │ └── department-form │ └── DepartmentForm.vue └── store └── AdminDepartmentListPc.store.ts before after
ディレクトリ構成見直し:modules components/ └── pages/ └── pc/ └── admin/ └── department-list
├── AdminDepartmentListPc.vue ├── AdminDepartmentListPc.type.ts ├── AdminDepartmentListPc.it.spec.ts ├── AdminDepartmentListPc.stories.ts ├── parts │ └── department-form │ └── DepartmentForm.vue └── store └── AdminDepartmentListPc.store.ts components/ └── pages/ └── pc/ └── admin/ └── department-list ├── AdminDepartmentListPc.vue ├── AdminDepartmentListPc.type.ts ├── AdminDepartmentListPc.it.spec.ts ├── AdminDepartmentListPc.stories.ts ├── AdminDepartmentListPc.modules.ts ├── AdminDepartmentListPc.modules.spec.ts ├── parts │ └── department-form │ └── DepartmentForm.vue └── store └── AdminDepartmentListPc.store.ts before after • pageコンポーネントの肥大 化を防げた • ロジックを抜き出したおかげ でテストも書きやすくなった
ディレクトリ構成見直し:Pros/Cons Pros • 各ファイルの影響箇所が分かりやす くなった • ロジック抜き出しによってコンポーネ ントやStoreの肥大化を防げた • テストも書きやすくなった
Cons • 共通化が減るので実装工数は増え た • 実装漏れには気をつける必要があ る • 画面特有のものにするか、共通のも のにするかの判断が難しいものもあ る • 移行作業を行うには工数がかかる ◦ デグレチェック ◦ コンフリクト解消
まとめ • 開発フェーズによって適切な設計は異なる • 楽楽勤怠では品質(保守性)重視での設計見直しを行った • 画面コンポーネント中心の設計にすることで修正の影響範囲が分かり やすくなった • ビジネスロジックの抜き出し層を設けたおかげでテストも書きやすくなっ
た • 全て画面の持ち物にすることは不可能なので共通部分は消せない、使 い分けはしていく必要がある
ありがとうございました!