autopilot operations with Kafka integration.
- Kafka message production and consumption
- Schema Registry integration for Avro message serialization
- Health check endpoints for Kafka and application monitoring
- Structured logging with Winston
- Environment-based configuration
- Graceful shutdown handling
- Error handling and validation
- Node.js (v18 or higher)
- Docker and Docker Compose
- Node.js v20 or higher
- Docker and Docker Compose
Create a .env
file in the root directory:
cp .env.example .env
Configure the following environment variables:
# App Configuration
NODE_ENV=development
PORT=3000
LOG_LEVEL=info
LOG_DIR=logs
# Kafka Configuration
KAFKA_BROKERS=localhost:9092
KAFKA_CLIENT_ID=autopilot-service
KAFKA_MAX_RETRY_TIME=30000
KAFKA_INITIAL_RETRY_TIME=300
KAFKA_RETRIES=5
# Schema Registry Configuration
SCHEMA_REGISTRY_URL=http://localhost:8081
# Using pnpm
pnpm install
- Start Kafka infrastructure using Docker Compose:
docker compose up -d
This will start:
- Zookeeper (port 2181)
- Kafka (ports 9092, 29092)
- Schema Registry (port 8081)
- Kafka UI (port 8080)
- Verify Docker containers are healthy:
# Check container status
docker compose ps
# Check container logs for any errors
docker compose logs
# Verify Kafka UI is accessible
http://localhost:8080
- Start the application locally:
# Using the start script
./start-local.sh
# Or manually with environment variables
npm run start:dev
- Check if the application is running:
curl http://localhost:3000/health
- Access Kafka UI:
- Open http://localhost:8080 in your browser
- Verify Kafka cluster connection
- Check Schema Registry status
- Access Schema Registry:
- Open http://localhost:8081 in your browser
- Verify schemas are registered
# Lint
$ npm run lint
GET /health
- Overall health check including KafkaGET /health/kafka
- Kafka-specific health checkGET /health/app
- Application health check
The service interacts with the following Kafka topics:
-
autopilot.command
- Used for sending commands to the autopilot service
- Example payload:
{ "command": "START_PHASE", "operator": "john.doe", "projectId": 123, "date": "2024-03-20T10:00:00Z" }
-
autopilot.phase.transition
- Used for phase transition events
- Example payload:
{ "projectId": 123, "phaseId": 456, "phaseTypeName": "Development", "state": "START", "operator": "john.doe", "projectStatus": "IN_PROGRESS", "date": "2024-03-20T10:00:00Z" }
-
autopilot.challenge.update
- Used for challenge update events
- Example payload:
{ "projectId": 123, "challengeId": 789, "status": "ACTIVE", "operator": "john.doe", "date": "2024-03-20T10:00:00Z" }
src/
├── app.module.ts # Root application module
├── main.ts # Application entry point
├── config/ # Configuration files
│ ├── configuration.ts # Main configuration
│ ├── validation.ts # Environment validation
│ └── sections/ # Configuration sections
├── kafka/ # Kafka related code
│ ├── kafka.module.ts # Kafka module
│ ├── kafka.service.ts # Kafka service
│ ├── consumers/ # Kafka consumers
│ └── producers/ # Kafka producers
├── common/ # Common utilities
│ ├── constants/ # Constants
│ ├── exceptions/ # Custom exceptions
│ ├── filters/ # Exception filters
│ ├── interceptors/ # Interceptors
│ ├── interfaces/ # TypeScript interfaces
│ ├── services/ # Common services
│ └── utils/ # Utility functions
└── autopilot/ # Autopilot specific code
├── autopilot.module.ts # Autopilot module
├── services/ # Autopilot services
└── interfaces/ # Autopilot interfaces
test/ # Test files
├── jest-e2e.json # Jest E2E configuration
└── app.e2e-spec.ts # E2E test specifications
.env # Environment variables
.env.example # Example env template
package.json # Dependencies and scripts
tsconfig.json # TypeScript config
README.md # Documentation