Contributing
This guide covers how to set up a development environment, run the test suite, and contribute code to Gatewyse. These are internal contribution guidelines for team members working on the product.
Development Setup
Prerequisites
- Node.js 24.0.0 or later
- pnpm 10.0.0 or later
- Docker and Docker Compose (for MongoDB, Redis, and integration tests)
Clone and Install
git clone <repository-url>cd ai-gatewaypnpm installStart Infrastructure
Launch MongoDB and Redis using Docker Compose:
docker compose -f docker/docker-compose.yml up -dThis starts:
- MongoDB on port 27017 (with initialization script at
docker/mongo-init.js) - Redis on port 6379
Build the Shared Package
The shared package must be built before other packages, since they depend on its compiled output:
pnpm build:sharedStart Development Servers
Run all services in development mode:
pnpm devOr run them individually:
pnpm dev:server # Express API on port 3000pnpm dev:worker # BullMQ workerpnpm dev:admin # Nuxt admin dashboard on port 3001Running Tests
The project has four test tiers with 869 total tests.
Unit Tests (777 tests)
Fast, isolated tests with no external dependencies:
pnpm test:unitUnit tests are located in tests/unit/ and use Jest. They cover services, adapters, utilities, and middleware.
Integration Tests (46 tests)
Tests that require MongoDB and Redis:
# Start test infrastructurepnpm test:integration:up
# Run integration testspnpm test:integration
# Tear down test infrastructurepnpm test:integration:downIntegration tests use docker/docker-compose.test.yml with isolated test databases. They run sequentially (--runInBand) to avoid port conflicts.
End-to-End Tests (46 tests)
Playwright tests for the admin dashboard:
pnpm --filter @ai-gateway/admin test:e2eE2E tests are located in packages/admin/e2e/ and test the full admin dashboard UI with mocked API responses. The admin runs in SPA mode (ssr: false), so Pinia auth state is in-memory and page.goto resets state.
Navigation in E2E tests uses sidebar clicks rather than direct URL navigation to match real user behavior.
Smoke Tests (6 phases)
Live tests against a running server:
npx tsx tests/smoke/run.tsSmoke tests run in six sequential phases:
- Infrastructure — Verify server health, MongoDB, and Redis connectivity
- Authentication — Test login, token refresh, and API key validation
- CRUD — Test admin API resource management (tenants, users, providers, models, etc.)
- Gateway Setup — Configure providers and routing for live testing
- Live Gateway — Send actual requests through configured providers
- Advanced — Test semantic cache, budget enforcement, and guard pipeline
Configuration is in tests/smoke/.env.smoke.
Code Structure
Package Conventions
packages/+-- shared/src/| +-- types/ # TypeScript interfaces and type definitions| +-- schemas/ # Zod validation schemas| +-- utils/ # Shared utility functions| +-- errors/ # AppError class and error codes+-- server/src/| +-- config/ # Environment, Redis, and database configuration| +-- middleware/ # Express middleware (auth, rate limiting, etc.)| +-- models/ # Mongoose models and schemas| +-- providers/ # Provider adapter implementations (28 adapters)| +-- routes/ # Express route handlers| +-- services/ # Business logic services| +-- utils/ # Server-specific utilities+-- worker/src/ # BullMQ job processors+-- admin/ +-- app/ # Nuxt 4 application (pages, components, stores) +-- e2e/ # Playwright E2E testsDevelopment Pattern
The codebase follows a layered pattern for new features:
- Types — Define interfaces in
packages/shared/src/types/ - Zod Schema — Add validation schemas in
packages/shared/src/schemas/ - Model — Create Mongoose model in
packages/server/src/models/ - Service — Implement business logic in
packages/server/src/services/ - Route — Add Express routes in
packages/server/src/routes/ - Tests — Write unit tests in
tests/unit/, integration tests intests/integration/
Linting and Formatting
pnpm lint # ESLint with auto-fixpnpm format # Prettier formattingpnpm typecheck # TypeScript type checking across all packagesCI Pipeline
GitHub Actions runs the following on every pull request:
- Lint — ESLint checks
- Typecheck — TypeScript compilation
- Build — Full monorepo build
- Unit Tests — All 777 unit tests
- Integration Tests — All 46 integration tests with Docker services
PR Process
- Create a feature branch from
main. - Make your changes following the development pattern above.
- Ensure all tests pass locally:
pnpm lint && pnpm typecheck && pnpm test:unit. - Write tests for new functionality. Aim to cover both success and error paths.
- Open a pull request against
mainwith a clear description of the change. - CI must pass before merge.
Commit Message Style
Use conventional commit format:
feat:— New featurefix:— Bug fixrefactor:— Code restructuring without behavior changetest:— Adding or updating testsdocs:— Documentation changeschore:— Build, CI, dependency updates
Next Steps
- Architecture Overview — Understand the system design
- Provider Adapters — How to add a new provider
- Routing Strategies — The ten routing algorithms