Refactor kafka to pure Go (franz-go), fix DBC stubs, update Dockerfile

This commit is contained in:
Chris Rai
2026-01-31 00:05:47 -05:00
parent fbb820d7b3
commit b5bec57dfa
776 changed files with 18945 additions and 2052 deletions

114
README.md
View File

@@ -1,49 +1,85 @@
# cloud-services
# Cloud Services
Go microservices for the vehicle cloud platform.
## Quick Start
```bash
# Install devbox (if needed)
curl -fsSL https://get.jetify.com/devbox | bash
# Enter dev environment
devbox shell
# Run a service locally
cd services/gateway
go run .
```
Refactored cloud microservices from project-ai.
## Structure
```
services/ # Individual Go microservices
shared/ # Shared Go modules
deploy/ # Kubernetes manifests (kustomize)
base/ # Base configs
overlays/ # Environment-specific (development, etc.)
cloud-services/
├── pkg/ # Shared Go packages
│ ├── kafka/ # Pure Go Kafka client (franz-go)
├── dbc/ # CAN database signal definitions
├── can-go/ # CAN protocol library
│ └── ... # Other shared modules
├── services/
│ └── gateway/ # API gateway service
├── deploy/
│ ├── base/ # Base k8s manifests
│ └── overlays/ # Environment-specific configs
└── scripts/ # Build and utility scripts
```
## Quick Start
```bash
# Build all
go build ./...
# Build gateway
go build ./services/gateway
# Run tests
go test ./...
# Build Docker image
docker build -t gateway -f services/gateway/Dockerfile .
```
## Services
| Service | Description |
|---------|-------------|
| gateway | API gateway, routes requests |
| auth | Authentication (Keycloak integration) |
| ota | OTA update management |
| depot | Vehicle registration & management |
| attendant | Event processing |
| cargo | Data ingestion to storage |
| ditto | Digital twin state |
| manufacture | Manufacturing integration |
| aftersales | Aftersales/diagnostic services |
## Local Development
Services connect to:
- PostgreSQL: `cloud-dev-rw.cnpg-system.svc:5432`
- MongoDB: `cloud-dev-svc.mongodb.svc:27017`
- Redis: `cloud-dev.redis.svc:6379`
- Kafka: `cloud-dev-kafka-bootstrap.kafka.svc:9092`
- Keycloak: `https://keycloak.mini.cloud.fiskerinc.com`
### Gateway
WebSocket gateway for TRex, HMI, and Mobile connections. Handles auth, message routing to Kafka.
- Port 8077: HTTP/WebSocket
- Port 11011: Health check
## Development
### Prerequisites
- Go 1.25+
- Docker (for container builds)
### Module Structure
Uses Go workspaces (`go.work`) for local development:
- `./pkg` - shared packages
- `./pkg/can-go` - CAN protocol library
- `./services/gateway` - gateway service
### Generating DBC Code
CAN signal definitions are generated from DBC files. See `pkg/dbc/README.md`.
```bash
./scripts/generate-dbc.sh /path/to/dbc/files
```
## Deployment
ArgoCD syncs from this repo. Push to main → auto-deploy to mini cluster.
Kubernetes manifests in `deploy/` use Kustomize overlays:
```bash
# Development
kubectl apply -k deploy/overlays/development
# Or via ArgoCD
# See k8s-gitops-setup repo
```
## Environment Variables
| Variable | Default | Description |
|----------|---------|-------------|
| `KAFKA_HOSTS` | `localhost:9092` | Kafka brokers |
| `REDIS_HOST` | `localhost` | Redis host |
| `REDIS_PORT` | `6379` | Redis port |
| `JWK_URL` | - | JWKS endpoint for JWT validation |
| `LOG_LEVEL` | `info` | Log level |