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
PythonでDDDをやってみた感想
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
PharmaX(旧YOJO Technologies)開発チーム
August 09, 2022
Technology
180
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)開発チーム
PdMによるLiveバイブコーディング〜プロトタイプ開発実践〜
pharma_x_tech
1
85
2025.10.28_CodexとClaude Codeの比較検討 社内座談会
pharma_x_tech
2
640
LLMのアウトプットの評価と改善 〜DSPyによるプロンプト最適化入門によせて〜
pharma_x_tech
6
1.2k
2025.09.02_AIコーディングを利用した開発自動化を目指しての座談会
pharma_x_tech
5
360
AIコーディングを前提にした開発プロセス再設計〜開発生産性向上に向けた試行錯誤〜
pharma_x_tech
4
450
AIエージェントの評価・改善サイクル
pharma_x_tech
2
640
MCP & Computer Useをフル活用した社内効率化事例〜現在地と将来の展望
pharma_x_tech
1
470
AIエージェントの継続的改善のためオブザーバビリティ
pharma_x_tech
7
2.7k
Roo CodeとClaude Code比較してみた
pharma_x_tech
5
6.4k
Other Decks in Technology
See All in Technology
人とエージェントが高め合う協業設計
kintotechdev
0
800
アップデートで何が変わった?デモで学んで使いこなすIBM Bob2.0
muehara
0
240
壊して学ぶAWS CDK: そのcdk deployで消えるもの、残るもの
k_adachi_01
1
490
そのドキュメント、自動化しませんか?
yuksew
1
420
AI、CDK と協働する Full TypeScript アプリケーション開発 / Full TypeScript Application with AI and CDK
geekplus_tech
2
490
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
15
110k
Vポイント分析基盤におけるデータモデリング20年史
taromatsui_cccmkhd
4
750
AI時代の開発生産性を捉え直す — 経営と現場をつなぐ「開発組織のオブザーバビリティ」— / AI Dev Ex Conference 2026
tkyowa
1
1.4k
伝票作成AIエージェントを支える、LLMOpsとインフラの選択肢 / AICon2026_takeda
rakus_dev
0
270
【公開用】AI_Dev_Ex2026_AI_登壇資料
matsuritechnologies
PRO
2
520
第67回コンピュータビジョン勉強会CVPR2026読会前編
tsukamotokenji
0
170
[Droidcon Orlando '26] The Android Lens: Applying Mobile Forensics to AI Performance
amanda_hinchman
1
110
Featured
See All Featured
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
30 Presentation Tips
portentint
PRO
1
350
Raft: Consensus for Rubyists
vanstee
141
7.6k
Designing Experiences People Love
moore
143
24k
Marketing to machines
jonoalderson
1
5.6k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
310
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
760
My Coaching Mixtape
mlcsv
0
170
HDC tutorial
michielstock
2
750
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
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 を定義するのに便利、上書き禁⽌に出来る