Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
connect-goとsqlboilerで構築するクリーンアーキテクチャ
Search
hirocy
September 26, 2024
Programming
0
1.6k
connect-goとsqlboilerで構築するクリーンアーキテクチャ
「PIXIV DEV MEETUP 2024」LT発表資料
https://conference.pixiv.co.jp/2024/dev-meetup
hirocy
September 26, 2024
Tweet
Share
Other Decks in Programming
See All in Programming
251126 TestState APIってなんだっけ?Step Functionsテストどう変わる?
east_takumi
0
300
関数実行の裏側では何が起きているのか?
minop1205
1
580
Rediscover the Console - SymfonyCon Amsterdam 2025
chalasr
2
140
How Software Deployment tools have changed in the past 20 years
geshan
0
28k
手が足りない!兼業データエンジニアに必要だったアーキテクチャと立ち回り
zinkosuke
0
380
AI時代もSEOを頑張っている話
shirahama_x
0
230
レイトレZ世代に捧ぐ、今からレイトレを始めるための小径
ichi_raven
0
490
sbt 2
xuwei_k
0
190
TypeScript 5.9 で使えるようになった import defer でパフォーマンス最適化を実現する
bicstone
1
1k
React Native New Architecture 移行実践報告
taminif
1
130
【CA.ai #3】ワークフローから見直すAIエージェント — 必要な場面と“選ばない”判断
satoaoaka
0
210
[SF Ruby Conf 2025] Rails X
palkan
0
440
Featured
See All Featured
Leading Effective Engineering Teams in the AI Era
addyosmani
8
1.2k
Producing Creativity
orderedlist
PRO
348
40k
Optimising Largest Contentful Paint
csswizardry
37
3.5k
Into the Great Unknown - MozCon
thekraken
40
2.2k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.1k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.3k
Navigating Team Friction
lara
191
16k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Side Projects
sachag
455
43k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
253
22k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Transcript
connect-goとsqlboilerで構築する クリーンアーキテクチャ hirocy
{広告なんでも, pixiv Ads}チーム エンジニア 💼 23新卒/広告開発 ❤ Go言語/VTuber https://x.com/hir0cy hirocy
話すこと • クリーンアーキテクチャとは • connect-go・sqlboilerとは • 広告管理サーバーを設計した際の最終的なディレクトリ 構成の紹介 • connect-go・sqlboilerをクリーンアーキテクチャに取
り込む上での工夫
話さないこと • connect-goとsqlboilerの使い方 • 基本的なクリーンアーキテクチャの実装 Ask the Speakerで僕と握手!
クリーンアーキテクチャ とは?
クリーンアーキテクチャ • Robert C. Martinが2012年に提唱したアーキテクチャ • 4層のレイヤー構造 ◦ Enterprise Business
Rules(domain層) ◦ Application Business Rules(usecase層) ◦ Interface Adapters(interface層) ◦ Frameworks & Drivers(infrastructure層)
クリーンアーキテクチャ • Robert C. Martinが2012年に提唱したアーキテクチャ • 4層のレイヤー構造 ◦ Enterprise Business
Rules(domain層) ◦ Application Business Rules(usecase層) ◦ Interface Adapters(interface層) ◦ Frameworks & Drivers(infrastructure層)
connect-go・sqlboiler とは?
connect-goの特徴 • The Go implementation of Connect: Protobuf RPC that
works. • ConnectというプロトコルのGo実装 • Protobufで記述された通信の定義に基づいてGoのパッ ケージを生成
sqlboilerの特徴 • Generate a Go ORM tailored to your database
schema. • 実際のDBスキーマからGoのORM(Object-Relational Mapping)をパッケージとして生成
どちらもパッケージ生成
クリーンアーキテクチャ のどこに生成?
〜広告管理サーバーの場合〜 最終的なディレクトリ構成
最終的なディレクトリ構成 "esakik/clean-architecture-python" (https://github.com/esakik/clean-architecture-python) より引用
最終的なディレクトリ構成
なぜinterface層に生成? • 例えばconnectについて... ◦ interface層 ▪ 通信の中身を見るレイヤー ◦ infrastructure層 ▪
通信について記述するレイヤー →ハンドラーやDBのクエリをinterface層で記述したい
connect-go・sqlboiler を扱う上での工夫
sqlboilerを扱う上での工夫 • sqlboilerは独自の型とdomainとの変換が必要 ◦ converterを実装して対応 • sqlboilerの実行には*sql.DBが必要 ◦ infrastructure層で接続を張った*sql.DBを返すよう に実装
connect-goを扱う上での工夫 • 決められたHandlerの型 で実装する必要がある • interactorから presenterを呼ぶ流れと 相性が悪い "esakik/clean-architecture-python" (https://github.com/esakik/clean-architecture-python)
より引用
connect-goを扱う上での工夫 controllerから presenterを呼び出す
connect-goを扱う上での工夫 controllerから presenterを呼び出す
connect-goを扱う上での工夫 "クリーンアーキテクチャの Presenter が分かりにくいのは MVC 2 じゃないから" (https://qiita.com/os1ma/items/c02af5b7783b58165c8d) より引用
まとめ • connect-goとsqlboilerはinterface層に生成 • presenterをcontrollerから呼び出すように改変 • 都度リファクタリングをすることでより良いアーキテク チャにしている • Goの互助会ブースやAsk
the Speakerも是非!