# dkapur17/djicontrolserver architecture

> Architecture diagram of the GitHub repository dkapur17/djicontrolserver, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dkapur17/djicontrolserver
- Repository: https://github.com/dkapur17/djicontrolserver

## Overview

##### Project type and purpose
- This is a single-module Android application (Kotlin) that runs an embedded REST HTTP server on port 8080.
- Its purpose is to accept high-level REST GET requests (e.g., /takeoff, /moveForward/{dist}, /getCurrentIMUState) from any client, translate them into DJI SDK commands, and relay them to a DJI drone via a connected remote controller.
- It also collects IMU state data in memory and exposes endpoints to start/stop sampling and retrieve or clear that data.

##### File structure
- Top-level:
- app/ – Android Studio Gradle module
- assets/ – static assets used in README (logo, screenshots)
- build.gradle, settings.gradle, gradle wrapper, etc.
- app/src/main/java/com/rrc/djiControlServer:
- MApplication.kt (Application subclass – initializes services)
- MainActivity.kt (UI + server startup)
- app/src/main/res: Android UI layouts & resource definitions
- app/src/test & androidTest: unit and instrumentation tests
- No external microservices – everything runs inside one monolithic APK.

##### README for additional insights
- The README enumerates ~40 GET endpoints (connection, takeoff/land, control modes, motion planning, IMU collection, positional/velocity commands, etc.).
- Usage instructions indicate you must supply the DJI API key in AndroidManifest and connect the phone to a DJI remote controller.
- Clients (Python or any REST client) issue HTTP calls to the phone’s IP:8080.

a. Main components
1. Android App (APK) on Mobile Device
- Application Layer
- Embedded HTTP Server (e.g., NanoHTTPD or Ktor)
- Controller Layer (maps REST endpoints → service calls)
- Service/Domain Layer (DroneControlService, IMUCollector)
- Data Store (in-memory list of IMUState objects)
- DJI Mobile SDK (3rd-party library)
2. DJI Remote Controller
3. DJI Drone Hardware
4. External REST Client (e.g., Python script, web UI, Postman)

b. Relationships & data flow
- REST Client → HTTP Server (GET request)
- HTTP Server → Controller Layer → Service Layer
- Service Layer → DJI SDK API → Remote Controller → Drone
- Drone → SDK → Service Layer for telemetry (IMU, heading)
- Service Layer → Data Store (collect/clear telemetry)
- Service Layer → HTTP Server → HTTP Response → REST Client

c. Architectural patterns & design principles
- Layered (Presentation/Network → Controller → Service → SDK/Hardware)
- Use of Kotlin Coroutines for asynchronous commands & IMU sampling
- In-memory state management (no persistent DB)
- Monolithic APK hosting both API layer and business logic

d. Key technologies & frameworks
- Kotlin & Android SDK
- Embedded HTTP server (NanoHTTPD or Ktor HTTP)
- DJI Mobile SDK (for drone control & telemetry)
- Android lifecycle components (Application, Activity)
- Kotlin Coroutines

## Diagram (Mermaid)

```mermaid
graph TB
  %% External Entities
  RESTClient["REST Client"]:::external
  DRController["DJI Remote Controller"]:::external
  DroneHardware["DJI Drone"]:::external

  %% Mobile App Boundary
  subgraph "Mobile App (APK)"
    direction TB

    %% Presentation/Network Layer
    subgraph "Presentation / Network Layer"
      direction TB
      MApplication["MApplication (Application Init)"]:::network
      AndroidManifest["AndroidManifest.xml"]:::network
      HTTPConfig["Embedded HTTP Server Config"]:::network
      HTTPServer["HTTP Server (NanoHTTPD/Ktor)"]:::network
      MainActivity["MainActivity (UI & Server Startup)"]:::network
    end

    %% Controller Layer
    subgraph "Controller Layer (REST Endpoints)"
      direction TB
      ConnectionCtrl["Connection Controller (/connect)"]:::network
      FlightCtrl["Flight Controller (/takeoff,/land)"]:::network
      ModeCtrl["Control Mode Controller"]:::network
      MotionCtrl["Motion Planning Controller"]:::network
      IMUCtrl["IMU Collection Controller"]:::network
      PosCtrl["Positional Commands Controller"]:::network
      VelCtrl["Velocity Commands Controller"]:::network
    end

    %% Service Layer
    subgraph "Service Layer"
      direction TB
      DroneService["DroneControlService"]:::services
      IMUService["IMUCollectorService"]:::services
    end

    %% SDK & Data Store
    subgraph "SDK & Data Store"
      direction TB
      SDK["DJI Mobile SDK"]:::external
      DataStore["In-Memory IMUState Store"]:::services
    end
  end

  %% Test and Assets
  subgraph "Tests & Documentation"
    direction TB
    UnitTests["ExampleUnitTest"]:::external
    InstrTests["ExampleInstrumentedTest"]:::external
    Assets["Static Assets (assets/)"]:::external
    Readme["README.md"]:::external
  end

  %% Connections
  RESTClient -->|"GET /... "| HTTPServer
  HTTPServer -->|"route to"| ConnectionCtrl
  HTTPServer --> FlightCtrl
  HTTPServer --> ModeCtrl
  HTTPServer --> MotionCtrl
  HTTPServer --> IMUCtrl
  HTTPServer --> PosCtrl
  HTTPServer --> VelCtrl

  ConnectionCtrl -->|"calls"| DroneService
  FlightCtrl --> DroneService
  ModeCtrl --> DroneService
  MotionCtrl --> DroneService
  PosCtrl --> DroneService
  VelCtrl --> DroneService

  IMUCtrl -->|"start/stop sampling"| IMUService
  DroneService -->|"SDK API calls"| SDK
  SDK --> DRController
  DRController --> DroneHardware

  DroneHardware -->|"telemetry via SDK"| SDK
  SDK --> DroneService
  SDK --> IMUService
  IMUService --> DataStore
  DataStore -->|"read/clear"| IMUService
  IMUService --> IMUCtrl
  DroneService --> HTTPServer
  IMUService --> HTTPServer
  HTTPServer -->|"HTTP Response"| RESTClient

  %% Click Events
  click MApplication "https://github.com/dkapur17/djicontrolserver/blob/master/app/src/main/java/com/rrc/djiControlServer/MApplication.kt"
  click MainActivity "https://github.com/dkapur17/djicontrolserver/blob/master/app/src/main/java/com/rrc/djiControlServer/MainActivity.kt"
  click AndroidManifest "https://github.com/dkapur17/djicontrolserver/blob/master/app/src/main/AndroidManifest.xml"
  click HTTPConfig "https://github.com/dkapur17/djicontrolserver/blob/master/app/build.gradle"
  click SDK "https://github.com/dkapur17/djicontrolserver/blob/master/app/build.gradle"
  click DroneService "https://github.com/dkapur17/djicontrolserver/tree/master/app/src/main/java/com/rrc/djiControlServer/"
  click IMUService "https://github.com/dkapur17/djicontrolserver/tree/master/app/src/main/java/com/rrc/djiControlServer/"
  click ConnectionCtrl "https://github.com/dkapur17/djicontrolserver/tree/master/app/src/main/java/com/rrc/djiControlServer/"
  click FlightCtrl "https://github.com/dkapur17/djicontrolserver/tree/master/app/src/main/java/com/rrc/djiControlServer/"
  click ModeCtrl "https://github.com/dkapur17/djicontrolserver/tree/master/app/src/main/java/com/rrc/djiControlServer/"
  click MotionCtrl "https://github.com/dkapur17/djicontrolserver/tree/master/app/src/main/java/com/rrc/djiControlServer/"
  click IMUCtrl "https://github.com/dkapur17/djicontrolserver/tree/master/app/src/main/java/com/rrc/djiControlServer/"
  click PosCtrl "https://github.com/dkapur17/djicontrolserver/tree/master/app/src/main/java/com/rrc/djiControlServer/"
  click VelCtrl "https://github.com/dkapur17/djicontrolserver/tree/master/app/src/main/java/com/rrc/djiControlServer/"
  click UnitTests "https://github.com/dkapur17/djicontrolserver/blob/master/app/src/test/java/com/rrc/djiControlServer/ExampleUnitTest.kt"
  click InstrTests "https://github.com/dkapur17/djicontrolserver/blob/master/app/src/androidTest/java/com/rrc/djiControlServer/ExampleInstrumentedTest.kt"
  click Assets "https://github.com/dkapur17/djicontrolserver/tree/master/assets/"
  click Readme "https://github.com/dkapur17/djicontrolserver/blob/master/README.md"

  %% Styles
  classDef network fill:#ADD8E6,stroke:#333,stroke-width:1px
  classDef services fill:#90EE90,stroke:#333,stroke-width:1px
  classDef external fill:#FFA500,stroke:#333,stroke-width:1px
```
