Search code examples
angularjsnode.jsmongodbarchitectureapplication-design

Where should I manage advanced algorithms/services on the server side in my project structure?


I'm working with nodejs, expressjs, mongodb and angular with RESTful API.

Here is my project structure.

-- config
-- models
-- public
---- css
---- js
------ controllers
------ services
---- views
-- routes          // API route

Everything was ok because my API calls were simple and most of the logic is managed by angular with services.

But now I have to implement advanced algorithms and some logic server side and I don't know where to do it.

Should I add another services folder server side? How would you manage it?


Solution

  • Depends on your application. Since you application has a node.js backend. and you want to implement advanced algorithms, it should be on the server side. Its always wise to keep the front-end light as possible because you don't want the user to be waiting.

    Keep some weight on the back-end, but again it all depends on what type of application you are talking about. All your advanced algorithms should be written in the Controllers or the .js files.

    Example server side structure for a shopping cart application : enter image description here

    Note how the categories.js, product.js, models.js, api.js are broken down to.

    In summary:
    If your advanced algorithms comes in pricing of a product in reference to the example shopping cart application, its better to write it in the product.js and if its related to sorting categories, or showing categories according to user, then better write that logic in the category.js. This will be handy for the existing and a new developer coming into the application. Remember, organized applications are fun to upgrade.