> flutter-layer-based-clean-architecture
Standards for separation of concerns, layer dependency rules, and DDD in Flutter. Use when applying DDD or layer-based clean architecture in Flutter. (triggers: lib/domain/**, lib/infrastructure/**, lib/application/**, domain, infrastructure, application, presentation, layers, dto, mapper)
curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/flutter-layer-based-clean-architecture?format=md"Layer-Based Clean Architecture
Priority: P0 (CRITICAL)
Standardized separation of concerns and dependency flow using DDD principles.
Structure
lib/
├── domain/ # Pure Dart: entities (@freezed), failures, repository interfaces
├── infrastructure/ # Implementation: DTOs, data sources, mappers, repo impls
├── application/ # Orchestration: BLoCs / Cubits
└── presentation/ # UI: Screens, reusable components
Implementation Guidelines
- Dependency Flow:
Presentation -> Application -> Domain <- Infrastructure. Dependencies point inward. - Pure Domain: No Flutter (Material/Store) or Infrastructure (Dio/Hive) dependencies in
Domain. - Functional Error Handling: Repositories must return
Either<Failure, Success>. - Always Map: Infrastructure must map DTOs to Domain Entities; do not leak DTOs to UI.
- Immutability: Use
@freezedfor all entities and failures. - Logic Placement: No business logic in UI; widgets only display state and emit events.
- Inversion of Control: Use
get_itto inject repository implementations into BLoCs.
Anti-Patterns
- No DTOs in UI: Never import a
.g.dartor Data class directly in a Widget. - No Material in Domain: Do not import
package:flutter/material.dartin thedomainlayer. - No Shared Prefs in Repo: Do not use
shared_preferencesdirectly in a Repository; use a Data Source.
Reference & Examples
For full implementation templates and DTO-to-Domain mapping examples: See references/REFERENCE.md.
Related Topics
feature-based-clean-architecture | bloc-state-management | dependency-injection | error-handling
> related_skills --same-repo
> typescript-tooling
Development tools, linting, and build config for TypeScript. Use when configuring ESLint, Prettier, Jest, Vitest, tsconfig, or any TS build tooling. (triggers: tsconfig.json, .eslintrc.*, jest.config.*, package.json, eslint, prettier, jest, vitest, build, compile, lint)
> typescript-security
Secure coding practices for TypeScript. Use when validating input, handling auth tokens, sanitizing data, or managing secrets and sensitive configuration. (triggers: **/*.ts, **/*.tsx, validate, sanitize, xss, injection, auth, password, secret, token)
> typescript-language
Modern TypeScript standards for type safety and maintainability. Use when working with types, interfaces, generics, enums, unions, or tsconfig settings. (triggers: **/*.ts, **/*.tsx, tsconfig.json, type, interface, generic, enum, union, intersection, readonly, const, namespace)
> typescript-best-practices
Idiomatic TypeScript patterns for clean, maintainable code. Use when writing or refactoring TypeScript classes, functions, modules, or async logic. (triggers: **/*.ts, **/*.tsx, class, function, module, import, export, async, promise)