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
910
Clean Architecture by TypeScript & NestJS
ryounasso
July 10, 2024
Tweet
Share
More Decks by ryounasso
See All by ryounasso
React inside basics: learn from “build own react"
ryounasso
0
130
抽象データ型について学んだ
ryounasso
0
240
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
2.9k
Fast API を用いた Web API の開発
ryounasso
0
530
テストゼロの個人開発プロジェクトにテストを導入した話
ryounasso
0
410
簡易 DI コンテナを作って DI コンテナを知る
ryounasso
1
1.2k
TypeScript_コンパイラの内側に片足を入れる
ryounasso
3
770
kintone新機能開発のお仕事
ryounasso
2
120
Other Decks in Programming
See All in Programming
実践!App Intents対応
yuukiw00w
1
290
Nuances on Kubernetes - RubyConf Taiwan 2025
envek
0
170
AI OCR API on Lambdaを Datadogで可視化してみた
nealle
0
100
Go製CLIツールをnpmで配布するには
syumai
2
1.2k
CLI ツールを Go ライブラリ として再実装する理由 / Why reimplement a CLI tool as a Go library
ktr_0731
3
1.1k
なぜ今、Terraformの本を書いたのか? - 著者陣に聞く!『Terraformではじめる実践IaC』登壇資料
fufuhu
4
630
UbieのAIパートナーを支えるコンテキストエンジニアリング実践
syucream
2
520
Dart 参戦!!静的型付き言語界の隠れた実力者
kno3a87
0
200
MCP連携で加速するAI駆動開発/mcp integration accelerates ai-driven-development
bpstudy
0
310
STUNMESH-go: Wireguard NAT穿隧工具的源起與介紹
tjjh89017
0
380
Claude Code と OpenAI o3 で メタデータ情報を作る
laket
0
130
Amazon Q CLI開発で学んだAIコーディングツールの使い方
licux
3
190
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3k
Docker and Python
trallard
45
3.5k
Done Done
chrislema
185
16k
Navigating Team Friction
lara
188
15k
How to Think Like a Performance Engineer
csswizardry
25
1.8k
Gamification - CAS2011
davidbonilla
81
5.4k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
36
2.5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Balancing Empowerment & Direction
lara
2
570
Art, The Web, and Tiny UX
lynnandtonic
301
21k
Bash Introduction
62gerente
614
210k
The Language of Interfaces
destraynor
160
25k
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