DEV Community

Riku Rouvila
Riku Rouvila

Posted on

Should I keep my UI and my API in different repositories?

Probably not. I would keep the number of repositories as low as possible.
You can easily start with just one repository and move some code to another when needed. This is to make your life within the project as easy as possible.
As most increments require changes both in the API and the UI, it makes sense to treat them as one


So in most cases, you can get by with just one repository for all packages of the same system (e.g. a web app) to the same repository:

my-project/
  ui/
  api/
Enter fullscreen mode Exit fullscreen mode

I tend to use Yarn workspaces when working a project like this. In most cases, you can go without. It is only when you have co-dependent packages that share the same dependencies as React.

Pros of having all subprojects in one repository

  • Much nicer to navigate the project and make changes
  • Easy to come up with descriptive commit messages. "Add a logout feature" vs backend: "Add an endpoint for removing user's session" + frontend: "Add a logout button"
  • You see all changes you've made with git status
  • You can run tests for all projects at once
  • No risk of deploying non-matching / incompatible versions of the project

Cons of using separate repositories:

  • You need to create 2 separate commits for each increment
  • Changes are reviewed in two separate PRs
  • 2 repositories can easily get out of sync when one PR is accepted before the other one is ready
  • "Why isn't this feature working? 🤔" "Ah, I forgot to pull in the latest changes from the backend repo"

Keep these in mind

  • Some tools are not made with monorepos in mind. Especially all tools that build your project (CI tools, static site hosts) sometimes make assumptions of where your "public" directory is. Most of these can be configured these days though. We've had some issues with for example Serverless and monorepos.
  • Should you put all your company's projects under one repository? Probably not. There are no absolutes when it comes to where different packages should be kept and you should discuss it within your team. If 2+ packages depend on each other, they probably belong to the same repo

Top comments (0)