Skip to main content

Creating Services and Libraries

The CoW Protocol BFF monorepo uses NX generators to scaffold new projects with proper TypeScript, Docker, and configuration setup.

Available Generators

Three main generators are available:

Fastify API Services

Running the Fastify generator creates a complete API structure with:
  • App configuration (src/app/app.ts)
  • Entry point (src/main.ts)
  • Docker setup
  • ESLint settings
  • Testing infrastructure

Route Organization

Keep route schemas in separate files (e.g., *.schemas.ts). Do not inline JSON schemas in route handlers.

Post-Generation Steps

  1. Add the new service to docker-compose.yml with appropriate networking and environment configuration
  2. Update CI/CD pipeline configurations
  3. Configure environment variables

Node.js Applications

The Node.js generator supports:
  • Background workers
  • Message queue consumers
  • Scheduled jobs
  • CLI tools

Bootstrap Pattern

Applications typically include graceful shutdown handling:

Shared Libraries

Libraries enable code reuse across multiple applications.

Post-Generation Setup

  1. TypeScript path alias - Register in tsconfig.base.json:
  1. Public API - Define exports in src/index.ts:
  1. Module boundaries - Follow these rules:
    • Apps can import from libs
    • Libs should only import from other libs
    • Never create circular dependencies

Existing Libraries

The monorepo includes these shared libraries:

Architecture Enforcement

NX enforces module boundaries to maintain clean architecture:
  • Apps can import from libs
  • Libs should only import from other libs
  • Circular dependencies are prevented

Pre-Commit Checklist

Before committing changes, run all checks:
Last modified on March 4, 2026