7
7
700ghz2019-01-06 14:04:04
Software design
700ghz, 2019-01-06 14:04:04

REST API backend file structure?

Hello!
I'm working on backend on Expressjs. The customer asks that the backend should consist of two APIs:
shop-api.routes.js: /api/shops/bla-bla
buyer-api.routes.js: /api/buyers/bla-bla
There are a lot of routes between the shops and buyers routes general functionality.
Please help with file structure. I see these options:
1) as few files as possible

src
..api
....shop-api.js <- весь функционал shop-api
....buyer-api.js <- весь функционал buyer-api
..helpers
....api-common.js <- общий функционал (между shop и buyer)

2) split into modules by entities:
src
..api
....shop-api 
......shop-api.users.js <- функционал сгруппирован по сущностям
......shop-api.books.js
....buyer-api
......buyer-api.users.js
......buyer-api.books.js
..helpers
....api-common.js <- общий функционал

3) 1 route - 1 file (split even more)
src
..api
....shop-api 
......users
........shop-api.users.get.js <- 1 роут - 1 файл
........shop-api.users.post.js 
....buyer-api
......users
........shop-api.users.get.js 
........shop-api.users.post.js 
..helpers
....api-common.js <- общий функционал

4) another problem: huge api-common.js . Can it be broken?
..helpers
....api-common.users.js <- общий функционал разбит на модули
....api-common.books.js

What is the correct structure? How to store a bunch (thousands of lines) of common functionality?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
grinat, 2019-01-06
@grinat

How would it be done like this: https://docs.nestjs.com/modules
https://www.yiiframework.com/doc/guide/2.0/en/stru...
https://symfony.com/doc/ 4.1/bundles/best_practices.html

V
Vitaly, 2019-01-07
@vshvydky

-src
--controllers
--models
--repositories
--services or workers
--tools or utils

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question