Setup
Compass is a monorepo that contains everything needed to get a calendar app up and running, including frontend, backend, database, and dev scripts.
By the end of this guide, you'll have a local development environment that has:
- a running NodeJS API server, which'll hot-reload upon changes
- a running React web app, which'll also hot-reload upon changes
- a MongoDB instance with your calendar data
- a CLI, which you can use to create a distributable artifact
package.jsonscripts to run local tests
You'll then be ready to play with the local web app and test any changes you'd like to make.
Ready? Let's go!
Get the Code
-
Clone the repo:
git clone https://github.com/SwitchbackTech/compass.git
cd compass
Setup the .env files
This is the file that contains your custom and sensitive information. We're creating the file now so we can update the values as we set up our third-party accounts.
- Copy
compass/packages/backend/.env.local.exampleand save ascompass/packages/backend/.env.local. - Read through the comments to familiarize yourself with the environment variables.
- If you plan on deploying Compass to a production environment, also create
.env.stagingand.env.productionfor further separation of environments.
Setup Accounts
Compass relies on a few external services. Let's start by creating accounts for those and adding the credentials to that environment file.
Google OAuth
Compass uses the Google Calendar API to import and sync events from GCal.
Google APIs require authentication through OAuth.
To use Google OAuth, create a Google Cloud Platform project and setup an OAuth screen.
- Create a Google Cloud account
- Create a project
- Configure your OAuth consent screen for internal testing
- Set the User type to
Externaland status toTesting - Add your test Google accounts to the list of authorized users
- You don't have to manually add scopes -- the Compass code does that for you (
Login.tsx)
- Set the User type to
- Get Google API Client ID & Secret
- Go to Credentials in your Google Cloud project
- Create an OAuth Client ID
- Select Web Application
- Add to Authorized JavaScript origins:
http://localhost:9080 - Add to Authorized redirect URIs:
http://localhost:3000 - Copy the Client ID and Secret to your
.env.localfile
- Enable the Google Calendar API in your GCP project
- Navigate to the API Library in your Google Cloud project
- Use the search bar at the top of the page to search for "Google Calendar API"
- Click on "Google Calendar API" from the search results
- Click the "Enable" button to activate the API for your project
- Wait for the API to be enabled (this usually takes a few seconds)
- Once enabled, you'll see a confirmation message and can verify the API is active by checking the Enabled APIs page
MongoDB
MongoDB Overview
Before using Mongo db, ensure you create a free MongoDB Atlas account that allows you to create a Mongo db database, which is the easiest and quickest way to get started with Mongo without needing to install it locally.
User data is stored across a few MongoDB collections. These collections are created automatically at runtime, so you just have to create an account to get started.
Instructions
Compass connects to MongoDB through the NodeJS driver.
- Create a free MongoDB Atlas account
- Get your Node.js driver connection string
- When you get your connection string, scroll down to the Network access in the left sidebar and add your current ip address. Make sure you always include your ip address when you switch networks because your device ip v4 address changes from one ISP to another and from time to time.
- Add connection string to your
.env.localfile - Recommended: Install MongoDB Compass desktop app to visually inspect and manage your database during local development. You can connect to your MongoDB Atlas instance using the same connection string from your
.envfile.