GraphQL API and Relay Starter Kit
Features
- Monorepo project structure powered by Yarn with PnP
- GraphQL API using code-first development approach (TypeScript, GraphQL.js, Google Cloud SQL)
- Authentication and authorization powered by Google Identity Platform
- Database tooling β seed files, migrations, Knex.js REPL shell, etc.
- Front-end boilerplate pre-configured with TypeScript, Vite, React, Relay, and Materia UI
- Serverless deployment β
api
,img
β Cloud Functions,app
β Cloudflare Workers - Deployment to CDN edge locations, all ~100 points on Lighthouse
- Pre-configured dev, test / QA, production, and preview environments
- Pre-configured VSCode code snippets and other VSCode settings
- The ongoing design and development is supported by these wonderful companies:
This project was bootstrapped with Relay Starter Kit. Be sure to join our Discord channel for assistance.
Directory Structure
βββ
.github
β GitHub configuration including CI/CD workflows
βββ
.vscode
β VSCode settings including code snippets, recommended extensions etc.
βββ
api
β GraphQL API and authentication (Could SQL, Cloud Functions, GraphQL.js)
βββ
app
β React / Relay web application with CDN rendering (Vite, Cloudflare Workers)
βββ
db
β database schema, seeds, and migrations (Cloud SQL, Knex.js)
βββ
edge
β Cloudflare Workers CDN endpoint (reverse proxy)
βββ
env
β environment variables that are used for local development (local
, test
, prod
)
βββ
img
β dynamic image resizing (Cloud Functions, Cloud Storage)
βββ
infra
β cloud infrastructure configuration (Terraform)
βββ
scripts
β automation scripts shared across the project
βββ ...
β add more packages such as worker
, admin
, mobile
, etc.
Requirements
- Node.js v18 or newer with Corepack enabled
- Local or remote instance of PostgreSQL (see Postgres.app, Google Cloud SQL)
- VS Code editor with recommended extensions
Getting Started
Just clone the repo
and run yarn install
followed by yarn start
:
$ git clone https://github.com/kriasoft/relay-starter-kit.git example
$ cd ./example # Change current directory to the newly created one
$ yarn install # Install project dependencies
$ yarn setup # Configure environment variables
$ yarn db:reset # Create or update PostgreSQL database
$ yarn api:start # Launch GraphQL API and authentication server
$ yarn app:start # Launch React/Relay front-end app
The API server must become available at http://localhost:8080/api.
The web application front-end must become available at http://localhost:5173/.
How to Deploy
Before you can deploy the app, ensure that the target
GCP project exists
and that all the environment variables (found in /env/*.env
files) are
up-to-date, for both test
(QA) and prod
(production) environments.
If you just created a brand new GCP project, you can configure it by running:
$ yarn gcp:setup --env=test
$ yarn gcp:setup --env=prod
OR, by using Terraform (found in /infra
), which one is more
convenient for you.
Once a new commit or PR lands onto the main
(or, release
) branch, it's going
to be deployed automatically using a GitHub Actions workflow. Alternatively,
you can deploy the app manually by running:
# Build and deploy the GraphQL API (GCF)
$ yarn api:build
$ yarn api:deploy --env=prod
# Build and deploy the web front-end to Cloudflare Workers (CDN)
$ yarn app:build
$ yarn app:deploy --env=prod
# Migrate the target database to the latest version
$ yarn db:migrate --env=prod
Where --env=prod
is the target (production) deployment environment,
using --env=test
when not specified.
References
- Getting Started with Cloud Functions (2nd gen)
- Yarn 2 (Berry) - Plug'n'play, constraints and workspaces by @jherr
- Google Cloud SQL β Tips & Tricks by @koistya
- Database change management with Node.js by @koistya
How to Update
In the case when you kept the original Node.js Starter Kit git history, you can always pull and merge updates from the "upstream" repository back into your project by running:
$ git fetch seed # Fetch Node.js Starter Kit (upstream) repository
$ git checkout main # Switch to the main branch (or, master branch)
$ git merge seed/main # Merge upstream/master into the local branch
In order to update Yarn and other dependencies to the latest versions, run:
$ yarn set version latest # Upgrade Yarn CLI to the latest version
$ yarn upgrade-interactive # Bump Node.js dependencies using an interactive mode
$ yarn install # Install the updated Node.js dependencies
$ yarn dlx @yarnpkg/sdks vscode # Update VSCode settings
Backers
How to Contribute
Anyone and everyone is welcome to contribute. Start by checking out the list of open issues marked help wanted. However, if you decide to get involved, please take a moment to review the guidelines.
License
Copyright Β© 2016-present Kriasoft. This source code is licensed under the MIT license found in the LICENSE file.
Made with