NUDelta / studio-api

API to read data from various tools used in DTR
0 stars 0 forks source link

reorganize routes and controllers #5

Open kapil1garg opened 2 years ago

kapil1garg commented 2 years ago

I currently have routes based on broad parts of the network that other systems may want to access (e.g., info on people; info on projects; info on venues; etc.). As I've begun to add more routes to the API, each of these files has started to get chunky and harder to maintain since, for each route, I need (1) the request handler; and (2) a controller that fetches/formats the data.

An alternative architecture may look like this:

routes/api/
|_ index.js // combines all routes
|_people/
|____index.route.js // combines all routes in this directory
|____all.route.js // gets all people in community
|____faculty.route.js // gets all faculty members
|____phdstudents.route.js // gets all phd students
|____nonphdstudents.route.js // gets all non-phd students (i.e., MS and UGrad)
|____ ...
|
|__tools/
|____sprints/
|______sprintForPerson.route.js // gets the sprint log for a specific person
|______sprintForProj.route.js // gets the sprint log for a specific project
|
|__venues/
|
|__processes/
|
|__ ...

Within each of the leaf .js files, I could have the request hander and controller related to just the route there, and store any common controllers in controllers/. index.js files in each subdirectory setup the routes with a router and export the router so that routes/api/index.js can combine and export them to be added to the application.

See here for an example.