Thank you for your interest in contributing to this project! We welcome contributions from the community.
- Code of Conduct
- Getting Started
- Development Setup
- Project Structure
- Development Workflow
- Coding Standards
- Commit Guidelines
- Pull Request Process
- Testing
- Documentation
By participating in this project, you agree to maintain a respectful and inclusive environment for everyone.
- Fork the repository on GitHub
- Clone your fork locally:
git clone https://github.com/YOUR_USERNAME/nodejs-backend-boilerplate.git cd nodejs-backend-boilerplate - Add upstream remote:
git remote add upstream https://github.com/devSahinur/nodejs-backend-boilerplate.git
- Node.js v18+ (v21.7.1 recommended)
- MongoDB v7.0+
- Redis v6.0+
- npm or yarn
-
Install dependencies:
npm install
-
Set up environment variables:
cp .env.example .env
Edit
.envwith your local configuration. -
Start required services:
# MongoDB brew services start mongodb-community # macOS # or sudo systemctl start mongod # Linux # Redis brew services start redis # macOS # or sudo systemctl start redis # Linux
-
Run the development server:
npm run dev
nodejs-backend-template/
├── src/
│ ├── config/ # Configuration files
│ ├── controllers/ # Route controllers
│ ├── middlewares/ # Custom middlewares
│ ├── models/ # Mongoose models
│ ├── routes/ # API routes
│ ├── services/ # Business logic
│ ├── utils/ # Utility functions
│ ├── validations/ # Request validation schemas
│ ├── queues/ # Bull queue jobs
│ ├── app.js # Express app setup
│ └── index.js # Server entry point
├── tests/ # Test files
├── public/ # Static files
└── logs/ # Application logs
-
Create a feature branch:
git checkout -b feature/your-feature-name
-
Make your changes following the coding standards
-
Test your changes:
npm test npm run lint -
Commit your changes (see Commit Guidelines)
-
Push to your fork:
git push origin feature/your-feature-name
-
Create a Pull Request on GitHub
- Use ES6+ features (arrow functions, destructuring, async/await)
- Use ESM (ES Modules) syntax with
.jsextensions - Follow the existing code style (enforced by ESLint)
- Use meaningful variable and function names
- Keep functions small and focused (single responsibility)
- Use kebab-case for filenames:
user-service.js - Use PascalCase for model files:
User.model.js - Add appropriate suffixes:
.controller.js,.service.js,.validation.js
- Controllers: Handle HTTP requests/responses
- Services: Contain business logic
- Models: Define database schemas
- Middlewares: Handle cross-cutting concerns
- Validations: Define request validation schemas
Always use ES6 module syntax:
// Good - Named and default exports
export default {
createUser,
getUser,
};
export { createUser, getUser };
// Good - Imports
import userService from './services/user.service.js';
import { createUser } from './services/user.service.js';We follow Conventional Commits specification.
<type>(<scope>): <subject>
<body>
<footer>
- feat: A new feature
- fix: A bug fix
- docs: Documentation changes
- style: Code style changes (formatting, semicolons, etc.)
- refactor: Code refactoring without adding features or fixing bugs
- perf: Performance improvements
- test: Adding or updating tests
- chore: Maintenance tasks, dependency updates
feat(auth): add JWT refresh token functionality
Implement refresh token rotation for improved security.
Tokens expire after 7 days and are automatically refreshed.
Closes #123fix(email): resolve SMTP connection timeout
Updated email service configuration to handle connection pooling
and added retry logic for failed sends.docs(readme): update installation instructions
Added prerequisite version requirements and troubleshooting section.-
Update your branch with latest upstream changes:
git fetch upstream git rebase upstream/main
-
Run all checks:
npm test npm run lint -
Update documentation if needed
-
Add/update tests for new features
Include in your PR description:
- What: Brief description of changes
- Why: Reason for the changes
- How: Implementation approach
- Testing: How you tested the changes
- Screenshots: If applicable (for UI changes)
Follow the same convention as commit messages:
feat(auth): add OAuth2 authentication
fix(validation): correct email regex pattern
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm test -- --coverage- Place tests in
__tests__directories next to the code they test - Use descriptive test names
- Follow AAA pattern: Arrange, Act, Assert
- Mock external dependencies
Example:
describe('User Service', () => {
describe('createUser', () => {
it('should create a new user with valid data', async () => {
// Arrange
const userData = { email: 'test@example.com', password: 'Test123!' };
// Act
const user = await userService.createUser(userData);
// Assert
expect(user).toHaveProperty('id');
expect(user.email).toBe(userData.email);
});
});
});- Use JSDoc for functions and classes
- Explain "why" not "what" in comments
- Keep comments up-to-date with code changes
Example:
/**
* Create a new user account
* @param {Object} userData - User registration data
* @param {string} userData.email - User's email address
* @param {string} userData.password - User's password (will be hashed)
* @returns {Promise<User>} Created user object
* @throws {ApiError} If email is already taken
*/
const createUser = async (userData) => {
// Implementation
};- Update Swagger/OpenAPI documentation for API changes
- Include request/response examples
- Document error responses
Update README.md when adding:
- New features
- New environment variables
- New dependencies
- Changed setup instructions
- Bug reports: Open an issue with detailed description and reproduction steps
- Feature requests: Open an issue describing the feature and use case
- Questions: Open a discussion or issue
By contributing, you agree that your contributions will be licensed under the same license as the project.
Thank you for contributing! 🎉