loading...

Should I have my backend and my frontend in the same repo ?

pol profile image Pol ・1 min read

Hi everyone,

I used to develop my app with express and ejs. With this configuration, I don’t really have a front/back-end separation.

I recently started learning React and with it the separation of the backend with my API, database, ... and the front-end with my react app.

So, I was wondering, do I need to separate my backend repo and my frontend repo ? It seems kinda strange to do so because, most of the time, a new feature on my frontend means new changes on the backend.

What should I do to practically put both on the same repo ? Having tow sub folders ? And what about Heroku ? I can’t configure it to build a subfolder app.

How are you managing that in your projects ?

Discussion

markdown guide
 

I kept them in separate folders named frontend and backend but in the same repo. I rather have one repo to push changes too (and less risk of them being out of sync) but somewhat organized.

 

I'm keeping everything in a single repository.
My approach to this setup is a lerna monorepo.

I'm typically using three subpackages, one for frontend, one for backend and a third one which basically contains entities used for communication between frontend and backend.
Since I'm mostly working with TypeScript, the communication package not only exports entities but also typeguards, which makes typechecking on both ends a breeze.

lerna makes working with multiple packages easy, which is why I stuck with this approach. yarn workspaces seem to be an alternative, but I haven't used them yet.

At the end of the day I'm deploying a bundle created with webpack.