Thank you for your interest in contributing to DatabaseKit! This guide will help you get started.
Before contributing, please read:
- README.md - Understand what DatabaseKit does
- SECURITY.md - Security guidelines
- This document - Contribution guidelines
- CODE_OF_CONDUCT - Community guidelines
- Node.js >= 18
- npm >= 8
- Git
- A code editor (VS Code recommended)
- MongoDB and/or PostgreSQL for testing
# Fork on GitHub first, then:
git clone https://github.com/YOUR-USERNAME/DatabaseKit.git
cd DatabaseKitnpm installcp .env.example .env
# Edit .env with your database credentialsnpm run buildnpm testsrc/
├── index.ts # Public API exports
├── database-kit.module.ts # NestJS module
├── adapters/ # Database adapters
│ ├── mongo.adapter.ts # MongoDB adapter
│ └── postgres.adapter.ts # PostgreSQL adapter
├── config/ # Configuration
│ ├── database.config.ts # Config helpers
│ └── database.constants.ts # Constants & tokens
├── contracts/ # TypeScript interfaces
│ └── database.contracts.ts # All type definitions
├── filters/ # Exception filters
│ └── database-exception.filter.ts
├── middleware/ # Decorators
│ └── database.decorators.ts
├── services/ # Business logic
│ ├── database.service.ts # Main service
│ └── logger.service.ts # Logging service
└── utils/ # Utilities
├── pagination.utils.ts
└── validation.utils.ts
Create feature branches from main:
feat/short-description- New featuresfix/short-description- Bug fixesdocs/short-description- Documentationrefactor/short-description- Code refactoringtest/short-description- Tests onlychore/short-description- Maintenance
We use Conventional Commits:
feat: add PostgreSQL connection retry logic
fix: handle null values in pagination
docs: update README with async config example
refactor: extract filter logic to separate function
test: add unit tests for MongoAdapter
chore: update dependencies
- Create a branch from
main - Make changes following our guidelines
- Write/update tests (aim for 80%+ coverage)
- Update documentation if needed
- Run all checks locally:
npm run lint npm run build npm test - Push your branch
- Create PR against
main - Fill out the PR template
- Address review feedback
- Wait for approval (at least 1 maintainer)
- Files:
kebab-casewith suffixmongo.adapter.tsdatabase.service.tspagination.utils.ts
- Classes:
PascalCaseexport class MongoAdapter {} export class DatabaseService {}
- Functions:
camelCaseexport function calculateOffset() {} export function isValidMongoId() {}
- Constants:
UPPER_SNAKE_CASEexport const DATABASE_TOKEN = 'DATABASE_KIT_DEFAULT'; export const DEFAULT_PAGE_SIZE = 10;
// ✅ DO: Use interfaces for data structures
interface UserData {
name: string;
email: string;
}
// ✅ DO: Use explicit return types
function getUser(id: string): Promise<User | null> {
// ...
}
// ✅ DO: Use readonly for immutable data
constructor(private readonly config: DatabaseConfig) {}
// ✅ DO: Use unknown instead of any
function parseData(input: unknown): ParsedData {
// ...
}
// ❌ DON'T: Use any
function parseData(input: any): any {
// ...
}// ✅ DO: Use specific NestJS exceptions
if (!user) {
throw new NotFoundException('User not found');
}
// ✅ DO: Log errors with context
try {
await this.repo.create(data);
} catch (error) {
this.logger.error('Failed to create user', error);
throw error;
}
// ❌ DON'T: Swallow errors
try {
await riskyOperation();
} catch (e) {
// Silent failure - BAD!
}// ✅ DO: Use environment variables
const uri = process.env.MONGO_URI;
if (!uri) throw new Error('MONGO_URI not configured');
// ❌ DON'T: Hardcode values
const uri = 'mongodb://localhost:27017/mydb';We aim for 80%+ code coverage.
Place test files next to source files:
src/services/database.service.ts
src/services/database.service.spec.ts
import { Test, TestingModule } from '@nestjs/testing';
import { DatabaseService } from './database.service';
describe('DatabaseService', () => {
let service: DatabaseService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
// Mock dependencies
],
}).compile();
service = module.get<DatabaseService>(DatabaseService);
});
describe('connect', () => {
it('should connect to MongoDB', async () => {
// Arrange
// Act
// Assert
});
it('should throw on invalid connection string', async () => {
// ...
});
});
});# All tests
npm test
# With coverage
npm run test:cov
# Watch mode
npm run test:watch
# Specific file
npm test -- database.service.spec.tsAll public functions must have JSDoc:
/**
* Creates a repository for a Mongoose model.
*
* @param opts - Options containing the Mongoose model
* @returns Repository instance with CRUD methods
* @throws Error if model is not provided
*
* @example
* ```typescript
* const repo = adapter.createRepository({ model: UserModel });
* ```
*/
createRepository<T>(opts: MongoRepositoryOptions<T>): Repository<T> {
// ...
}If your change affects usage, update README.md:
- New features → Add examples
- Breaking changes → Update migration guide
- New config options → Document in configuration section
For user-facing changes, add entry to CHANGELOG.md:
## [Unreleased]
### Added
- New feature description (#PR)
### Fixed
- Bug fix description (#PR)
### Changed
- Change description (#PR)- ❌ Don't commit directly to
main - ❌ Don't merge your own PRs
- ❌ Don't include
node_modulesordist - ❌ Don't hardcode credentials or secrets
- ❌ Don't skip tests
- ❌ Don't ignore linting errors
- ❌ Don't make breaking changes without discussion
- ❌ Don't add unnecessary dependencies
Releases are handled by maintainers:
- Update version in
package.json - Update
CHANGELOG.mdwith release date - Create release commit:
chore: release v1.x.x - Create git tag:
v1.x.x - Push to GitHub
- CI publishes to npm
- Patch (1.0.X): Bug fixes, no API changes
- Minor (1.X.0): New features, backwards compatible
- Major (X.0.0): Breaking changes
Have an idea but not ready to implement?
- Check existing discussions
- Open a new discussion to propose your idea
- Get feedback from maintainers
- Once approved, create an issue and start working
Contributors are recognized in:
- CHANGELOG.md (for each release)
- GitHub contributors page
- README.md (for significant contributions)
- 💬 GitHub Discussions
- 📧 Email: info@ciscod.com
Thank you for contributing to DatabaseKit! 🎉