maximecb / noisecraft

Browser-based visual programming language and platform for sound synthesis.

Home Page:https://noisecraft.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

splitting server.js file

victorKochkarev opened this issue · comments

server.js file contains the complete server functionality.
I think it might be a good idea to start splitting it up.
It might be good to move out database initialisation into a separate file.
HTTP method handlers could be grouped into different controllers.

These actions might make the project better organised and more maintainable.

I would be happy to the work.

Not opposed to it but I kind of like that right now, server.js is relatively small and fits into one file.

If you were to split it, how would you factor it, something like this?

server/database.js
server/api.js

What are your thoughts?

I would even try to go even more granular.

It could be something like this:

server/controllers/projects.js - to handle all projects related requests
server/controllers/users.js - to handle all user-related requests
server/controllers/public.js - for all pages and static content handling.

server/db/init.js - method to handle initial database migration.

Later another layer of services could be introduced.
It can be taken step by step.

Here are a few random articles that describe the similar pattern.

https://softwareontheroad.com/ideal-nodejs-project-structure/
https://www.coreycleary.me/project-structure-for-an-express-rest-api-when-there-is-no-standard-way

At the moment server.js sits under 700LOC and I'd like to keep it relatively simple and minimalistic. I like that you can quickly look at the whole thing at a glance and that it's not split into 4+ different source files. If it's going to be split, I'd rather not split it into multiple subdirectories.