This is a mono repo template for building full-stack applications with Turborepo. It includes a frontend and backend application, shared libraries, and utilities. This template is a great starting point for building full-stack applications with TypeScript. It consists of a Next.js frontend, NestJs backend, shared libraries, and utilities.
- Monolith
Create a repository and follow the steps below to use this template project locally.
- Add template on your existing repo using
git remote add template https://github.com/CodingWithDibesh/monolith.gitcommand. - Fetch the template repo using
git fetch templatecommand. - Merge the template branch to your desired branch using
git merge template/[branch-name]
For more information follow the Stack Overflow conversation for more details.
Copy the .env.example file to .env and fill in the necessary environment variables.
cp .env.example .envTo get started, install the dependencies and run following commands:
yarn - Postgres: http://localhost:7001
- Backend: http://localhost:7002
- PGAdmin: http://localhost:7003
- Storybook: http://localhost:7004
- Frontend: http://localhost:7005
Run the following command:
yarn devThis will start the frontend, Storybook.
yarn dev:beThis command will initialize the docker container and backend server. Docker container includes Postgres database, PGAdmin and Backend server.
yarn dev:feThis command will start the frontend server.
yarn dev:uiThis command will start the Storybook server.
To build all apps and packages, run the following command:
yarn buildThis command will build all the packages and apps.
yarn build:beThis command will build the backend application.
yarn build:feThis command will build the frontend application.
Monolith includes the following packages/apps:
frontend: a Next.js appbackend: a NestJs app@repo/ui: a stub React component library forfrontend@repo/shared: a stub utils library shared by bothfrontendandbackendapplications@repo/schemas: a stub library for shared schemas@repo/tailwindcss-config: a stub Tailwind CSS configuration@repo/eslint-config:eslintconfigurations (includeseslint-config-nextandeslint-config-prettier)@repo/typescript-config:tsconfig.jsons used throughout the monorepo
Each package/app is 100% TypeScript.
Monolith has some additional tools already set for you:
- TypeScript for static type checking
- ESLint for code linting
- Prettier for code formatting
To run NestCLI commands, you can use the following command:
yarn workspace backend nest [nest command]Here are some useful Prisma operations you can run in the monorepo.
Make sure you have the necessary environment variables set in the .env file, and the database is running.
To create a migration, run the following command:
yarn workspace backend prisma migrate dev --name [migration name]To run a migration, run the following command:
yarn workspace backend prisma migrate deployTo generate the Prisma Client, run the following command:
yarn workspace backend prisma generateTo seed the database, run the following command:
yarn workspace backend prisma db seedTo setup Bruno click open collections and browse the bruno_docs folder and click open. You should see a monolith collection with all the requests.
The CI/CD pipeline is set up using Github Actions. The pipeline includes the following steps:
- Create an Azure Storage Account
- Go to the Azure Portal.
- Search for Storage Accounts in the search bar and click Create.
- Select your resource group or create a new one.
- Choose a Storage Account Name (this will be used as the subdomain for your static website).
- Choose the Region closest to your users for better performance.
- Under Performance, select Standard.
- Choose StorageV2 (general-purpose v2) for the account kind.
- Under Replication, choose Locally-redundant storage (LRS) for cost-efficiency.
- Click Review + Create and then Create.
- Enable Static Website Hosting
- Once the storage account is created, go to the Storage Account.
- On the left panel, under Data Management, find Static Website.
- Click Enable to turn on static website hosting.
- Set the Index document name (e.g., index.html), and if necessary, the Error document path (e.g., 404.html).
- Click Save.
- Getting Required keys
Install the Azure CLI and login to your Azure account using the following command:
az login- Creating and assigning Role
Create a new role assignment for the storage account using the following command:
az role assignment create --role "Storage Blob Data Contributor" --assignee <your-email> --scope /subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Storage/storageAccounts/<storage-account-name>- Get the Storage Account Key
Run the following command to get the storage account key:
az storage account keys list --account-name <storage-account-name> --resource-group <resource-group-name>- Add the Storage Account Key to Github Secrets
Copy the key1/key2 value and add it into github secrets under Secrets and Variables -> Actions -> Repository secrets.
Create AZURE_STORAGE_KEY and paste the key value.
Similarly, create AZURE_STORAGE_ACCOUNT and paste the storage account name.
- Create a new Azure Database for PostgreSQL server.
- Create a new github secret with the name
DATABASE_URLand paste the connection string. The connection string should look like this:
postgresql://<username>:<password>@<host>:<port>/<database>?sslmode=requireTo ensure your backend service can connect to the PostgreSQL server, you must adjust the network firewall settings.
Backend Hosted on Azure (e.g., Azure App Service, Virtual Machines, Kubernetes):
- Enable Azure Services Access:
- Go to your PostgreSQL Flexible Server in the Azure Portal.
- Navigate to Networking.
- Enable the option Allow Azure services and resources to access this server. This creates a firewall rule that allows all trusted Azure services (like Azure App Service or Azure Kubernetes Service) to access your database without needing to manage IP addresses manually.
Backend Hosted on Non-Azure Platforms (e.g., AWS, GCP, or any other hosting provider): If your backend is hosted on a non-Azure platform (e.g., AWS, DigitalOcean, or any cloud provider):
Identify the Public IP Address of your backend instance. Your hosting provider’s dashboard should display this.
In the Azure Portal:
- Go to PostgreSQL Flexible Server -> Networking.
- Add the public IP address (or a range of IPs) to the allowed list of IP addresses in the firewall settings.
Example:
54.23.43.89 (Your backend's public IP address)Remove IPs when no longer needed: If your backend service IP changes or rotates, you’ll need to update this manually.
Tip: If your backend service uses dynamic IP addresses or is in a different network configuration, using a VPN or a Bastion Host can help maintain a static IP for secure connections.
To create a new release, follow the steps below:
- Merge all the changes to the
mainbranch. - Create a new release by going to the releases page.
- Click on the
Draft a new releasebutton. - Add the tag version and title.
- Add the release notes.
- Click on the
Publish releasebutton. - The release will trigger the CI/CD pipeline and deploy.
Learn more about the power of Turborepo: