Logo

dev-resources.site

for different kinds of informations.

MVVM directory structure for larger project

Published at
1/15/2025
Categories
swift
architecture
Author
Pheak Pheasa
Categories
2 categories in total
swift
open
architecture
open
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

Featured ones: