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
Clean Architecture by TypeScript & NestJS
Search
ryounasso
July 10, 2024
Programming
0
640
Clean Architecture by TypeScript & NestJS
ryounasso
July 10, 2024
Tweet
Share
More Decks by ryounasso
See All by ryounasso
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
2.1k
Fast API を用いた Web API の開発
ryounasso
0
460
テストゼロの個人開発プロジェクトにテストを導入した話
ryounasso
0
370
簡易 DI コンテナを作って DI コンテナを知る
ryounasso
1
860
TypeScript_コンパイラの内側に片足を入れる
ryounasso
3
700
kintone新機能開発のお仕事
ryounasso
2
100
Other Decks in Programming
See All in Programming
未経験でSRE、はじめました! 組織を支える役割と軌跡
curekoshimizu
1
140
Rubyで始める関数型ドメインモデリング
shogo_tksk
0
140
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
150
ソフトウェアエンジニアの成長
masuda220
PRO
12
2.1k
PRレビューのお供にDanger
stoticdev
1
230
負債になりにくいCSSをデザイナとつくるには?
fsubal
10
2.6k
GoとPHPのインターフェイスの違い
shimabox
2
210
責務と認知負荷を整える! 抽象レベルを意識した関心の分離
yahiru
8
1.3k
自力でTTSモデルを作った話
zgock999
0
100
Rubyと自由とAIと
yotii23
6
1.6k
Bedrock Agentsレスポンス解析によるAgentのOps
licux
3
910
2025.2.14_Developers Summit 2025_登壇資料
0101unite
0
180
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Being A Developer After 40
akosma
89
590k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Rebuilding a faster, lazier Slack
samanthasiow
80
8.9k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
Raft: Consensus for Rubyists
vanstee
137
6.8k
Fireside Chat
paigeccino
34
3.2k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2.1k
The Language of Interfaces
destraynor
156
24k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
RailsConf 2023
tenderlove
29
1k
Practical Orchestrator
shlominoach
186
10k
Transcript
Clean Architecture by TypeScript & NestJS
クリーンアーキテクチャを学んで 実装してみた経験をお話します
Clean Architecture とは ビジネスロジックを中心におき、インタフェースや技術を外側に配置する設計アプローチ 依存の向きは常に内側を向き、ユースケースと周辺の関心事を分離する 持つ特性 • フレームワーク非依存 • テスト可能
• UI 非依存 • データベース非依存 • 外部エージェント非依存 Clean Architecture 達人に学ぶソフトウェアの構造と設計
4 つのレイヤー Enterprise Business Rules Entities と呼ばれる、ビジネスルールをカプセル化したものが存在するレイヤ− Application Business Rules
システムのユースケースがカプセル化・実装されているレイヤー Interface Adapters 円の内側に便利な形から、Web や DB などに便利な形に変換するレイヤー Frameworks & Drivers フレームワークやツールで構成されるレイヤー (必ずしも 4 つである必要はない ただし依存関係の向きだけは守る必要がある)
Web ベースのシステムに落とし込むと 依存の向きを見てみると、 全てが依存性のルールに従って、 内側に向いている Clean Architecture 達人に学ぶソフトウェアの構造と設計
実装 お題 : Todo アプリ 使用技術 : TypeScript, NestJS, Prisma
リポジトリ : https://github.com/ryounasso/todo-app-by-clean-architecture
Entity constructor / getter は省略
Usecase ( Service )
Interface ( Controller )
Interface ( Repository )
じゃあこの Todo アプリでできることは?
この Todo アプリでできること
実装振り返り
実装振り返り Presenter を実装していない
実装振り返り getTodoList の返り値 当初は、Todo Entity の内容全てを返す設計 ↓ ユースケースとして、 Todo の一覧をユーザーが見るときに、
全ての情報が欲しいケースがありそうか? → なさそう
実装振り返り getTodoList の返り値 ユーザーが欲しいフィールドを返す設計に変更
まとめ • 各レイヤーに意図があり、それらの間に境界を設けて、 分けて管理することで可動性の向上を実感 • ユースケースをしっかり考えることが重要 • DB や Framework
の置き換えのコストを減らせる • テストがしやすい
参考資料 • Clean Architecture 達人に学ぶソフトウェアの構造と設計 • The Clean Architecture https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architectur
e.html