githubEdit

Developer Guide

Project Architecture

High-Level Structure

oktopus/
├── agent/          # USP Agent configuration and examples
├── backend/        # Core backend services
│   └── services/
│       ├── controller/    # Main controller service
│       └── mtp/          # Message Transfer Protocol adapters
├── frontend/       # Next.js web application
├── deploy/         # Deployment configurations
└── docs/           # GitBook documentation

Backend Architecture

The backend is built with Go and follows a modular service architecture:

Controller Service

Located in backend/services/controller/, this is the core service that manages devices and handles protocol communications.

Key Components:

  • API Layer (internal/api/): REST API endpoints for device management

    • api.go: Main API router and middleware setup

    • Device message handlers (GET, SET, ADD, DELETE operations)

  • CWMP Support (internal/cwmp/): TR-069 protocol implementation

    • Handles CWMP-specific operations like GetParameterNames, SetParameterValues

  • Entity Layer (internal/entity/): Core business entities and data models

  • Database Layer (internal/db/): Database abstraction and persistence

  • Bridge (internal/bridge/): Communication bridge between services

MTP Adapters

The Message Transfer Protocol adapters handle different communication protocols:

  • WebSocket Adapter (backend/services/mtp/ws-adapter/): Implements WebSocket MTP for USP

  • MQTT Adapter: Handles MQTT-based communication

  • STOMP Adapter: Handles STOMP protocol

As mentioned in the USP MTP documentation, USP supports multiple MTPs including WebSockets, MQTT, and STOMP.

Frontend Architecture

The frontend is built with Next.js and located in frontend/. It provides a web interface for managing devices.

Development Setup

Prerequisites

  • Go: Version 1.23+

  • Node.js: Version 18+

  • NATS: Message broker for inter-service communication

  • Docker: For containerized development (optional)

Building the Services

Docker Development

From the root build/ directory, you can build all services at once:

Building Individual Microservices

Each microservice has its own build directory with a Makefile and Dockerfile. The general pattern is:

Available Backend Services:

  1. Controller Service - Core device management

    • Built from: cmd/controller/main.go

    • Binary: controller

    • Base image: Alpine Linux

  2. ACS Service - Auto Configuration Server (CWMP)

    • Built from: cmd/acs/main.go

    • Binary: acs

    • Base image: Alpine Linux

  3. MTP Adapters - Message Transfer Protocol handlers

    WebSocket Adapter:

    • Built from: cmd/ws-adapter/main.go

    • Handles WebSocket connections for USP

    WebSocket Service:

    • Built from: cmd/ws/main.go

    MQTT Adapter:

    • Built from: cmd/mqtt-adapter/main.go

    • Handles MQTT connections for USP

    MQTT Service:

    • Built from: cmd/mqtt/main.go

    STOMP Adapter:

    • Built from: cmd/stomp-adapter/main.go

    • Handles STOMP connections for USP

    STOMP Service:

    • Built from: cmd/stomp/main.go

    Generic Adapter:

    • Built from: cmd/adapter/main.go

  4. Utility Services

    Socket.IO Service:

    • Node.js service for real-time communication

    • Base image: Node 16.20.2-alpine

    File Server:

    • Serves firmware files and other static content

  5. Bulk Data Collector

    • Built from: cmd/http-bulk-collector/main.go

    • Collects bulk data from devices [WIP]

Building the Frontend

  • Next.js application

  • Node.js 18.18.0-alpine base image

  • Production build with optimizations

Local Development

Backend Services (Go):

Frontend (Next.js):

Makefile Commands

Each service's Makefile supports these commands:

  • make build - Build Docker image

  • make push - Push image to registry

  • make run - Create and start container

  • make stop - Stop running container

  • make remove - Remove container

  • make delete - Delete Docker image

  • make logs - Show container logs

  • make bash - Access container shell

  • make release - Tag as latest and push

Customization:

Running the Services

The project includes:

  • Build configurations in build/Makefile

  • Docker Compose deployment in deploy/compose/

  • Kubernetes deployment in deploy/kubernetes/

Code Organization

Backend Service Structure

The controller service follows a clean architecture pattern:

Pull Request Process

  1. Fork the repository and create a feature branch

  2. Make your changes following the code style guidelines

  3. Write clear commit messages describing what and why

  4. Test thoroughly with both protocols if applicable

  5. Update documentation if you're adding new features

  6. Submit a pull request to the main repository

Include in your PR description:

  • What problem does it solve?

  • How was it tested?

  • Any breaking changes?

  • Screenshots (for UI changes)

Understanding Key Concepts

Device Communication Flow

  1. Device connects via MTP adapter (WebSocket/MQTT/STOMP for USP, or ACS connection for CWMP)

  2. Adapter ingest and digest messages through NATS message broker

  3. API endpoint at Controller processes the user requests

  4. Message is queued and sent to the device

  5. Response is awaited with timeout

  6. Result is returned to the client

CWMP vs USP Implementation

The codebase supports both protocols:

CWMP (TR-069):

  • Synchronous request/response model

  • XML-based RPC

  • Direct parameter paths (e.g., InternetGatewayDevice.LANDevice.*.WLANConfiguration.*)

  • See internal/cwmp/ for implementation

USP (TR-369):

  • Supports multiple MTPs (MQTT, WebSocket, STOMP)

  • Protocol Buffers encoding

  • More flexible messaging model

Documentation

When adding features, update:

  1. Code comments: Especially for exported functions

  2. GitBook docs in docs/: Add user-facing documentation

  3. README files: Update relevant README files

  4. API documentation: If adding new endpoints

Resources

Getting Help

License

Oktopus is released under the license specified in the LICENSE file. Make sure your contributions comply with this license.

Last updated