App Build Flow
This document outlines the steps required to build and deploy the applications in our monorepo. The structure of the repository and the build process are described below.
📁 Repository Structure
Our monorepo is organized as follows:
🗂️ Folder Structure
Here's a brief overview of the folder structure:
/apps
/backend # Contains the NestJS application (APP1)
/comdeall-admin # Contains the Next.js application (APP2)
/comdeall-mobile # Mobile application (APP3)
/documentation # Documentation docusaurus application
/libs/shared # Shared code between apps (utils, models, services, etc.)
/k3s # k3s[kubernetes] specific file
/package.json # Root package.json for managing dependencies
/tsconfig.base.json # Shared TypeScript configuration
/.prettierrc # Prettier configuration
/eslint.config.js # ESLint configuration
/playwright.config.js # Playwright configuration
🛠️ Build Process
1. Install all dependencies for the monorepo
npm install
2. Generate schema for the backend application
yarn backend:prisma-generate
4. Build Applications
You can build the specific application using the commands below in the root directory:
Frontend (Next.js application)
yarn gen
Build the Next.js frontend application
yarn build
Alternative build command using workspace
yarn start
Alternative build command using workspace
Backend (NestJS application)
yarn backend:build
Build the NestJS backend application
export DOCTL_ACCESS_TOKEN=${DOCTL_TOKEN}
echo "${DOCTL_TOKEN}" | docker login registry.digitalocean.com -u doctl --password-stdin
docker build -f prod.Dockerfile -t ${DOCKER_IMAGE}:${DOCKER_TAG} .
docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:${COMMIT_HASH}
docker push ${DOCKER_IMAGE}:${COMMIT_HASH}
docker push ${DOCKER_IMAGE}:${DOCKER_TAG}
Docker build and push commands
export DOCTL_ACCESS_TOKEN=${DOCTL_TOKEN}
echo "${DOCTL_TOKEN}" | docker login registry.digitalocean.com -u doctl --password-stdin
if kubectl get secret docker-creds -n comdeall >/dev/null 2>&1; then
echo "Deleting existing docker-creds secret..."
kubectl delete secret docker-creds -n comdeall
else
echo "docker-creds secret not found. Skipping deletion."
fi
kubectl create secret docker-registry docker-creds --namespace comdeall --docker-server=${REGISTRY_URL} --docker-username=doctl --docker-password=${DOCTL_TOKEN}
kubectl apply -f backend/configmap.yml
kubectl apply -f backend/manifest.yml
kubectl patch deployment backend-prod -n comdeall -p "{"spec":{"template":{"metadata":{"annotations":{"kubernetes.io/change-cause":"Triggered rolling update ${currentDate}"}}}}}"
kubectl apply -f backend/manifest.yml
kubectl rollout status deployment/backend-prod -n comdeall
Kubectl commands to deploy the backend application to the production environment
Hasura (graphQL application)
export DOCTL_ACCESS_TOKEN=${DOCTL_TOKEN}
echo "${DOCTL_TOKEN}" | docker login registry.digitalocean.com -u doctl --password-stdin
if kubectl get secret docker-creds -n comdeall >/dev/null 2>&1; then
echo "Deleting existing docker-creds secret..."
kubectl delete secret docker-creds -n comdeall
else
echo "docker-creds secret not found. Skipping deletion."
fi
kubectl create secret docker-registry docker-creds --namespace comdeall --docker-server=${REGISTRY_URL} --docker-username=doctl --docker-password=${DOCTL_TOKEN}
kubectl apply -f backend/configmap.yml
kubectl apply -f backend/hasura-manifest.yml
kubectl patch deployment hasura-graphql -n comdeall -p "{"spec":{"template":{"metadata":{"annotations":{"kubernetes.io/change-cause":"Triggered rolling update ${currentDate}"}}}}}"
kubectl apply -f backend/hasura-manifest.yml
kubectl rollout status deployment/hasura-graphql -n comdeall
Kubectl commands deploy hasura to the production environment
secret="--admin-secret="$( npm run --silent hasura:secret )
hasura metadata apply $secret
hasura migrate apply --database-name comdeall $secret
hasura metadata apply $secret
hasura metadata reload $secret
Hasura migration steps
Docs (Docusaurus application)
yarn workspace documentation clear
yarn docs:build
yarn serve
Docs deployment commands
🌍 Environments and Key Considerations
- The production environment uses a Jenkins pipeline for automation.
- Jenkins automatically picks up the .env for frontend services. If you want to build this manually, please visit the Env management section for more details.
- The pipeline clones the repository, installs dependencies, and runs the build commands for the required application.
- The project is cloned from the repo and built on-the-fly. For more details, visit the pipeline section of production.
- The project is cloned from the repo and built on-the-fly. For more details, visit the pipeline section of production 12345
🐳 Docker Usage
For production, we are using Docker for containerization, which does not rebuild but simply copies the build folder and installs that particular app's dependencies. The Docker image is then pushed to the repository, and this step is handled by the Jenkins pipeline. For more information, refer pipeline section.
📋 Quick Reference Commands
Global Commands
| Command | Description |
|---|---|
npm install | Install all dependencies for the monorepo |
yarn backend:prisma-generate | Generate schema for the backend application |
Application Build Commands
Frontend
| Command | Description |
|---|---|
yarn gen | Build the Next.js frontend application |
yarn build | Alternative build command using workspace |
yarn start | To start the frontend application |
Backend
| Command | Description |
|---|---|
yarn backend:build | Build the NestJS backend application |
export DOCTL_ACCESS_TOKEN=${DOCTL_TOKEN} | Export doctl token |
echo "${DOCTL_TOKEN}" | docker login registry.digitalocean.com -u doctl --password-stdin | Authenticate to Docker registry |
docker build -f prod.Dockerfile -t ${DOCKER_IMAGE}:${DOCKER_TAG} . | Build docker image |
docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:${COMMIT_HASH} | Tag docker image |
docker push ${DOCKER_IMAGE}:${COMMIT_HASH} | Push docker image with commit hash |
docker push ${DOCKER_IMAGE}:${DOCKER_TAG} | Push docker image |
kubectl create secret docker-registry docker-creds --namespace comdeall --docker-server=${REGISTRY_URL} --docker-username=doctl --docker-password=${DOCTL_TOKEN} | Create new docker-registry secret |
kubectl apply -f backend/configmap.yml | Apply configmap |
kubectl apply -f backend/manifest.yml | Apply backend manifest |
kubectl patch deployment backend-prod -n comdeall -p "{"spec":{"template":{"metadata":{"annotations":{"kubernetes.io/change-cause":"Triggered rolling update ${currentDate}"}}}}}" | Trigger rolling update |
kubectl rollout status deployment/backend-prod -n comdeall | wait for rollout |
Hasura
| Command | Description |
|---|---|
export DOCTL_ACCESS_TOKEN=${DOCTL_TOKEN} | Export doctl token |
echo "${DOCTL_TOKEN}" | docker login registry.digitalocean.com -u doctl --password-stdin | Authenticate to Docker registry |
kubectl create secret docker-registry docker-creds --namespace comdeall --docker-server=${REGISTRY_URL} --docker-username=doctl --docker-password=${DOCTL_TOKEN} | Create new docker-registry secret |
kubectl apply -f backend/configmap.yml | Apply configmap |
kubectl apply -f backend/hasura-manifest.yml | Apply hasura manifest |
kubectl patch deployment hasura-graphql -n comdeall -p "{"spec":{"template":{"metadata":{"annotations":{"kubernetes.io/change-cause":"Triggered rolling update ${currentDate}"}}}}}" | Trigger rolling update |
kubectl rollout status deployment/hasura-graphql -n comdeall | wait for rollout |
secret="--admin-secret="$( npm run --silent hasura:secret ) | Fetch admin secret |
hasura metadata apply $secret | Apply metadata |
hasura migrate apply --database-name comdeall $secret | Apply migrations |
hasura metadata reload $secret | Reload metadata |
Docs
| Command | Description |
|---|---|
yarn workspace documentation clear | Clear the workspace |
yarn docs:build | Build the docs application |
yarn serve | Start docs application |
🔗 Related Documentation
- Environment Management: Details about managing environment variables and configurations (See Env management section)
- Pipeline Documentation: Detailed information about the CI/CD pipeline process (See pipeline section of production)
⚠️ Important Notes
- Always run commands from the root directory unless specified otherwise
- Ensure all dependencies are installed before building applications
- For production builds, the Jenkins pipeline handles the entire process automatically
- Manual builds are possible but require proper environment configuration
- Each application may have multiple build command options - choose the one that fits your workflow
Generated: 2025-11-21T12:58:11Z
Project: ComDEALL
Repository Type: Monorepo