# brprb08/aircraft-tracking-system architecture

> Architecture diagram of the GitHub repository brprb08/aircraft-tracking-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/brprb08/aircraft-tracking-system
- Repository: https://github.com/brprb08/aircraft-tracking-system

## Overview

##### Main Components
- Frontend Application:
- Built in React with TypeScript and Leaflet for mapping.
- Key components include UI elements (e.g., AircraftPage, Login, Signup) and services (API calls and Socket.IO client connections).
- Backend Server:
- Developed in Node.js/Express with TypeScript.
- Organized into subcomponents like DAO, routes, services, middlewares (authentication, rate limiting), validation, and utility functions.
- Manages REST API endpoints (user management, aircraft data operations) and broadcasts real-time updates via Socket.IO.
- Database:
- MongoDB (with Mongoose) is used to persist aircraft and user data.
- Data persistence layer and its interaction with the backend.
- Hardware Integration (Raspberry Pi):
- Contains Python scripts (e.g., plane-collect.py) interfacing with dump1090 to capture ADS-B data.
- Acts as the data source that pushes real-time aircraft information to the backend.
- External Services:

##### Relationships and Data Flow
- Data Flow from Hardware to Backend:
- Raspberry Pi (with ADS-B antenna, SDR dongle) running Python scripts collecting aircraft data.
- Backend Processing:
- API endpoints for user registration, login, adding/updating aircraft, and deleting records.
- Data validation (using Joi) followed by storage or in-memory caching.
- Real-time broadcasting through Socket.IO to connected clients.
- Frontend Interaction:
- React app, highlighting its connection to the backend via both RESTful API calls and a persistent WebSocket connection.
- Real-time data presentation on the Leaflet map; aircraft markers update based on backend events.
- Database Connection:

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- Distinguish between the frontend and backend, ensuring API boundaries are clear.
- The backend components (data access, business logic, validation, and middleware) should be grouped to show layered architecture.
- Real-Time Communication:
- Use of Socket.IO for bidirectional real-time data broadcasting between the backend and frontend.
- Security Measures:
- Hardware Integration as an External Data Source:
- ADS-B data collection as an edge component that feeds into the central backend.

##### Final Recommendations
- Be as detailed as possible by breaking down the system into the distinct modules outlined above.
- Integration of real-time data from hardware into the application ecosystem, clearly showing the update paths from data capture to final rendering on the map.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Application"
        UI_Components("UI Components"):::frontend
        API_Service("API Service"):::frontend
        WebSocket_Client("WebSocket Handler"):::frontend
    end

    subgraph "Backend Server"
        Routes("Routes"):::backend
        Middlewares("Middlewares"):::backend
        Validation("Validation"):::backend
        Services("Services"):::backend
        DAO("DAO"):::backend
        Utils("Utility Functions"):::backend
    end

    subgraph "Database"
        MongoDB("MongoDB Database"):::database
    end

    subgraph "Hardware Integration"
        ADSB("Raspberry Pi ADS-B Collector"):::hardware
    end

    %% Data Flow Connections
    ADSB -->|"data_via_/api/aircraft"| Routes
    API_Service -->|"REST_API_calls"| Routes
    Routes -->|"JWT/Auth_check"| Middlewares
    Routes -->|"validate_data"| Validation
    Routes -->|"execute_business_logic"| Services
    Services -->|"persist_data"| DAO
    DAO -->|"CRUD_operations"| MongoDB
    Services -->|"broadcast_updates"| WebSocket_Client
    UI_Components -->|"calls_API_Service"| API_Service
    UI_Components -->|"listens_to_Socket"| WebSocket_Client

    %% Click Events for Frontend
    click UI_Components "https://github.com/brprb08/aircraft-tracking-system/tree/main/frontend/src/components/"
    click API_Service "https://github.com/brprb08/aircraft-tracking-system/blob/main/frontend/src/service/apiService.ts"
    click WebSocket_Client "https://github.com/brprb08/aircraft-tracking-system/blob/main/frontend/src/utils/useSocket.ts"

    %% Click Events for Backend
    click Routes "https://github.com/brprb08/aircraft-tracking-system/blob/main/backend/src/routes/aircraftRoutes.ts"
    click DAO "https://github.com/brprb08/aircraft-tracking-system/tree/main/backend/src/dao/"
    click Services "https://github.com/brprb08/aircraft-tracking-system/tree/main/backend/src/service/"
    click Middlewares "https://github.com/brprb08/aircraft-tracking-system/tree/main/backend/src/middlewares/"
    click Validation "https://github.com/brprb08/aircraft-tracking-system/tree/main/backend/src/validation/"
    click Utils "https://github.com/brprb08/aircraft-tracking-system/blob/main/backend/src/utils/helpers.ts"

    %% Click Events for Database
    click MongoDB "https://github.com/brprb08/aircraft-tracking-system/blob/main/backend/src/db/db.ts"

    %% Click Events for Hardware
    click ADSB "https://github.com/brprb08/aircraft-tracking-system/blob/main/rasberryPi/plane-collect.py"

    %% Class Definitions with Colors
    classDef frontend fill:#cce5ff,stroke:#1a8cff,stroke-width:2px;
    classDef backend fill:#e2f0cb,stroke:#6abf69,stroke-width:2px;
    classDef database fill:#ffd6a5,stroke:#ff7f50,stroke-width:2px;
    classDef hardware fill:#f7d794,stroke:#f1a340,stroke-width:2px;
```
