Skip to content

Commit 3fea6d6

Browse files
committed
Init
0 parents  commit 3fea6d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+23585
-0
lines changed

.dockerignore

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Version control
2+
.git
3+
.gitignore
4+
.gitattributes
5+
6+
# Dependencies
7+
node_modules
8+
npm-debug.log
9+
yarn-debug.log
10+
yarn-error.log
11+
12+
# Build output
13+
dist
14+
build
15+
16+
# Environment variables
17+
.env
18+
.env.*
19+
!.env.example
20+
21+
# IDE files
22+
.idea
23+
.vscode
24+
*.swp
25+
*.swo
26+
27+
# Logs
28+
logs
29+
*.log
30+
31+
# Test coverage
32+
coverage
33+
.nyc_output
34+
35+
# Docker
36+
Dockerfile*
37+
docker-compose*
38+
.dockerignore
39+
40+
# Documentation
41+
README.md
42+
CHANGELOG.md
43+
docs/
44+
45+
# OS files
46+
.DS_Store
47+
Thumbs.db

.env

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# KAFKA_BROKERS=localhost:29092
2+
# SCHEMA_REGISTRY_URL=http://localhost:8081
3+
# KAFKA_CLIENT_ID=autopilot-service
4+
# KAFKA_MAX_RETRY_TIME=30000
5+
# KAFKA_INITIAL_RETRY_TIME=300
6+
# KAFKA_RETRIES=5
7+
8+
NODE_ENV=development
9+
PORT=3000
10+
LOG_LEVEL=info
11+
LOG_DIR=logs
12+
13+
# Kafka Configuration
14+
KAFKA_BROKERS=localhost:9092
15+
KAFKA_CLIENT_ID=autopilot-service
16+
KAFKA_MAX_RETRY_TIME=30000
17+
KAFKA_INITIAL_RETRY_TIME=300
18+
KAFKA_RETRIES=5
19+
20+
# Schema Registry Configuration
21+
SCHEMA_REGISTRY_URL=http://localhost:8081

.env.example

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# KAFKA_BROKERS=localhost:29092
2+
# SCHEMA_REGISTRY_URL=http://localhost:8081
3+
# KAFKA_CLIENT_ID=autopilot-service
4+
# KAFKA_MAX_RETRY_TIME=30000
5+
# KAFKA_INITIAL_RETRY_TIME=300
6+
# KAFKA_RETRIES=5
7+
8+
NODE_ENV=development
9+
PORT=3000
10+
LOG_LEVEL=info
11+
LOG_DIR=logs
12+
13+
# Kafka Configuration
14+
KAFKA_BROKERS=localhost:9092
15+
KAFKA_CLIENT_ID=autopilot-service
16+
KAFKA_MAX_RETRY_TIME=30000
17+
KAFKA_INITIAL_RETRY_TIME=300
18+
KAFKA_RETRIES=5
19+
20+
# Schema Registry Configuration
21+
SCHEMA_REGISTRY_URL=http://localhost:8081

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM node:20-alpine as builder
2+
3+
WORKDIR /usr/src/app
4+
5+
# Install dependencies
6+
COPY package*.json ./
7+
RUN npm ci
8+
9+
# Copy source code
10+
COPY . .
11+
12+
# Build the application
13+
RUN npm run build
14+
15+
# Production stage
16+
FROM node:20-alpine
17+
18+
WORKDIR /usr/src/app
19+
20+
# Copy package files
21+
COPY package*.json ./
22+
23+
# Install production dependencies only
24+
RUN npm ci --only=production
25+
26+
# Copy built application
27+
COPY --from=builder /usr/src/app/dist ./dist
28+
29+
# Expose port
30+
EXPOSE 3000
31+
32+
# Start the application
33+
CMD ["npm", "run", "start:prod"]

Dockerfile.dev

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:18-alpine
2+
3+
WORKDIR /app
4+
5+
# Install dependencies
6+
COPY package*.json ./
7+
RUN npm install
8+
9+
# Copy source code
10+
COPY . .
11+
12+
# Expose port
13+
EXPOSE 3000
14+
15+
# Start development server with hot reloading
16+
CMD ["npm", "run", "start:dev"]

README.md

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
# Autopilot Service
2+
3+
autopilot operations with Kafka integration.
4+
5+
## Features
6+
7+
- Kafka message production and consumption
8+
- Schema Registry integration for Avro message serialization
9+
- Health check endpoints for Kafka and application monitoring
10+
- Structured logging with Winston
11+
- Environment-based configuration
12+
- Graceful shutdown handling
13+
- Error handling and validation
14+
15+
## Prerequisites
16+
17+
- Node.js (v18 or higher)
18+
- Docker and Docker Compose
19+
20+
## Installation
21+
22+
### 1. Prerequisites
23+
24+
- Node.js v20 or higher
25+
- Docker and Docker Compose
26+
27+
### 2. Environment Setup
28+
29+
Create a `.env` file in the root directory:
30+
31+
```bash
32+
cp .env.example .env
33+
```
34+
35+
Configure the following environment variables:
36+
37+
```env
38+
# App Configuration
39+
NODE_ENV=development
40+
PORT=3000
41+
LOG_LEVEL=info
42+
LOG_DIR=logs
43+
44+
# Kafka Configuration
45+
KAFKA_BROKERS=localhost:9092
46+
KAFKA_CLIENT_ID=autopilot-service
47+
KAFKA_MAX_RETRY_TIME=30000
48+
KAFKA_INITIAL_RETRY_TIME=300
49+
KAFKA_RETRIES=5
50+
51+
# Schema Registry Configuration
52+
SCHEMA_REGISTRY_URL=http://localhost:8081
53+
```
54+
55+
### 3. Install Dependencies
56+
57+
```bash
58+
# Using npm
59+
npm install
60+
61+
# Using yarn
62+
yarn install
63+
64+
# Using pnpm
65+
pnpm install
66+
```
67+
68+
### 4. Development Setup
69+
70+
1. Start Kafka infrastructure using Docker Compose:
71+
```bash
72+
docker-compose up -d
73+
```
74+
75+
This will start:
76+
- Zookeeper (port 2181)
77+
- Kafka (ports 9092, 29092)
78+
- Schema Registry (port 8081)
79+
- Kafka UI (port 8080)
80+
81+
2. Verify Docker containers are healthy:
82+
```bash
83+
# Check container status
84+
docker-compose ps
85+
86+
# Check container logs for any errors
87+
docker-compose logs
88+
89+
# Verify Kafka UI is accessible
90+
http://localhost:8080
91+
```
92+
93+
3. Start the application locally:
94+
```bash
95+
# Using the start script
96+
./start-local.sh
97+
98+
# Or manually with environment variables
99+
npm run start:dev
100+
```
101+
102+
### 5. Verify Installation
103+
104+
1. Check if the application is running:
105+
```bash
106+
curl http://localhost:3000/health
107+
```
108+
109+
2. Access Kafka UI:
110+
- Open http://localhost:8080 in your browser
111+
- Verify Kafka cluster connection
112+
- Check Schema Registry status
113+
114+
3. Access Schema Registry:
115+
- Open http://localhost:8081 in your browser
116+
- Verify schemas are registered
117+
118+
# Test coverage
119+
120+
## Scripts
121+
122+
```bash
123+
# Lint
124+
$ npm run lint
125+
126+
```
127+
128+
## API Endpoints
129+
130+
### Health Checks
131+
132+
- `GET /health` - Overall health check including Kafka
133+
- `GET /health/kafka` - Kafka-specific health check
134+
- `GET /health/app` - Application health check
135+
136+
## Kafka Topics
137+
138+
The service interacts with the following Kafka topics:
139+
140+
1. `autopilot.command`
141+
- Used for sending commands to the autopilot service
142+
- Example payload:
143+
```json
144+
{
145+
"command": "START_PHASE",
146+
"operator": "john.doe",
147+
"projectId": 123,
148+
"date": "2024-03-20T10:00:00Z"
149+
}
150+
```
151+
152+
2. `autopilot.phase.transition`
153+
- Used for phase transition events
154+
- Example payload:
155+
```json
156+
{
157+
"projectId": 123,
158+
"phaseId": 456,
159+
"phaseTypeName": "Development",
160+
"state": "START",
161+
"operator": "john.doe",
162+
"projectStatus": "IN_PROGRESS",
163+
"date": "2024-03-20T10:00:00Z"
164+
}
165+
```
166+
167+
3. `autopilot.challenge.update`
168+
- Used for challenge update events
169+
- Example payload:
170+
```json
171+
{
172+
"projectId": 123,
173+
"challengeId": 789,
174+
"status": "ACTIVE",
175+
"operator": "john.doe",
176+
"date": "2024-03-20T10:00:00Z"
177+
}
178+
```
179+
180+
## Project Structure
181+
182+
```
183+
src/
184+
├── app.module.ts # Root application module
185+
├── main.ts # Application entry point
186+
├── config/ # Configuration files
187+
│ ├── configuration.ts # Main configuration
188+
│ ├── validation.ts # Environment validation
189+
│ └── sections/ # Configuration sections
190+
├── kafka/ # Kafka related code
191+
│ ├── kafka.module.ts # Kafka module
192+
│ ├── kafka.service.ts # Kafka service
193+
│ ├── consumers/ # Kafka consumers
194+
│ └── producers/ # Kafka producers
195+
├── common/ # Common utilities
196+
│ ├── constants/ # Constants
197+
│ ├── exceptions/ # Custom exceptions
198+
│ ├── filters/ # Exception filters
199+
│ ├── interceptors/ # Interceptors
200+
│ ├── interfaces/ # TypeScript interfaces
201+
│ ├── services/ # Common services
202+
│ └── utils/ # Utility functions
203+
└── autopilot/ # Autopilot specific code
204+
├── autopilot.module.ts # Autopilot module
205+
├── services/ # Autopilot services
206+
└── interfaces/ # Autopilot interfaces
207+
208+
test/ # Test files
209+
├── jest-e2e.json # Jest E2E configuration
210+
└── app.e2e-spec.ts # E2E test specifications
211+
212+
.env # Environment variables
213+
.env.example # Example env template
214+
package.json # Dependencies and scripts
215+
tsconfig.json # TypeScript config
216+
README.md # Documentation
217+
```

0 commit comments

Comments
 (0)