I've been doing some research on how we should organize our file structure. The goal is to standardize our file organization. Mostly, there're 2 ways to classify file organization:
1 - By type
This separates file by its type. Files will be grouped by what they are. A pretty traditional way to do. The file structure will be somewhat like this
ROOT
├─ Models
├─ Views
├─ Controllers
├─ Helpers
├─ Services/Networking
├─ Stores/Managers
2 - By use case
Files are to be grouped only by its feature. The structure varies on each preference, but well, it'd look similar to this
ROOT
├─ Modules
├─ Login
├─ Booking
├─ Account
├─ Extensions
├─ Resources
Personally, I prefer this approach more as it separate unnecessary concerns out when we're working on some certain feature. One tradeoff of this approach is that, when any view is to be used by multiple modules, then we'll have to create Common
and put them inside it. I'm not against this one tho, but well, still looking for a better option.
The second one doesn't differ from the structure we're having on our current projects. I'm thinking that we could adapt from it by combining both approaches to something like
ROOT
├─ Application // AppDelegate, Plist, Entitlements
├─ Constants // Colors, Fonts, Configurations
├─ Module/Flow/Controller
├─ Authorization
├─ Login
├─ Register
├─ AuthorizationFlowController.swift
├─ ...
├─ Model
├─ View
├─ Protocol // should we keep this tho?
├─ Extension // could perhaps create subdirectory for UIKit, Foundation
├─ Service
With this grouping, we will have more groups on the base level, but IMO, it's acceptable as long as we can have less deeper structure. For any view that needs to be generic and reused in multiple places, we could put it inside View
folder e.g. AvatarImageView
, AnimatedButton
. Otherwise, We'll put it to where it belongs like putting LoginTableViewCell
inside Login
directory, putting BookingHeaderTableViewCell
inside Booking
module.
There's some concern I couldn't come up with an answer. Let's say there's a class like Calculator
or Validator
, where should we put it into? I think we could perhaps have another base directory named Module
and put it inside, but it still doesn't seem much right to me.
Another thing is that, do you think Protocol
directory should exist or not? I'd prefer to have it tho, but not sure how you guys would see it. I mean, I'd like to separate things as much as possible without creating excessive junk directory, so that we can focus what we're working on and find related files easier.