Overview
Server is system's central component. It accepts WebSocket connections from devices and controllers on connection port, routes data, serves user interface on http port, stores system image in systemImage.json file and Server Storage data under ServerStorage directory. By default, it broadcasts it's discovery keyword and connection port number via UDP. Below is detailed explanation of each feature:

Connecting device
Whenever new WebSocket is opened on connection port, server performs handshake procedure to determine which component opened the connection. If component identifies itself as device, server requests it's manifest (you can read more about manifest in Device section). Received manifest is updated with any modifications done previously via user interface (such as device name, group, values visibility etc.), saved within system image and broadcast via deviceConnected event to all connected controllers.
Connecting controller
If component identifies itself as controller, it is registered on controllers list (volatile) and provided with current system image and list of currently active devices. Those data are used to initialize or sync controller's model with current system state (see Controller section for more details).
Data routing
Controllers can subscribe selected Gate Values and/or create data pipes between Gate Values. Relevant devices are notified whenever their Gate Values gets subscribed or unsubscribed. On subscribing Gate Value, or whenever subscribed Gate Value changes, it's current value is send to Local Server, which forwards the value to all subscribers. When controller disconnects, Local Server automatically removes it's subscriptions from devices. Data pipe is saved within system image and remains until removed - it activates automatically whenever both source and target Gate Values becomes available.
User interface
User interface is static website stored under ./out directory and is served to web browser on http port. When user interface is started in browser, it uses Controller library internally to connect with Local Server it was loaded from (from server perspective, user interface is an ordinary controller). See User interface section for more details.
Data storage
Local Server persists device manifests and data pipes declarations in ./systemImage.json file. Server Storage data are saved in ./ServerStorage directory. Default subdirectory name for device data is device id, for controller data is "controller".
Discovery
Local Server broadcasts it's discovery keyword and connection port number over UDP on discovery port. Components using GateDiscovery library can capture such message and automatically connect to desired server ip address on proper connection port. Discovering Local Server is optional, components can be configured to use fixed parameters to establish connection.
Configuration
Server configuration is stored in ./dist/config.js and - if necessary - can be overriden directly in file, or using environment variables (with parameter names in upper snake case - i.e. httpPort should be HTTP_PORT). By default, Local Server is configured as follows:
httpPort: 8080
connectionPort: 10002
discoveryKeyword: GateServer
discoveryPort: 10001
discoveryInterval: 5000
broadcastingPort: 11000
enableDiscovery: true
Meaning of parameters:
httpPort - port to serve user interface
connectionPort - port to connect devices and controllers
discoveryKeyword - server identifier for discovery
discoveryPort - port to which discovery messages will be delivered
discoveryInterval - interval of sending discovery messages (milliseconds)
broadcastingPort - port used by server to send discovery messages
enableDiscovery - if set to "false", server will not send discovery messages