Building an Appointment Booking app in Go
Tags: go, tutorial, microservices, cloud
Published: 2024-01-12 10:23:47

## TL;DR

In this short guide we'll deploy the foundation for an appointment booking app (similar to Calendly) in Go using [Encore](https://encore.dev).

We'll use an example project to get started, and in just a few minutes you will have an app running in Encore's free development cloud — ready for you to keep building on top of.

_If you want to build it yourself step-by-step, check out the complete tutorial [here](https://encore.dev/docs/tutorials/booking-system)._

The finished appointment booking app will look like this:

![appointment booking app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/onr446g1ia409tre8h6s.jpg)

## 🚀 What's on deck
- Install Encore
- Create your app
- Run locally
- Save SendGrid API key using Encore's [secret manager](https://encore.dev/docs/primitives/secrets)
- Deploy to Encore's free development cloud

🏁 Let's go!

## 💽 Install Encore

Install the Encore CLI to run your local environment:
- **macOS:** `brew install encoredev/tap/encore`
- **Linux:** `curl -L https://encore.dev/install.sh | bash`
- **Windows:** `iwr https://encore.dev/install.ps1 | iex`

## Create your app

Let's create our app from a starter template by running:

```
encore app create my-app --example=booking-system
```

This will create an Encore app using a template for an Appointment Booking System.

It has both a user facing section (finding and booking appointments) and an admin section (setting availability and managing scheduled appointments).

The frontend is a React app and the backend is a Go microservices application with an event-driven architecture using [Pub/Sub](https://encore.dev/docs/primitives/pubsub).

When a new appointment is booked, the backend sends a confirmation email to the user (using a Sendgrid integration).

Not implemented in the example:
- Calendar integration with e.g. Google Calendar
- Authentication for admin login

Here's the architecture diagram, generated by Encore:

![Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qlc7y31ifog3dfwx4vj0.jpg)

(White boxes are services, and the black box is a Pub/Sub topic.)

## 🏁 Run the app locally

To run locally you need to have [Docker](https://docker.com) installed and running.

Then run your application:

```bash
encore run
```

You should see this:

![run locally](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zpoexpw418h7jhbxbhuk.jpg)

## 🛠 Open the Local Development Dashboard

While `encore run` is running, open <http://localhost:9400/> to access Encore's [local development dashboard](https://encore.dev/docs/observability/dev-dash).

Here you can see API docs, make requests in the API explorer, and view traces of the responses.

![local dev dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ukjlvs6412dq9dyelmk9.jpg)

## 🖥 Open the app in your browser

While `encore run` is running, head over to <http://localhost:4000/frontend/> to view the frontend for your appointment booking system.

![appointment booking frontend](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zk9em55sms8ja03lzgls.jpg)

## 🔑 Set SendGrid API Key

Before we deploy our app to the cloud, we need to set an API key for the SendGrid integration. We can use Encore's built-in secrets manager to securely store our key.

You will need an [API key from SendGrid](https://docs.sendgrid.com/ui/account-and-settings/api-keys) to use this package. You can get one by signing up for a free account at https://sendgrid.com/.

(Or if you just want to test out the deployment flow, you can just use any random string.)

Once you have the API key, set it as a secret using the name `SendGridAPIKey`.
```bash
encore secret set --dev SendGridAPIKey
```

This sets the key for development environments. It is good practice to separate API keys for development and production environments, so for prod we can set a separate key using:

```bash
encore secret set --prod SendGridAPIKey
```

_Please note that emails will only be sent in the production environment to avoid spending your email sending limits._

PS. You can also use the Secret Manager UI in Encore's [Cloud Dashboard](https://app.encore.dev).

![secret manager](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xad37ktmayssw4jpjvst.jpg)

## 🚀 Deploy to the cloud

Simply **push to deploy** your application to a staging environment in Encore's free development cloud:

```bash
git add -A .
git commit -m 'First commit'
git push encore
```

Then head over to the [Cloud Dashboard](https://app.encore.dev) to monitor your deployment.

Encore will automatically provision all the necessary infrastructure, including compute instances, databases, Pub/Sub, and more.

![infra provisioning in progress detailed view](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cju5oxzuhxzjm4bfyceg.jpg)

![infra provisioning in progress](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pfj3r3hri702qyqkr4d9.jpg)

Once the deploy is completed, you can find your app's URL by opening the `staging` environment in the [Cloud Dashboard](https://app.encore.dev), it will be something like:
`https://staging-my-app-gfoi.encr.app/frontend/`

![Deployed app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9uavx3bllnxxpfb6gvfw.jpg)

**🎉 Great job, you're done!**

You now have a scalable Go based app running in the cloud, ready for you to extend further or use as inspiration for your next project.

## Explore the Cloud Dashboard

From the Cloud Dashboard you can also [connect your own AWS or GCP account](https://encore.dev/docs/deploy/own-cloud) to use for production deployment, connect GitHub, and view [traces](https://encore.dev/docs/observability/tracing), [metrics](https://encore.dev/docs/observability/metrics), and [API docs](https://encore.dev/docs/develop/api-docs) for your cloud environments.

## Wrapping up

- ⭐️ Support the project by [starring Encore on GitHub](https://github.com/encoredev/encore).
- Learn more about building Go apps with Encore using these [Tutorials](https://encore.dev/docs/tutorials).👈
- Find inspiration on what to build with these Open Source [App Templates](https://encore.dev/templates).👈
- If you have questions or want to share your work, join the developers hangout in [Encore's community on Discord](https://encore.dev/discord).👈