Clean Arch Management — Inventory management with DDD and Clean Architecture.
A simple inventory ecosystem designed to showcase Clean Architecture, Domain-Driven Design (DDD), and Type-Safe development with Next.js 16. The application manages coffee products, stores, and stock levels while keeping the business rules fully decoupled from the framework and the database.
This project started as a deep dive into decoupled software design. The goal was to build a scalable React application where the business logic (Core) remains agnostic of the framework (Next.js) or database (Prisma/Postgres). It serves as a laboratory for implementing DDD principles, boundary separation, and Type-Safe development.
- Clean Architecture: Strict separation of concerns between
core,infra,app, andlib. - Domain-Driven Design (DDD): Business rules modeled through Entities, Aggregates, Value Objects, and Use Cases.
- Ports & Adapters:
core/portsdefines contracts;infraprovides Prisma/service implementations via factories. - Type-Safe end-to-end: TypeScript strict mode, Zod schemas, and typed Server Actions across the boundary.
- Immutability & explicit state: Predictable data flow, no side effects leaking into domain rules.
- Next.js 16 — React 19, Turbopack, App Router
- Prisma Postgres — Type-safe database management
- Next-Auth v5 — Secure server-side authentication
- Shadcn UI — Radix UI & Tailwind CSS 4
- React Hook Form — Validated with Zod
- Jest & React Testing Library — Unit tests (Vitest also wired for Storybook)
- next-intl — Dynamic translations (EN / PT)
- Storybook — Component isolation & docs
- pnpm — Package manager
src/
├── app/ # Next.js App Router (UI / framework layer)
│ ├── actions/ # Type-safe Server Actions
│ └── api/ # Route handlers
├── core/ # THE BRAIN — zero framework dependencies
│ ├── domain/ # Entities, Aggregates (DDD)
│ ├── ports/ # Interfaces / Contracts
│ ├── use-cases/ # Pure business logic
│ └── utils/ # Domain-level helpers
├── infra/ # Implementation details
│ ├── database/ # Prisma client & adapters
│ ├── factories/ # Wires use cases to concrete repos
│ └── services/ # External services
├── components/ # React components (Shadcn-based)
├── lib/ # Framework-specific utils (Zod, Tailwind, helpers)
├── i18n/ # next-intl config
├── messages/ # Translation files (en.json, pt.json)
└── test/ # Testing setup & mocks
core/— The heart. Agnostic to any database or UI framework. TypeScript at its purest form.infra/— Implementation details. Prisma, external services, and factories are mapped here.lib/— Cross-cutting concerns like Shadcn UI config, Zod schemas, and shared utilities.
A robust automation workflow using GitHub Actions to ensure code stability and immutable deployments:
- Setup & Cache — Initializes environment and caches pnpm store for ultra-fast builds.
- Quality Assurance — Runs ESLint and Prettier check. Any code style violation breaks the build.
- Automated Testing — Executes Jest suite. High coverage ensures DDD business rules remain intact.
- Production Build — Validates Prisma schemas and Next.js compilation for a type-safe artifact.
- Vercel Deployment — Pre-built strategy: what passes in CI is exactly what goes to production.
- Node.js (v20 or higher)
- pnpm (
npm install -g pnpm) - Docker (for the local Postgres instance via
docker-compose.yml)
- Clone the repository:
git clone https://github.com/mateuscdomingos/nextjs-clean-architecture-ddd.git cd nextjs-clean-architecture-ddd - Install dependencies:
pnpm install
- Start the database:
docker compose up -d
- Apply Prisma migrations:
pnpm prisma migrate dev
- Run the development server:
pnpm dev
| Script | Description |
|---|---|
pnpm dev |
Start Next.js in development mode |
pnpm build |
Build the production bundle |
pnpm start |
Start the production server |
pnpm test |
Run Jest unit tests (UTC timezone) |
pnpm test:watch |
Run Jest in watch mode |
pnpm lint |
Run ESLint |
pnpm format |
Format files with Prettier |
pnpm format:check |
Check formatting without writing |
pnpm storybook |
Start Storybook on port 6006 |
pnpm build-storybook |
Build the static Storybook |
Translations live in src/messages/ and are consumed through next-intl. Currently supported:
- 🇺🇸 English (
en.json) - 🇧🇷 Portuguese (
pt.json)
This project follows the Conventional Commits specification for a clear and organized commit history. Examples:
feat: add budget validation logic to Order entityfix: correct stock deduction calculationtest: add unit tests for order approval use casedocs: update readme with architectural patternschore: configure github actions pipeline
I am a Software Engineer focused on high-performance web applications and scalable architectures. This project represents my commitment to clean code and continuous learning.