diff --git a/.gitignore b/.gitignore
index 7a7668ed1986247d30e3ca51ac02e7708a7839c8..96d9a054a56c093ea93a6a0f47a5f81419911938 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,9 +5,9 @@ sdkconfig.old
 # This directory contains user-specific devices
 /devices/*
 # Ignore symlink to current device
-/main/device
+/main
 
 # This directory contains user-specific environment configurations
 /environments/*
 # Ignore symlink to current environment
-/main/environment.h
+/qthing/environment.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9b7fea559fb7a52f7612a757905e6c6b9ead9994..177652e42fd05cf94557b1cb62dcbe17f5a7366f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,4 +3,5 @@
 cmake_minimum_required(VERSION 3.5)
 
 include($ENV{IDF_PATH}/tools/cmake/project.cmake)
+idf_build_component(qthing)
 project(qthing)
diff --git a/default.nix b/default.nix
index c48d5eaef94e53345a72326301ee4ec6b9429572..abc7b6e79e2a1144187232ce1f689f923591d616 100644
--- a/default.nix
+++ b/default.nix
@@ -37,15 +37,14 @@ let
   '';
 
   qthingBaseRepo = pkgs.runCommand "qthing" {} ''
-    mkdir -p $out/main
+    mkdir -p $out/qthing
     for file in CMakeLists.txt components esp-idf sdkconfig; do
       ln -s ${./.}/$file $out/$file
     done
-    cd ${./.}/main
+    cd ${./.}/qthing
     for file in *; do
-      [[ "$file" == device ]] && continue
       [[ "$file" == environment.h ]] && continue
-      ln -s ${./.}/main/$file $out/main/$file
+      ln -s ${./.}/qthing/$file $out/qthing/$file
     done
   '';
 
@@ -57,7 +56,7 @@ in rec {
     shellHook = shellSetup;
   };
 
-  mkProject = { name, device, environment }: let
+  mkProject = { name, src, environment }: let
     flashScript = pkgs.writeScript "flash" ''
       PATH=${pkgs.esptool}/bin/:$PATH
       cd @out@
@@ -68,9 +67,9 @@ in rec {
     buildInputs = qthingDependencies;
     unpackPhase = ''
       cp --reflink=auto -r ${qthingBaseRepo}/* ./
-      chmod -R u+w .
-      cp --reflink=auto -r ${device} ./main/device
-      cp --reflink=auto ${environment} ./main/environment.h
+      chmod u+w qthing
+      cp --reflink=auto -r ${src} ./main
+      cp --reflink=auto ${environment} ./qthing/environment.h
     '';
     configurePhase = shellSetup + ''
       patchShebangs esp-idf
diff --git a/main/CMakeLists.txt b/qthing/CMakeLists.txt
similarity index 96%
rename from main/CMakeLists.txt
rename to qthing/CMakeLists.txt
index 1377d140624f99bc40e20c9f7fb4e0bc76e75272..ffe1285dbe0ab2c71ac2021a2ce5b968416c9d9d 100644
--- a/main/CMakeLists.txt
+++ b/qthing/CMakeLists.txt
@@ -1,7 +1,6 @@
 idf_component_register(
   SRC_DIRS
   "."
-  "device"
   "network"
   "peripherals"
   "system"
@@ -15,6 +14,7 @@ idf_component_register(
   LiquidCrystal
   app_update
   arduino-esp32
+  main
   mqtt
   nvs_flash
   rc-switch
diff --git a/main/color.cpp b/qthing/color.cpp
similarity index 100%
rename from main/color.cpp
rename to qthing/color.cpp
diff --git a/main/device.h b/qthing/device.h
similarity index 100%
rename from main/device.h
rename to qthing/device.h
diff --git a/main/event.cpp b/qthing/event.cpp
similarity index 100%
rename from main/event.cpp
rename to qthing/event.cpp
diff --git a/main/event.h b/qthing/event.h
similarity index 100%
rename from main/event.h
rename to qthing/event.h
diff --git a/main/io.cpp b/qthing/io.cpp
similarity index 100%
rename from main/io.cpp
rename to qthing/io.cpp
diff --git a/main/io.h b/qthing/io.h
similarity index 100%
rename from main/io.h
rename to qthing/io.h
diff --git a/main/lcd.cpp b/qthing/lcd.cpp
similarity index 100%
rename from main/lcd.cpp
rename to qthing/lcd.cpp
diff --git a/main/lcd.h b/qthing/lcd.h
similarity index 100%
rename from main/lcd.h
rename to qthing/lcd.h
diff --git a/main/main.cpp b/qthing/main.cpp
similarity index 100%
rename from main/main.cpp
rename to qthing/main.cpp
diff --git a/main/measured.cpp b/qthing/measured.cpp
similarity index 100%
rename from main/measured.cpp
rename to qthing/measured.cpp
diff --git a/main/measured.h b/qthing/measured.h
similarity index 97%
rename from main/measured.h
rename to qthing/measured.h
index 08c86136a0359f2ebf39b20c8ef4139b40f02ebc..7eb634a2ea5a03a8d3391194e0410ad431db3366 100644
--- a/main/measured.h
+++ b/qthing/measured.h
@@ -4,7 +4,7 @@
 #include <vector>
 #include <functional>
 
-#include "device/device_config.h"
+#include "device_config.h"
 
 #ifndef MEASURED_PERIOD_MS
 #define MEASURED_PERIOD_MS 1000
@@ -55,4 +55,4 @@ namespace qthing {
             void mqtt(const std::vector<qthing::measured::sensor_data_t>& data);
         }
     }
-}
\ No newline at end of file
+}
diff --git a/main/mqtt.cpp b/qthing/mqtt.cpp
similarity index 99%
rename from main/mqtt.cpp
rename to qthing/mqtt.cpp
index f626f4b95da487106f83c5eae42bcf9763987151..6f93615294a84a7e34ebdc64a1c198defa37a708 100644
--- a/main/mqtt.cpp
+++ b/qthing/mqtt.cpp
@@ -4,7 +4,7 @@
 
 #include "environment.h"
 #include "event.h"
-#include "device/device_config.h"
+#include "device_config.h"
 #include "io.h"
 
 #include <new>
diff --git a/main/mqtt.h b/qthing/mqtt.h
similarity index 100%
rename from main/mqtt.h
rename to qthing/mqtt.h
diff --git a/main/mqtt_c.c b/qthing/mqtt_c.c
similarity index 100%
rename from main/mqtt_c.c
rename to qthing/mqtt_c.c
diff --git a/main/mqtt_c.h b/qthing/mqtt_c.h
similarity index 100%
rename from main/mqtt_c.h
rename to qthing/mqtt_c.h
diff --git a/main/mqtt_common.h b/qthing/mqtt_common.h
similarity index 94%
rename from main/mqtt_common.h
rename to qthing/mqtt_common.h
index 30b778f87165e37daa69e5bc8dc80624b9da8fbd..945f3164f64aa2dc9fb6a1563360f58110f35a13 100644
--- a/main/mqtt_common.h
+++ b/qthing/mqtt_common.h
@@ -2,7 +2,7 @@
 #define MQTT_COMMON_H
 
 #include "environment.h"
-#include "device/device_config.h"
+#include "device_config.h"
 
 #define STATUS_TOPIC DEVICE_NAMESPACE "status"
 #define STATUS_MESSAGE_ONLINE "online"
@@ -21,4 +21,4 @@
 #define OTA_STATE_TOPIC    DEVICE_NAMESPACE "ota/state"
 #define OTA_ERROR_TOPIC    DEVICE_NAMESPACE "ota/error"
 
-#endif
\ No newline at end of file
+#endif
diff --git a/main/mqtt_ota.cpp b/qthing/mqtt_ota.cpp
similarity index 100%
rename from main/mqtt_ota.cpp
rename to qthing/mqtt_ota.cpp
diff --git a/main/mqtt_ota.h b/qthing/mqtt_ota.h
similarity index 100%
rename from main/mqtt_ota.h
rename to qthing/mqtt_ota.h
diff --git a/main/network/broken/ethernet_lan8720.cpp b/qthing/network/broken/ethernet_lan8720.cpp
similarity index 100%
rename from main/network/broken/ethernet_lan8720.cpp
rename to qthing/network/broken/ethernet_lan8720.cpp
diff --git a/main/network/network.cpp b/qthing/network/network.cpp
similarity index 98%
rename from main/network/network.cpp
rename to qthing/network/network.cpp
index 723a30a0c8c908225aff31644f57dbef3fa96239..e26c269e47cc5d0df17012a738530cb11fc5abe1 100644
--- a/main/network/network.cpp
+++ b/qthing/network/network.cpp
@@ -1,7 +1,7 @@
 #include "qthing.h"
 #include "io.h"
 #include "environment.h"
-#include "device/device_config.h"
+#include "device_config.h"
 #include "event.h"
 #include "mqtt.h"
 #include "network/udp.h"
diff --git a/main/network/network.h b/qthing/network/network.h
similarity index 100%
rename from main/network/network.h
rename to qthing/network/network.h
diff --git a/main/network/network_animation.cpp b/qthing/network/network_animation.cpp
similarity index 100%
rename from main/network/network_animation.cpp
rename to qthing/network/network_animation.cpp
diff --git a/main/network/udp.cpp b/qthing/network/udp.cpp
similarity index 100%
rename from main/network/udp.cpp
rename to qthing/network/udp.cpp
diff --git a/main/network/udp.h b/qthing/network/udp.h
similarity index 100%
rename from main/network/udp.h
rename to qthing/network/udp.h
diff --git a/main/network/wlan.cpp b/qthing/network/wlan.cpp
similarity index 97%
rename from main/network/wlan.cpp
rename to qthing/network/wlan.cpp
index 128b32d5821078ae94e6bb7ffc775f1f3669db98..3214f0b1aa3430dafa9d93bf087b305e3bb124b2 100644
--- a/main/network/wlan.cpp
+++ b/qthing/network/wlan.cpp
@@ -2,7 +2,7 @@
 #include "network.h"
 #include "io.h"
 #include "environment.h"
-#include "device/device_config.h"
+#include "device_config.h"
 #include "event.h"
 #include "mqtt.h"
 
diff --git a/main/ntp.cpp b/qthing/ntp.cpp
similarity index 100%
rename from main/ntp.cpp
rename to qthing/ntp.cpp
diff --git a/main/ntp.h b/qthing/ntp.h
similarity index 100%
rename from main/ntp.h
rename to qthing/ntp.h
diff --git a/main/oled.cpp b/qthing/oled.cpp
similarity index 100%
rename from main/oled.cpp
rename to qthing/oled.cpp
diff --git a/main/oled.h b/qthing/oled.h
similarity index 100%
rename from main/oled.h
rename to qthing/oled.h
diff --git a/main/oled_symbols.h b/qthing/oled_symbols.h
similarity index 100%
rename from main/oled_symbols.h
rename to qthing/oled_symbols.h
diff --git a/main/peripherals/button_panel_5x5.cpp b/qthing/peripherals/button_panel_5x5.cpp
similarity index 100%
rename from main/peripherals/button_panel_5x5.cpp
rename to qthing/peripherals/button_panel_5x5.cpp
diff --git a/main/peripherals/led_strip.cpp b/qthing/peripherals/led_strip.cpp
similarity index 100%
rename from main/peripherals/led_strip.cpp
rename to qthing/peripherals/led_strip.cpp
diff --git a/main/peripherals/led_strip.h b/qthing/peripherals/led_strip.h
similarity index 100%
rename from main/peripherals/led_strip.h
rename to qthing/peripherals/led_strip.h
diff --git a/main/polyfill.h b/qthing/polyfill.h
similarity index 100%
rename from main/polyfill.h
rename to qthing/polyfill.h
diff --git a/main/qthing.h b/qthing/qthing.h
similarity index 100%
rename from main/qthing.h
rename to qthing/qthing.h
diff --git a/main/rc_433.cpp b/qthing/rc_433.cpp
similarity index 100%
rename from main/rc_433.cpp
rename to qthing/rc_433.cpp
diff --git a/main/rc_433.h b/qthing/rc_433.h
similarity index 100%
rename from main/rc_433.h
rename to qthing/rc_433.h
diff --git a/main/sensor.cpp b/qthing/sensor.cpp
similarity index 100%
rename from main/sensor.cpp
rename to qthing/sensor.cpp
diff --git a/main/sensor.h b/qthing/sensor.h
similarity index 100%
rename from main/sensor.h
rename to qthing/sensor.h
diff --git a/main/status.cpp b/qthing/status.cpp
similarity index 100%
rename from main/status.cpp
rename to qthing/status.cpp
diff --git a/main/status.h b/qthing/status.h
similarity index 100%
rename from main/status.h
rename to qthing/status.h
diff --git a/main/system/power.cpp b/qthing/system/power.cpp
similarity index 100%
rename from main/system/power.cpp
rename to qthing/system/power.cpp
diff --git a/main/util.cpp b/qthing/util.cpp
similarity index 100%
rename from main/util.cpp
rename to qthing/util.cpp
diff --git a/main/util.h b/qthing/util.h
similarity index 100%
rename from main/util.h
rename to qthing/util.h