mern-monorepo-starter
is a GitHub template designed to kickstart your next TypeScript 5 project, offering an opinionated, ready-to-use monorepo structure that takes care of all the tricky configuration for you.
The following packages are implemented and at your disposal:
- app-node-express [TS Compiler, NodeJS, Express API, MongoDB, Keycloak, Railway]
- app-vite-react [Vite, ReactJS, Railway]
- lib-api-client [TS Compiler, ts-rest]
- lib-commons [TS Compiler]
TOC
- 🧐 What is
mern-monorepo-starter
? - 🔧 Prerequisites
- 💻 Installation
- 🚢 Deploy
- 🧩 Recommended VSCode extensions
- PNPM
- Node.js
- Git
- VS Code (Optional)
-
Configure GitHub permissions
Enable GitHub actions to create and approve pull requests.- Go to Settings > Actions > General > Workflow permissions
- Enable the following settings:
- ✅
Read and write permissions
- ✅
Allow GitHub Actions to create and approve pull requests
- ✅
- Save changes.
-
Configure GitHub actions
Run existing actions for the first time.- Go to Actions > typedoc-generator.yml
- Click on the
Run workflow
button. - Repeat the process for all
test-
prefixed workflows. - After all workflows finish, navigate to Settings > Pages.
- Select the
gh-pages
branch as the deployment source. - Save changes.
-
Configure GitHub ci
Configure branch protection rules to prevent direct pushes to themain
branch, require pull requests for merging, and all status checks to pass before merging.- Set the branch name pattern to
main
. - Enable the following settings:
- ✅
Require a pull request before merging
- ✅
Require status checks to pass before merging
- ✅
Require branches to be up to date before merging
- ✅
- Disable the setting:
- ❌
Require approvals
- ❌
- Select the following workflows as required for all pull requests:
- test-app-node-express
- test-app-vite-react
- test-lib-commons
- test-lib-api-client
- Save changes.
- Set the branch name pattern to
-
Unpack files to a desired destination
-
Run Keycloak in dev mode
sh [PATH_TO_KC]/bin/kc.sh start-dev
-
Add admin user (realm-level)
- Open http://localhost:8080 to access Keycloak admin GUI
- Enter your admin user credentials (which you use for your future logins)
- Save and login to Keycloak admin GUI
-
Create a client for your app
- Navigate to Clients > Create client
- Enter client data
- Client type: OpenID Connect
- Client id: app-vite-react
- Client authentication: Off
- Authorization: Off
- Authentication flow: Standard flow, Implicit flow & Direct access grants
- Valid redirect URIs: *
- Valid post logout redirect URIs: *
- Web origins: *
- Save client
-
Add roles to your app client
- Open app-vite-react client
- Navigate to Roles tab
- Click on Create role
- Add the following roles:
- avr-admin
- avr-user
-
Set role avr-admin on admin user
- Open admin user details
- Navigate to Role mapping tab
- Click on Assign role and select avr-admin role
-
Configure admin-cli client
- Open admin-cli client details
- On Settings tab choose the same options as defined in 2nd step with exception of setting Client authentication to On and also checking the Service accounts roles checkbox
- On Credentials tab choose Client Authenticator: Client Id and Secret and generate a Client Secret
- Copy the secret, you will put it in project's .env file
- Save changes
-
Clone to local machine
Clone previously created repository into your local machine.git clone https://github.com/YOUR_USER/YOUR_REPO.git
-
Install dependencies
Install dependencies withpnpm
.pnpm install
-
Configure environment variables
Configure.env.development.local
variables for app-node-express (see full env schema defined at @org/app-node-express/env)SERVER_SESSION_SECRET Your server session secret string KEYCLOAK_ADMIN_CLI_SECRET Your Keycloak admin-cli secret -
Run a sample app locally
You can now run your app-node-express with:pnpm run app-node-express:dev
-
Create new Railway project
Create a new project through Railway's dashboard and connect it to your GitHub monorepo -
Import template to your Railway project
- Within the project, select
+ Create
and chooseFrom Template
- Select
mern-monorepo-starter
- Follow through with setup (and environment variables)
- Within the project, select
-
Deploy
Deploy all project changes by clickingDeploy
button 🚀