Introduction to the LuCI Architecture in OpenWrt

1. What is LuCI

LuCI is the Web UI framework for OpenWrt, with core features:

  • Based on Lua + uhttpd + ubus/uci

  • Configuration-driven (does not directly modify files, but modifies UCI)

  • Light coupling, plugin support (package)

2. Overall Architecture Diagram

Introduction to the LuCI Architecture in OpenWrt

3. Core Components

Layer

Role

Common Content

uhttpd

HTTP Entry

/etc/config/uhttpd

Lua/dispatcher

URL Router → Controller

/usr/lib/lua/luci/dispatcher.lua

Controller

Handles requests & calls UCI/ubus

/usr/lib/lua/luci/controller/…

Model

Read/Write UCI / RPCD

/usr/lib/lua/luci/model/…

View

Render HTML

/usr/lib/lua/luci/view/…

UCI

Persistent configuration data

/etc/config/…

ubus/rpcd

API layer interacting with the system

wifi, firewall, system

4. Request Handling Process (Example: “Save Wi-Fi Configuration”)

(1) Browser clicks “Save” → POST

(2) uhttpd forwards to LuCI dispatcher

(3) Dispatcher finds the corresponding Controller

(4) Controller calls Model to write UCI: wifi.ssid=”MyAP”

(5) Submit UCI → uci commit wireless

(6) Controller triggers system action (ubus call hostapd reload)

(7) Returns JSON / HTML page

Features: All configurations do not directly modify files, but go through UCI + commit

5. Configuration Persistence Mechanism

  • Edit = uci set
  • Save & Apply = uci commit + reload/restart
  • Modifies the /etc/config/* files (unified entry, convenient for scripts/CLI/GUI to share)

6. Plugin Extension Mechanism (How to Add a Page)

Adding new functionality generally requires three things:

/usr/lib/lua/luci/controller/myapp.lua ← Routing + Control Logic

/usr/lib/lua/luci/model/cbi/myapp/.lua ← Model file for calling UCI

/usr/lib/lua/luci/view/myapp/.htm ← Page template

After registering the route, restart uhttpd/LuCI to display the UI module.

7. Why LuCI is Suitable for Routers/Embedded Systems

  • Runs on low RAM/Flash (Lua is lightweight)
  • Unified system configuration model (UCI)
  • RPC-oriented (can seamlessly collaborate with CLI/scripts/daemon)
  • Plugin structure adapts to ODM/OEM scenarios

Leave a Comment