This project is archived because I don't have time to keep it up to date anymore. It was created originally as a starting point for several projects I had in mind but I barely even find the time to work on the first of them and backporting changes to this repository just hinders my progress.
This project provides a monorepo setup for a Fullstack TypeScript project and comes with the following:
-
Clone this repository
-
Create the env files mentioned in .env files. For a starter setup you can just copy the .example files to their name without the .example (for Chromatic, see the general steps below).
-
Local development:
Runyarn install
, thenyarn server:generate
and use one of the available scripts! Everything should just work together in the setup you download (Note:yarn web:generate
requires the backend to be running because the code generator loads the schema directly from the server). -
Docker setup: Run
docker-compose up
, wait for the images to build, then have a look at the ports, where the built production instances will be running (Note: The docker setup is not suitable for development as it doesn't use volumes, storybook won't be launched in containers either).
If you are building a serious project with this, there are a few additional changes required to get everything running smoothly:
You should follow these steps whenever you start a new project with this boilerplate.
- Replace
@project/
with@<projectname>/
in all package.json files - Replace
fullstack-typescript-boilerplate-example
with your actual project's name indocker-compose.yml
anddocker-compose.yml
- Create a new project on Chromatic and place your project token in
packages/ui/.env
asCHROMATIC_PROJECT_TOKEN=token
You should follow these steps when you have this repository on GitHub and want to use Actions as CI/CD tool.
- Replace
fullstack-typescript-boilerplate-example
with your actual project's name in.github/workflows/build.yml
- Create three Docker repositories on Docker Hub, named
<name>-migration
,<name>-server
and<name>-web
replacing<name>
with your project's name - Go to your repository > Settings > Secrets and create these secrets:
CHROMATIC_PROJECT_TOKEN
- contains the Chromatic token for the projectDOCKERHUB_USERNAME
- contains the username you created the repositories inDOCKERHUB_TOKEN
- contains a Docker Hub access token
The repository comes with a bunch of yarn scripts you can run to do several things. The most important ones are available from the root directory of the project and listed here:
yarn eslint:check
- Runs linting in all packages.
yarn eslint:write
- Runs linting in all packages and fixes auto-fixable problems.
yarn format:check
- Runs prettier on the entire project and reports styling issues.
yarn format:write
- Runs prettier on the entire project and fixes styling issues.
yarn server:dev
- Runs the backend for development (using ts-node-dev).
yarn server:generate
- Generates backend source and packages using prisma.
yarn storybook
- Runs and opens the Storybook project.
yarn test
- Runs the test script in all workspaces.
yarn web:dev
- Runs the next frontend for development.
yarn web:generate
* - Generates GraphQL types and hooks for the frontend.
*
- This script requires the backend to be running on http://localhost:5000/graphql
because the code generator loads
the schema directly from the server.
Currently, the boilerplate utilizes several .env
files (I am not too happy about it, feel free to open an issue for
suggesting an approach to only use one):
.env
contains environment variables used in the Docker setuppackages/server/.env
contains environment variables local to the server package, currently only used for providing theDATABASE_URL
variable to prismapackages/ui/.env
contains the chromatic project tokenpackages/web/.env.local
contains variables usable in Next.js (docs)
For all used .env
files listed above, there is a .env.example
file in this repository that you can copy to ./.env
and adapt to your needs.
The server and web packages have been dockerized, and a docker-compose setup using postgres as database is available.
The docker-compose setup expects a series of environment variables to be set:
DATABASE_HOST
- The host on which to find the database on
DATABASE_DB_NAME
- The name of the database to use
DATABASE_USER
- The user to use for database login
DATABASE_PASSWORD
- The password to use for database login
BACKEND_PORT
* - The port to run the backend on (default: 5000)
BACKEND_HOST
- The hostname used inside the docker-network to connect to the server (default: server)
*
This value is used during build-time of the container already to expose the correct port. If you change it, you have
to rebuild the container!
The boilerplate currently uses the following ports:
Port | Service |
---|---|
3000 | Next.js |
5000 | Backend* |
5432 | Database |
6006 | Storybook |
*
The port can be changed using the BACKEND_PORT
environment variable.