# Livelocd
**Livelocd** is a lightweight Axum-compatible plugin for real-time location tracking via WebSockets and a JSON API. Easily drop it into any Rust backend to enable live geolocation dashboards, game user tracking, or delivery fleet monitoring.
---
## β¨ Features
- π‘ WebSocket support for sending real-time location updates
- π Subscribe to all users or individual users' locations
- π REST API to query current locations
- π§© Designed as a plugin for Axum or Loco.rs apps
- β‘ Built with minimal dependencies, powered by `tokio`, `axum`, and `serde_json`
---
## π¦ Installation
In your projectβs `Cargo.toml`:
```toml
livelocd = { path = "../livelocd" } # or use Git/crates.io in the future
```
---
## π Usage
In your Axum project:
```rust
use axum::Router;
use livelocd::livelocd_routes;
#[tokio::main]
async fn main() {
let app = Router::new().merge(livelocd_routes());
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}
```
---
## π‘ WebSocket Endpoints
- `GET /ws/send-location` β Send JSON with a `user_id` and any arbitrary fields (e.g., lat/lng)
- `GET /ws/subscribe` β Receive real-time updates for all users
- `GET /ws/subscribe/:user_id` β Subscribe to updates for a specific user
### Example JSON payload:
```json
{
"user_id": "user123",
"lat": 33.7489954,
"lng": -84.3879824,
"status": "moving"
}
```
---
## π REST API Endpoints
- `GET /api/users` β Get current known location for all users
- `GET /api/users/:user_id` β Get most recent location for a single user
---
## π Privacy & Security
You are responsible for securing the WebSocket and API endpoints (auth, rate limiting, etc.) based on your use case.
---
## π Use Cases
- Live fleet or delivery tracking
- Multiplayer game player positions
- Dashboards for location-aware apps
- IoT geolocation feeds
---
## π§ͺ Testing Locally
Use [`websocat`](https://github.com/vi/websocat):
```bash
# Send location
websocat ws://localhost:3000/ws/send-location
{"user_id": "car-1", "lat": 40.7, "lng": -74.0}
# Subscribe to all
websocat ws://localhost:3000/ws/subscribe
```
---
## π Built With
- [Axum](https://github.com/tokio-rs/axum)
- [Serde](https://serde.rs/)
- [Tokio](https://tokio.rs/)
---
## π License
MIT
---
## π€ Contributing
Pull requests welcome! Letβs make real-time dashboards in Rust even easier.