P
P
Pogran2016-08-22 16:04:25
React
Pogran, 2016-08-22 16:04:25

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

2 answer(s)
N
Nikita Gushchin, 2016-08-22
@iNikNik

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).

P
Pogran, 2016-08-22
@Pogran

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}`)
);

Here is the app.get request that I send to /entity/add . but is it correct to write api/entity/add ?
and then if I have a lot of requests (app.get, app.post) is it not correct to store them all in the entry point file? And do you have the opportunity to throw which of your projects with the correct structure? you can just the server part, or a piece of some kind, in order to somehow capture the essence of how it should be

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question