Skip to main content

Clean Architecture in Viax

Viax implements Clean Architecture as proposed by Robert C. Martin (Uncle Bob), separating code into distinct layers with well-defined responsibilities.

What is Clean Architecture?

Clean Architecture is a software design philosophy that enforces separation of concerns through layered architecture, making code:

Maintainable

Organized code that’s easy to understand and modify

Testable

Each layer can be tested independently

Scalable

Easy to add features without breaking existing code

Framework Independent

Business logic doesn’t depend on Flutter or any framework

The Dependency Rule

Critical Principle: Source code dependencies must point INWARD. Inner layers know nothing about outer layers.

Layer Architecture

Viax organizes each feature into three distinct layers:

Domain Layer (Core Business Logic)

Location: lib/src/features/{feature}/domain/
The domain layer contains pure business logic with ZERO external dependencies.

Components

Entities are business objects that encapsulate enterprise business rules.
Key Points:
  • Immutable objects (all fields final)
  • Business logic methods (completionPercentage, canSubmitForApproval)
  • No dependencies on UI or data layers
  • Pure Dart code
Benefits of Domain Layer:
  • ✅ 100% testable without mocks
  • ✅ Reusable across platforms (web, mobile, desktop)
  • ✅ Independent of frameworks
  • ✅ Pure business logic

Data Layer (Implementation)

Location: lib/src/features/{feature}/data/
The data layer implements repository contracts and handles all external data sources.

Components

Data Sources handle actual communication with external services.
Key Points:
  • Concrete implementations
  • HTTP calls, database queries, etc.
  • Throws technical exceptions
  • Returns raw data (Maps, Lists)
Benefits of Data Layer:
  • ✅ Swappable data sources (API → Local DB)
  • ✅ Centralized error handling
  • ✅ Easy to mock for testing
  • ✅ Isolates technical details

Presentation Layer (UI & State)

Location: lib/src/features/{feature}/presentation/
The presentation layer handles UI rendering and state management.

Components

Providers manage UI state and invoke use cases.
Key Points:
  • Extends ChangeNotifier (Provider pattern)
  • NO business logic (only state management)
  • Calls use cases
  • Converts failures to user messages

Data Flow Example

Let’s trace a complete flow: Loading driver profile
1

User Interaction

User taps “Ver Perfil” button in the app
2

Screen Triggers Load

3

Provider Invokes Use Case

4

Use Case Calls Repository

5

Repository Calls Data Source

6

Data Source Makes HTTP Call

7

Backend Processes Request

8

Response Flows Back

Dependency Injection

Viax uses a Service Locator pattern for dependency injection:
Usage:

Testing Benefits

Migration Path to Microservices

Clean Architecture makes migrating to microservices straightforward - only the data layer needs changes!
Current (Monolith):
Future (Microservices):
No other code changes needed! The domain and presentation layers remain unchanged.
Viax’s Clean Architecture implementation ensures maintainable, testable, and scalable code that’s ready for future growth.