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
connect-goとsqlboilerで構築するクリーンアーキテクチャ
Search
hirocy
September 26, 2024
Programming
0
1.7k
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
Pythonではじめるオープンデータ分析〜書籍の紹介と書籍で紹介しきれなかった事例の紹介〜
welliving
3
630
AI 駆動開発ライフサイクル(AI-DLC):ソフトウェアエンジニアリングの再構築 / AI-DLC Introduction
kanamasa
11
4.2k
[AtCoder Conference 2025] LLMを使った業務AHCの上⼿な解き⽅
terryu16
6
840
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
460
AtCoder Conference 2025
shindannin
0
720
AI Agent Dojo #4: watsonx Orchestrate ADK体験
oniak3ibm
PRO
0
110
Patterns of Patterns
denyspoltorak
0
370
ゲームの物理 剛体編
fadis
0
380
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
220
Navigation 3: 적응형 UI를 위한 앱 탐색
fornewid
1
480
まだ間に合う!Claude Code元年をふりかえる
nogu66
5
900
愛される翻訳の秘訣
kishikawakatsumi
3
350
Featured
See All Featured
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
130
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
980
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
93
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
53
47k
Exploring anti-patterns in Rails
aemeredith
2
210
Designing Experiences People Love
moore
143
24k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
The Invisible Side of Design
smashingmag
302
51k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
320
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
2.8k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
520
Marketing to machines
jonoalderson
1
4.4k
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も是非!