def build_edge_topic_prefix(device_id: str, module_id: str) -> str:
    """
    Helper function to build the prefix that is common to all topics.

    :param str device_id: The device_id for the device or module.
    :param str module_id: (optional) The module_id for the module.  Set to `None` if build a prefix for a device.

    :return: The topic prefix, including the trailing slash (`/`)
    """
    if module_id:
        return "$iothub/{}/{}/".format(device_id, module_id)
    else:
        return "$iothub/{}/".format(device_id)