Covers: - Development environment setup - Code style and conventions - Testing requirements (go test, regression tests, benchmarks) - Commit message conventions (conventional commits) - Pull request process - How to add new features or fix bugs - Documentation guidelines - Getting help Bead-Id: bf-4ys
7.7 KiB
7.7 KiB
Contributing to zai-proxy
Thank you for your interest in contributing to zai-proxy! This document provides guidelines and instructions for contributing to the project.
Table of Contents
- Development Environment Setup
- Code Style and Conventions
- Testing Requirements
- Commit Message Conventions
- Pull Request Process
- Adding New Features or Fixing Bugs
- Documentation
- Getting Help
Development Environment Setup
Prerequisites
- Go 1.21+ - For the proxy backend
- Node.js 18+ and npm - For the dashboard frontend
- Docker - For container builds and testing
- Make (optional) - For convenience targets
Clone and Setup
# Clone the repository
git clone https://git.ardenone.com/jedarden/zai-proxy.git
cd zai-proxy
# Setup Go environment (proxy)
cd proxy
go mod download
# Setup Node environment (dashboard)
cd ../dashboard/frontend
npm install
Running Locally
Proxy:
cd proxy
export ZAI_API_KEY="your-api-key-here"
go run .
# Proxy listens on :8080
# Metrics available at :8080/metrics
Dashboard:
cd dashboard/frontend
npm run dev
# Frontend dev server on :5173
# Backend API on :8081
Code Style and Conventions
Go Code (proxy/)
- Follow standard Go conventions as described in Effective Go
- Run
gofmtbefore committing:gofmt -w . - Use meaningful names - err, ctx, req, resp are acceptable; i, j, x should be avoided unless trivial
- Exported functions must have doc comments
- Error handling - Always check and handle errors, use
fmt.Errorfwith%wfor wrapping - Package organization - Keep related functions together, separate concerns into files (e.g.,
tokenizer.go,translator.go,metrics.go)
TypeScript/React Code (dashboard/frontend/)
- Use functional components with hooks
- Follow existing patterns - check similar components before adding new ones
- Type safety - Avoid
any, use proper interfaces - File naming -
PascalCase.tsxfor components,kebab-case.tsfor utilities
General
- Keep functions focused - Single responsibility principle
- Add comments for non-obvious logic
- Update tests when modifying behavior
- Run linters before committing
Testing Requirements
Go Tests
# Run all tests
go test -v ./...
# Run specific test
go test -v -run TestTokenCountingBasicRequest
# Run with coverage
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
# Run benchmarks
go test -bench=. -benchmem
Testing Requirements:
- Unit tests for new functions and methods
- Integration tests for API endpoints
- Regression tests in
tokenizer_regression_test.gofor token counting accuracy - Benchmarks for performance-critical code (target: <5ms per token counting operation)
Frontend Tests
cd dashboard/frontend
npm test # Run Jest tests
npm run lint # Run ESLint
Manual Testing
- Test streaming responses - Ensure SSE streams work correctly
- Verify metrics - Check
:8080/metricsafter operations - Test edge cases - Empty inputs, malformed JSON, concurrent requests
Commit Message Conventions
We use conventional commits format:
<type>(<scope>): <description>
[optional body]
[optional footer]
Types:
feat- New featurefix- Bug fixdocs- Documentation changeschore- Maintenance tasks (version bumps, dependencies)refactor- Code refactoring (no behavior change)test- Adding or updating testsperf- Performance improvements
Scopes:
proxy- Go proxy backenddashboard- Dashboard (Go backend + React frontend)frontend- React frontend specifically- (none) - General or multiple components
Examples:
feat(proxy): add GLM-4 tokenizer support
fix(dashboard): correct token count display for large numbers
docs(proxy): update environment variables reference
chore: bump VERSION to 1.1.0
Pull Request Process
- Branch naming - Use descriptive names:
feat/add-glm-4-support,fix/token-leak - Update documentation - Include doc changes in the same PR
- Add tests - Ensure tests pass before submitting
- Single purpose - One PR should do one thing well
- Commit squash - Keep history clean, squash related commits
PR Description Template
## What
Brief description of changes.
## Why
Context and motivation for the change.
## How
Implementation approach and key decisions.
## Testing
- [ ] Unit tests pass
- [ ] Integration tests pass
- [ ] Manual testing completed
## Checklist
- [ ] Documentation updated
- [ ] No breaking changes (or documented)
- [ ] Tests added/updated
Adding New Features or Fixing Bugs
Feature Workflow
- Discuss first - Open an issue or discussion for significant features
- Design phase - Consider architecture, metrics, edge cases
- Implementation - Write code following conventions
- Testing - Add comprehensive tests
- Documentation - Update relevant docs
- Metrics - Add Prometheus metrics for observability
Bug Fix Workflow
- Reproduce - Create a test case that reproduces the bug
- Fix - Implement the minimal fix
- Verify - Ensure the test now passes
- Regression check - Run full test suite
- Document - Add comments if the fix is non-obvious
Adding Metrics
New metrics should follow the Prometheus naming convention:
var myMetric = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "zai_proxy_<metric_name>",
Help: "<Description>",
},
[]string{"label1", "label2"},
)
Register in metrics.go:
- Add to
MetricsRegistry - Initialize in
initMetrics()
Documentation
Documentation Structure
zai-proxy/
├── README.md # Project overview
├── CONTRIBUTING.md # This file
├── proxy/
│ ├── README.md # Proxy-specific docs
│ └── docs/ # Detailed proxy documentation
└── dashboard/
└── README.md # Dashboard-specific docs
When to Update Docs
- README.md - When adding user-facing features
- docs/ - When adding detailed implementation notes
- Comments - When code is non-trivial
Writing Style
- Be concise - Get to the point
- Include examples - Show, don't just tell
- Keep current - Update docs when code changes
- Use diagrams - For complex flows
Getting Help
Questions
- Check documentation -
docs/directories have detailed info - Search issues - Your question may have been answered
- Contact:
jedarden@jedarden.com
Reporting Issues
When reporting bugs, include:
- Environment - Go version, OS, reproduction steps
- Expected behavior - What should happen
- Actual behavior - What actually happens
- Logs - Relevant error messages or stack traces
- Minimal reproduction - Smallest code that reproduces the issue
Security Issues
For security vulnerabilities, contact directly: jedarden@jedarden.com
Development Workflow Summary
# 1. Create feature branch
git checkout -b feat/my-feature
# 2. Make changes and test
go test -v ./...
npm test
# 3. Format and lint
gofmt -w .
npm run lint
# 4. Commit with conventional message
git commit -m "feat(proxy): add my feature"
# 5. Push and create PR
git push origin feat/my-feature
License
By contributing to zai-proxy, you agree that your contributions will be licensed under the same license as the project.