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
1.1k
0
Share
Clean Architecture by TypeScript & NestJS
ryounasso
July 10, 2024
More Decks by ryounasso
See All by ryounasso
明日から始めるリファクタリング
ryounasso
0
230
駆け足で Google から学ぶテスト設計の指針
ryounasso
0
200
React inside basics: learn from “build own react"
ryounasso
0
210
抽象データ型について学んだ
ryounasso
0
410
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
4k
Fast API を用いた Web API の開発
ryounasso
1
620
テストゼロの個人開発プロジェクトにテストを導入した話
ryounasso
0
480
簡易 DI コンテナを作って DI コンテナを知る
ryounasso
1
1.4k
TypeScript_コンパイラの内側に片足を入れる
ryounasso
3
940
Other Decks in Programming
See All in Programming
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
150
密結合なバックエンドから TypeScript のコードを生成する
kemuridama
1
360
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
310
ビジネスモデルから紐解く、AI+型駆動開発
hirokiomote
2
2.8k
These Five Tricks Can Make Your Apps Greener, Cheaper, & Nicer
hollycummins
0
210
分析エージェント精度向上における データアナリストの役割
oura_shoya
0
120
New "Type" system on PicoRuby
pocke
1
210
~ 秘伝のタレ化した『神スプシ』と戦う ~ 関数型パラダイムで壊れない仕組みへ
h0r15h0
1
130
OSもどきOS
arkw
0
180
AI時代になぜ書くのか
mutsumix
0
460
JavaDoc 再入門
nagise
0
130
横断組織出身のQAEがインプロセスQAEでつまずいたこと・活かせたこと
ty89
0
370
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.7k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
270
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
Faster Mobile Websites
deanohume
310
31k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
1.5k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
190
WENDY [Excerpt]
tessaabrams
10
37k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.6k
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