# codevector/blynk-server architecture

> Architecture diagram of the GitHub repository codevector/blynk-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/codevector/blynk-server
- Repository: https://github.com/codevector/blynk-server

## Overview

- Mobile Clients (Blynk mobile apps on iOS/Android)
- End-users using a web-based Administration UI (accessed via HTTPS)
- Hardware Devices (Arduino, Raspberry Pi, ESP8266, etc.)

2. Inside the system, clearly separate the application’s “layers” or modules based on the directory structure:
- Client Module
– Although the “client” directory (with its own pom.xml and source code) is present, it likely contains client utilities used by the mobile app or for testing the protocol. If it becomes part of integration testing then you may represent it as a client‐SDK block.
- Core Server and Protocol Handler Modules (located in “server/core”)
– This is the heart of message management. Represent components for:
- Netty pipelines (encoders, decoders, and protocol message handlers)
- Session management (state holders, token management, and user profile processing)
- DAO/Database access (for storing user data, dashboards, raw data, etc.)
- Reporting components (aggregation, raw data processing, CSV generators)
- TCP & SSL Layers
– Display separate blocks (or processes) for the different “server” modules:
- “tcp-app-server” (for mobile application connections)
- “tcp-hardware-server” (for hardware device connections, including SSL and non‑SSL handling)
- HTTP/S Components
– “http-api” and “http-core” modules that expose RESTful endpoints. These serve requests from mobile browsers or for server-to-server communication.
– “http-admin” for the web-based administration user interface (with static assets, handlers, and logic for IP filtering and admin authentication).
- Notification Modules
- Launcher and Tools
– “server/launcher”: this module ties together all the components and starts the worker threads, sets up the pipelines and signals the service to bootstrap.
– “server/tools” and “server/utils”: group these as supporting libraries that provide helper functions (logging, token generators, file utilities, etc.).
- Integration Tests

##### Relationships, dependencies, and data flow
- That the Core Server modules (messaging, authentication, session management, widget handling, etc.) interact with the Database (and optionally PostgreSQL when raw data storage is enabled) using DAOs.
- In parallel, show that the HTTP/S modules (REST API and admin UI) allow external systems or user administrators to query or change data.
- Separate flows from the core to the Notification Modules. For example, when a push or email is triggered by user action or system alerts, the core “invokes” a notification process which then may use external SMTP, SMS gateway (e.g., Nexmo), or other providers.
- Optionally, annotate that the file tree is built with Maven (pom.xml exists in each module) and therefore the build is modular.

##### Major technical design principles
- Modularity: Clearly show how the “server” project is broken into separate modules (core, tcp-app, tcp-hardware, http, launcher, notifications, tools, etc.) which are built and integrated together.
- Non-blocking IO: Emphasize that Netty is used to handle asynchronous and non‑blocking network I/O.
- Integration and Testing: Note that there is an “integration-tests” component which validates the protocol across hardware, mobile app, and HTTP components.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Actors
    subgraph "External Actors"
        mobileClients("Mobile Clients"):::external
        adminUser("Web Admin UI"):::external
        hardwareDevices("Hardware Devices"):::external
    end

    %% Client Module
    subgraph "Client Module"
        clientSDK("Client SDK"):::tool
    end

    %% TCP & SSL Layers
    subgraph "TCP & SSL Layers"
        tcpApp("TCP App Server"):::tcp
        tcpHardware("TCP Hardware Server"):::tcp
    end

    %% HTTP/S Components
    subgraph "HTTP/S Components"
        httpApi("HTTP REST API"):::http
        httpCore("HTTP Core"):::http
        adminUI("Admin UI"):::http
    end

    %% Core Server Modules
    subgraph "Core Server Modules"
        coreEngine("Blynk Core - Protocol Engine"):::core
        database("Database/Raw Data Storage"):::db
        configuration("Configuration"):::config
    end

    %% Notification Modules
    subgraph "Notification Modules"
        email("Email Notifications"):::notification
        push("Push Notifications"):::notification
        sms("SMS Notifications"):::notification
        twitter("Twitter Notifications"):::notification
    end

    %% Utility Modules
    subgraph "Utility Modules"
        launcher("Launcher & Bootstrap"):::tool
        tools("Tools & Utilities"):::tool
    end

    %% Integration Tests
    integrationTests("Integration Tests"):::test

    %% Connections from External Actors to TCP & HTTP Layers
    mobileClients -->|"tcp_binary"| tcpApp
    hardwareDevices -->|"tcp_binary"| tcpHardware
    mobileClients -->|"HTTP_REST"| httpApi
    adminUser -->|"HTTP_Admin"| adminUI

    %% TCP Layers feeding into Core Engine via Netty pipelines
    tcpApp -->|"Netty_pipeline"| coreEngine
    tcpHardware -->|"Netty_pipeline"| coreEngine

    %% HTTP Layers feeding into Core Engine
    httpApi -->|"REST_calls"| coreEngine
    httpCore -->|"HTTP_processing"| coreEngine
    adminUI -->|"Admin_ops"| coreEngine

    %% Core Engine interactions
    coreEngine -->|"DAO_calls"| database
    coreEngine -->|"Notify_Email"| email
    coreEngine -->|"Notify_Push"| push
    coreEngine -->|"Notify_SMS"| sms
    coreEngine -->|"Notify_Twitter"| twitter

    %% Launcher bootstrapping components
    launcher -->|"Bootstraps"| coreEngine
    launcher --> tcpApp
    launcher --> tcpHardware
    launcher --> httpApi
    launcher --> httpCore
    launcher --> adminUI

    %% Tools supporting the Core Engine
    tools -->|"Support_funcs"| coreEngine

    %% Integration Tests verifying interactions
    integrationTests ---|"Tests_Core"| coreEngine
    integrationTests ---|"Tests_HTTP_API"| httpApi
    integrationTests ---|"Tests_TCP_App"| tcpApp
    integrationTests ---|"Tests_TCP_Hardware"| tcpHardware

    %% Click Events based on component mapping
    click clientSDK "https://github.com/codevector/blynk-server/tree/master/client/src/main/java/cc/blynk/client"
    click coreEngine "https://github.com/codevector/blynk-server/tree/master/server/core/src/main/java/cc/blynk/server"
    click tcpApp "https://github.com/codevector/blynk-server/tree/master/server/tcp-app-server/"
    click tcpHardware "https://github.com/codevector/blynk-server/tree/master/server/tcp-hardware-server/"
    click httpApi "https://github.com/codevector/blynk-server/tree/master/server/http-api/"
    click httpCore "https://github.com/codevector/blynk-server/tree/master/server/http-core/"
    click adminUI "https://github.com/codevector/blynk-server/tree/master/server/http-admin/"
    click email "https://github.com/codevector/blynk-server/tree/master/server/notifications/email/"
    click push "https://github.com/codevector/blynk-server/tree/master/server/notifications/push/"
    click sms "https://github.com/codevector/blynk-server/tree/master/server/notifications/sms/"
    click twitter "https://github.com/codevector/blynk-server/tree/master/server/notifications/twitter/"
    click launcher "https://github.com/codevector/blynk-server/tree/master/server/launcher/"
    click tools "https://github.com/codevector/blynk-server/tree/master/server/tools/"
    click integrationTests "https://github.com/codevector/blynk-server/tree/master/integration-tests/"

    %% Styling Definitions
    classDef external fill:#f9c,stroke:#333,stroke-width:2px;
    classDef tcp fill:#bbf,stroke:#333,stroke-width:2px;
    classDef http fill:#afa,stroke:#333,stroke-width:2px;
    classDef core fill:#fcc,stroke:#333,stroke-width:2px;
    classDef db fill:#cfc,stroke:#333,stroke-width:2px;
    classDef notification fill:#ff9,stroke:#333,stroke-width:2px;
    classDef tool fill:#9cf,stroke:#333,stroke-width:2px;
    classDef config fill:#fc9,stroke:#333,stroke-width:2px;
    classDef test fill:#ccc,stroke:#333,stroke-width:2px;
```
