# MeshCore Hub Python 3.11+ project for managing and orchestrating MeshCore networks. ## Repo Monorepo structure with the following packages: - `meshcore_interface`: Component to interface with MeshCore companion nodes over Serial/USB and publish/subscribe to MQTT broker - `meshcore_collector`: Component to collect and store MeshCore events from MQTT broker into a database - `meshcore_api`: REST API to query collected data and send commands to the MeshCore network via MQTT broker - `meshcore_web`: Frontend web dashboard for visualizing MeshCore network status and statistics - `meshcore_common`: Shared utilities, models and configurations used by all components Project configuration should use Pydantic for settings management, with all options available via environment variables for easy Docker deployment as well as command-line arguments. Docker image contains all components, with entrypoint to select which component to run. Docker volumes for persistent storage of database. MeshCore events and schemas are defined in [SCHEMAS.md](SCHEMAS.md) for reference. ## Dependencies - Python 3.11+ (pyproject configured for 3.11) - All development in virtual environments (`.venv`) - Use `pip` for package management - Use `black` for code formatting - Use `flake8` for linting - Use `mypy` for type checking - Use `pytest` for testing - Pre-commit hooks for code quality - Click for CLI interfaces - Pydantic for data validation and settings management - SQLAlchemy for database interactions - Alembic for database migrations - FastAPI for REST API - MQTT client library (e.g. `paho-mqtt` or `gmqtt`) - meshcore_py for MeshCore device interactions - Docker for containerization - Single Dockerfile for all components - Docker Compose for multi-container orchestration ## Testing `meshcore_interface` should also include a mocked MeshCore device for testing purposes, allowing simulation of various events and conditions without requiring physical hardware. This should be enabled by a command-line flag or equivalent and will facilitate unit and integration testing without the need for actual MeshCore devices. ## Project Components ### Interface This component interacts with a MeshCore companion node over Serial/USB. It should subscribe to all events provided by the [meshcore_py](https://github.com/meshcore-dev/meshcore_py) Python library. It should also support sending a selection of commands to the companion node, primarily sending messages to contacts or channels, and also sending node advertisments. This component should run in one of two modes: - RECEIVER: The component subscribes to all MeshCore events and then publishes them to an MQTT message broker - SENDER: The component subscribes to an MQTT message broker and sends commands to the MeshCore companion node The `meshcore_py` library provides a method of querying the connected MeshCore devices "public address" (64 character hex string) which uniquely identifies any MeshCore node on the network. The public key should be the primary identifier for the node in all communications. Both sender and receiver modes should use a common MQTT topic structure including a customisable prefix, the nodes public address, and the event/command name. For example: ``` //event/ //command//+/command/`, but ideally there should only be one sender node active at any time. The API should also provide a basic dashboard endpoint that provides summary statistics about the MeshCore network, such as number of nodes, number of messages sent/received, active channels etc. This would provide a quick overview of the network status without needing to query individual endpoints. This should use simple HTML templates served by FastAPI for easy access via web browsers. Styling should use simple CSS, no JavaScript required. ### Web Dashboard This component provides a more user-friendly web interface for visualizing the MeshCore network status and statistics. It should connect to the API component to retrieve data and display it in an intuitive manner. The dashboard should include the following views: - Front Page: Customisable welcome page with network name, details and radio configuration. - Members List: List of all network member profiles (read from static JSON file) - Network Overview: Summary statistics about the MeshCore network, including number of nodes, messages, advertisements etc. - Node List: A list of all known nodes with their details and tags. Ability to filter and search nodes. - Node Map: A visual map showing the locations of nodes based on latitude/longitude from node tags. - Message Log: A log of all messages sent/received on the network with filtering options. The following should be configurable via environment variables or command-line arguments: - NETWORK_DOMAIN: Domain name for the web dashboard (e.g. "meshcore.example.com") - NETWORK_NAME: Name of the MeshCore network - NETWORK_CITY: Town/City where the network is located (e.g. "Ipswich") - NETWORK_COUNTRY: Country where the network is located (ISO 3166-1 alpha-2 code) - NETWORK_LOCATION: Latitude/Longitude of the network area location - NETWORK_RADIO_CONFIG: Details about the radio configuration (frequency, power etc) - NETWORK_CONTACT_EMAIL: Contact email address for network enquiries - NETWORK_CONTACT_DISCORD: Discord server link for network community The web dashboard should be a multi-page application using server-side rendering with FastAPI templates. It should use Tailwind CSS for styling and a modern UI component library (DaisyUI or similar) for consistent design. No JavaScript frameworks are required, any JS should be minimal and only for enhancing user experience (e.g. form validation, interactivity).