This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a monorepo for the Surgio project containing multiple packages managed by pnpm workspaces, Lerna, and Turbo. Surgio is a network configuration management tool. The repository contains:
- @surgio/gateway: NestJS-based API Gateway backend that serves Surgio configuration
- @surgio/gateway-frontend: React-based frontend UI for the gateway (built with CRA/Craco, Tailwind CSS, MobX, shadcn/ui)
- @surgio/logger: Winston-based logging utility shared across packages
- @surgio/eslint-config-surgio: ESLint configuration for Surgio config stores
# Install dependencies
pnpm install
# Build all packages (uses Turbo)
pnpm build
# Run tests across all packages
pnpm test
# Lint all packages
pnpm lint
# Release management
pnpm release # Create new version and publish
pnpm release:beta # Create beta version and publish with beta tagNavigate to specific packages for targeted development:
# Build
pnpm build
# Development mode with watch
pnpm dev
# Start production server
pnpm start:prod
# Debug mode
pnpm debug
# Run all tests (unit + e2e)
pnpm test
# Run unit tests only
pnpm test:unit
# Run e2e tests only
pnpm test:e2e
# Watch mode for tests
pnpm test:watch
# Test with coverage
pnpm test:cov
# Lint
pnpm lint# Development server
pnpm dev
# Build for production
pnpm build
# Run tests
pnpm test
# Watch tests
pnpm test:watch
# Test with coverage
pnpm test:cov
# Lint
pnpm lint# Build
pnpm build
# Test
pnpm test
# Watch tests
pnpm test:watch
# Test with coverage
pnpm test:cov
# Lint
pnpm lint- Build System: Turbo handles build orchestration with dependency-aware caching
- Package Manager: pnpm with workspaces (version: 10.27.0+)
- Versioning: Lerna with independent versioning and conventional commits
- Git Hooks: Husky + lint-staged for pre-commit checks
- Commit Convention: Angular-style conventional commits (enforced by commitlint)
The gateway is a NestJS application that integrates with the main Surgio library:
Core Bootstrap Flow:
main.ts→bootstrap()inbootstrap.ts- Creates NestJS application with custom Express adapter
- Initializes
SurgioModule(global) with project directory fromSURGIO_PROJECT_DIRenv var SurgioHelperloads Surgio config and initializes helper utilities- Serves static frontend from
@surgio/gateway-frontend/build
Module Organization:
AppModule: Root module, configures static file serving, global config, and middlewareSurgioModule: Global module that providesSurgioServiceandSurgioHelperto entire appApiModule: API endpoints for configuration managementAuthModule: Authentication using Passport (cookie & bearer token strategies)
Key Middleware:
CookieParserMiddleware: Parses cookies with secret from Surgio config hashPrepareMiddleware: Runs before controller actions (excluded from render routes)
Deployment Options:
- HTTP Server:
createHttpServer()- Standard Node.js HTTP server - Standalone:
startServer()- Starts on configured port - Serverless:
createLambdaHandler()- AWS Lambda handler with lazy initialization
Testing Strategy:
- Unit tests:
*.spec.tsfiles insrc/ - E2E tests:
*.e2e-spec.tsfiles in__tests__/e2e/ - Test fixtures in
__tests__/__fixtures__/ - Separate Jest configs for unit vs e2e
Built with React 18, using:
- State Management: MobX with mobx-react-lite
- Routing: React Router v6
- Data Fetching: SWR (stale-while-revalidate)
- Forms: React Hook Form + Zod validation
- UI Components: shadcn/ui (Radix UI primitives + Tailwind)
- Styling: Tailwind CSS with custom config
- Build: Create React App with Craco customization
The frontend is bundled into build/ and served as static files by the gateway backend.
Simple Winston-based logger factory:
- Provides
createLogger()function - Log level controlled by
SURGIO_LOG_LEVELenv var (default: 'info') - Formats: timestamp, label (service name), level, message
- Colorized output in non-production
- Used by gateway and main Surgio project
The gateway depends on the main surgio package (peer dependency). The SurgioModule.register() function:
- Accepts
cwdoption (project directory) - Calls
loadConfig()fromsurgio/configto load user's Surgio configuration - Creates
SurgioHelperinstance with loaded config - Makes helper available globally via dependency injection
The gateway sets x-frontend-version header on static assets (JS/CSS/JSON) to track frontend version in production.
The gateway package uses workspace:* protocol to depend on @surgio/gateway-frontend, ensuring it always uses the local workspace version.
# Unit test for specific file
cd packages/gateway
pnpm test -- surgio.service.spec.ts
# E2E test for specific file
cd packages/gateway
pnpm test:e2e -- api.e2e-spec.ts
# Frontend test for specific file
cd packages/gateway-frontend
pnpm test -- App.test.tsx- Gateway unit tests:
__tests__/setup-tests.ts - Gateway e2e tests:
__tests__/setup-e2e-tests.ts - Frontend tests:
src/setupTests.ts
- Lerna manages versions independently for each package
- Conventional commits determine version bumps automatically
pnpm releaserunslerna version(prompts for confirmation) thenlerna publish from-git- Beta releases use
--preid betaflag and publish to@betadist-tag - Build step runs automatically via
prepublishOnlyscript
All packages require Node.js >= 18.0.0