This project is a lightweight boilerplate, crafted to kick-start GraphQL API projects using TypeScript, TypeORM, PostgreSQL, GraphQL, Apollo Server, Type-GraphQL, and Docker. It's a robust and flexible foundation, ideal for swiftly building backend applications with some cool tech! ๐๐ง
- Simple book CRUD example
- Basic JWT authentication (SignUp and Login)
- Custom decorator example to protect resolver
- Script to reset database and create data fixtures
Make sure you have Node.js and/or Docker installed on your machine to use this app.
-
Clone the Project
git clone https://github.com/096benjaminbenoit/backend-boilerplate
-
Start the application in a Docker container
docker compose up
Go to http://localhost:4000 to access the Apollo Sandbox, ET VOILA ๐ฅ
-
Clone the Project
git clone https://github.com/096benjaminbenoit/backend-boilerplate
-
Install Dependencies
npm install
-
Configure Environment
- Create a
.env
file at the root of the project based on.env.example
. - Add the necessary environment variables (for your database connection and JWT secret key). ๐
- Create a
-
Start the Application
npm start
Go to http://localhost:4000 to access the Apollo Sandbox, ET VOILA ๐ฅ
Simply type this command (in terminal or in Docker shell):
npm run resetDB
You can add some data fixtures by modifying the resetDb.ts
file.
The project structure is deliberately simple, but there's nothing to stop you from adding to it as you see fit!
โโโ src
โ โโโ database
โ โ โโโ DataSource.ts // Database connection
โ โโโ entities // All entities
โ โ โโโ Book.ts
โ โ โโโ User.ts
โ โโโ inputs // All inputs/dto
โ โ โโโ BookInput.ts
โ โ โโโ LoginInput.ts
โ โ โโโ UserInput.ts
โ โโโ resolvers
โ โ โโโ BookResolver.ts // A resolver example with CRUD
โ โ โโโ UserResolver.ts // User management (SignUp, Login, ...)
โ โโโ types
โ โ โโโ interfaces.ts // All interfaces
โ โโโ utils
โ โโโ auth.ts // Password management and user authentication
โ โโโ jwt.ts // JWT management
โ โโโ security.ts // Custom decorators to protect resolvers
โโโ env.ts
โโโ index.ts
โโโ resetDb.ts // Little script to reset database and create data fixtures
Made with love โค๏ธ