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
- Add the new service to
docker-compose.yml with appropriate networking and environment configuration
- Update CI/CD pipeline configurations
- 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
- TypeScript path alias - Register in
tsconfig.base.json:
- Public API - Define exports in
src/index.ts:
- 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