A powerful backend ready for your next app 🚀
Tags: backend, docker, javascript, cloud
Published: 2020-11-28 01:05:35

I am a primarily frontend developer. 

Whenever I start a new project I keep going into the dilemma of:
- Which backend?
- Which database?
- Which hosting provider? 
- Which complexity for the cloud service provider will I have to go through this time?
- What if I need later on to move to another provider?
- Should I go serverless?
- Do I need authentication? should I use a 3rd party service for that?
- How to handle HTTPS certificates issuing and renewal?
- How about the CI/CD setup?
- How to get a convenient local development environment that also matches production deployment?

Services like Firebase and AWS Amplify, have always been appealing. However, I felt uncomfortable with having marked restrictions on the database design (with lots of de-normalization) because of pay-per-read model. I know, I know, this is how NoSQL works, but still I was not happy. In addition, I do not want to [pay $30K in 72 hours because of a coding mistake](https://hackernoon.com/how-we-spent-30k-usd-in-firebase-in-less-than-72-hours-307490bd24d). And then [not be able to do a basic full-text search](https://firebase.google.com/docs/firestore/solutions/search)!

Serverless can be very cost-effective on small scale but can be quite expensive on large scales. I want to have a predictable budget.

In addition, the ease of local development with a cloud backend was concerning. There are many good solutions or workarounds for all of these questions, but none felt as easy and flexible for the requirements of different projects.

All of that, and we have not even started talking about what I care about most, my app!

Frontend development has become complex enough to also get distracted by all of these questions.

Recently, I have come across [Parse server](https://github.com/parse-community/parse-server). It is a project that was acquired by Facebook (parse.com) and was later open-sourced when they decided to stop providing the cloud service. It is such a nice project that ticks nearly all my boxes.

So, I created a monorepo starter project that is managed by [Docker Compose](https://docs.docker.com/compose/) which runs the feature-rich ready-to-use setup that works out of the box for local development and can be easily deployed.

You can find it on github: 

{% github hatemhosny/parse-starter no-readme %}

## Feature Summary 

- **[Parse server](https://github.com/parse-community/parse-server)**: Backend-as-a-Service (BaaS) that features:
  - [SDKs](https://parseplatform.org/#sdks) for popular platforms
  - [REST API](https://docs.parseplatform.org/rest/guide/)
  - [Graphql API](https://docs.parseplatform.org/graphql/guide/)
  - [LiveQuery](https://docs.parseplatform.org/parse-server/guide/#live-queries) for realtime apps
  - Security features including authentication, [users](https://docs.parseplatform.org/js/guide/#users), [roles](https://docs.parseplatform.org/js/guide/#roles), [access control lists (ACL)](https://docs.parseplatform.org/rest/guide/#object-level-access-control) and [class-level permissions (CLP)](https://docs.parseplatform.org/rest/guide/#class-level-permissions)
  - [3rd party authentication](https://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication)
  - [Push notifications](https://docs.parseplatform.org/parse-server/guide/#push-notifications)
  - Adapters for [file storage](https://docs.parseplatform.org/parse-server/guide/#configuring-file-adapters) and [caching](https://docs.parseplatform.org/parse-server/guide/#configuring-cache-adapters)
  - [Analytics](https://docs.parseplatform.org/rest/guide/#analytics)
  - [Cloud code](https://docs.parseplatform.org/rest/guide/#cloud-code) for custom server-side logic
  - [Web hooks](https://docs.parseplatform.org/rest/guide/#hooks)
  - Runs on top of [Express](https://expressjs.com) allowing the use of Express middleware
  - Comprehensive [documentation](https://docs.parseplatform.org/)
  - Large [community](https://github.com/parse-community)
- **[MongoDB](https://www.mongodb.com)** database.
- **[Parse dashboard](https://github.com/parse-community/parse-dashboard)** (optional): a powerful dashboard for managing the parse server.
- **API-First Headless CMS** (optional): using [chisel-cms](https://chiselcms.com).
- A sample realtime **frontend app**.
- **Automatic HTTPS** for the frontend and backend using [Caddy server](https://caddyserver.com).
- Reproducible setup using **[Docker](https://www.docker.com/)** containers managed by a single **[Docker Compose](https://docs.docker.com/compose)** file.
- **Local development workflow** with hot reload for frontend and backend.
- **Easy deployment**.
- **CI/CD** ([continuous integration and deployment](https://www.atlassian.com/continuous-delivery/principles/continuous-integration-vs-delivery-vs-deployment)): using [github actions](https://docs.github.com/en/free-pro-team@latest/actions).
- Optional **deployment to multiple environments** (e.g. development, staging and production).
- Highly **configurable**.
- The whole stack is **open source** with no vendor lock-in or pay-per-request restrictions.

## Getting Started

Run the shell command:

```sh
docker-compose up
```

By default, the following will be served:

- parse server backend: <span>https:</span>//localhost:1337/api
- parse graphql API: <span>https:</span>//localhost:1337/graphql
- parse dashboard: <span>https:</span>//localhost:1337/dashboard
- frontend local dev server (with HMR): <span>https:</span>//localhost:1234

After [production build](https://github.com/hatemhosny/parse-starter#production-build):

- frontend app: <span>https:</span>//localhost

When [CMS is enabled](https://github.com/hatemhosny/parse-starter#headless-cms):

- chisel CMS: <span>https:</span>//localhost:1337

Now you can edit/replace the app in the `frontend` directory and start building your own app making use of the feature-rich backend.

## Deployment

Docker and Docker Compose significantly simplify deployment. All the setup and dependencies are already taken care of in the docker images.

So, in principle, the steps required for deployment are:

- Defining the variables for the deployment environment.
- Building the docker images and verifying them.
- Running the containers on the host server.

Although this can be done manually, it is greatly simplified using the included automated CI/CD setup that uses github actions.

### Quick Start

Assuming you can connect using SSH to your server which has Docker and Docker Compose installed (see [Server Setup](https://github.com/hatemhosny/parse-starter#server-setup)), and that you have a github personal access token (see [Container Registry](https://github.com/hatemhosny/parse-starter#container-registry)), add the following [Github Secrets](https://github.com/hatemhosny/parse-starter#github-secrets):

- PROD_DOCKER_REGISTRY_TOKEN: your personal github access token
- PROD_SSH_HOST: your server IP address
- PROD_SSH_KEY: your server SSH private key
- PROD_ENV_VARS: edit the following example with your values

  ```
  HOST_NAME=mywebsite.com
  APP_ID=myappid
  MASTER_KEY=mymasterkey
  PARSE_DASHBOARD_USER_ID=user
  PARSE_DASHBOARD_USER_PASSWORD=pass
  ```

  Note: The environment variable `HOST_NAME` is required for remote deployment.

Now pushing code to main/master branch should trigger build and deploy to your server. Note that you can follow the progress and read logs of CI/CD workflows on the "Actions" tab in the gihub repo.

## That's it!

You have launched your powerful backend locally and deployed it within a few minutes.

You can find the documentation and configuration details in the github repo: [https://github.com/hatemhosny/parse-starter](https://github.com/hatemhosny/parse-starter)

This is clearly not the magic bullet that solves all the problems of the world, but it has made my life easier, and I hope it makes yours too.

Please let me know your suggestions/advices/comments, and I would be very grateful for contributions.

Happy coding, go build some great apps!