Prerequisites for PeerPrep Monorepo:
Yarn: Ensure you have the latest version of Yarn installed. Yarn Workspaces is available in Yarn v1.0 and later.
Installation (if not already installed):
npm install -g yarn
Node.js: Check each application's documentation for the recommended Node.js version.
Git
Docker (If deploying with Docker):
Kubernetes Tools (If deploying with Kubernetes):
Adjust these prerequisites based on the specific requirements of your services / frontend.
/peerprep
├── /services
│ ├── /admin-service (express application)
│ ├── /user-service (express application)
│ ├── /matching-service (express application)
│ ├── /question-service (express application)
│ ├── /collaboration-service (express application)
│ └── /gateway (express application)
├── /frontend
│ └── /pages for peerprep (NextJs application)
├── /deployment
│ ├── /gke-prod-manifests
│ ├── /prod-dockerfiles
│ └── build-export-prod-images.sh
├── /prisma
├── /utils
├── .env (not in git)
├── .env.firebase_emulators_test (not in git)
└── README.md (and other root-level files & docs)
.env
file at the root directory with the following variables:
PRISMA_DATABASE_URL=<redacted>
MONGO_ATLAS_URL=<redacted>
FIREBASE_SERVICE_ACCOUNT=<redacted>
NEXT_PUBLIC_FRONTEND_FIREBASE_CONFIG={"apiKey": <redacted>,"authDomain": <redacted>,"projectId": <redacted>,"storageBucket": <redacted>,"messagingSenderId": <redacted>,"appId": <redacted>}
TWILIO_ACCOUNT_SID=<redacted>
TWILIO_API_KEY=<redacted>
TWILIO_API_SECRET=<redacted>
Note: For NEXT_PUBLIC_FRONTEND_FIREBASE_CONFIG
, the JSON should not have newlines since Next.js may not process it correctly.
The difference between it and FIREBASE_SERVICE_ACCOUNT
are shown below:
Variable | Purpose |
---|---|
FIREBASE_SERVICE_ACCOUNT | For backend verification and administrative tasks |
NEXT_PUBLIC_FRONTEND_FIREBASE_CONFIG | For the frontend to connect to Firebase |
pip install pre-commit
pre-commit install
This step requires Git to be installed.
Disclaimer: There is no guarantee that all secrets will be detected. As a tip, if you think a file will eventually store secrets, immediately add it to .gitignore upon creating it in case you forget later on when you have a lot more files to commit.
Installing Dependencies: From the root directory (/peerprep
), run:
yarn install
or
yarnpkg install
(if you have hadoop yarn installed)
If you want to use the exact yarn.lock
versions without any modification, add a --frozen-lockfile
flag to the
command.
This command will install dependencies for all services and the frontend in a
centralized node_modules
directory at the root as well as within the respective directories.
Adding Dependencies: To add a dependency to a specific workspace (e.g.,
user-service
), use:
yarn workspace user-service add [dependency-name]
Initializing Prisma: In the root file, run the following:
yarn prisma generate ## Do this whenever we change the models in schema.prisma
Running Backend Scripts: To run a script specific to a workspace (e.g.,
the start
script for user-service
), use:
yarn workspace user-service start
Running Frontend Scripts: To run the frontend cod, use:
yarn workspace frontend dev ## For development
# or
yarn workspace frontend build ## For first time setup run the build command
yarn workspace frontend start ## For subsequent runs
Running everything at once: To run everything at once and still maintain the ability to hot-reload your changes, use:
./start-app-no-docker.sh # on mac /linus
# You can also use the above command on Windows with Git Bash
Docker and Docker Compose are used to set up a simulated production build (meaning that the Docker images and containers that will be spun up locally are almost identical to those in the production environment, with the exception of some environment variables).
NOTE: Do not run both Docker and No Docker at the same time. This will cause port conflicts.
yarn docker:build
This will create new Docker images.
yarn docker:devup
This will start all the containers.
Run the start-app-with-docker.sh script: From the root repo, run
./start-app-with-docker.sh # on mac / linus
# You can also use the above command on Windows with Git Bash
This will create new Docker images everytime it is run. Be careful of how much disk space you have left.
yarn docker:devdown
This will stop and delete all the containers. You must run this to delete containers regardless of whether you used
./start-app-with-docker.sh
or yarn docker:devup
.
Any edits you make to the source code will not be automatically reflected on the site. We recommend using Docker Compose to check if your changes are likely to work on the production environment once they have been proven to work in your local development environment.
Access to remote databases may be blocked when using NUS WiFi. You will need a VPN to overcome this limitation if you are running the local app on campus.
Next steps:
The Firebase Local Emulator Suite is used to support automated testing of any Firebase-related functionality.
The following files at the project root define the Firebase project as well as the emulators used:
.firebaserc
- The Firebase project definitionsfirebase.json
- The emulators that are usedFor local testing, the file used for passing in environment variables has to be named:
.env.firebase_emulators_test
This file should contain the following environment variables:
FIREBASE_AUTH_EMULATOR_HOST="127.0.0.1:9099"
FIREBASE_SERVICE_ACCOUNT={insert secret JSON value here}
In the CI environment, the environment variables have to be defined separately. For example, FIREBASE_SERVICE_ACCOUNT will be passed in as a secret on GitHub Actions.