Stop Mixing FastAPI with Business Logic: Fix It with Ports & Adapters
π§± Build software that lasts. Join the Software Design Mastery waiting list β https://arjan.codes/mastery. In this video, I refactor a FastAPI + SQLAlchemy example into a clean Ports & Adapters (Hexagonal Architecture) design. I separate domain logic from frameworks, introduce domain types and errors, define ports with Protocols, and implement adapters step by step. The result is pure, testable business logic thatβs easier to maintain and evolve. π₯ GitHub Repository: https://git.arjan.codes/2026/ports. π ArjanCodes Courses: https://www.arjancodes.com/courses. π¬ Join my Discord server: https://discord.arjan.codes. β¨οΈ Keyboard Iβm using: https://amzn.to/49YM97v. π Chapters: 0:00 Intro 1:23 Whatβs the Actual Problem? 3:11 Ports & Adapters in One Minute 4:25 The Demo Use Case (Keep It Tiny, but Real) 5:44 Step 1 β Create Domain Types (Stop Returning API-Shaped Dicts) 9:39 Step 2 β Introduce Domain Errors (No HTTP in the Domain) 12:54 Step 3 β Define the Port (What the Domain Needs) 14:39 St
Watch on ArjanCodes
Opens in a new tab




