Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hmake98/nestjs-graphql-starter
๐ A robust and scalable backend starter kit built with NestJS, GraphQL, Prisma, and PostgreSQL. Features Docker support, JWT authentication, and comprehensive testing.
https://github.com/hmake98/nestjs-graphql-starter
aws docker graphql nestjs nestjs-boilerplate nestjs-graphql prisma typescript
Last synced: 8 days ago
JSON representation
๐ A robust and scalable backend starter kit built with NestJS, GraphQL, Prisma, and PostgreSQL. Features Docker support, JWT authentication, and comprehensive testing.
- Host: GitHub
- URL: https://github.com/hmake98/nestjs-graphql-starter
- Owner: hmake98
- License: mit
- Created: 2024-09-08T14:16:11.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2024-10-06T07:41:19.000Z (5 months ago)
- Last Synced: 2024-12-19T02:21:18.713Z (2 months ago)
- Topics: aws, docker, graphql, nestjs, nestjs-boilerplate, nestjs-graphql, prisma, typescript
- Language: TypeScript
- Homepage:
- Size: 191 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NestJS GraphQL Boilerplate
[](https://github.com/hmake98/nestjs-graphql-starter/actions/workflows/main.yml)





A robust backend starter built with NestJS, GraphQL, Prisma, and PostgreSQL. This boilerplate includes authentication, Docker support, and comprehensive testing setup.
## ๐ Features
- **NestJS**: A powerful Node.js framework for scalable server-side applications
- **GraphQL & Apollo Server**: Fully-featured GraphQL API
- **Prisma**: Modern ORM for type-safe database access
- **PostgreSQL**: Reliable, open-source relational database
- **Authentication**: Secure user authentication system
- **Docker**: Containerization for easy deployment and development
- **Testing**: Comprehensive test suite using Jest
- **Yarn**: Fast and secure dependency management## ๐ Prerequisites
Ensure you have the following installed:
- Node.js (v20.x or later)
- Yarn (v1.22.x or later)
- Docker and Docker Compose## ๐ Quick Start with Docker
1. **Clone the repository**
```bash
git clone https://github.com/yourusername/your-repo-name.git
cd your-repo-name
```2. **Set up environment variables**
```bash
cp example.env .env
```Update the `.env` file with your configuration
3. **Start the application**
```bash
docker-compose up -d
```4. **Access the application**
- Main: `http://localhost:3001`
- GraphQL Playground: `http://localhost:3001/graphql`## ๐ฅ Manual Installation
If you prefer to run the application without Docker:
1. Follow steps 1-2 from the Quick Start guide
2. **Install dependencies**
```bash
yarn install
```3. **Set up the database**
- Ensure PostgreSQL is running
- Run migrations:
```bash
yarn migrate
```4. **Start the application**
```bash
yarn dev
```## โ๏ธ Configuration
The application uses environment variables for configuration. Copy the `example.env` file to `.env` and update the values accordingly. Here's an explanation of the key environment variables:
| Variable | Description | Example Value |
| ----------------------------- | ------------------------------------- | -------------------------------------------------- |
| `NODE_ENV` | Application environment | `local` |
| `APP_CORS_ORIGIN` | CORS origin setting | `*` |
| `HTTP_HOST` | HTTP server host | `0.0.0.0` |
| `HTTP_PORT` | HTTP server port | `3001` |
| `GRAPHQL_PLAYGROUND` | Enable GraphQL Playground | `true` |
| `DATABASE_URL` | PostgreSQL connection string | `postgresql://user:password@localhost:5432/dbname` |
| `AUTH_ACCESS_TOKEN_SECRET` | Secret for JWT token generation | `my-access-token-secret` |
| `AUTH_ACCESS_TOKEN_EXP` | JWT token expiration time | `1d` |
| `AWS_REGION` | AWS region for services | `ap-south-1` |
| `AWS_LOCAL_PROFILE_NAME` | AWS local profile name | `default` |
| `AWS_ROLE_ARN` | AWS IAM role ARN | `arn:aws:iam::123456789012:role/YourRoleName` |
| `AWS_S3_PRESIGN_LINK_EXPIRES` | S3 presigned URL expiration (seconds) | `1800` |
| `AWS_S3_BUCKET` | S3 bucket name | `your-bucket-name` |Ensure all variables are properly set before running the application.
## ๐ Authentication
This boilerplate includes a JWT-based authentication system:
1. Register a user or use the default admin account
2. Obtain a JWT token by logging in
3. Include the token with `Bearer` in the `Authorization` header of your requestsJWT configuration:
- Secret key: Set in `AUTH_ACCESS_TOKEN_SECRET`
- Token expiration: Set in `AUTH_ACCESS_TOKEN_EXP`## ๐งช Testing
Run the test suite:
```bash
yarn test
```## ๐ Database Management
Prisma CLI commands for database management:
| Command | Description |
| ------------------- | ---------------------- |
| `yarn generate` | Generate Prisma client |
| `yarn migrate:prod` | Apply migrations |Ensure `DATABASE_URL` is correctly set in your `.env` file.
## ๐ GraphQL Development
- Schema is auto-generated from your resolvers
- GraphQL Playground is enabled by default in development (`GRAPHQL_PLAYGROUND=true`)
- Access GraphQL Playground at `http://localhost:3001/graphql`
- Disable GraphQL Playground in production for security## ๐ณ Docker in Development
For a consistent development environment with hot-reloading:
```bash
docker-compose -f docker-compose.dev.yml up
```## โ๏ธ AWS Configuration
This project uses AWS services. Ensure proper configuration:
1. Set `AWS_REGION` to your desired AWS region
2. Configure `AWS_LOCAL_PROFILE_NAME` with your AWS CLI profile name
3. Set `AWS_ROLE_ARN` to the appropriate IAM role ARN
4. For S3 operations, set `AWS_S3_BUCKET` and `AWS_S3_PRESIGN_LINK_EXPIRES`## ๐ข Deployment
1. **Build the Docker image**
```bash
docker build -t your-app-name .
```2. Push the image to your container registry
3. On your server, run:
```bash
docker run -d -p 3001:3001 --env-file .env your-app-name
```## ๐ค Contributing
Contributions are welcome! Please read our contributing guidelines and code of conduct.
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.