Thank you for your interest in contributing to ZodKit! This document provides comprehensive guidelines for contributing to the project.
- Getting Started
- Development Setup
- Project Structure
- Development Workflow
- Testing
- Code Style
- Pull Request Process
- Areas for Contribution
- Node.js: v18+ (LTS recommended)
- npm: v9+ (comes with Node.js)
- Git: v2.0+
- TypeScript: Knowledge of TypeScript basics
- Zod: Familiarity with Zod schema validation
-
Fork the repository on GitHub
-
Clone your fork:
git clone https://github.com/YOUR_USERNAME/zodkit.git cd zodkit -
Add upstream remote:
git remote add upstream https://github.com/JSONbored/zodkit.git
-
Install dependencies:
npm install
-
Build the project:
npm run build
-
Run tests:
npm test -
Start development mode (watch for changes):
npm run dev
# Build TypeScript
npm run build:tsc
# Build webpack bundle
npm run build:webpack
# Watch mode (auto-rebuild on changes)
npm run dev
# Run CLI locally
npm start [command]
# or
node dist/cli/index.js [command]
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
# Run specific test file
npm test -- tests/unit/stats.test.ts
# Linting
npm run lint
npm run lint:fix
# Formatting
npm run format
# Generate documentation
npm run docszodkit/
├── src/
│ ├── cli/ # CLI interface
│ │ ├── commands/ # Command implementations
│ │ │ ├── lint.ts # Schema linting (6 rules)
│ │ │ ├── stats.ts # Statistics & bundle impact
│ │ │ ├── create.ts # Interactive schema builder
│ │ │ ├── check.ts # Fast validation
│ │ │ ├── analyze.ts # Deep analysis
│ │ │ └── ...
│ │ ├── command-builder.ts # Command definitions
│ │ ├── global-options.ts # Shared options
│ │ └── index.ts # CLI entry point
│ ├── core/ # Core functionality
│ │ ├── ast/ # AST parsing (ts-morph)
│ │ │ ├── parser.ts # TypeScript parser
│ │ │ ├── extractor.ts # Zod schema extractor
│ │ │ ├── visitor.ts # AST visitor
│ │ │ └── walker.ts # AST walker
│ │ ├── rules/ # Linting rules
│ │ │ ├── engine.ts # Rule execution engine
│ │ │ ├── fixer.ts # Auto-fix system
│ │ │ └── builtin/ # Built-in rules
│ │ │ ├── no-any-type.ts
│ │ │ ├── no-loose-objects.ts
│ │ │ ├── require-description.ts
│ │ │ └── ...
│ │ ├── schema-stats.ts # Statistics aggregator
│ │ ├── analysis.ts # Schema analysis
│ │ ├── hot-reload.ts # File watching
│ │ └── ...
│ ├── types/ # TypeScript type definitions
│ └── utils/ # Utility functions
├── tests/
│ ├── unit/ # Unit tests
│ │ ├── stats.test.ts # Stats tests (21 tests)
│ │ ├── lint.test.ts # Lint tests (89 tests)
│ │ ├── create.test.ts # Create tests (166 tests)
│ │ └── ...
│ ├── integration/ # Integration tests
│ └── performance/ # Performance benchmarks
├── scripts/ # Build scripts
├── docs/ # Documentation
└── dist/ # Compiled output
- parser.ts: Wraps ts-morph for TypeScript AST parsing
- extractor.ts: Extracts Zod schema information from AST
- visitor.ts: Visits AST nodes to find schema definitions
- walker.ts: Walks AST tree for analysis
- engine.ts: Executes rules on schemas
- fixer.ts: Applies auto-fixes to code
- builtin/: 6 built-in linting rules
- Type distribution analysis
- Complexity metrics calculation
- Hotspot detection
- Bundle impact estimation
- lint.ts: Schema linting with auto-fix
- stats.ts: Statistics and bundle analysis
- create.ts: Interactive schema builder with 7 templates
- We use ESLint and Prettier for code formatting
- Run
npm run lintto check for linting errors - Run
npm run lint:fixto auto-fix linting issues - Run
npm run formatto format code with Prettier
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
# Run specific test file
npm test -- tests/unit/stats.test.ts
# Run integration tests
npm run test:integration
# Run performance tests
npm run test:performanceWe use Jest for testing. Place tests in the tests/ directory matching the source structure:
import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
import { mkdirSync, writeFileSync, rmSync, existsSync } from 'node:fs';
import { createStatsAggregator } from '../../src/core/schema-stats';
describe('Stats Aggregator', () => {
const testDir = join(__dirname, '.temp-test');
beforeEach(() => {
if (!existsSync(testDir)) {
mkdirSync(testDir, { recursive: true });
}
});
afterEach(() => {
if (existsSync(testDir)) {
rmSync(testDir, { recursive: true, force: true });
}
});
it('should calculate bundle impact', async () => {
const aggregator = createStatsAggregator();
await aggregator.addFile('path/to/schema.ts');
const stats = aggregator.generateStats({ includeBundleImpact: true });
expect(stats.bundleImpact).toBeDefined();
expect(stats.bundleImpact!.estimatedSize).toBeGreaterThan(0);
});
});Coverage thresholds are enforced by Jest (see jest.config.js):
- Global: 35% branches, 35% functions, 45% lines, 45% statements
- Core modules (well-tested):
src/core/schema-stats.ts: 65-80%src/cli/commands/lint.ts: 55-70%
- Unit tests (
tests/unit/): Test individual functions and modules - Integration tests (
tests/integration/): Test command workflows - Performance tests (
tests/performance/): Benchmark critical paths
Current Test Stats:
- 21 tests for stats module (bundle impact, type detection, complexity)
- 89 tests for lint module (rules, auto-fix, severity filtering)
- 166 tests for create module (templates, interactive flow, validation)
We follow conventional commit format:
feat:new featuresfix:bug fixesdocs:documentation changesstyle:formatting changesrefactor:code refactoringtest:adding or updating testschore:maintenance tasks
Example: feat: add schema validation for API routes
-
Create a feature branch from
main:git checkout -b feature/your-feature-name
-
Make your changes and commit them with descriptive messages
-
Ensure all tests pass and code follows our style guidelines:
npm run validate
-
Push your branch and create a pull request
-
Fill out the pull request template with:
- Description of changes
- Related issue numbers
- Testing instructions
- Breaking changes (if any)
- Use strict TypeScript configuration
- Avoid
anytypes - use proper type definitions - Add JSDoc comments for public APIs
- Use meaningful variable and function names
- Follow the existing project structure
- Keep functions small and focused
- Use dependency injection where appropriate
- Write self-documenting code
- Consider performance implications of changes
- Use appropriate data structures
- Avoid unnecessary computations
- Profile performance-critical code
When reporting issues, please include:
- zodkit version
- Node.js version
- Operating system
- Steps to reproduce
- Expected vs actual behavior
- Error messages (if any)
- Minimal reproduction case
For feature requests, please:
- Check if the feature already exists or is planned
- Describe the use case and motivation
- Provide examples of how it would be used
- Consider implementation complexity
- Be respectful and inclusive
- Welcome newcomers and help them get started
- Focus on constructive feedback
- Assume good intentions
We welcome contributions in the following areas:
- Bug fixes: Check open issues labeled
bug - Test coverage: Increase coverage for core modules
- Documentation: Improve examples, tutorials, and API docs
- Performance: Optimize AST parsing and schema analysis
- New linting rules: Additional schema validation rules
- Example:
no-circular-refs,max-nesting-depth,required-examples
- Example:
- Schema templates: More predefined templates for create command
- Example: Event, Order, Invoice, Settings, Config
- Export formats: Additional output formats
- Example: GraphQL schema, Protobuf, JSON Schema draft-2020-12
- IDE integration: VS Code extension, Language Server Protocol
Look for issues labeled good-first-issue - these are beginner-friendly:
- Documentation improvements
- Adding test cases
- Fixing typos
- Simple bug fixes
- Adding examples to README
- Add a new template to the create command (e.g., EventSchema, OrderSchema)
- Improve error messages with more context and suggestions
- Add examples to the documentation
- Write a blog post about using ZodKit
- Create a tutorial video or guide
- Questions: Open a Discussion
- Bugs: Open an Issue
- Feature Requests: Open an Issue with the
enhancementlabel - Security: Email security concerns privately (do not open public issues for security vulnerabilities)
Contributors will be recognized in:
- CHANGELOG.md for each release
- README.md contributors section
- GitHub contributors page
By contributing to ZodKit, you agree that your contributions will be licensed under the MIT License.
Thank you for contributing to ZodKit! 🎉