This repository is an opinionated starter project to build a robust and scalable backend service in TypeScript, with a code-first approach, exposing a GraphQL endpoint, and using a postgres database as an example
- 🚀Apollo Server → Spec-compliant GraphQL server that's compatible with any GraphQL client
- 🏄♂️TypeGraphQL → Create GraphQL schema and resolvers using classes and decorators
- 🔰TypeDI → Simple yet powerful dependency injection tool
- 💎Prisma → Database toolkit replacing traditional ORMs and makes database access easy with an auto-generated query builder
- 🚦Jest → Testing Framework with a focus on simplicity
- 💅ESLint + Prettier → Linting tool with an opinionated code formatter
First you need Node, Yarn and Docker installed on your machine to run this project.
Then run the following commands :
-
yarn install
→ Install the dependencies -
yarn prisma:generate
→ Generate the prisma client -
yarn start
-> Start the server and external dependencies🖥 Open a new terminal prompt
-
yarn prisma:migration:up
-> Create initial tables -
yarn prisma:seed
-> Populate the database -
The server is ready at http://localhost:3000/
The starter project comes with an architecture proposal inspired from the clean architecture. I recommend to read this article to better understand how it works. Feel free to use it or adapt it to your needs.
.
├── prisma
│ ├── migrations
│ │ ├── 20200904123736-user
│ │ │ ├── README.md
│ │ │ ├── schema.prisma
│ │ │ └── steps.json
│ │ └── migrate.lock
│ ├── schema.prisma
│ └── seed.ts
├── src
│ ├── components
│ │ └── user
│ │ ├── __tests__
│ │ │ └── user.service.spec.ts
│ │ ├── adapters
│ │ │ └── user.repository.ts
│ │ ├── user.entity.ts
│ │ ├── user.service.ts
│ │ └── user.source.ts
│ ├── infrastructure
│ │ ├── database
│ │ │ └── prisma.client.ts
│ │ └── resolvers
│ │ └── user.resolver.ts
│ ├── index.ts
│ └── module.ts
├── docker-compose.deps.yml
├── package.json
└── tsconfig.json
yarn start
→ Start the server with auto-restart on changes and the external dependenciesyarn start:server
→ Start the server with auto-restart on changesyarn start:deps
→ Start the external dependencies with Dockeryarn lint
→ Check linting and code formattingyarn test
→ Launch all tests with Jestyarn build
→ Build the project into plain javascript in thedist
folderyarn prisma:generate
→ Generate the prisma client based on the schemayarn prisma:migration:new
→ Save a new migration toprisma/migrations
yarn prisma:migration:up
→ Executes the migration against the databaseyarn prisma:seed
→ Populate the database using a seed
This project use Prisma Migrate to create and update tables. Unfortunately this migration tool is still in an experimental state, if it's unsuitable for your project, you can replace this tool with db-migrate and use Prisma Introspection