Skip to content

πŸ—οΈ NestJS + GraphQL + MongoDB starter template crafted for scalable backend projects and rapid API development

License

Notifications You must be signed in to change notification settings

Ridho894/nestjs-graphql-mongo-starter

Repository files navigation

πŸš€ NestJS + GraphQL + MongoDB Starter

A professional, scalable boilerplate for building GraphQL APIs with NestJS and MongoDB

NestJS GraphQL MongoDB

✨ Features

  • πŸ”₯ NestJS - A progressive Node.js framework
  • ⚑️ GraphQL with Apollo Server - Code-first approach
  • πŸ“¦ MongoDB integration with Mongoose
  • 🧩 Modular architecture
  • πŸ“ ESLint + Prettier for consistent code style
  • 🚦 Class Validator for DTO validation
  • πŸ”„ Conventional Commits for structured commit messages

πŸ“š Tech Stack

NestJS GraphQL MongoDB Mongoose JWT Node.js TypeScript

πŸš€ Getting Started

Prerequisites

  • Node.js (v14 or newer)
  • MongoDB (local or Atlas connection)
  • Yarn or NPM

Installation

  1. Clone the repository
git clone https://github.com/Ridho894/nestjs-graphql-mongo-starter.git
cd nestjs-graphql-mongo-starter
  1. Install dependencies
npm install
# or
yarn install
  1. Environment Setup

Create a .env file in the root directory with the following variables:

# Server
PORT=3000

# MongoDB
MONGO_URI=mongodb://localhost:27017/nestjs-gql-mongo

# JWT
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRES=1d
  1. Start the development server
npm run start:dev
# or
yarn start:dev

Your GraphQL API will be available at http://localhost:3000/graphql

πŸ“Š GraphQL Playground

Once your application is running, you can access the GraphQL Playground to interact with your API:

GraphQL Playground Screenshot

Screenshot: GraphQL Playground interface showing query execution

Sample Queries

Here's a simple query you can try in the playground:

{
  users {
    _id
    name
    email
  }
}

🧰 Development Commands

Command Description
npm run build Builds the application
npm start Starts the application
npm run start:dev Starts the application in watch mode
npm run start:debug Starts with debugging
npm run start:prod Starts in production mode
npm run lint Lints the code
npm run test Runs tests
npm run test:watch Runs tests in watch mode
npm run test:cov Shows test coverage

πŸ—οΈ Project Structure

nestjs-gql-mongo-starter/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/            # Configuration files and constants
β”‚   β”œβ”€β”€ graphql/           # GraphQL specific files
β”‚   β”œβ”€β”€ modules/           # Feature modules
β”‚   β”‚   └── users/         # User module example
β”‚   β”‚       β”œβ”€β”€ dto/       # Data Transfer Objects
β”‚   β”‚       β”œβ”€β”€ schemas/   # Mongoose schemas
β”‚   β”‚       β”œβ”€β”€ users.module.ts
β”‚   β”‚       β”œβ”€β”€ users.resolver.ts
β”‚   β”‚       └── users.service.ts
β”‚   β”œβ”€β”€ app.module.ts      # Main application module
β”‚   └── main.ts           # Application entry point
β”œβ”€β”€ public/
β”‚   └── screenshots/       # Screenshots for documentation
β”œβ”€β”€ test/                  # Testing utilities
β”œβ”€β”€ .env                   # Environment variables (create this)
β”œβ”€β”€ .gitignore             # Git ignore file
β”œβ”€β”€ nest-cli.json          # NestJS CLI configuration
β”œβ”€β”€ package.json           # Dependencies and scripts
β”œβ”€β”€ tsconfig.json          # TypeScript configuration
└── README.md              # Documentation

πŸ’» Features Implementation

  • GraphQL API
    • Code-first approach using decorators
    • Schema auto-generation
    • Resolvers for queries and mutations

πŸ“ Commit Message Convention

This project follows Conventional Commits for clear and structured commit messages. This helps in maintaining a standardized commit history and automated versioning.

Commit Message Format

Each commit message consists of a header, an optional body, and an optional footer:

<type>(<scope>): <short summary>
β”‚       β”‚             β”‚
β”‚       β”‚             └─⫸ Summary in present tense. Not capitalized. No period at the end.
β”‚       β”‚
β”‚       └─⫸ Commit Scope (optional): modules|config|schema
β”‚
└─⫸ Commit Type: feat|fix|docs|style|refactor|test|chore|ci|build|perf

Types

  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, etc)
  • refactor: A code change that neither fixes a bug nor adds a feature
  • test: Adding missing tests or correcting existing tests
  • chore: Changes to the build process or auxiliary tools
  • ci: Changes to CI configuration files and scripts
  • build: Changes that affect the build system or external dependencies
  • perf: Performance improvements

Examples

feat(auth): add JWT authentication
fix(users): resolve issue with user creation
docs(readme): update installation instructions

🀝 Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'feat: add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ‘ Acknowledgments

About

πŸ—οΈ NestJS + GraphQL + MongoDB starter template crafted for scalable backend projects and rapid API development

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published