How kuldeepsinh/yams works
Project type and purpose
• This is an Erlang/OTP application implementing an MQTT broker (“Yet Another MQTT Server”).
• Its goal is to accept thousands/millions of concurrent TCP connections from MQTT clients, route publish/subscribe messages, manage topic state, and optionally persist data.
File structure
• Top-level files:
• rebar.config (build configuration)
• /yams_db.hrl (shared record/type definitions)
• README.md, LICENSE, NOTICE
• Sandbox directory: lightweight demos/tests of core modules (coner, pinger, puber, router, suber).
• src directory: the OTP application code.
• yams.app.src, yams_app.erl, yams_sup.erl – application entry point and top supervisor
• * _sup.erl files – supervisors for each major subsystem
• Erlang modules handling:
– TCP Listener & Acceptor (listener.erl, acceptor.erl)
– Connection/session management (connect.erl, client_to_apid.erl)
– Message dispatch & relay (publish.erl, subscribe.erl, router.erl)
– Topic parsing (topic_parser.erl), subscriptions DB (subscriptions.erl), publications DB (publications.erl), and the yams_db interface
Key insights from README
• Plain description: it’s a standalone MQTT broker written to leverage Erlang/OTP concurrency & supervision.
a. Main components
1. External MQTT Clients (any MQTT‐compatible client)
2. Network Stack
– Listener (listener.erl)
– Acceptor (acceptor.erl)
3. Connection Manager
– Connection processes (connect.erl)
– Client-to-AppID translator (client_to_apid.erl)
4. Message Handling
– Publisher (publish.erl) & Subscription (subscribe.erl) interfaces
– Router (router.erl) for matching topics to subscribers
– Topic Parser (topic_parser.erl)
5. State Storage
– Subscriptions datastore (subscriptions.erl)
– Publications datastore (publications.erl)
– yams_db interface (yams_db.erl + include)
6. OTP Supervision Tree
– Top‐level: yams_app → yams_sup
– Child supervisors: listener_sup, acceptor_sup, connect_sup, publish_sup, subscribe_sup, router_sup, topic_parser_sup, mh_sup, msg_sup
7. Utility library (yams_lib.erl)
b. Relationships and interactions
• Clients → TCP Listener (port) → Acceptor spawns a Connection →
Connection process handles handshake/auth →
Based on MQTT packet type, forward to Publish or Subscribe subsystem →
Router & Topic Parser dispatch the message →
Update Subscriptions or Publications datastore →
Router notifies all matching Connection processes →
Connections push packets back to clients.
• Supervisors monitor sets of workers for fault tolerance.
c. Architectural patterns & principles
• OTP supervision tree for process isolation and automated restarts.
• “One connection = one process” concurrency model.
• Clear separation of concerns: networking vs message logic vs storage.
d. Technologies / frameworks
• Erlang/OTP (gen_server, supervisor behaviors)
• rebar (build tool)
• ETS or Mnesia (potential backing store inside yams_db)
Capturing essential elements
• Don’t omit any OTP supervisor or major worker: each _sup and its child group should appear.
• Yams_db.hrl as the schema interface for the datastores.
• If desired, in a corner show the sandbox folder as “Test Harnesses” separate from the production supervision tree.