2025-11-14 08:42:26 +08:00
# go-caatsm
2025-12-24 15:09:39 +08:00
Civil Aviation Authority Telegram Message Processor.
2025-11-14 08:42:26 +08:00
2025-12-24 15:09:39 +08:00
High-performance processing for aviation telegrams using Clean Architecture, NATS JetStream, and PostgreSQL/TimescaleDB.
2025-11-14 08:42:26 +08:00
## Architecture
2025-12-24 15:09:39 +08:00
Clean Architecture with clear separation of concerns:
2025-11-14 08:42:26 +08:00
2025-12-24 15:09:39 +08:00
- cmd: application entry points
- internal/domain: core domain types
- internal/port: interfaces/contracts
- internal/app: application orchestration
- internal/adapter: parsing, mapping, DTOs
- internal/infra: NATS, PostgreSQL, config, logging, metrics, telemetry
- pkg/di: dependency injection (Wire)
2025-11-14 08:42:26 +08:00
## Features
2025-12-24 15:09:39 +08:00
- JetStream ingestion with retries and DLQ support
- PostgreSQL/TimescaleDB persistence
- Structured logging (Zap)
- OpenTelemetry tracing and Prometheus metrics
- Optional AFTN protocol validation
- Batch processing and health monitoring
2025-12-24 16:38:03 +08:00
- Weather report parsing (METAR, SPECI, TAF)
2025-11-17 16:25:23 +08:00
2025-11-14 08:42:26 +08:00
## Prerequisites
2025-12-24 15:09:39 +08:00
- Go 1.24+
2025-11-14 08:42:26 +08:00
- PostgreSQL 12+
- NATS Server with JetStream enabled
2025-12-24 15:09:39 +08:00
- Docker (integration tests)
2025-11-14 08:42:26 +08:00
2025-12-24 15:09:39 +08:00
## Quick Start
2025-11-14 08:42:26 +08:00
2025-12-24 15:09:39 +08:00
1. Start dependencies:
```bash
docker compose -f docker-compose.dev.yml up -d postgres nats nats-box
` ``
2025-11-14 08:42:26 +08:00
2025-12-24 15:09:39 +08:00
2. Configure the application:
- Copy ` configs/config.dev.toml` and edit as needed
- Or set environment variables with the ` CAATSM_` prefix
2025-11-14 08:42:26 +08:00
2025-12-24 15:09:39 +08:00
3. Run in dev mode:
` ``bash
make run-dev
` ``
2025-11-14 08:42:26 +08:00
2025-12-24 15:09:39 +08:00
## Build and Run
- Build: ` make build`
- Run (dev): ` make run-dev`
- Run (prod): ` make run-prod`
- Run (local go run): ` make run-local`
2025-11-14 08:42:26 +08:00
## Configuration
2025-12-24 15:09:39 +08:00
Configuration loads from ` configs/config.{env}.toml`, where ` {env}` is ` GO_ENV` (default: ` dev`).
2025-11-14 08:42:26 +08:00
2025-12-24 15:09:39 +08:00
Required values:
- ` nats.url`
- ` postgres.url`
- ` publisher.topic`
2025-11-14 23:18:10 +08:00
2025-12-24 15:09:39 +08:00
Defaults:
- ` nats.stream` defaults to ` TELEGRAM`
- ` subscription.topic` defaults to ` telegram.>`
- ` nats.mode` must be ` jetstream` or empty (defaults to JetStream)
Minimal example:
2025-11-14 08:42:26 +08:00
` ``toml
[nats]
url = "nats://localhost:4222"
2025-11-17 16:25:23 +08:00
mode = "jetstream"
2025-11-14 08:42:26 +08:00
stream = "TELEGRAM"
consumer = "telegram-consumer"
[publisher]
2025-11-14 21:42:04 +08:00
topic = "telegram.json"
2025-11-14 08:42:26 +08:00
2025-12-24 15:09:39 +08:00
[subscription]
topic = "telegram.serial"
2025-11-14 08:42:26 +08:00
[postgres]
url = "postgres://user:password@localhost:5432/aviation?sslmode=disable"
[app]
batch_size = 50
batch_timeout = "2s"
2025-11-14 21:42:04 +08:00
monitor_interval = "30s"
2025-11-14 08:42:26 +08:00
[log]
level = "info"
format = "json"
2025-12-24 15:09:39 +08:00
` ``
2025-11-18 11:47:35 +08:00
2025-11-14 23:18:10 +08:00
### Timeouts and Ack Wait
2025-12-24 15:09:39 +08:00
` [timeouts]` is optional. To tune redelivery, set ` timeouts.ack_wait` and/or ` nats.consumer_rules.ack_wait`. When neither is specified the application defaults to ` 30s`.
## JetStream Notes
- JetStream is required; other modes are not supported.
- In dev/test (` GO_ENV=dev` or ` GO_ENV=test`), the stream and consumer are auto-created.
- In production, ensure the stream and consumer exist before starting the service.
- Configure retention and delivery behavior under ` [nats.stream_limits]` and ` [nats.consumer_rules]`.
## AFTN Validation
AFTN validation is optional and disabled by default. Enable it with:
` ``toml
[aftn]
validation_enabled = true
message_gap_threshold = "2m"
enable_sequence_gap_detection = true
2025-11-14 08:42:26 +08:00
` ``
2025-12-24 15:09:39 +08:00
When enabled, invalid telegrams are logged, recorded with error details, and can be routed to a DLQ if configured.
2025-11-14 08:42:26 +08:00
2025-12-24 15:09:39 +08:00
## Observability
2025-11-14 08:42:26 +08:00
2025-12-24 15:09:39 +08:00
- Metrics: ` GET /metrics`
- Liveness: ` GET /livez`
- Readiness: ` GET /readyz`
2025-11-14 08:42:26 +08:00
2025-12-24 15:09:39 +08:00
Monitoring server settings are under ` [monitoring]`. Tracing is configured via ` [telemetry]`.
2025-11-14 08:42:26 +08:00
2025-12-24 15:09:39 +08:00
## CLI
2025-11-14 08:42:26 +08:00
` ``bash
./bin/receiver listen --help
` ``
2025-12-24 15:09:39 +08:00
Common flags:
- ` --nats-url`
- ` --subject`
- ` --stream`
- ` --consumer`
- ` --publisher-topic`
- ` --postgres-url`
- ` --log-level`
- ` --replay-from`
- ` --ack-wait`
- ` --telemetry-enabled`, ` --telemetry-endpoint`, ` --telemetry-insecure`
2025-11-15 09:01:24 +08:00
2025-12-24 15:09:39 +08:00
## Testing
2025-11-15 09:01:24 +08:00
2025-12-24 15:09:39 +08:00
- Unit tests (Ginkgo): ` make test`
- Integration tests (Docker): ` make test-int`
- All tests: ` make test-all`
- Lint: ` make lint`
- Coverage: ` make coverage`
2025-11-15 09:01:24 +08:00
2025-12-24 15:09:39 +08:00
Single test example:
2025-11-15 09:46:29 +08:00
` ``bash
2025-12-24 15:09:39 +08:00
ginkgo -r -v --focus "Test Description" ./path/to/package
2025-11-15 09:46:29 +08:00
` ``
2025-12-24 15:09:39 +08:00
## Seed Tool
` cmd/seed-telegrams` publishes synthetic telegrams for development and testing.
Example:
2025-11-15 09:46:29 +08:00
` ``bash
2025-11-19 17:14:22 +08:00
go run ./cmd/seed-telegrams \
--nats-url nats://localhost:4222 \
--jetstream \
--stream TELEGRAM \
--js-subject telegram.serial \
2025-12-24 15:09:39 +08:00
--count 10 \
--category mixed \
--status random
2025-11-19 17:14:22 +08:00
` ``
2025-12-24 15:09:39 +08:00
## Documentation
2025-11-19 17:14:22 +08:00
2025-12-24 15:09:39 +08:00
- ` docs/dev-guide.md`
- ` docs/prod-guide.md`
- ` docs/nats.md`
- ` docs/observability.md`
- ` docs/performance.md`
- ` docs/migrations.md`
- ` docs/secret-management.md`
- ` docs/reliability.md`
2025-11-16 17:24:16 +08:00
2025-12-24 15:09:39 +08:00
## Contributing
2025-11-14 08:42:26 +08:00
2025-12-24 15:09:39 +08:00
See ` AGENTS.md` for coding standards, testing expectations, and release hygiene.
2025-11-14 08:42:26 +08:00
## License
2025-11-15 16:30:29 +08:00
This repository has not declared a public license yet.