Skip to content

Instantly share code, notes, and snippets.

@rikukissa
Last active September 10, 2023 14:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rikukissa/726bb514d42a85fbb43bd9e70c25f3db to your computer and use it in GitHub Desktop.
Save rikukissa/726bb514d42a85fbb43bd9e70c25f3db to your computer and use it in GitHub Desktop.
Should I have my UI and my API in separate repositories?

Should I have my UI and my API in separate repositories?


Keep the number of repositories as small 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



Put all subprojects of the same system (e.g. a web app) to the same repository:
my-project/
  ui/
  api/

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 subprojects 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 having all projects in one repository

  • 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 tho.
  • If you are building a multipurpose standalone API meant to be used in many projects (that cannot be in the same monorepo), this might not be the best approach. I'd suggest you use a monorepo if the subprojects are clearly linked and depend on each other.

Cons of using 2 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment