The Industrial Factory: A Metaphor for Clean Architecture

The Industrial Factory: A Metaphor for Clean Architecture

Why Clean Architecture?

Before I learned about Clean Architecture, when working on large projects with a team, I naturally found myself separating the project into clear, manageable sections. I instinctively organized my code, even before fully understanding the principles behind Clean Architecture. This approach allowed me to avoid the chaos of tightly coupled codebases, and it made the project more scalable, maintainable, and easier to manage.

Traditional Development vs. Clean Architecture Factory

Without Clean Architecture: 

Imagine a chaotic workshop where everything is mixed together. Tools, materials, and products are scattered around with no clear organization. Workers step on each other’s toes, and finding anything requires searching through the entire mess.

With Clean Architecture (Factory Model):

Now, envision a sophisticated factory complex with specialized departments. Each department has clear responsibilities, standardized procedures, and efficient communication channels. Workers can focus on their specialized tasks without disrupting others.


Key Benefits of the Factory Approach

  • Organization: Traditional codebases resemble cluttered workshops where business logic, UI code, and data access are all intermingled. Our factory model establishes separate departments with clear boundaries and responsibilities.

  • Independence: Without Clean Architecture, components become tightly coupled like interdependent machinery that can’t be modified without breaking everything else. In our factory model, sub-factories operate independently, communicating through well-defined channels.

  • Testability: In a chaotic workshop, testing components in isolation is nearly impossible. With our departmentalized factory, each unit can be tested independently without requiring the entire factory to be operational.

  • Platform Flexibility: Traditional development binds code tightly to platform specifics. Our factory’s Domain Department operates with platform-agnostic blueprints, making it easier to build for both Android and iOS.

  • Adaptability: Rigid codebases make adaptation difficult. Our factory model allows for renovating individual departments without disrupting the entire operation, making it easier to respond to changing requirements.

  • Comprehension: New developers joining a traditional project must understand the entire system before making changes. With our factory blueprint, the standardized structure makes onboarding much easier.

  • Maintenance: In poorly structured systems, fixing one bug often creates several more. In our factory model, maintenance can be performed on isolated departments without side effects elsewhere.

  • Development Speed: Traditional approaches require understanding the entire system to make changes. Our factory allows teams to work on different sub-factories simultaneously, accelerating development.


Introduction

Understanding Clean Architecture in mobile development can be challenging, especially when working across Android and iOS platforms. This industrial factory metaphor creates a visual mental model that makes Clean Architecture concepts more intuitive and memorable, particularly for cross-platform development.

The Industrial Factory Overview

Factory Component

Architecture Component

Main Factory

Mobile Application

Operations HQ

Core Module (shared code)

Navigation Control

Navigation System

Road Network

Navigation Components

Navigation Trucks

Navigation tools (Deep Links, Routers, Coordinators, Navigation Components, Graphs)

Sub-Factories

Feature Modules (MVVM, MVP, MVI)

Clean Architecture Factory Metaphor

Level 1: The Factory Complex

Main Factory (Mobile Application)

The Main Factory represents the entire mobile application. It’s where everything comes together to build and ship the final product that users interact with. This central hub coordinates all operations across the factory complex.


Operations HQ (Core Module)

Adjacent to the Main Factory stands Operations HQ, housing essential resources used by all factories:

  • Utilities Department: Common tools (date formatters, loggers, etc.)

  • Shared Department: Adapter functions and utility workers

  • Base Department: Standardized templates (BaseViewModel, Result, ErrorModel)


Navigation Control Center

Prominently located at the front of the Main Factory, the Navigation Control Center:

  • Launches Navigation Trucks (screen transitions)

  • Knows all paths between factories

  • Manages route logic, graphs, and argument payloads


Different types of Navigation Trucks serve different purposes:

  • Deep Links Trucks: External entry routes

  • Router Trucks: Direct point-to-point navigation (Common in iOS)

  • Coordinator Trucks: Complex multi-step journeys (Used in both platforms)

  • Navigation Component Trucks: Standard route management (Android Jetpack)

  • Intent Trucks: Activity/Fragment navigation (Android-specific)

  • Graphs Trucks: Visual route mapping (Android Navigation Component)


Sub-Factories (Feature Modules)

Each Sub-Factory is responsible for a specific product line (authentication, payments, etc.). All follow the same standardized layout for consistency and efficiency.

Level 2: Inside Each Sub-Factory (Feature Module)

Every Sub-Factory in our industrial complex is divided into four departments that correspond to Clean Architecture layers:

1. Presentation Workshop

 presentation/

├── ui/ # Assembly Line (Activity/Fragment in Android, ViewController/SwiftUI View in iOS)
├── presenter/ # MVP: Workshop Managers (Presenter classes)
├── contract/ # MVP: Production Specifications (View-Presenter contracts)
├── viewmodel/ # MVVM & MVI: Production Controllers (ViewModels)
├── state/ # MVVM & MVI: Production Status Monitors (UI State & Events, Swift: enums, structs)
├── intent/ # MVI: Production Orders (User Intents, Swift: enum-based)
└── mapper/ # UI ↔ Domain Mappers (Assembly Adapters)

Purpose: Assembles and delivers the final product interface

  • Assembly Line (UI): Where components are visually assembled

    Android: Activities, Fragments

    iOS: ViewControllers, SwiftUI Views

  • Workshop Managers (Presenters): MVP pattern - coordinate between views and models

  • Production Specifications (Contracts): MVP pattern - define communication protocols

  • Production Controllers (ViewModels):

    MVVM pattern: State holders and business logic processors

    MVI pattern: Process intents and emit states

  • Production Status Monitors (State): Track current production status

    Android: State classes, StateFlow, LiveData

    iOS: Structs, enums with associated values

  • Production Orders (Intent): MVI pattern: User actions translated into clear intents

    Android: Sealed classes

    iOS: Enum-based representations

  • Assembly Adapters (Mappers): Convert between UI models and domain models


2. Domain Department

 domain/

├── model/ # Product Blueprints
├── repository/ # Material Requisition Contracts
└── usecase/ # Production Procedures

Purpose: The engineering center where core product designs and rules are defined

  • Product Blueprints (Models): The essential entities that define each product

  • Material Requisition Contracts (Repository Interfaces): Define how to obtain required resources

  • Production Procedures (Use Cases): Specific processes that execute core operations


3. Data Department

 data/

├── repository/ # Resource Management Centers
├── datasource/ # Resource Collection Facilities
│ ├── local/ # Warehouses (Room, CoreData)
│ └── remote/ # Supply Chain Centers (Retrofit, URLSession)
├── model/ # Raw Materials (DTOs)
└── mapper/ # Material Processors

Purpose: Processes and manages all data resources

  • Resource Centers (Repositories): Implement the material contracts

  • Warehouses (Local Data Sources): Room (Android), CoreData/UserDefaults (iOS)

  • Supply Chain Centers (Remote Data Sources): Retrofit (Android), URLSession/Alamofire (iOS)

  • Raw Materials (DTOs): The raw data formats before processing

  • Material Processors (Mappers): Convert raw materials into production-ready components

4. Framework Department

The infrastructure connecting the factory to external systems:

  • Power Grid: OS services and APIs

  • Equipment Suppliers: Third-party libraries and services

  • Distribution Network: Database and network connections

  • External Partners: Platform-specific integrations

Conclusion

The Industrial Factory metaphor provides a concrete and intuitive way to understand Clean Architecture in mobile development. By visualizing components as parts of a manufacturing environment with clear boundaries and responsibilities, developers can better grasp:

  • The separation of concerns between layers

  • The proper flow of data and dependencies

  • How platform-specific implementations fit into a shared architectural concept


This mental model helps maintain clean, maintainable, and testable code across both Android and iOS platforms while preserving the core principles of Clean Architecture.


Share on: