> ## Documentation Index
> Fetch the complete documentation index at: https://docs.boringdatabase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Start building your boring database in 5 mins

## Setup your development environment

Learn how to pull the boring database repo and start building your own data service app.

## Requirements

You should already have your accounts setup for Resend, Fly.io and Stripe so we can access the required envrionment variables for these services.

<CardGroup cols={3}>
  <Card title="Emails" icon="envelope" href="/emails/resend">
    Setup Resend for One-Time-Login code emails, and subscription success.
  </Card>

  <Card title="Stripe" icon="stripe" href="payments/stripe">
    Setup Stripe account for subscription payments and one-time payments.
  </Card>

  <Card title="Fly.io" icon="fly" href="/deploy/fly">
    Setup Fly.io account and CLI for easy deployment.
  </Card>
</CardGroup>

## Steps

There a few steps to follow closely when setting up your boring database for the first time. But we should be up and running in no time!

### 1. Get the Repo

<AccordionGroup>
  <Accordion icon="github" title="Clone the boring database repo">
    Ensure you have added your github profile through the boringdatabase
    dashboard. [dashboard](https://boringdatabase.com/dashboard/repo). If you
    have successfully been added as a collaborator, you can clone the repository
    locally by following these
    [instructions](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository)
    in your terminal.

    Once you have cloned the repo, navigate to the root directory and open in VScode, run `npm i` to install all dependecies
  </Accordion>
</AccordionGroup>

### 2. Set up local SQlite Database

If you've never setup a SQLite database before, we recommend checking out this [tutorial](https://www.sqlitetutorial.net/getting-started/what-is-sqlite/) to learn more about it.

If you are using brew you can install sqlite with `brew install sqlite` and create a new database with `sqlite3 sqlite.db`.

When you deploy your app, the dockerfile with let Fly will create it's own sqlite.db file.

### 3. Set environment variables

<AccordionGroup>
  <Accordion icon="code" title="Set environment variables">
    Navigate to the .env in the repository and make sure you set your values for
    all the 3rd party services.
  </Accordion>
</AccordionGroup>

### 4. Seed local SQlite with Prisma

Now you have your .env file set, you can setup your local sqlite database by running first migration of prisma and seed the database with permissions, roles, and admin user.

This seed file will also create products in your stripe dashboard. Please ensure you are using the `test` environment vairables for your stripe account until you are ready to go live!

To see how the seed file works/make any changes navigate to the `prisma/seed.ts`

`npx prisma migrate dev --name init` - will run the initial migration

`npx prisma migrate reset` - this will force the seed.ts file to run and load your database with data.

You should see success messages logged to the console.

To check the seed has worked you can run `npx prisma studio` in a new terminal window to start a database UI and explore the tables and records created.

### 5. Start local environment

If your data has been successfully seeded you can run `npm run dev` in the terminal to start your app.

You can click one of the purchase buttons to test stripe checkout is correctly linked up.

Or try login with `admin@admin.com` at [Login](http://localhost:3000/auth/login) no One time passcode is sent via email for admin user, you can grab the passcode from the terminal of the running app.

## Going live

By this point you should be able to go ahead and customize your boring database app, adding a custom landing page and loading in your dataset.

But when you are ready to deploy for the first time here are the steps:

### 1. Keeping Local and Production Stripe in sync

The `prisma/seed.ts` should keep prices in sync for you.

If you ever need to reset your database for a clean start locally you can run `npx prisma migrate reset --force`.
This will remove all the data from the sqlite database and force the seed.ts file to run again.
The seed.ts file will fetch products from stripe and populate your plans and products.

### 2. Launch a new Fly app

Navigate in the terminal to the root of your project and run `fly launch`. You can
follow the prompts to create a new fly app.

If you have not logged into fly through the CLI before you will be prompted to login.

In the Fly CLI you'll see your app being built from the dockerfile. Once it has been deployed you can run `fly apps open` in the terminal to open up a browser window with your new app.

## Next Steps

That covers the basics of getting your app setup, running locally and deploying to Fly.

When make any changes you can use `fly deploy` to rebuild and push your new changes to production.

We can do better than that though! In our next step we will cover setting up a Github Action for running tests and deploying our app to fly automatically.

<CardGroup cols={2}>
  <Card title="Github Actions" icon="github" href="/deploy/github">
    Configure your Github Actions for automatic deployment.
  </Card>

  <Card title="Advanced Fly Tips" icon="fly" href="/deploy/tips">
    Some handy tips for naviagting and maintaining your fly app.
  </Card>
</CardGroup>
