This document provides context and guidelines for AI coding assistants working on the Meshview project.
Meshview is a real-time monitoring and diagnostic tool for Meshtastic mesh networks. It provides web-based visualization and analysis of network activity, including:
- Real-time packet monitoring from MQTT streams
- Interactive map visualization of node locations
- Network topology graphs showing connectivity
- Message traffic analysis and conversation tracking
- Node statistics and telemetry data
- Packet inspection and traceroute analysis
- MQTT Reader (
meshview/mqtt_reader.py) - Subscribes to MQTT topics and receives mesh packets - Database Manager (
meshview/database.py,startdb.py) - Handles database initialization and migrations - MQTT Store (
meshview/mqtt_store.py) - Processes and stores packets in the database - Web Server (
meshview/web.py,main.py) - Serves the web interface and API endpoints - API Layer (
meshview/web_api/api.py) - REST API endpoints for data access - Models (
meshview/models.py) - SQLAlchemy database models - Decode Payload (
meshview/decode_payload.py) - Protobuf message decoding
- Python 3.13+ - Main language
- aiohttp - Async web framework
- aiomqtt - Async MQTT client
- SQLAlchemy (async) - ORM with async support
- Alembic - Database migrations
- Jinja2 - Template engine
- Protobuf - Message serialization (Meshtastic protocol)
- SQLite/PostgreSQL - Database backends (SQLite default, PostgreSQL via asyncpg)
- Async/Await - All I/O operations are asynchronous
- Database Migrations - Use Alembic for schema changes (see
docs/Database-Changes-With-Alembic.md) - Configuration - INI file-based config (
config.ini, seesample.config.ini) - Modular API - API routes separated into
meshview/web_api/module
meshview/
├── alembic/ # Database migration scripts
├── docs/ # Technical documentation
├── meshview/ # Main application package
│ ├── static/ # Static web assets (HTML, JS, CSS)
│ ├── templates/ # Jinja2 HTML templates
│ ├── web_api/ # API route handlers
│ └── *.py # Core modules
├── main.py # Web server entry point
├── startdb.py # Database manager entry point
├── mvrun.py # Combined runner (starts both services)
├── config.ini # Runtime configuration
└── requirements.txt # Python dependencies
- Use Python 3.13+ virtual environment
- Database:
./env/bin/python startdb.py - Web Server:
./env/bin/python main.py - Both:
./env/bin/python mvrun.py
- Line length: 100 characters (see
pyproject.toml) - Linting: Ruff (configured in
pyproject.toml) - Formatting: Ruff formatter
- Type hints: Preferred but not strictly required
- Async: Use
async defandawaitfor I/O operations
config.ini- Runtime configuration (server, MQTT, database, cleanup)sample.config.ini- Template configuration filealembic.ini- Alembic migration configuration
meshview/models.py- SQLAlchemy models (Packet, Node, Traceroute, etc.)meshview/database.py- Database initialization and session managementalembic/versions/- Migration scripts
meshview/mqtt_reader.py- MQTT subscription and message receptionmeshview/mqtt_store.py- Packet processing and storagemeshview/decode_payload.py- Protobuf decodingmeshview/web.py- Web server routes and handlersmeshview/web_api/api.py- REST API endpoints
meshview/templates/- Jinja2 HTML templatesmeshview/static/- Static files (HTML pages, JS, CSS)
- Add route handler in
meshview/web_api/api.py - Register route in
meshview/web.py(if needed) - Update
docs/API_Documentation.mdif public API
- Modify models in
meshview/models.py - Create migration:
alembic revision --autogenerate -m "description" - Review generated migration in
alembic/versions/ - Test migration:
alembic upgrade head - Never modify existing migration files after they've been applied
- Create template in
meshview/templates/ - Add route in
meshview/web.py - Add navigation link if needed (check existing templates for pattern)
- Add static assets if needed in
meshview/static/
- Check
meshview/decode_payload.pyfor existing decoders - Add decoder function if new type
- Update
meshview/mqtt_store.pyto handle new packet type - Update database models if new data needs storage
- Uses Protobuf for message serialization
- Packets contain various message types (text, position, telemetry, etc.)
- MQTT topics follow pattern:
msh/{region}/{subregion}/#
- packet - Raw packet data
- node - Mesh node information
- traceroute - Network path information
- packet_seen - Packet observation records
- Web pages use Server-Sent Events (SSE) for live updates
- Map and firehose pages auto-refresh based on config intervals
- API endpoints return JSON for programmatic access
- Always use async/await for database and network operations
- Use Alembic for all database schema changes
- Follow existing patterns - check similar code before adding new features
- Update documentation - keep
docs/and README current - Test migrations - verify migrations work both up and down
- Handle errors gracefully - log errors, don't crash on bad packets
- Respect configuration - use
config.inivalues, don't hardcode
- Don't modify applied migrations - create new ones instead
- Don't block the event loop - use async I/O, not sync
- Don't forget timezone handling - timestamps are stored in UTC
- Don't hardcode paths - use configuration values
- Don't ignore MQTT reconnection - handle connection failures gracefully
- Main README:
README.md- Installation and basic usage - Docker Guide:
README-Docker.md- Container deployment - API Docs:
docs/API_Documentation.md- API endpoint reference - Migration Guide:
docs/Database-Changes-With-Alembic.md- Database workflow - Contributing:
CONTRIBUTING.md- Contribution guidelines
- Current Version: 3.0.0 (November 2025)
- Python Requirement: 3.13+
- Key Features: Alembic migrations, automated backups, Docker support, traceroute return paths
- Always run ruff check and ruff format after making changes (only on python changes)
When working on this project, prioritize:
- Maintaining async patterns
- Following existing code structure
- Using proper database migrations
- Keeping documentation updated
- Testing changes thoroughly