Skip to content

Add WebSocketSpec and MQTTSpec real-time protocol implementations#10

Merged
warkanum merged 1 commit intowebsocketspecfrom
copilot/sub-pr-9
Dec 30, 2025
Merged

Add WebSocketSpec and MQTTSpec real-time protocol implementations#10
warkanum merged 1 commit intowebsocketspecfrom
copilot/sub-pr-9

Conversation

Copy link
Contributor

Copilot AI commented Dec 30, 2025

Extends ResolveSpec beyond REST with two new real-time protocol specifications sharing the same JSON message protocol, enabling WebSocket and MQTT-based database operations.

Core Implementations

  • WebSocketSpec (pkg/websocketspec/): Real-time bidirectional communication over WebSocket

    • Full CRUD with subscriptions and automatic change notifications
    • Connection manager with lifecycle tracking
    • ~3,938 LOC implementation, ~2,245 LOC tests
  • MQTTSpec (pkg/mqttspec/): Pub/sub-based operations for IoT/mobile/distributed systems

    • Dual broker support: embedded Mochi MQTT or external broker connection
    • QoS 1 guaranteed delivery with offline message support
    • Topic hierarchy: spec/{client_id}/request|response|notify/{sub_id}
    • ~3,938 LOC implementation, ~2,246 LOC tests

Shared Protocol

All three specs (REST/WebSocket/MQTT) use identical JSON message structure:

{
  "id": "msg-123",
  "type": "request",
  "operation": "read",
  "schema": "public",
  "entity": "users",
  "options": {
    "filters": [{"column": "status", "operator": "eq", "value": "active"}],
    "sort": [{"column": "created_at", "direction": "desc"}],
    "limit": 10
  }
}

Unified Hook System

12 lifecycle hooks across all specs (BeforeRead, AfterCreate, BeforeSubscribe, etc.) for:

  • Authentication via BeforeConnect
  • Multi-tenancy via filter injection
  • RBAC via operation guards
  • Audit logging via After* hooks
handler.Hooks().Register(mqttspec.BeforeRead, func(ctx *mqttspec.HookContext) error {
    tenantID := ctx.Metadata["mqtt_client"].(*mqttspec.Client).GetMetadata("tenant_id")
    ctx.Options.Filters = append(ctx.Options.Filters, common.FilterOption{
        Column: "tenant_id", Operator: "eq", Value: tenantID,
    })
    return nil
})

Infrastructure Additions

  • Event Broker: 3 new providers (Database/NATS/Redis) for cross-component event streaming with pattern matching and retry logic (~1,759 LOC)
  • Server Manager: Production HTTP/HTTPS manager with graceful shutdown, TLS (cert files/self-signed/Let's Encrypt), health endpoints
  • Cache: Memcache provider, enhanced Redis/Memory providers
  • OpenAPI: UI handler with Swagger/Redoc/RapiDoc support

Client Support

Examples provided for JavaScript (MQTT.js/native WebSocket), Python (paho-mqtt/websockets), and Go (paho.mqtt.golang/gorilla/websocket).

Both specs support database-agnostic operations via GORM/Bun adapters with consistent filtering, sorting, pagination, and preloading across all protocols.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add Websocket and MQTT specifications Add WebSocketSpec and MQTTSpec real-time protocol implementations Dec 30, 2025
Copilot AI requested a review from warkanum December 30, 2025 12:47
Copy link
Member

@warkanum warkanum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks looks good

@warkanum warkanum marked this pull request as ready for review December 30, 2025 12:50
@warkanum warkanum merged commit 4ce5afe into websocketspec Dec 30, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants