Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
PythonでDDDをやってみた感想
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
PharmaX(旧YOJO Technologies)開発チーム
August 09, 2022
Technology
190
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PythonでDDDをやってみた感想
2022.05.31 LT会 竹内さん発表資料
PharmaX(旧YOJO Technologies)開発チーム
August 09, 2022
More Decks by PharmaX(旧YOJO Technologies)開発チーム
See All by PharmaX(旧YOJO Technologies)開発チーム
LLMアプリケーション評価駆動開発の歩き方
pharma_x_tech
1
420
LLMアプリケーションやAIエージェントの評価の基本
pharma_x_tech
1
400
「動くだけ」で終わらせない ― LLMアプリを継続的に改善・運用するための評価駆動開発
pharma_x_tech
2
46
LangSmithによるAIエージェントの継続的改善のためのオブザーバビリティの向上
pharma_x_tech
1
320
PdMによるLiveバイブコーディング〜プロトタイプ開発実践〜
pharma_x_tech
1
97
2025.10.28_CodexとClaude Codeの比較検討 社内座談会
pharma_x_tech
2
680
LLMのアウトプットの評価と改善 〜DSPyによるプロンプト最適化入門によせて〜
pharma_x_tech
6
1.3k
2025.09.02_AIコーディングを利用した開発自動化を目指しての座談会
pharma_x_tech
5
380
AIコーディングを前提にした開発プロセス再設計〜開発生産性向上に向けた試行錯誤〜
pharma_x_tech
4
470
Other Decks in Technology
See All in Technology
AIエージェントの権限管理 3: Agentic RAG の Fine grained access control 編
ren8k
0
120
C#コードの結合を可視化する Roslyn解析による設計改善と リファクタリング判断
dora56
0
150
目の前の楽しいが人生を変える - コミュニティの螺旋の歩き方と楽しむコツ / change your life
soudai
PRO
5
640
ユーザー価値を届け続けるためにウォンテッドリーが大切にしている文化
kotaminato
0
180
Reactの設計論
uhyo
24
14k
ソフトウェアDNAとクラウドエージェントのススメ
cloudace
0
110
LLMに渡さなかった仕事
nanaism
0
880
30座EKS, 180次升級淬煉的EKS Upgrade Skill 的歷程
eric8230
0
180
JSONataとAWS Step Functionsで目指すRuntimelessな世界
mu7889yoon
0
190
幾何アルゴリズムで なめらかなピン操作を / iOSDC Japan 2026 / smoothpin
kazumanagano
0
360
俺の仕事は AIに奪われないし、たぶんその BIも要らない
hikaruri
0
520
開発投資の期待値を上げるプロダクトロードマップづくり ~プロダクトエンジニアが越境して事業を伸ばす~
kekekenta
1
220
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
76k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
From π to Pie charts
rasagy
1
370
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
550
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
How STYLIGHT went responsive
nonsquared
100
6.3k
The SEO Collaboration Effect
kristinabergwall1
1
570
Transcript
Python でDDD をやってみた感想 1 Python でDDD をやってみた感想 バックエンドアーキテクチャ api ├─config
├─api │ ├─urls.py │ └─v1 │ ├─urls.py │ └─views │ └─post_view.py ├─post (Domain 毎にアプリケーションを作成) │ ├─__init__.py │ ├─admin.py │ ├─apps.py │ ├─commands.py │ ├─domain_services.py( 必要な場合に実装) │ ├─entities.py │ ├─exceptions.py │ ├─models.py │ ├─queries.py │ ├─repositories.py │ ├─schemas.py │ ├─tests.py │ └─use_cases.py ├─recommend │ ├─__init__.py │ ├─admin.py ・・・ (備考)Django でアプリケーションを作成する例 Django は疎結合・⾼凝集の設計思想で作成されています。 1 つのプロジェクトの中で複数のアプリケーションを作ることができ、また1 つのアプ リケーションを複数のプロジェクトを共有することができます。 ひと
Python でDDD をやってみた感想 2 python manage.py startapp post オニオンアーキテクチャ UserInterface/Presentation
エンドポイントを提供する層。⼀般的なコントローラークラス。 views.py ApplicationService/DomainService/DomainModel の呼び出し・組み⽴てを ⾏い、レスポンスを返す ⼊⼒値のバリデーションチェックを⾏う バリエーションチェックはmarshmallow で⾏う class PostAPIView(APIView): use_case = PostUseCase def post(self, request): try: schema = PostWriteSchema(request.data) post_entity = use_case.write(schema)
Python でDDD をやってみた感想 3 return JsonResponse(post_entity.to_json()) except ValidationError as e:
return JsonResponse({'error': f'{e.message}'}, status=404) except PostDoesNotExist: return JsonResponse({'error': f'Cannot find a post with this id({request_schem a.id}).'}, status=404) ApplicationService アプリケーション向けのデータ加⼯やDomainService/DomainModel の呼び出し を⾏う データの取得においてはquery を呼び出す user_cases.py(CQRS のCommand の部分) ドメインロジックの組み⽴てを⾏う。 class PostUseCase: # DI コンテナの注⼊ _repo = inject.attr(PostRepositoryImpl) @classmethod def write(cls, schema:) -> PostEntity: entity = PostEntity.from_schema(schema) self._repo.save(entity) @classmethod def update(cls, schema:) -> PostEntity: entity = PostEntity.from_schema(schema) self._repo.save(entity) queries.py (CQRS のQuery 部分) データを取得するだけのクラス(CQRS のQuery 部分) class PostQuery: @classmethod def find_by_id(cls, post_id: int) -> PostEntity: entity = self._repo.find_by_id(self, post_id) if entity is None: raise PostNotFoundError return entity @classmethod def get_all(cls, post_id: int) -> PostEntity:
Python でDDD をやってみた感想 4 entities = self._repo.get_all(self, post_id) return entities
DomainService (複雑な場合に使⽤。現状は使⽤していない) ドメインロジックの組み⽴てを⾏う。 ApplicationService やDomainModel でも実装が難しい複雑なケースで使⽤する Infrastructure DB や外部サービス(File Access, Access, ORM, etc...) にアクセスして永続化を 担当する層。 repositories.py インフラ層 ドメインオブジェクトの永続化層の実装を伴うクラス Entity クラスを返す class PostRepository: @classmethod def save(cls, post: PostEntity) -> Optional[Post]: post_model = Post.objects.update_or_create( id=post.id, defalults={ "title": post.title, "content": post.content } ) return PostEntity.from_model(post_model) @classmethod def find_by_id(cls, post_id: int) -> Optional[PostDto]: post_model = Post.objects.get(id=post_id) return PostEntity.from_model(post_model) @classmethod def get_all(cls, post_id: int) -> Optional[PostDto]: post_entities = [] for post_model in Post.objects.all: entity = PostEntity.from_model(post_model)
Python でDDD をやってみた感想 5 post_entities.append(entity) return post_entities Tests テストコードモジュール。 UI
の変更に伴い、テスト項⽬も変動する不安定な層。 実際にやったこと 既存アプリケーションのリプレイス 社内専⽤アプリはこんな感じ 在庫管理 CRM ヤフオク操作 ⾃動出品とか落札情報⾃動取得とか 既存の構成、問題点 現在はDjango のMTV (MVC )で作成 アーキテクチャもコーディング規約も存在せず、クラスの責任がバラバラ 書いた本⼈しかわからないコードだらけ え、こんなところでクエリ実⾏されてるの?ってのがザラにある ドメインモデリングも試してみた やってみて 良かったこと ⼩さく試す コード規約っぽいのが初めてできて、開発者同⼠で認識が揃った
Python でDDD をやってみた感想 6 最初は疑問に思われていたため、まず⼩さい機能でペアプロしたりコード レビューをしてもらったりして理解を深めてもらった その後実際に少し実装してもらうことで良さを実感してもらうことができ た バリューオブジェクトや集約はあえて最初は導⼊しなかった 簡単なところから浸透させ、徐々にレベルをあげていく⽅針
Django が思ったよりもDDD やりやすい設計思想になっていて⾯⽩かった このライブラリとかまさにそう payment アプリだけオーバーライドして実装、みたいなのが可能 https://github.com/django-oscar/django-oscar ドメインエキスパートにかなり喜ばれた SUDO 図は⼤感謝祭り 今までシステムの中⾝や会話が出来ず、何をしているかがわかってい なかった ⼀緒に議論したり、図で可視化することで共通認識が取れるように システムの動きが分かりやすくなったり、開発者と議論しやすくなり そうとのこと アーキテクチャの理解⼒が上がった 他社の事例、PyCon などの動画を⾒てDDD を徹底的にアーキテクチャの理 解が深まった 今後のやりたいこと バリューオブジェクトや集約など、DDD のテクニックを実践してみたい PyCon などで登壇したい Django の便利ライブラリ
Python でDDD をやってみた感想 7 django restframework api サーバーを⽴てるのに必要 dataclass デコレーター
Entity を定義するのに便利、上書き禁⽌に出来る