Answer the question
In order to leave comments, you need to log in
What is the correct structure for a react-redux application with a mongo database connection?
I came to the conclusion that a mess formed in my head about how to organize the structure of the application. it's just that each example has its own structure and it's hard to understand what it should actually be.
For example, as I now understand there must be something like this.
server
-db
-model
client
- component
- container
-store
-reducer
But at the same time there are connections, i.e. there must be an api folder, where to put it, etc. I would just like to figure out how the structure of the application should be built as a result
Answer the question
In order to leave comments, you need to log in
First, let's separate the backend (server part): there you should have a rest-api that returns JSON.
As for the structure of the client: in general - yes, components, containers, reducers (why store separately?). You do all the work with api in actions. It turns out the following structure:
- components
- containers
- reducers
- actions
I divide the application into modules (if it is large). And, it turns out that the modules with the above structure are in separate folders, and the application itself is a set of pages (and their containers).
But could you write a little more about the server part, otherwise I still don’t understand how it should be. For example, in my server entry point, this is
app.get('/entity/add', (req, res) => {
db.createEntity(req.body).then(data => res.send(data));
});
/** Create HTTP server. **/
const server = http.createServer(app);
server.listen(port, () =>
console.log(`Server started on port ${port}`)
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question