A robust backend starter built with NestJS, GraphQL, Prisma, and PostgreSQL. This boilerplate includes authentication, Docker support, and comprehensive testing setup.
- 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
Ensure you have the following installed:
- Node.js (v20.x or later)
- Yarn (v1.22.x or later)
- Docker and Docker Compose
-
Clone the repository
git clone https://github.com/yourusername/your-repo-name.git cd your-repo-name
-
Set up environment variables
cp example.env .env
Update the
.env
file with your configuration -
Start the application
docker-compose up -d
-
Access the application
- Main:
http://localhost:3001
- GraphQL Playground:
http://localhost:3001/graphql
- Main:
If you prefer to run the application without Docker:
-
Follow steps 1-2 from the Quick Start guide
-
Install dependencies
yarn install
-
Set up the database
- Ensure PostgreSQL is running
- Run migrations:
yarn migrate
-
Start the application
yarn dev
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.
This boilerplate includes a JWT-based authentication system:
- Register a user or use the default admin account
- Obtain a JWT token by logging in
- Include the token with
Bearer
in theAuthorization
header of your requests
JWT configuration:
- Secret key: Set in
AUTH_ACCESS_TOKEN_SECRET
- Token expiration: Set in
AUTH_ACCESS_TOKEN_EXP
Run the test suite:
yarn test
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.
- 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
For a consistent development environment with hot-reloading:
docker-compose -f docker-compose.dev.yml up
This project uses AWS services. Ensure proper configuration:
- Set
AWS_REGION
to your desired AWS region - Configure
AWS_LOCAL_PROFILE_NAME
with your AWS CLI profile name - Set
AWS_ROLE_ARN
to the appropriate IAM role ARN - For S3 operations, set
AWS_S3_BUCKET
andAWS_S3_PRESIGN_LINK_EXPIRES
-
Build the Docker image
docker build -t your-app-name .
-
Push the image to your container registry
-
On your server, run:
docker run -d -p 3001:3001 --env-file .env your-app-name
Contributions are welcome! Please read our contributing guidelines and code of conduct.
This project is licensed under the MIT License - see the LICENSE file for details.