It's 2 AM. Your mobile app just crashed because someone changed a database field. Your frontend is showing the wrong data. Your Python backend is throwing errors. And nobody knows which piece broke first.
Sound familiar?
Now imagine a different world: You change your database schema, press save, and watch as your entire appโfrom mobile screens to backend APIsโupdates itself automatically. No hunting for broken code. No surprise bugs. Just smooth, predictable progress.
That's HexDDD.
๐ Think of it as a master blueprint for building homes: where every room (feature) has clear walls (boundaries), every pipe and wire (data flow) connects exactly right, and you can renovate the kitchen without tearing down the bedroom.
You're building a modern app. Maybe it's a customer portal, an admin dashboard, or a mobile experience. You hire great developers, choose the latest frameworks, and start coding.
Then reality hits:
-
๐๏ธ The House of Cards: Frontend says the user has a "firstName", backend expects "first_name", database stores "user_first_name". One typo, three different names, infinite bugs.
-
๐ Spaghetti Junction: Your payment logic is tangled with your UI components. Changing one thing breaks three others. Testing becomes a nightmare.
-
๐ฒ Team Chaos: Sarah writes clean code. Tom shortcuts everything. Maria uses a different pattern. Six months later, nobody understands the codebase.
-
โฐ Time Drain: You spend 70% of your week fixing bugs and untangling messes instead of building features customers actually want.
The hidden cost? Talented developers burning out. Launches delayed. Opportunities missed. All because the foundation was shaky from day one.
HexDDD is like hiring an expert architect who ensures every part of your app fits together perfectlyโautomatically.
Here's how it works, step by step:
Instead of typing the same thing in ten different files, you define your data structure once (in your database). HexDDD instantly generates perfectly matching code for:
- Your React/Next.js/Remix frontend
- Your Python backend
- Your mobile app
- All validation rules
Like a blueprint: draw once, build everywhere.
Remember that master blueprint analogy? HexDDD organizes your code into distinct "rooms":
-
๐ The Vault (Domain): Your pure business logic. "A user can't have a negative balance." No clutter, no dependenciesโjust the rules that never change.
-
โ๏ธ The Control Center (Application): Your workflows. "When someone updates their profile, save it and send a notification." Coordinates everything but doesn't do the heavy lifting itself.
-
๐ The Utility Room (Infrastructure): All the messy real-world stuffโdatabases, email services, payment processors. Swap them out without touching your business logic.
-
๐จ The Showroom (Interface): Your beautiful UI that customers see. Mobile apps, web dashboards, admin panelsโall talking to the same solid foundation.
The magic? These rooms have "doors" (we call them ports and adapters) that only open in one direction. You literally cannot accidentally tangle your UI with your database code. The system won't let you.
Change your database? HexDDD updates your types everywhere. Add a new field? Your forms, validators, and API contracts update automatically. Refactor your backend? Your frontend knows immediately if something brokeโwhile you're still coding, not when customers complain.
It's like having a brilliant assistant who keeps all your documents in sync, catches every inconsistency, and never sleeps.
Because your code has clear walls, testing becomes obvious:
- Test your business rules (the Vault) with zero setupโno databases, no APIs, just pure logic
- Test your workflows (Control Center) with simple mock doors
- Test everything together only when you need to
Result? Tests that run in seconds, not minutes. Bugs caught before your first coffee, not after your customer's complaint.
Imagine starting your workday and:
๏ฟฝ Morning Coffee: You update a user field in your database schema. Before you take your first sip, HexDDD has already updated 47 files across your frontend, backend, and mobile app. All tests pass. Nothing broke.
โ๏ธ Midday Flow: A new developer joins your team. Instead of spending weeks deciphering "the way we do things," they run one command and generate a perfectly structured featureโmatching exactly how the rest of the codebase works.
๐ Evening Calm: You deploy a major refactor with confidence. Not because you tested every edge case manually, but because the architecture prevents the bugs from existing in the first place.
The feeling? Like driving a car with perfect alignmentโeffortless, smooth, and you arrive faster than you expected.
While you experience the magic above, here's what HexDDD does behind the scenes:
- Your database schema becomes the single source of reality
- TypeScript types (with runtime validation) auto-generate for your React apps
- Python types (with API contracts) auto-generate for your FastAPI backend
- Mobile, web, admin panelโall speak the same language automatically
Think of a Michelin-star restaurant kitchenโevery station has a specific role:
- ๐ The Prep Station (Domain): Pure ingredients, no cooking yet. Your business rules in their simplest form.
- โ๏ธ The Line Cooks (Application): Take orders, coordinate prep station and expeditors. Your use cases and workflows.
- ๐ The Expeditors (Infrastructure): Connect to suppliers, manage inventory, handle equipment. Your databases, APIs, and external services.
- ๐จ The Dining Room (Interface): Beautiful presentation for guests. Your user-facing apps.
Each station has clear hand-off points (ports). You can change suppliers (databases) or update presentation (UI) without touching the recipes (business logic).
- Automated boundaries: The system physically prevents you from breaking architectural rules
- Instant feedback: Type errors show up while you're typing, not when customers click
- Test at the speed of thought: Most tests run without databases or APIsโjust pure logic
Here's how your app organizes itselfโlike a well-designed office building where every department knows its role:
๏ฟฝ Your HexDDD Project
โ
โโโ ๏ฟฝ apps/ โ The Customer-Facing Floor
โ โโโ ๐ backend-api/ โ Your API reception desk (FastAPI)
โ โโโ โ๏ธ web-next/ โ Modern web experience (Next.js)
โ โโโ ๐ต web-remix/ โ Progressive web app (Remix)
โ โโโ ๐ฑ web-expo/ โ Mobile experience (React Native)
โ
โโโ ๏ฟฝ๏ธ libs/ โ The Departments & Shared Resources
โ โโโ ๐ง ddd/ โ Your toolkit (the HexDDD plugin itself)
โ โโโ ๐ shared/ โ Company-wide resources
โ โ โโโ ๐ database-types/ โ Universal data definitions (TypeScript)
โ โ โโโ ๐ api-types/ โ Contract agreements (API specs)
โ โ โโโ ๏ฟฝ web/ โ Shared web utilities
โ โ โโโ ๐ type_system/ โ Python data definitions
โ โ
โ โโโ ๐๏ธ <your-domain>/ โ Feature Departments (e.g., "user-management")
โ โโโ ๐ domain/ โ The Strategy Room (business rules)
โ โโโ โ๏ธ application/ โ The Operations Center (workflows)
โ โโโ ๐ infrastructure/ โ The Utilities (databases, APIs, integrations)
โ
โโโ ๐ ๏ธ tools/ โ The Maintenance Crew
โ โโโ ๐ type-generator/ โ Keeps everyone speaking the same language
โ โโโ ๐๏ธ supabase/ โ Local development playground
โ
โโโ ๐งช tests/ โ Quality Assurance Department
โโโ ๐ e2e/ โ Full customer journey tests
โโโ ๐ cross/ โ Translation verification tests
โโโ ๏ฟฝ fixtures/ โ Test scenarios & examples
The beauty of this layout?
- New team members instantly know where to find things
- Features live in isolated departmentsโchange one without affecting others
- Shared resources eliminate duplicationโwrite once, use everywhere
- Tests mirror your structureโobvious what to test and where
It's like a city with clear districts and well-marked streets. No one gets lost.
Let's get you building. No PhD required.
# Get HexDDD on your machine
git clone https://github.com/GodSpeedAI/HexDDD.git
cd HexDDD
# Install everything
npm installPick your favorite flavor and watch it run:
nx serve backend-api
# ๐ Visit: http://localhost:8000
# ๐ Interactive API Docs: http://localhost:8000/docsnx run web-next:dev
# ๐ Visit: http://localhost:4200nx run web-remix:dev
# ๐ Visit: http://localhost:4201nx run web-expo:start
# ๐ฑ Scan the QR code with Expo Go on your phone๐ก Notice something cool? All these apps share the exact same types and validation. Change one thing, and everything stays in sync.
Want to see the full type generation magic? Spin up a local database:
# Set up your local environment
cp example.env .env.supabase.local
# Start your local Supabase stack
nx run supabase-devstack:start
# ๐ Supabase Studio: http://localhost:54323
# When you're done experimenting
nx run supabase-devstack:stopWhat just happened? You now have a complete PostgreSQL database, authentication, and API running locally. Change the schema, and watch HexDDD update your entire codebase automatically.
Ready to create something? Let's build a complete feature in seconds, not hours.
Think of a domain as a complete "department" in your appโlike User Management, Order Processing, or Notifications.
# Generate everything you need for user management
nx g @ddd-plugin/ddd:hex-domain user-managementWhat you just created:
- โจ
libs/user-management/domain/โ Your business rules (pure logic, no tech) - โจ
libs/user-management/application/โ Your workflows and contracts - โจ
libs/user-management/infrastructure/โ Database connections and APIs - โจ Proper boundaries that prevent architectural mistakes
Now let's give users a way to interact with it:
# Create a Next.js admin portal with all the connections
nx g @ddd-plugin/ddd:web-app admin-portal --framework=next
# Or a Remix customer portal that shares the same backend
nx g @ddd-plugin/ddd:web-app customer-portal --framework=remix
# Or a mobile app for on-the-go access
nx g @ddd-plugin/ddd:web-app mobile-app --framework=expoYour options:
--framework=nextโ Modern Next.js with App Router--framework=remixโ Progressive web app with Remix--framework=expoโ React Native mobile app--apiClient=trueโ Include shared, type-safe API client (default)--includeExamplePage=trueโ Get example routes to learn from (default)
The magic moment: Every frontend automatically understands your backend. The types flow through. The validation just works. You focus on the user experience, not plumbing.
As your app grows, add exactly what you need:
# Add an event notification system
nx g @ddd-plugin/ddd:port notification-service
# Add database transaction handling
nx g @ddd-plugin/ddd:uow user-management
# Add an event bus for decoupled features
nx g @ddd-plugin/ddd:event-bus user-managementโจ Pro move: All generators are idempotentโrun them multiple times safely. They'll only add what's missing, never break what exists.
Here's where HexDDD becomes your silent partnerโkeeping your entire stack harmonized without you lifting a finger.
# Generate TypeScript + Python types from your database schema
nx run type-generator:generate
# Verify everything matches perfectly across languages
nx run type-generator:verifyOur CI/CD watches your back:
- โ Schema change? โ Types regenerate automatically
- โ Type mismatch? โ Build fails before merge (catches bugs early)
- โ Updates needed? โ Pull request created with all changes
- โ Weekly check? โ Scheduled validation ensures nothing drifts
Triggers:
- You modify schema files in
supabase/ - You manually trigger from GitHub Actions
- Weekly scheduled verification (every Sunday at 2 AM)
Result: Your TypeScript, Python, and database speak the same language, always. No silent drift. No surprise runtime errors.
Want to peek behind the curtain? Here's what makes HexDDD tickโexplained like you're explaining it to a bright 12-year-old.
Imagine building with LEGO blocks. Each block (layer) only connects in specific ways:
// โ
Pure business logicโno tech dependencies, no framework imports
export class User {
constructor(
private readonly id: UserId,
private readonly email: Email,
private readonly profile: UserProfile
) {}
updateProfile(newProfile: UserProfile): UserProfileUpdated {
// Just the business rulesโnothing else
return new UserProfileUpdated(this.id, newProfile);
}
}Why this matters: Your core business rules never change when you swap databases or frameworks. They're timeless.
// โ
Coordinates domain logic with external services
export class UpdateUserProfileUseCase {
constructor(
private readonly userRepository: UserRepository, // A contract, not the real thing
private readonly eventBus: EventBus // Another contract
) {}
async execute(request: UpdateProfileRequest): Promise<void> {
const user = await this.userRepository.findById(request.userId);
const event = user.updateProfile(request.profile);
await this.userRepository.save(user);
await this.eventBus.publish(event);
}
}Why this matters: This layer doesn't care how users are saved or where events go. It just knows what should happen.
# โ
Actual implementation with real databases and APIs
class SupabaseUserRepository(UserRepository):
async def find_by_id(self, user_id: UserId) -> User:
# Real database queries here
pass
async def save(self, user: User) -> None:
# Real persistence here
passWhy this matters: Swap Supabase for MongoDB tomorrow? Just change this file. The rest of your app doesn't even notice.
Here's how one schema change ripples perfectly through everything:
1. ๐ You update: Supabase Schema (database)
โ
2. ๐ HexDDD generates: TypeScript types (with runtime validation)
โ
3. ๐ HexDDD generates: Python types (with API contracts)
โ
4. โ๏ธ React apps get: Auto-updated interfaces and forms
โ
5. ๐ FastAPI gets: Auto-updated request/response models
โ
6. โ
Tests verify: Everything still works together
Benefits you feel:
- ๐ก๏ธ Errors caught while coding, not when customers complain
- ๐ Schema changes propagate everywhere, automatically
- ๐งช Mock implementations match real ones, always
- ๐ New features don't break old code, by design
Traditional testing feels like untangling Christmas lights. HexDDD makes it feel like clicking LEGO blocks together.
# Test everything at once
nx run-many --target=test --all
# Check for architectural violations (boundaries, imports)
nx run-many --target=lint --all
# Verify Python types are bulletproof
npm run type-check:py
# Full end-to-end customer journey
nx run ddd-e2e:e2e- โ Pure unit testsโno databases, no APIs, no setup
- โ Test business rules in isolation
- โ Run in milliseconds, not minutes
- โ Use case testing with simple mock "doors" (ports)
- โ In-memory implementationsโfast and reliable
- โ Verify workflows without real infrastructure
- โ Real adapter tests with actual databases
- โ Contract verificationโdoes your adapter match its contract?
- โ Database migration validation
- โ Full stack validation from button click to database
- โ API contract verification across languages
- โ Type safety confirmation between frontend and backend
Boundary Enforcement (Your Architectural Guardian):
{
"rules": {
"@nx/enforce-module-boundaries": [
"error",
{
"depConstraints": [
{
"sourceTag": "type:domain",
"onlyDependOnLibsWithTags": ["type:domain"]
},
{
"sourceTag": "type:application",
"onlyDependOnLibsWithTags": ["type:domain", "type:application"]
}
]
}
]
}
}Translation: Your domain code cannot accidentally import database stuff. The linter won't let it compile. Mistakes become impossible.
CI/CD Verification:
- ๐ค Every pull request validates architectural boundaries
- ๐ Type drift detection catches schema mismatches
- ๐ Test coverage reporting shows what's protected
- ๐จ Breaking change detection prevents surprise bugs
| Technology | Version | Purpose |
|---|---|---|
| Next.js | 14+ (App Router) | ๐ Full-stack React framework |
| Remix | 2.15+ | ๐ต Progressive web apps |
| Expo | 54+ | ๐ฑ React Native mobile development |
| TypeScript | 5.0+ (Strict) | ๐ Type-safe development |
| Zod | 3.23+ | โ Runtime type validation |
| React | 19.0 | โ๏ธ Component library |
| Technology | Version | Purpose |
|---|---|---|
| FastAPI | Latest | ๐ High-performance async API |
| Python | 3.11+ | ๐ Backend development |
| Pydantic | 2.x | ๐ Data validation & serialization |
| SQLAlchemy | 2.x | ๐๏ธ Async ORM |
| mypy | Latest | ๐ Static type checking |
| pytest | Latest | ๐งช Testing framework |
| Technology | Version | Purpose |
|---|---|---|
| Nx | 21.5+ | ๐ง Monorepo tooling |
| Supabase | Latest | ๐๏ธ PostgreSQL + Auth + API |
| Docker | Latest | ๐ฆ Containerization |
| GitHub Actions | - | ๐ค CI/CD pipelines |
| ESLint | Latest | ๐ Code quality enforcement |
HexDDD is better because of contributors like you. Here's how to get involved:
# Update your local dev branch
git checkout dev
git pull origin dev
# Create your feature branch from dev
git checkout -b feat/your-awesome-feature# Test your changes locally
nx run-many --target=test --all
# Ensure code quality
nx run-many --target=lint --all
# Verify Python types
npm run type-check:py- README.md โ User-facing changes or new features
- AGENTS.md โ Architectural patterns or AI guidance updates
- ADRs (in
docs/) โ Significant architectural decisions - Generator schemas โ New generator options or behaviors
Test that your generator is idempotent (safe to run twice):
# First run - creates everything
nx g @ddd-plugin/ddd:web-app test-app --framework=next
# Second run - should show "no changes"
nx g @ddd-plugin/ddd:web-app test-app --framework=next- Target the
devbranch (notmain) - Provide clear context: what changed and why
- Include test evidence (screenshots, logs, test results)
- Document any breaking changes prominently
- ๐จ New Frameworks (Vite, SvelteKit, Astro)
- ๐ Additional Adapters (Redis, Kafka, GraphQL, gRPC)
- ๐ฑ Mobile Patterns (React Navigation, offline-first, native modules)
- ๐งช Testing Utilities (Test builders, factories, fixtures)
- ๐ Documentation (Tutorials, video guides, blog posts)
- ๐๏ธ Generator Enhancements (More options, better error messages, clearer output)
Your expertise mattersโwhether you're a designer, developer, or documentation wizard.
- ๐ AGENTS.md โ AI collaboration guidelines and architectural context
- ๐๏ธ ADR Documents โ Architectural decision records with rationale
- ๐ Product Requirements โ Feature specifications and roadmap
- ๐ง Technical Specifications โ Implementation deep dives
- ๐ Hexagonal Architecture โ Alistair Cockburn's original vision
- ๐๏ธ Domain-Driven Design โ Martin Fowler's distilled wisdom
- ๐ง Clean Architecture โ Robert Martin's timeless patterns
- โ๏ธ React Patterns โ Frontend architecture best practices
- ๐ง Nx Monorepo Guide โ Workspace orchestration
- โ๏ธ Next.js Documentation โ React framework mastery
- ๐ต Remix Framework โ Progressive web apps
- ๐ FastAPI Guide โ Modern Python APIs
HexDDD follows what we call "The Photoshop Rule" โ a simple way to understand how you can use HexDDD without getting lost in legal jargon:
๐ผ๏ธ Think of HexDDD like Photoshop. You can use Photoshop to design, paint, or build anything โ logos, posters, full digital worlds. You can sell your art, keep it private, or use it inside your company.
What you can't do is sell Photoshop itself or offer "Photoshop as a service."
It's the same with HexDDD:
- โ Use HexDDD freely inside your organization โ build applications, generate architecture, support your engineering workflows
- โ Use it to create applications (web apps, mobile apps, APIs, microservices) and use or sell those applications however you like
- โ Don't resell HexDDD itself โ you can't package it up and offer it as a hosted platform or SaaS to third parties without a commercial license
- โ Don't strip out HexDDD's core to make a competing scaffolding service
HexDDD is released under a dual license:
- ๐งฉ MPL-2.0 (Open Source) โ for personal, educational, and internal company use
- ๐ผ Commercial License โ required if you want to embed, resell, or offer HexDDD as a hosted service
See LICENSE for complete legal details.
This license balances openness with protectionโuse it freely, improve it collaboratively, share it widely.
This project wouldn't exist without:
- Nx โ The monorepo platform that makes this possible
- nx-ddd-plugin โ Original inspiration for DDD patterns in Nx
- @nxlv/python โ Python workspace integration that bridges ecosystems
The best apps aren't just codedโthey're architected.
HexDDD gives you the blueprint, the tools, and the guardrails to build apps that:
โจ Scale effortlessly as your team grows ๐ก๏ธ Stay maintainable as requirements evolve ๐ Ship faster because the architecture works with you, not against you
โญ Star this repo โข ๐ Report issues โข ๐ฌ Join discussions
Built with โค๏ธ by developers who've felt the pain of bad architectureโ and decided to do something about it.