name: design-mobile-project-structure
description: Use when starting a mobile app (Android/Kotlin, iOS/Swift, Flutter, React Native) or when an existing app has grown hard to build and change — one giant app module, slow incremental builds, screens mixing UI, networking, and persistence, or teams stepping on each other's code.
source: 'Android Developers, "Guide to app architecture" and "Guide to Android app modularization"; Google, "Now in Android" sample app (GitHub); Flutter Documentation, "Guide to app architecture", 2024; Apple, "Swift Package Manager" documentation; Uber Engineering, "Introducing RIBs", 2017'
tags: [project-structure, mobile, modularization, android, ios, build-performance]
related: [apply-package-by-feature, apply-module-boundary-enforcement, design-offline-first, design-frontend-project-structure]
Design Mobile Project Structure
Structure a mobile app in layers (UI → optional domain → data) and, as it grows, modules: a thin app module, independent feature modules, and shared core modules. Features depend on core, never on each other.
Why This Is Best Practice
Adopted by:
- Google's official Android architecture and modularization guides, demonstrated in the "Now in Android" reference app.
- Flutter's official architecture guide (views, view models, repositories, services).
- Uber (RIBs), Airbnb, and Spotify, which modularized large iOS and Android codebases.
- Apple's Swift Package Manager supports local packages for the same purpose.
Impact:
- Google's modularization guide cites these benefits:
- faster builds through parallel and incremental compilation
- better reusability and stricter visibility control
- ownership and testability
- the ability to use dynamic feature delivery
- Separating UI from data lets view models and repositories be unit tested without a device or emulator.
Why best:
- A single module with screens that call network and database directly works for a prototype.
- That approach collapses as the app grows: builds slow, changes ripple, and testing needs a device.
- Layering plus feature modules follows the same proven principles as backend and web, and the platform vendors officially recommend it.
Sources: Android Developers, "Guide to app architecture" and "Guide to Android app modularization". Now in Android (github.com/android/nowinandroid). Flutter docs (2024), "Guide to app architecture". Apple, Swift Package Manager docs. Uber Engineering (2017), "Introducing RIBs".
Steps
Layer every feature:
- UI layer: screens/views plus a state holder (ViewModel, Bloc/Cubit, ObservableObject). Unidirectional data flow: state goes down, events go up.
- Domain layer (optional): use cases for complex or reused business logic.
- Data layer: repositories (the single source of truth, exposing data as streams) backed by data sources (network, database, cache). See
design-offline-first for offline needs.
Start as a single module with feature packages (apply-package-by-feature):
app/src/main/java/com/acme/
feature/home/ (HomeScreen, HomeViewModel)
feature/profile/
core/data/ core/network/ core/database/ core/designsystem/
Modularize when builds slow down or teams grow. Use the "Now in Android" pattern:
app/ # entry point, navigation graph, DI wiring
feature/
home/ profile/ settings/
core/
designsystem/ ui/ data/ domain/ network/ database/ model/ common/ testing/
build-logic/ # convention plugins (Gradle) for shared build config
feature:* depends on core:* only. Features never depend on other features. Navigate through routes defined in app or a navigation contract module.
core:model holds plain data models shared across layers.
Apply platform equivalents:
- iOS (Swift): a thin app target plus local Swift packages (
Features/Home, Core/Networking, Core/DesignSystem) declared in a Packages/ folder. Use internal access by default and expose a minimal public API. Tuist or XcodeGen can generate the project to avoid .pbxproj conflicts.
- Flutter:
lib/ui/<feature>/{views,view_models}, lib/data/{repositories,services}, lib/domain/models, and lib/config, per the Flutter architecture guide. For large apps, use Dart packages in a melos or pub workspace.
- React Native/Expo: feature folders (
src/features/<feature>/{screens,components,hooks,api}) plus src/shared and Expo Router's app/ for routes, following the frontend structure (see design-frontend-project-structure).
Centralize dependencies and build config: a Gradle version catalog (libs.versions.toml) plus convention plugins, a single SPM manifest per package, and pinned Flutter/Dart SDK versions.
Wire with dependency injection in the app module (Hilt/Koin, Swift initializer injection or Factory, Riverpod/get_it), so features stay decoupled from concrete implementations.
Mirror the structure in tests:
- unit tests for view models and repositories, using fakes from
core:testing
- UI tests per feature
- a few end-to-end flows in the app module
Enforce boundaries. Rely on module visibility first (Gradle implementation, Swift internal). Add Konsist or a dependency-analysis plugin for rules such as "no feature-to-feature dependencies" (see apply-module-boundary-enforcement).
Rules
- UI never talks to network or database directly. It goes through repositories.
- Repositories are the single source of truth for their data.
- Features depend on core modules, never on each other.
- The app module only wires and navigates. It holds no business logic.
- Modularize to solve real problems (build time, ownership), not preemptively.
Common Mistakes
- God activity or ViewController. UI, networking, and persistence in one class that can't be tested.
- Feature-to-feature dependencies for navigation. Use route contracts instead.
- Over-modularizing early. Fifty modules in a three-screen app create build-config overhead with no gain.
- A
core:common dumping ground. Split by purpose (network, database, designsystem).
- Duplicated build config across modules. Use convention plugins or a version catalog.
Examples
Android news app: app + feature:foryou, feature:bookmarks, feature:search + core:data, core:network (Retrofit), core:database (Room), core:designsystem (Compose theme). Hilt wiring sits in app. Clean builds run modules in parallel, and incremental builds rebuild only the changed feature.
iOS app: an App target plus Packages/Features/{Feed,Profile} and Packages/Core/{API,Persistence,DesignSystem} as local SPM packages. Previews and unit tests run per package without launching the whole app.
When NOT to Use
- Prototypes and very small apps. A single module with feature packages is enough.
- Cross-platform shells around a web app (Capacitor/WebView). Follow the web structure instead.
1---2name: design-mobile-project-structure3description: Use when starting a mobile app (Android/Kotlin, iOS/Swift, Flutter, React Native) or when an existing app has grown hard to build and change — one giant app mod4---5---6name: design-mobile-project-structure7description: Use when starting a mobile app (Android/Kotlin, iOS/Swift, Flutter, React Native) or when an existing app has grown hard to build and change — one giant app module, slow incremental builds, screens mixing UI, networking, and persistence, or teams stepping on each other's code.8source: 'Android Developers, "Guide to app architecture" and "Guide to Android app modularization"; Google, "Now in Android" sample app (GitHub); Flutter Documentation, "Guide to app architecture", 2024; Apple, "Swift Package Manager" documentation; Uber Engineering, "Introducing RIBs", 2017'9tags: [project-structure, mobile, modularization, android, ios, build-performance]10related: [apply-package-by-feature, apply-module-boundary-enforcement, design-offline-first, design-frontend-project-structure]11---1213# Design Mobile Project Structure1415Structure a mobile app in **layers** (UI → optional domain → data) and, as it grows, **modules**: a thin `app` module, independent `feature` modules, and shared `core` modules. Features depend on core, never on each other.1617## Why This Is Best Practice1819**Adopted by:**20- Google's official Android architecture and modularization guides, demonstrated in the "Now in Android" reference app.21- Flutter's official architecture guide (views, view models, repositories, services).22- Uber (RIBs), Airbnb, and Spotify, which modularized large iOS and Android codebases.23- Apple's Swift Package Manager supports local packages for the same purpose.2425**Impact:**26- Google's modularization guide cites these benefits:27 - faster builds through parallel and incremental compilation28 - better reusability and stricter visibility control29 - ownership and testability30 - the ability to use dynamic feature delivery31- Separating UI from data lets view models and repositories be unit tested without a device or emulator.3233**Why best:**34- A single module with screens that call network and database directly works for a prototype.35- That approach collapses as the app grows: builds slow, changes ripple, and testing needs a device.36- Layering plus feature modules follows the same proven principles as backend and web, and the platform vendors officially recommend it.3738Sources: Android Developers, "Guide to app architecture" and "Guide to Android app modularization". Now in Android (github.com/android/nowinandroid). Flutter docs (2024), "Guide to app architecture". Apple, Swift Package Manager docs. Uber Engineering (2017), "Introducing RIBs".3940## Steps41421. **Layer every feature:**43 - **UI layer:** screens/views plus a state holder (ViewModel, Bloc/Cubit, ObservableObject). Unidirectional data flow: state goes down, events go up.44 - **Domain layer (optional):** use cases for complex or reused business logic.45 - **Data layer:** repositories (the single source of truth, exposing data as streams) backed by data sources (network, database, cache). See `design-offline-first` for offline needs.46472. **Start as a single module with feature packages** (`apply-package-by-feature`):48 ```49 app/src/main/java/com/acme/50 feature/home/ (HomeScreen, HomeViewModel)51 feature/profile/52 core/data/ core/network/ core/database/ core/designsystem/53 ```54553. **Modularize when builds slow down or teams grow.** Use the "Now in Android" pattern:56 ```57 app/ # entry point, navigation graph, DI wiring58 feature/59 home/ profile/ settings/60 core/61 designsystem/ ui/ data/ domain/ network/ database/ model/ common/ testing/62 build-logic/ # convention plugins (Gradle) for shared build config63 ```64 - `feature:*` depends on `core:*` only. Features never depend on other features. Navigate through routes defined in `app` or a navigation contract module.65 - `core:model` holds plain data models shared across layers.66674. **Apply platform equivalents:**68 - **iOS (Swift):** a thin app target plus local Swift packages (`Features/Home`, `Core/Networking`, `Core/DesignSystem`) declared in a `Packages/` folder. Use `internal` access by default and expose a minimal `public` API. Tuist or XcodeGen can generate the project to avoid `.pbxproj` conflicts.69 - **Flutter:** `lib/ui/<feature>/{views,view_models}`, `lib/data/{repositories,services}`, `lib/domain/models`, and `lib/config`, per the Flutter architecture guide. For large apps, use Dart packages in a melos or pub workspace.70 - **React Native/Expo:** feature folders (`src/features/<feature>/{screens,components,hooks,api}`) plus `src/shared` and Expo Router's `app/` for routes, following the frontend structure (see `design-frontend-project-structure`).71725. **Centralize dependencies and build config:** a Gradle version catalog (`libs.versions.toml`) plus convention plugins, a single SPM manifest per package, and pinned Flutter/Dart SDK versions.73746. **Wire with dependency injection** in the app module (Hilt/Koin, Swift initializer injection or Factory, Riverpod/get_it), so features stay decoupled from concrete implementations.75767. **Mirror the structure in tests:**77 - unit tests for view models and repositories, using fakes from `core:testing`78 - UI tests per feature79 - a few end-to-end flows in the app module80818. **Enforce boundaries.** Rely on module visibility first (Gradle `implementation`, Swift `internal`). Add Konsist or a dependency-analysis plugin for rules such as "no feature-to-feature dependencies" (see `apply-module-boundary-enforcement`).8283## Rules8485- UI never talks to network or database directly. It goes through repositories.86- Repositories are the single source of truth for their data.87- Features depend on core modules, never on each other.88- The app module only wires and navigates. It holds no business logic.89- Modularize to solve real problems (build time, ownership), not preemptively.9091## Common Mistakes9293- **God activity or ViewController.** UI, networking, and persistence in one class that can't be tested.94- **Feature-to-feature dependencies** for navigation. Use route contracts instead.95- **Over-modularizing early.** Fifty modules in a three-screen app create build-config overhead with no gain.96- **A `core:common` dumping ground.** Split by purpose (network, database, designsystem).97- **Duplicated build config across modules.** Use convention plugins or a version catalog.9899## Examples100101**Android news app:** `app` + `feature:foryou`, `feature:bookmarks`, `feature:search` + `core:data`, `core:network` (Retrofit), `core:database` (Room), `core:designsystem` (Compose theme). Hilt wiring sits in `app`. Clean builds run modules in parallel, and incremental builds rebuild only the changed feature.102103**iOS app:** an `App` target plus `Packages/Features/{Feed,Profile}` and `Packages/Core/{API,Persistence,DesignSystem}` as local SPM packages. Previews and unit tests run per package without launching the whole app.104105## When NOT to Use106107- **Prototypes and very small apps.** A single module with feature packages is enough.108- **Cross-platform shells around a web app** (Capacitor/WebView). Follow the web structure instead.