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
- 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.ymlwith appropriate networking and environment configuration - Update CI/CD pipeline configurations
- Configure environment variables
Node.js Applications
- Background workers
- Message queue consumers
- Scheduled jobs
- CLI tools
Bootstrap Pattern
Applications typically include graceful shutdown handling:Shared Libraries
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