Quickly ship your apps with the power of code generation.
Product boilerplate is @brianlovin and @mxstbr's personal setup to quickly build new apps. It aims to get all the common stuff out of the way and make shipping a product as quick as possible.
There are three important traits in all the included tooling that we pay attention to:
- Mastery: We know most of these tools inside and out and have a lot of experience with them.
- Code generation: The less boilerplate code we need to write, the more we can focus on our app. Code generation allows us to automate the tedious parts.
- Type safety: Counterintuitively, having strict type safety lets you move faster because you get warnings about bugs right in your IDE without having to recompile.
Note that this is our personal boilerplate. You are more than welcome to use it (that's why it's open source), but we cannot give any support when using it. Make sure you understand the tools in it before using it!
The entire app (front- and backend) uses Zeit Now for development and deployment, and is fully serverless.
- TypeScript
- Prettier
- ESLint
- yarn workspaces for the monorepo support
- GraphQL Codegen
- GraphQL
- Apollo Server for exposing said GraphQL schema through the API
- GraphQL Nexus for creating a type-safe GraphQL API
- Prisma for type-safe database access
- Passport for authentication
There are three code generators at work in this boilerplate:
- GraphQL Codegen automatically generates React components for the frontend that fetch from the API. They are fully typed too, so you know exactly what the shape of the returned data is.
- Prisma generates a fully type-safe database client from our datamodel.
- GraphQL Nexus (in combination with Prisma) lets us expose a production-ready GraphQL API from the database client.
All routing happens via the folder structure:
- Frontend: TypeScript files within
web/pages/
are served at their respective path, e.g.web/pages/about.tsx
is served atlocalhost:3000/about
- Backend: TypeScript files within
server/routes/
are served at their respective path with/api/
prefixed, e.g.server/routes/auth/google.ts
is served atlocalhost:3000/api/auth/gooogle
To add dynamic routing you'll need to edit the now.json
file. See the now documentation on the routes config.
To start the app locally you have to run these two commands:
yarn run dev
: Stars the development process for the serverless front- and backend withnow dev
.yarn run db
: Starts the database locally (note: requires Docker to be up and running and docker-compose to be installed)
Further, you will frequently use these commands while developing and they are automatically run whenever you switch branches or pull new code to make sure your generated files are up to date:
yarn run db:deploy
: Update your local database with changes you made to the datamodel.yarn run generate
: Runs all the codegeneration commands in sequence. You can also run them manually if necessary:yarn run generate:db
: Generate the Prisma database client for the server.yarn run generate:server
: Generate theschema.graphql
file for the backend from the Nexus schemayarn run generate:web
: Generate the fetching hooks and types for the frontend from the.graphql
files contained within it
These are automatically run in a pre-commit hook, so don't worry about calling them manually unless you have a reason to:
yarn run prettify
: Prettifies thesrc
folder with Prettier.yarn run lint
: Lints thesrc
folder with ESLint.
To deploy the database, look at the Prisma docs, e.g. their tutorial on deploying the database to AWS fargate.
Once that is up and running, to deploy the app you simply run now
, that's it! We recommend enabling the Now GitHub integration for CD.
Licensed under the MIT License.