Developer Setup Guide
Developer Setup Guide
Section titled “Developer Setup Guide”Overview
Section titled “Overview”This guide provides comprehensive setup instructions for the WorkerSQL development environment - a MySQL-compatible edge database platform built on Cloudflare Workers.
Prerequisites
Section titled “Prerequisites”Required Software
Section titled “Required Software”- Node.js: v18.0.0 or higher (Download)
- npm: v8.0.0 or higher (comes with Node.js)
- Git: Latest version (Download)
- Python: v3.8+ (for security scanning tools)
- VS Code: Recommended IDE (Download)
Cloudflare Account Requirements
Section titled “Cloudflare Account Requirements”- Cloudflare account with Workers enabled
- Workers Paid plan (required for Durable Objects)
- API Token with the following permissions:
Cloudflare Workers:Edit
Account:Read
Zone:Read
Installation
Section titled “Installation”1. Clone the Repository
Section titled “1. Clone the Repository”git clone https://github.com/healthfees-org/workersql.gitcd workersql
2. Install Dependencies
Section titled “2. Install Dependencies”# Install Node.js dependenciesnpm install
# Install Python dependencies for security scanningpython -m pip install --user pre-commit bandit
3. Setup Pre-commit Hooks
Section titled “3. Setup Pre-commit Hooks”# Install pre-commit hooksnpm run prepare
# Test pre-commit installationpre-commit run --all-files
4. Configure Wrangler
Section titled “4. Configure Wrangler”# Install Wrangler CLI globally (if not already installed)npm install -g wrangler
# Authenticate with Cloudflarewrangler auth login
# Copy and configure wrangler.tomlcp wrangler.toml.template wrangler.toml
5. Environment Configuration
Section titled “5. Environment Configuration”Development Environment
Section titled “Development Environment”Create a .env.local
file:
# Copy environment templatecp .env.example .env.local
# Edit with your valuesENVIRONMENT=developmentLOG_LEVEL=debugMAX_SHARD_SIZE_GB=1CACHE_TTL_MS=300000CACHE_SWR_MS=600000SHARD_COUNT=4
Configure Secrets
Section titled “Configure Secrets”# Set JWT secret for authenticationwrangler secret put JWT_SECRET
# Set encryption keyswrangler secret put ENCRYPTION_KEY_PRIMARYwrangler secret put ENCRYPTION_KEY_SECONDARY
Development Workflow
Section titled “Development Workflow”1. Build the Project
Section titled “1. Build the Project”# TypeScript compilationnpm run build
# Watch mode for developmentnpm run build -- --watch
2. Run Tests
Section titled “2. Run Tests”# Run all testsnpm test
# Run specific test suitesnpm run test:unitnpm run test:integrationnpm run test:coverage
# Run tests in watch modenpm run test:watch
3. Local Development
Section titled “3. Local Development”# Start local development servernpm run dev
# Test local deploymentcurl -X POST http://localhost:8787/query \ -H "Content-Type: application/json" \ -H "Authorization: Bearer test-token-12345" \ -d '{"sql": "SELECT 1 as test"}'
4. Code Quality
Section titled “4. Code Quality”# Lint codenpm run lint
# Fix linting issuesnpm run lint:fix
# Format codenpm run format
# Check formattingnpm run format:check
# Run security scansnpm run security:check
# Complete workflow checknpm run workflow:check
IDE Setup
Section titled “IDE Setup”VS Code Extensions
Section titled “VS Code Extensions”Install these recommended extensions:
{ "recommendations": [ "ms-vscode.vscode-typescript-next", "esbenp.prettier-vscode", "ms-vscode.vscode-eslint", "bradlc.vscode-tailwindcss", "ms-python.python", "ms-python.bandit" ]}
VS Code Settings
Section titled “VS Code Settings”Add to your .vscode/settings.json
:
{ "typescript.preferences.strictFunctionTypes": true, "typescript.preferences.strictNullChecks": true, "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, "eslint.workingDirectories": ["src", "tests"]}
Testing Strategy
Section titled “Testing Strategy”Unit Tests
Section titled “Unit Tests”- Located in
tests/unit/
- Use Jest with ts-jest transformer
- Mock Cloudflare Workers environment
- Focus on individual service logic
Integration Tests
Section titled “Integration Tests”- Located in
tests/integration/
- Use Miniflare for Cloudflare Workers simulation
- Test service interactions
- Validate cache and queue behaviors
End-to-End Tests
Section titled “End-to-End Tests”- Located in
tests/e2e/
- Test complete workflows
- Validate API contracts
- Performance benchmarking
Browser Tests
Section titled “Browser Tests”- Located in
tests/browser/
- Use Playwright for browser automation
- Test client SDK functionality
- Cross-browser compatibility
Deployment
Section titled “Deployment”Development Deployment
Section titled “Development Deployment”# Deploy to development environmentwrangler deploy --env development
# View deployment logswrangler tail
Staging Deployment
Section titled “Staging Deployment”# Deploy to staging environmentwrangler deploy --env staging
# Run smoke tests against stagingnpm run test:smoke -- --env=staging
Production Deployment
Section titled “Production Deployment”# Deploy to production (requires approval)wrangler deploy --env production
# Monitor production deploymentwrangler tail --env production
Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”Build Failures
Section titled “Build Failures”# Clear TypeScript cachenpx tsc --build --clean
# Reinstall dependenciesrm -rf node_modules package-lock.jsonnpm install
Test Failures
Section titled “Test Failures”# Update test snapshotsnpm test -- --updateSnapshot
# Run tests with verbose outputnpm test -- --verbose
# Debug specific testnpm test -- --testNamePattern="test name"
Wrangler Issues
Section titled “Wrangler Issues”# Re-authenticatewrangler auth logoutwrangler auth login
# Clear Wrangler cacherm -rf ~/.wrangler/cache
Pre-commit Hook Failures
Section titled “Pre-commit Hook Failures”# Update pre-commit hookspre-commit autoupdate
# Skip hooks temporarily (emergency only)git commit --no-verify
Performance Issues
Section titled “Performance Issues”Slow Tests
Section titled “Slow Tests”- Use
--testPathPattern
to run specific tests - Implement test parallelization
- Mock external dependencies
Build Performance
Section titled “Build Performance”- Use
--incremental
flag with TypeScript - Configure path mapping correctly
- Exclude unnecessary files from compilation
Security Issues
Section titled “Security Issues”Token Validation Failures
Section titled “Token Validation Failures”- Verify JWT_SECRET is set correctly
- Check token expiration times
- Validate issuer and audience claims
CORS Issues
Section titled “CORS Issues”- Update gateway CORS configuration
- Check request headers and methods
- Validate origin whitelist
Contributing
Section titled “Contributing”Code Style
Section titled “Code Style”- Follow TypeScript strict mode guidelines
- Use ESLint and Prettier configurations
- Write comprehensive JSDoc comments
- Follow security best practices
Pull Request Process
Section titled “Pull Request Process”- Create feature branch from
main
- Implement changes with tests
- Run
npm run workflow:check
- Submit PR with description
- Address review feedback
- Merge after approval
Security Guidelines
Section titled “Security Guidelines”- Never commit secrets or credentials
- Use Wrangler secrets for sensitive data
- Follow OWASP security guidelines
- Run security scans before commits
Support
Section titled “Support”Documentation
Section titled “Documentation”Community
Section titled “Community”- GitHub Issues: Report bugs and feature requests
- GitHub Discussions: Community support and questions
- Security Issues: [email protected]
Internal Support
Section titled “Internal Support”- Development Team: [email protected]
- DevOps Team: [email protected]
- Security Team: [email protected]
Last updated: September 1, 2025 Version: 1.0.0