DEV Community

Discussion on: Looking for Code Organization Advice

Collapse
 
recursivefaults profile image
Ryan Latta

I wish I could give a quick answer here, but sadly there is no silver bullet I've found.

Most frameworks come with their own advice for structuring things, so if that exists I'll follow that, even if I think its odd.

If a convention doesn't exist, then things tend to break down into two ways which is to create directories by category like views, apis, services, etc. The other is to do it by features so you'd get something like login, dashboard, account, etc.

Beyond that I am a fan of each file does one thing for the most part. Sometimes I'll break that rule if, for example, I have a bunch of small model things I might lump them into one single model file.

The idea though is to make things so that you could guess where they are without a lot of extra help. The bigger and older the code base gets the more important this becomes, but for a lot of smaller projects you can get pretty far with out overthinking it.

Collapse
 
adron profile image
Adron Hall

Big fan of one thing per file too.

The whole focal point of "make things so that you could guess where they are" I think is a good and noteworthy objective. After all, the code is for us humans eh!