How stark-tech-group/stg-sdk-golang works
Project type and purpose
• Type: Go-SDK + CLI wrapper (open-source tool)
• Purpose: Provide Go bindings around Stark Platform’s REST APIs, plus a CLI entrypoint (cmd/stg-sdk-golang/main.go).
• Context: Includes a docker-compose.yml and a suite of Dockerfiles to spin up a sandbox of all backend microservices, data stores, and message buses for local testing of the SDK.
Main components
1. SDK/CLI Layer
– CLI Executable (cmd/stg-sdk-golang)
– starkapi Client (in pkg/starkapi) exposing sub-APIs: AssetApi, PointApi, AuthApi, etc.
– Domain Models (in pkg/domain) representing JSON payloads
– HTTP Layer (in pkg/http) handling requests, errors, response parsing
– Context & Env (in pkg/context, pkg/env) managing configuration and auth tokens
2. Docker-Compose “Local Platform”
– API Gateway (container from docker/api.Dockerfile)
– Auth Service (docker/auth-service.Dockerfile)
– Microservices (e.g., tag-api, stark-asset-api, reporting, finance, geo, etc.)
– Data Stores: Redis, Elasticsearch, TimescaleDB
– Message Buses: event-message-bus, iot-message-bus, telemetry-bus
– Auxiliary Services: migrations, notification, search, diagnostics, etc.
3. External Dependencies
– Azure Event Hub (via pkg/azure/eventhub_api.go)
– Stark Platform Hosted Endpoints (remote API host when not using Docker)
Relationships & Data Flows
• CLI/SDK → API Gateway:
– Client.Init(host) & Client.Login(un,pw)
– HTTP(S) calls bearing auth token in header
– Request paths map to microservices via the API Gateway
• API Gateway → Microservices:
– REST calls dispatched internally
– Each microservice communicates with its datastore or publishes/subscribes on a message bus
• Microservices → Data Stores / Buses
– e.g., Telemetry data → telemetry-bus → telemetry-data service → TimescaleDB
– Audit logs in Redis or Elastic for search
• SDK Internal:
– starkapi.Client holds HTTP client + auth state
– Sub-API methods call shared request builder → unmarshal into domain structs → return to user
Architectural Patterns & Principles
– Clean/Hexagonal Architecture inside the SDK: separation of domain, transport (HTTP), and external API client layers
– Microservices pattern for backend sandbox: each service is single-responsibility, independently containerized
– Environment-driven configuration: pkg/env reads OS vars; Docker Compose injects .my.env
Technologies, Frameworks & Libraries
– Go Modules (go.mod, go.sum)
– Docker & Docker Compose
– Redis, Elasticsearch, TimescaleDB
– Azure Event Hub
– Sonar (quality checks) in CI workflows