Skip to content

Structure repo as workspaces for creation of "shared" package#604

Open
benkoppe wants to merge 9 commits intomasterfrom
bek76/shared_folder
Open

Structure repo as workspaces for creation of "shared" package#604
benkoppe wants to merge 9 commits intomasterfrom
bek76/shared_folder

Conversation

@benkoppe
Copy link
Contributor

@benkoppe benkoppe commented Oct 27, 2025

Summary

This PR makes some changes to the overall structure of the codebase, bringing it more in line with modern standards for monorepos.

Context: The npm workspaces feature was created for use in codebases exactly like ours: with a main package.json on the outside, with more specific package.json files in each subfolder to define separate packages. Currently, each package.json is separate: they get their own package-lock.json and node_modules. This makes it hard to share files.

In this PR, the main package.json's name of carriage-web is used as a base for the workspace. The backend is renamed from carriage-web-backend to @carriage-web/server, while the frontend is renamed from carriage-web to @carriage-web/frontend. In this new structure, a single package-lock.json and node_modules is stored in the primary carriage-web folder, allowing for deduplication.

This change also allows for the easy creation of a new package, shared. This shared gets its own package.json, so it can have its own dependencies, and is imported by the frontend and backend. As a result, type and enum definitions that are meant to be shared between the two packages are moved to this shared package. In the frontend and backend, the dependency is defined with a asterisk "*", telling npm to use local copy of the package in the workspace:

package.json

"dependencies": {
    "@carriage-web/shared": "*",
    ...
},

file.ts

import { RideType } from '@carriage-web/shared/types/ride';

CAUTION: We must be careful to avoid placing sensitive code in the shared package, as it can be seen by users!

  • modify codebase to use workspaces
  • create shared package and migrate shared types from backend
  • remove duplicated types from frontend and replace imports with shared
  • fully test that things still work properly with this setup:
    • for example, enums don't seem to work well across the shared barrier with Create React App. This problem is fixed when using Vite, however. For that reason, we might want to consider Replace Create React App with Vite #605 before this PR.

Test Plan

Typescript's linting and compiling should be very useful in testing that this migration was successful. However, we will also need to manually comb through the webpage and make sure things are still working with this change, especially pieces of shared code that convert to real javascript such as functions and enums.

Breaking Changes

  • Removal of previously used package-lock.json folders in favor of a single consolidated file. Could this have caused multiple packages to upgrade? I'm not sure.
  • Devs will need to delete their separate node_modules folder, as this change also deduplicates that folder.
  • These changes could have unknown consequences on the CI (such as the building of docker images), and this will need to be checked

@benkoppe benkoppe requested a review from a team as a code owner October 27, 2025 02:56
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@dti-github-bot
Copy link
Member

[diff-counting] Significant lines: 948.

Base automatically changed from dka34/changes to master November 2, 2025 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants