Skip to content

Ahaif/air_space_guardian

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛰️ Drone NFZ Violation Detection Backend

A fault-tolerant, secure, and high-performance backend system written in Rust to monitor drone activity, detect no-fly zone (NFZ) violations, and expose secure endpoints for real-time data access.


✨ Features

  • ✅ Polls live drone data every 10 seconds from a remote API
  • 🚫 Detects NFZ violations within a 1000-unit circular boundary centered at (0, 0)
  • 🔒 Fetches and stores drone owner information only if a violation occurs
  • 💾 Persists violations in PostgreSQL
  • 🔐 Secured access to personal violation data using X-Secret header
  • 🧩 Built with SOLID principles, modular design patterns
  • 🐳 Fully containerized with Docker and Docker Compose

🏗️ Architecture

+---------------------+
| External Drone API  |
+---------------------+
          |
          v
   +---------------+               +------------------+
   | Poller (task) |-------------->|   PostgreSQL DB  |
   +---------------+               +------------------+
          |                                ^
          |                                |
+---------v----------+          +----------+---------+
| Axum RESTful API   |<-------->|  /nfz, /drones, /  |
+--------------------+          +--------------------+

⚙️ Tech Stack & Dependencies

Tech Role
Rust (2021) Core programming language
Axum Fast, modular web server
SQLx Async-safe PostgreSQL ORM
Reqwest HTTP client for polling APIs
Tokio Async runtime
Serde JSON parsing
dotenvy Environment management
tracing Structured, async logging
Docker + Compose Container orchestration and networking

📁 Project Structure

fdf_fi/
├── src/
│   ├── config.rs         # AppConfig, AppState, .env parsing
│   ├── db.rs             # PostgreSQL connection pool
│   ├── main.rs           # Application entrypoint
│   ├── models/           # Violation, Drone, Owner structs
│   ├── routes/           # REST endpoints: /nfz, /health, /drones
│   ├── tasks/            # Poller logic
├── migrations/           # SQLx migrations
├── .env.example          # Example environment variables
├── Dockerfile            # Multi-stage build for Rust
├── docker-compose.yml    # Orchestration with PostgreSQL
└── README.md

🔍 REST API Usage

✅ Health Check

curl http://localhost:8000/health
{ "success": "ok" }

📡 Drone Data (proxy to external API)

curl http://localhost:8000/drones

Returns raw array of drones from upstream.


🚨 NFZ Violations (last 24h, protected)

curl -H "X-Secret: your-secret-here" http://localhost:8000/nfz

Returns:

[
  {
    "id": "...",
    "owner_id": 123,
    "x": 45.0,
    "y": 30.0,
    "z": 80.0,
    "timestamp": "...",
    "owner_first_name": "John",
    "owner_last_name": "Doe",
    "owner_ssn": "123-45-6789",
    "owner_phone": "+123456789"
  },
  ...
]

🛠️ Getting Started

1. Create .env

Copy from .env.example:

DATABASE_URL=postgres://root:password@postgres:5432/air_guardian
NFZ_API_SECRET=your-secret-here
DRONES_API_BASE_URL=https://drones-api
DRONES_ENDPOINT=/drones
USERS_ENDPOINT=/users
POLL_INTERVAL_SECS=10

POSTGRES_USER=root
POSTGRES_PASSWORD=password
POSTGRES_DB=air_guardian

2. Build and Run

docker-compose up --build

This will:

  • Run the backend at http://localhost:8000
  • Start PostgreSQL at localhost:5432

3. Test the endpoints

curl http://localhost:8000/health
curl http://localhost:8000/drones
curl -H "X-Secret: your-secret-here" http://localhost:8000/nfz

🚀 Future Ideas

  • investigate more error handling, Api responses and logging

🛡️ MIT License — secure and production-ready.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published