How to organize the project folders and files?
Tags: iOS, Xcode, projectOrganization
Published: 2020-05-02 00:54:34

Project structure (folder structure) is a very basic thing and usually ignored, especially junior developers. 
<img src="https://firebasestorage.googleapis.com/v0/b/blogs-1de93.appspot.com/o/assets%2Fproject_structure%2Funorder.png?alt=media&token=99fb4814-eaa2-45e5-8b43-9d94af62a9fa" width="40%"/>

Good structure can help you increase your efficiency. 

> What are the most common ways to oganize the project structure?
>>There is not correct answer here, depend on developers. 
#I. Structure
Today, I will show you 2 common ways to arrange files in project which can help you access to files easier. 
##1. Group files by features 
Any projects have at least 2 features. Large projects have many features. This way has 2 advantages: 
- You can access to other related files in the same folder. Press `Ctrl + 5` to quick access files in the same folder. 
- You can copy folders to new projects and reuse it easily. This is the reason I love this way.
<img src="https://firebasestorage.googleapis.com/v0/b/blogs-1de93.appspot.com/o/assets%2Fproject_structure%2Fgroup_by_features.png?alt=media&token=c0372cb6-665c-4af4-9ae9-0b3e0a580b12" width="40%"/>


> Where should I put the models, which are used in many features? 
>>`Common` folder is an option. 
>>But I usually put it in the most related folder. For example: `Product` model is in folder `Products`, `User` model is in folder `Membership` or `Login`. 


##2. Group files by type
You can make many folders of same purpose files like, `Models`, `Controllers`, `Views`
You have right folders for right types, don't have to confuse where to put files. 
This way is very easy for newcomers (junior developers), they can easily find the files they want. 
<img src="https://firebasestorage.googleapis.com/v0/b/blogs-1de93.appspot.com/o/assets%2Fproject_structure%2Fgroup_by_types.png?alt=media&token=c3435d46-26c2-410a-9993-a32939e0076d" width="40%"/>

I don't use this way so I don't know more benefits of it. Anyone who is using it, please share me in comments. 


#II. Naming 
Naming is very important. Descriptive names help you easy to find and understand the mission of files. 
Some things you should know in naming. 
##1. Class name is file name
`RegisterController` should be written in `RegisterController.swift`. You don't have to remember 2 names, just one for Register feature. Keep your mind free to remember other things. 

##2. Feature name is folder name and prefix of file names
This is for `group by features` way. `Register` feature should have structure like below. 
<img src="https://firebasestorage.googleapis.com/v0/b/blogs-1de93.appspot.com/o/assets%2Fproject_structure%2Ffolder_name.png?alt=media&token=029bb578-006d-4de6-b114-54674dea859d" width="40%"/>


The folder name can be `Register` or `RegisterController`, no problem. You can understand its functionality at first glance, right. 

If you're using `group by types` way, you can name your files with prefix is feature name as above example. Benefits are below. 

<img src="https://firebasestorage.googleapis.com/v0/b/blogs-1de93.appspot.com/o/assets%2Fproject_structure%2Fquick_access.png?alt=media&token=cf38f01c-6eb6-4db0-958b-9a9fa7dd7a97" width="40%"/>

<img src="https://firebasestorage.googleapis.com/v0/b/blogs-1de93.appspot.com/o/assets%2Fproject_structure%2Fsearch.png?alt=media&token=01b147f6-c362-482a-ada5-877485c3e138" width="40%"/>


# Conclusion 
Hope these tips can help you increase your coding performance. Please share me how you organize your project structure. I am sure your ways are awesome ways. 

Introduce a very cool tool: [https://github.com/venmo/synx](https://github.com/venmo/synx). You should try it.