Comments (8)
For avoidance of doubt, any time I use a word below I'm referring to its meaning under the proposed New World Order :)
What's the value proposition in adding another layer? What's the benefit of having a Controller, Model and Schema? What responsibility would the Model hold that the Controller and Schema wouldn't?
Or, perhaps a better question, what responsibility would the Route hold that the Controller wouldn't?
from dendritic.
What responsibility would the Model hold that the Controller and Schema wouldn't?
Model would have your findAll, create, update methods using the database library. Schema would just be the json schema. Controller would take your req and res, call the model functions and pass it to res.send.
what responsibility would the Route hold that the Controller wouldn't?
The route would just be a mapping of a string representation of a route, and the controller action to call, eg:
{ route: '/todos/:todoId', action: todoController.create }
There is no real extra layer here, besides importing an action instead of using an anonymous function, it's more just a shift of naming to more closely reflect rails.
Route is a definition, controller handles the request, model is responsible for retrieving and updating data.
from dendritic.
The value in the change is to reflect current naming conventions in these types of applications, so that we reduce confusion when talking about concepts and help involve a wider community that may be moving from platforms with the current naming conventions.
from dendritic.
Cool. I think that's probably a reasonable way to go. Next step I think is a PR. That way we can look at the implications of the change, decide how it feels, and merge if we're happy. No need to ensure the PR is the most polished perfect thing it can be. Let's get something quick together, validate the direction, then polish it up before merging assuming that we like it.
from dendritic.
Related #40
from dendritic.
Oh, cool, you have this discussion already. I've touched a bit my thoughts on this in #40, but a few more words. @Nicktho is generally right, I +1 his definition of a model and a schema. A model is basically a type or a value object that conforms with a schema.
One thing though. I'd steer away from controller
, this causes confusion in teams all the time, because routes in nodejs apps basically play the role of a controller in your everyday MVC structure. Some projects, like rails for example, split routes and controllers, but their routes is just a dumb config. it doesn't really have much logic. In case of expressjs and similar, your routes basically play the role of what's called the front controller.
Basically a router in node should be an equivalent of a shallow controller. That router-controller thing is supposed to talk to either a Model (if it is a simple case) or a business logic thing. That businesslogic thing is often called services
(to avoid confusion with controllers
).
Business logic is basically the smarts around the model. It does data transformation and such, but it is completely gnostic from the use case. Busniess logic should now know anything about the HTTP server. It shouldn't care about query params, forms and such. It just deals with data.
So, in this light what works and scales well is a split that looks so:
routes/ <- deal with the HTTP requests and call models or services
services/ <- contains the business logic, can be missing in simple CRUD apps
models/ <- value objects or records that represent the db schema
Also, in the context of a nodejs app, it is worth having a separate folder called middleware
, that is where
your reuseable data transformation things go, like authenticate
, authorize
, findThing
, logActions
, etc.
As for schema it is heavily depend on a specific ORM implementation. In most cases the schema is defined within the models definitions. As for connection details, json schema constraints and such, that should go into a config/
folder.
That is pretty much a structure and naming convention that repeats itself in many projects and the one that scales well from a small project to a pretty large monolith.
from dendritic.
any feedback on this? @davidbanham @nwinch @Nicktho
from dendritic.
This can be tagged as "todo" I believe, as everyone seems to generally agree with the direction outlined by @Nicktho, and then also furthered by @MadRabbit.
from dendritic.
Related Issues (20)
- "utils" vs "lib" HOT 3
- Route paths using filenames as relative base HOT 7
- Build analytics HOT 5
- Revision id is not checked when updating HOT 1
- "definitions" schema returned via /schema HOT 4
- /schemas folder location HOT 3
- Add the soft-delete option for models HOT 3
- Last build time + commit HOT 3
- Validation errors do not show fieldname HOT 2
- Validation errors difficult to match to form inputs HOT 6
- Docker automation package
- Move the redbeard specific code from boilerplate into dependencies
- v5 Validations
- thinky.dbReady is borked in docker
- Tests are flaky due to random project/resource names
- app-module-path must go
- Update deps
- createdAt/updatedAt as default schema/model fields HOT 7
- Base Controller .update uses this.find which can be overwritten. HOT 4
- Interview partners for research about communication in GitHub projects wanted
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dendritic.