ericholiveira / studio

A nodejs framework to create decoupled and scalable applications
MIT License
488 stars 61 forks source link

File structure #43

Closed sean-hill closed 8 years ago

sean-hill commented 8 years ago

Hey I was just curious what a good file structure would be for use with Studio and an Express API. I'm thinking something like this:

- services
    - config-service.js
    - user-module
        - index.js
        - create-service.js
        - update-service.js
        - remove-service.js
    - auth-module
        - index.js
        - signup-service.js
        - login-service.js

- api
    - user-routes
        - index.js
        - create-route.js
        - update-route.js
        - etc.
- app
    - index.js

Under the services folder, they are group by Studio module's if appropriate, or just standalone files if the service doesn't need a module. Then each api route would have its own file, which would then require its associated service.

Thoughts? Also, what have you guys done?

sean-hill commented 8 years ago

Another idea, would be to group services and routes together like:

- app
    index.js
    - user
        index.js
        - create
            - service.js
            - route.js
        - update
            - service.js
            - route.js

But I don't really like that approach as much.

ericholiveira commented 8 years ago

I usually take a slightly diferent approach than 2 . i do the following:

Im using node4 so i just implement my services in a class and use Studio.serviceClass to load it all. If it happens of the service become really big, then you can break it in more subfolders, but for me, it is working really well this way.

This approach (as the second you discribed) has the advantage of being really easy to distribute, if i need different deploys for my services i could do the following

Just a minor change and are ready to distribute by functionality

sean-hill commented 8 years ago

Hey @ericholiveira!

Thanks. Would you mind screenshotting your file structure as an example? I'm a little confused at what you mean. Thanks :)

sean-hill commented 8 years ago

Also I don't see any docs for Studio.serviceClass in the repo.

ericholiveira commented 8 years ago

Oh, thx i will add it tonight. Anyway you can see it here: https://medium.com/adopting-microservices-architecture/nodejs-microservices-from-zero-to-hero-pt2-72fbb2a1b1c4#.dahyaklx5

(I will keep the issue open for a while if anyone wants to comment something on this )

ericholiveira commented 8 years ago

Something like this (attaching this, because i only have my company code, so i prefer to avoid printing it) , on express.js i initialize express to use on the routes captura de tela 2016-05-11 as 15 40 39