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
930
Clean Architecture by TypeScript & NestJS
ryounasso
July 10, 2024
Tweet
Share
More Decks by ryounasso
See All by ryounasso
駆け足で Google から学ぶテスト設計の指針
ryounasso
0
95
React inside basics: learn from “build own react"
ryounasso
0
130
抽象データ型について学んだ
ryounasso
0
250
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
3k
Fast API を用いた Web API の開発
ryounasso
0
540
テストゼロの個人開発プロジェクトにテストを導入した話
ryounasso
0
410
簡易 DI コンテナを作って DI コンテナを知る
ryounasso
1
1.2k
TypeScript_コンパイラの内側に片足を入れる
ryounasso
3
780
kintone新機能開発のお仕事
ryounasso
2
120
Other Decks in Programming
See All in Programming
実用的なGOCACHEPROG実装をするために / golang.tokyo #40
mazrean
1
260
テストコードはもう書かない:JetBrains AI Assistantに委ねる非同期処理のテスト自動設計・生成
makun
0
250
私の後悔をAWS DMSで解決した話
hiramax
4
210
知っているようで知らない"rails new"の世界 / The World of "rails new" You Think You Know but Don't
luccafort
PRO
1
110
為你自己學 Python - 冷知識篇
eddie
1
350
JSONataを使ってみよう Step Functionsが楽しくなる実践テクニック #devio2025
dafujii
1
520
Laravel Boost 超入門
fire_arlo
2
210
Putting The Genie in the Bottle - A Crash Course on running LLMs on Android
iurysza
0
140
250830 IaCの選定~AWS SAMのLambdaをECSに乗り換えたときの備忘録~
east_takumi
0
390
ファインディ株式会社におけるMCP活用とサービス開発
starfish719
0
310
Oracle Database Technology Night 92 Database Connection control FAN-AC
oracle4engineer
PRO
1
440
2025 年のコーディングエージェントの現在地とエンジニアの仕事の変化について
azukiazusa1
23
12k
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
61k
4 Signs Your Business is Dying
shpigford
184
22k
Code Reviewing Like a Champion
maltzj
525
40k
The Art of Programming - Codeland 2020
erikaheidi
56
13k
Faster Mobile Websites
deanohume
309
31k
Building Better People: How to give real-time feedback that sticks.
wjessup
368
19k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
18
1.1k
The World Runs on Bad Software
bkeepers
PRO
70
11k
Embracing the Ebb and Flow
colly
87
4.8k
A designer walks into a library…
pauljervisheath
207
24k
Docker and Python
trallard
45
3.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