# destan19/openappfilter architecture

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

- Interactive diagram: https://gitdiagram.com/destan19/openappfilter
- Repository: https://github.com/destan19/openappfilter

## Overview

##### Project Type and Purpose
- The README clearly states that OAF is a parental control plug-in for OpenWrt routers, focusing on filtering apps (games, videos, chats, downloads, etc.) and allowing custom app rules.
- The project comprises several components: a LuCI-based web interface (for configuration) and underlying filtering modules (in C) that interact with the OpenWrt kernel/system.

##### File Structure
- Notice the presence of multiple packages:
– The “luci-app-oaf” directory contains the web interface components structured with MVC patterns:
▪ “luasrc/controller” – handles the routing of requests.
▪ “luasrc/model/cbi/appfilter” – contains configuration settings and business logic.
▪ “luasrc/view” – includes the front-end templates (HTML) to render configuration pages.
– The “oaf” and “open-app-filter” directories contain C source files and Makefiles:
▪ They implement the core filtering logic, configuration handling, possibly netlink communications with the kernel, and utilities (like JSON parsing via cJSON, regex handling, etc.).
– The “root” folder under “luci-app-oaf” includes UCI default configuration files which integrate the plug-in with OpenWrt’s system initialization.
- The separation into luci-app (UI) and C source code (core service/daemon) indicates a clear division between the presentation layer and the backend filtering functionality.

##### README for Additional Insights
- The README lays out the preparation, compilation, and installation steps. This highlights dependencies on the OpenWrt environment and the modular nature of the plug-in.
- It shows that proper version matching with OpenWrt and kernel compatibility is essential, implying a tight integration with the router’s firmware system.

a. Main Components:
- LuCI Web Interface Module:
- Controller, Model, and View layers found in “luci-app-oaf” facilitate user interactions and configurations.
- Core Filtering Service:
- C source modules (e.g., af_client, app_filter, and others in “oaf/src” and “open-app-filter/src”) implement the actual filtering logic.
- System Integration & Configuration:
- UCI defaults and Makefiles that integrate the plug-in into the OpenWrt environment.
- External Dependencies:
- Libraries such as cJSON and regexp, plus any netlink or kernel interaction components.

b. Relationships and Interactions:
- The LuCI interface (web frontend) sends configuration data via its controllers (Lua scripts) to the underlying service.
- The service layer (C components) processes these configurations, applies filtering rules, and interacts with the OpenWrt kernel or system (likely via netlink or system calls).
- Configuration files (such as those in “open-app-filter/files” and “luci-app-oaf/root/etc/uci-defaults”) ensure that when the router boots, the correct filtering rules and parameters are loaded.

c. Architectural Patterns & Design Principles:
- Use of the MVC pattern within the LuCI module for clear separation between UI and application logic.
- Modular design that separates user interface, business logic, and system integration.
- Clear delineation of compile-time configuration (Makefiles, UCI defaults) which enable integration into the OpenWrt system.

d. Relevant Technologies/Frameworks:
- OpenWrt and its SDK/build system.
- LuCI framework for the web interface.
- C programming for the filtering engine and related network/process management.
- Utility libraries such as cJSON and regular expression handling libraries.

## Diagram (Mermaid)

```mermaid
flowchart TD
    userBrowser["User (Browser)"]:::external

    subgraph "LuCI Web Interface Module"
        controller["LuCI Controller"]:::frontend
        model["LuCI Model"]:::frontend
        viewTemplates["LuCI View Templates"]:::frontend
        staticAssets["LuCI Static Assets"]:::frontend
    end

    subgraph "C Filtering Engine"
        oaf["oaf/src Modules"]:::core
        openApp["Open-App-Filter Modules"]:::core
    end

    subgraph "External Dependencies"
        cJSON["cJSON Library"]:::core
        regex["Regex Library"]:::core
    end

    subgraph "System Integration & Configuration"
        uciDefaults["UCI Defaults"]:::integration
        suppConfig["Supplementary Config"]:::integration
    end

    kernel["Kernel/System"]:::integration

    userBrowser -->|"configRequest"| controller
    controller -->|"process_config"| model
    model -->|"render_view"| viewTemplates
    viewTemplates -->|"load_assets"| staticAssets
    controller -->|"send_config"| oaf
    oaf -->|"integrate"| openApp
    oaf -->|"push_filtering"| kernel
    openApp -->|"push_filtering"| kernel
    uciDefaults -->|"init_config"| kernel
    suppConfig -->|"additional_config"| kernel
    oaf -->|"uses"| cJSON
    oaf -->|"uses"| regex

    click controller "https://github.com/destan19/openappfilter/blob/master/luci-app-oaf/luasrc/controller/appfilter.lua"
    click model "https://github.com/destan19/openappfilter/tree/master/luci-app-oaf/luasrc/model/cbi/appfilter"
    click viewTemplates "https://github.com/destan19/openappfilter/tree/master/luci-app-oaf/luasrc/view"
    click staticAssets "https://github.com/destan19/openappfilter/tree/master/luci-app-oaf/htdocs/luci-static"
    click oaf "https://github.com/destan19/openappfilter/tree/master/oaf/src"
    click openApp "https://github.com/destan19/openappfilter/tree/master/open-app-filter/src"
    click uciDefaults "https://github.com/destan19/openappfilter/blob/master/luci-app-oaf/root/etc/uci-defaults/94_feature_3.0"
    click suppConfig "https://github.com/destan19/openappfilter/tree/master/open-app-filter/files"
    click cJSON "https://github.com/destan19/openappfilter/blob/master/oaf/src/cJSON.c"
    click regex "https://github.com/destan19/openappfilter/blob/master/oaf/src/regexp.c"

    classDef frontend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef core fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef integration fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
