mirror of
https://github.com/pablorevilla-meshtastic/meshview.git
synced 2026-03-04 23:27:46 +01:00
* Add alembic DB schema management (#86) * Use alembic * add creation helper * example migration tool * Store UTC int time in DB (#81) * use UTC int time * Remove old index notes script -- no longer needed * modify alembic to support cleaner migrations * add /version json endpoint * move technical docs * remove old migrate script * add readme in docs: * more doc tidy * rm * update api docs * ignore other database files * health endpoint * alembic log format * break out api calls in to their own file to reduce footprint * ruff and docs * vuln * Improves arguments in mvrun.py * Set dbcleanup.log location configurable * mvrun work * fallback if missing config * remove unused loop * improve migrations and fix logging problem with mqtt * Container using slim/uv * auto build containers * symlink * fix symlink * checkout and containerfile * make /app owned by ap0p * Traceroute Return Path logged and displayed (#97) * traceroute returns are now logged and /packetlist now graphs the correct data for a return route * now using alembic to update schema * HOWTO - Alembic --------- Co-authored-by: Joel Krauska <jkrauska@gmail.com> * DB Backups * backups and cleanups are different * ruff * Docker Docs * setup-dev * graphviz for dot in Container * Summary of 3.0.0 stuff * Alembic was blocking mqtt logs * Add us first/last timestamps to node table too * Worked on /api/packet. Needed to modify - Store.py to read the new time data - api.py to present the new time data - firehose.html chat.html and map.html now use the new apis and the time is the browser local time * Worked on /api/packet. Needed to modify - Store.py to read the new time data - api.py to present the new time data - firehose.html chat.html and map.html now use the new apis and the time is the browser local time * Improves container build (#94) * Worked on /api/packet. Needed to modify - Store.py to read the new time data - api.py to present the new time data - firehose.html chat.html and map.html now use the new apis and the time is the browser local time * Worked on /api/packet. Needed to modify - Store.py to read the new time data - api.py to present the new time data - firehose.html chat.html and map.html now use the new apis and the time is the browser local time * Worked on /api/packet. Needed to modify - Added new api endpoint /api/packets_seen - Modified web.py and store.py to support changes to APIs. - Started to work on new_node.html and new_packet.html for presentation of data. * Worked on /api/packet. Needed to modify - Added new api endpoint /api/packets_seen - Modified web.py and store.py to support changes to APIs. - Started to work on new_node.html and new_packet.html for presentation of data. * Finishing up all the pages for the 3.0 release. Now all pages are functional. * Finishing up all the pages for the 3.0 release. Now all pages are functional. * fix ruff format * more ruff * Finishing up all the pages for the 3.0 release. Now all pages are functional. * Finishing up all the pages for the 3.0 release. Now all pages are functional. * pyproject.toml requirements * use sys.executable * fix 0 epoch dates in /chat * Make the robots do our bidding * another compatibility fix when _us is empty and we need to sort by BOTH old and new * Finishing up all the pages for the 3.0 release. Now all pages are functional. * Finishing up all the pages for the 3.0 release. Now all pages are functional. * Remamed new_node to node. shorter and descriptive. * Remamed new_node to node. shorter and descriptive. * Remamed new_node to node. shorter and descriptive. * Remamed new_node to node. shorter and descriptive. * Remamed new_node to node. shorter and descriptive. * Remamed new_node to node. shorter and descriptive. * More changes... almost ready for release. Ranamed 2 pages for easy or reading. * Fix the net page as it was not showing the date information * Fix the net page as it was not showing the date information * Fix the net page as it was not showing the date information * Fix the net page as it was not showing the date information * ruff --------- Co-authored-by: Óscar García Amor <ogarcia@connectical.com> Co-authored-by: Jim Schrempp <jschrempp@users.noreply.github.com> Co-authored-by: Pablo Revilla <pablorevilla@gmail.com>
205 lines
7.2 KiB
Markdown
205 lines
7.2 KiB
Markdown
# AI Agent Guidelines for Meshview
|
|
|
|
This document provides context and guidelines for AI coding assistants working on the Meshview project.
|
|
|
|
## Project Overview
|
|
|
|
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
|
|
|
|
## Architecture
|
|
|
|
### Core Components
|
|
|
|
1. **MQTT Reader** (`meshview/mqtt_reader.py`) - Subscribes to MQTT topics and receives mesh packets
|
|
2. **Database Manager** (`meshview/database.py`, `startdb.py`) - Handles database initialization and migrations
|
|
3. **MQTT Store** (`meshview/mqtt_store.py`) - Processes and stores packets in the database
|
|
4. **Web Server** (`meshview/web.py`, `main.py`) - Serves the web interface and API endpoints
|
|
5. **API Layer** (`meshview/web_api/api.py`) - REST API endpoints for data access
|
|
6. **Models** (`meshview/models.py`) - SQLAlchemy database models
|
|
7. **Decode Payload** (`meshview/decode_payload.py`) - Protobuf message decoding
|
|
|
|
### Technology Stack
|
|
|
|
- **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)
|
|
|
|
### Key Patterns
|
|
|
|
- **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`, see `sample.config.ini`)
|
|
- **Modular API** - API routes separated into `meshview/web_api/` module
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
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
|
|
```
|
|
|
|
## Development Workflow
|
|
|
|
### Setup
|
|
|
|
1. Use Python 3.13+ virtual environment
|
|
|
|
### Running
|
|
|
|
- **Database**: `./env/bin/python startdb.py`
|
|
- **Web Server**: `./env/bin/python main.py`
|
|
- **Both**: `./env/bin/python mvrun.py`
|
|
|
|
|
|
## Code Style
|
|
|
|
- **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 def` and `await` for I/O operations
|
|
|
|
## Important Files
|
|
|
|
### Configuration
|
|
- `config.ini` - Runtime configuration (server, MQTT, database, cleanup)
|
|
- `sample.config.ini` - Template configuration file
|
|
- `alembic.ini` - Alembic migration configuration
|
|
|
|
### Database
|
|
- `meshview/models.py` - SQLAlchemy models (Packet, Node, Traceroute, etc.)
|
|
- `meshview/database.py` - Database initialization and session management
|
|
- `alembic/versions/` - Migration scripts
|
|
|
|
### Core Logic
|
|
- `meshview/mqtt_reader.py` - MQTT subscription and message reception
|
|
- `meshview/mqtt_store.py` - Packet processing and storage
|
|
- `meshview/decode_payload.py` - Protobuf decoding
|
|
- `meshview/web.py` - Web server routes and handlers
|
|
- `meshview/web_api/api.py` - REST API endpoints
|
|
|
|
### Templates
|
|
- `meshview/templates/` - Jinja2 HTML templates
|
|
- `meshview/static/` - Static files (HTML pages, JS, CSS)
|
|
|
|
## Common Tasks
|
|
|
|
### Adding a New API Endpoint
|
|
|
|
1. Add route handler in `meshview/web_api/api.py`
|
|
2. Register route in `meshview/web.py` (if needed)
|
|
3. Update `docs/API_Documentation.md` if public API
|
|
|
|
### Database Schema Changes
|
|
|
|
1. Modify models in `meshview/models.py`
|
|
2. Create migration: `alembic revision --autogenerate -m "description"`
|
|
3. Review generated migration in `alembic/versions/`
|
|
4. Test migration: `alembic upgrade head`
|
|
5. **Never** modify existing migration files after they've been applied
|
|
|
|
### Adding a New Web Page
|
|
|
|
1. Create template in `meshview/templates/`
|
|
2. Add route in `meshview/web.py`
|
|
3. Add navigation link if needed (check existing templates for pattern)
|
|
4. Add static assets if needed in `meshview/static/`
|
|
|
|
### Processing New Packet Types
|
|
|
|
1. Check `meshview/decode_payload.py` for existing decoders
|
|
2. Add decoder function if new type
|
|
3. Update `meshview/mqtt_store.py` to handle new packet type
|
|
4. Update database models if new data needs storage
|
|
|
|
|
|
## Key Concepts
|
|
|
|
### Meshtastic Protocol
|
|
- Uses Protobuf for message serialization
|
|
- Packets contain various message types (text, position, telemetry, etc.)
|
|
- MQTT topics follow pattern: `msh/{region}/{subregion}/#`
|
|
|
|
### Database Schema
|
|
- **packet** - Raw packet data
|
|
- **node** - Mesh node information
|
|
- **traceroute** - Network path information
|
|
- **packet_seen** - Packet observation records
|
|
|
|
### Real-time Updates
|
|
- 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
|
|
|
|
## Best Practices
|
|
|
|
1. **Always use async/await** for database and network operations
|
|
2. **Use Alembic** for all database schema changes
|
|
3. **Follow existing patterns** - check similar code before adding new features
|
|
4. **Update documentation** - keep `docs/` and README current
|
|
5. **Test migrations** - verify migrations work both up and down
|
|
6. **Handle errors gracefully** - log errors, don't crash on bad packets
|
|
7. **Respect configuration** - use `config.ini` values, don't hardcode
|
|
|
|
## Common Pitfalls
|
|
|
|
- **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
|
|
|
|
## Resources
|
|
|
|
- **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
|
|
|
|
## Version Information
|
|
|
|
- **Current Version**: 3.0.0 (November 2025)
|
|
- **Python Requirement**: 3.13+
|
|
- **Key Features**: Alembic migrations, automated backups, Docker support, traceroute return paths
|
|
|
|
|
|
## Rules for robots
|
|
- Always run ruff check and ruff format after making changes (only on python changes)
|
|
|
|
|
|
---
|
|
|
|
When working on this project, prioritize:
|
|
1. Maintaining async patterns
|
|
2. Following existing code structure
|
|
3. Using proper database migrations
|
|
4. Keeping documentation updated
|
|
5. Testing changes thoroughly
|
|
|
|
|
|
|