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
750
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.5k
Fast API を用いた Web API の開発
ryounasso
0
490
テストゼロの個人開発プロジェクトにテストを導入した話
ryounasso
0
390
簡易 DI コンテナを作って DI コンテナを知る
ryounasso
1
1.1k
TypeScript_コンパイラの内側に片足を入れる
ryounasso
3
730
kintone新機能開発のお仕事
ryounasso
2
110
Other Decks in Programming
See All in Programming
今話題のMCPサーバーをFastAPIでサッと作ってみた
yuukis
0
130
KawaiiLT 登壇資料 キャリアとモチベーション
hiiragi
0
160
KANNA Android の技術的課題と取り組み
watabee
1
500
個人開発の学生アプリが企業譲渡されるまで
akidon0000
2
1.2k
Browser and UI #2 HTML/ARIA
ken7253
2
180
カウシェで Four Keys の改善を試みた理由
ike002jp
1
140
Golangci-lint v2爆誕: 君たちはどうすべきか
logica0419
1
260
MySQL初心者が311個のカラムにNot NULL制約を追加していってALTER TABLEについて学んだ話
hatsu38
2
140
ニーリーQAのこれまでとこれから
nealle
2
810
生成AI時代のフルスタック開発
kenn
4
520
Designing Your Organization's Test Pyramid ( #scrumniigata )
teyamagu
PRO
5
1.4k
状態と共に暮らす:ステートフルへの挑戦
ypresto
3
1.2k
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2k
The Cost Of JavaScript in 2023
addyosmani
49
7.8k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
41
2.3k
Building an army of robots
kneath
305
45k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.7k
What's in a price? How to price your products and services
michaelherold
245
12k
Code Review Best Practice
trishagee
68
18k
Done Done
chrislema
184
16k
Site-Speed That Sticks
csswizardry
6
540
Gamification - CAS2011
davidbonilla
81
5.3k
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