DEV Community

Pheak Pheasa
Pheak Pheasa

Posted on

MVVM directory structure for larger project

Key Additions:
1. Modularization: Break the app into separate modules (e.g., UserModule, ProductModule) to improve scalability and collaboration in large teams.
2. DependencyInjection: Using DI frameworks (like Swinject) to handle dependencies across the app, improving testability and flexibility.
3. Managers: More specific app-wide managers like PushNotificationManager, AnalyticsManager for cross-functional management.
4. Tests: Better structured tests with different types of testing (e.g., unit tests, UI tests, integration tests).
5. Documentation: More extensive documentation covering architecture, APIs, and other design considerations.

MyApp/
│
├── Models/                        # Data models representing app entities
│   ├── User.swift
│   ├── Product.swift
│   └── ...
│
├── Views/                         # UI components (Views)
│   ├── MainView.swift
│   ├── UserView.swift
│   ├── ProductView.swift
│   └── ...
│
├── ViewModels/                    # ViewModels responsible for data-binding and logic
│   ├── MainViewModel.swift
│   ├── UserViewModel.swift
│   ├── ProductViewModel.swift
│   └── ...
│
├── Services/                      # Layer for API calls, data handling, etc.
│   ├── NetworkService.swift
│   ├── AuthService.swift
│   ├── ImageService.swift
│   └── ...
│
├── Persistence/                   # Local data storage, CoreData, SQLite, etc.
│   ├── CoreDataManager.swift
│   ├── DatabaseMigration.swift
│   └── PersistenceService.swift
│
├── Helpers/                       # Reusable utilities or helper methods
│   ├── Extensions/
│   ├── DateFormatterHelper.swift
│   ├── NetworkingHelper.swift
│   └── ...
│
├── Resources/                     # Images, JSON, etc.
│   ├── Images/
│   ├── Localizations/
│   ├── Fonts/
│   └── ...
│
├── Supporting Files/              # Configurations, AppDelegate, SceneDelegate, etc.
│   ├── AppDelegate.swift
│   ├── SceneDelegate.swift
│   ├── Info.plist
│   └── Assets.xcassets
│
├── UI/                            # UI-specific components (e.g., custom buttons, loaders)
│   ├── CustomButton.swift
│   ├── LoadingIndicator.swift
│   ├── CustomView.swift
│   └── ...
│
├── Coordinators/                  # Responsible for navigation flow
│   ├── MainCoordinator.swift
│   ├── UserCoordinator.swift
│   └── FlowCoordinator.swift
│
├── Network/                       # Network layer, handling API calls, caching, etc.
│   ├── APIClient.swift
│   ├── APIConstants.swift
│   ├── ResponseHandler.swift
│   └── ...
│
├── Managers/                      # Handles app-wide management logic
│   ├── SessionManager.swift
│   ├── PushNotificationManager.swift
│   └── AnalyticsManager.swift
│
├── Utils/                         # Miscellaneous utilities
│   ├── AppUtils.swift
│   └── Logging.swift
│
├── Modularization/                # For large projects, consider splitting into modules
│   ├── UserModule/                # Example of separate feature module
│   │   ├── UserModels/
│   │   ├── UserViews/
│   │   ├── UserViewModels/
│   │   ├── UserServices/
│   │   └── UserCoordinator.swift
│   └── ProductModule/             # Another example
│       ├── ProductModels/
│       ├── ProductViews/
│       ├── ProductViewModels/
│       ├── ProductServices/
│       └── ProductCoordinator.swift
│
├── DependencyInjection/           # Dependency Injection setup (e.g., using Swinject)
│   ├── DIContainer.swift
│   ├── ServicesAssembly.swift
│   └── ViewModelsAssembly.swift
│
├── Tests/                          # Unit and UI tests
│   ├── ViewModelsTests/
│   ├── ServicesTests/
│   ├── PersistenceTests/
│   ├── UITests/
│   └── ...
│
└── Documentation/                 # Project-related documentation
    ├── README.md
    ├── API_Documentation.md
    └── Architecture.md
Enter fullscreen mode Exit fullscreen mode

Sentry blog image

The Visual Studio App Center’s retiring

But sadly….you’re not. See how to make the switch to Sentry for all your crash reporting needs.

Read more

Top comments (0)

Sentry mobile image

Improving mobile performance, from slow screens to app start time

Based on our experience working with thousands of mobile developer teams, we developed a mobile monitoring maturity curve.

Read more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay