# globalpolicy/phonemonitor architecture

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

- Interactive diagram: https://gitdiagram.com/globalpolicy/phonemonitor
- Repository: https://github.com/globalpolicy/phonemonitor

## Overview

##### Project type and purpose
- This is a full-stack remote administration tool.
- Android client (PhoneMonitor app) that runs in the background, monitors calls/SMS/files/camera, and uploads data to a server.
- Web panel (PHP scripts) for administrators to view logs, send commands, and manage users.
- MySQL database (“phonemonitor”) to store device data, user accounts, and command queues.

##### File structure
- Top-level folders:
- AndroidStudioProject/PhoneMonitor – native Android app project (Gradle build, Java source, resources, manifests, tests, libs).
- Webpanel – collection of PHP endpoints (authenticate.php, getcommands.php, setcommands.php, helperfuncs.php, etc.) and UI pages.
- LICENSE, README.md – documentation and license.
- Key patterns:
- Android: BroadcastReceivers (Alarm, CallState, SMS, NetworkChange, OnBootCompleted) trigger actions in MainService or directly start tasks.
- Background service pattern: MainService + ServerTalkLoopThread handles periodic polling and data upload.
- Web panel: procedural PHP pages act as REST‐style endpoints; helperfuncs.php centralizes DB helper routines.
- Database integration: PHP scripts connect to MySQL with credentials in helperfuncs.php.

##### Extract README insights
- Android minimum API 15, target API 21.
- Setup involves replacing placeholders in AppSettings.java, building signed APK, installing on device.
- Web setup involves editing helperfuncs.php DB credentials, uploading PHP files, creating MySQL “phonemonitor” database, approving a user account.

a. Main components
- Android Device
- Android App:
– UI Layer: MainActivity (app settings, manual triggers)
– Background Layer: MainService, BroadcastReceivers, HelperMethods, RepeatTask
– Network Layer: FileUploader, ServerTalkLoopThread, WebCommandsExecutor, SMSExecutor
- Server:
– Web Server (Apache/Nginx + PHP runtime) hosting Webpanel directory with endpoints
– PHP helper library: helperfuncs.php
- Data Store: MySQL database “phonemonitor” (tables: users, calls, sms, photos, commands, settings)
- Administrator’s Browser (Web UI for clientlist, displaycalllogs, setcommands, etc.)
b. Relationships and data flows
1. Device events (call received, SMS, boot, network change, alarm) → BroadcastReceiver → MainService or task executor
2. Data capture (camera image, call log, SMS content) → HelperMethods → FileUploader → HTTP POST to server endpoint (e.g., setoutput.php)
3. Periodic polling: ServerTalkLoopThread → HTTP GET getcommands.php → WebCommandsExecutor or SMSExecutor executes remote commands
4. Web UI (admin) interacts via browser → PHP scripts (clientlist.php, displayphotos.php, setcommands.php) → helperfuncs.php → MySQL queries
c. Architectural patterns/design principles
- Client-server architecture with REST-style PHP endpoints
- Observer pattern in Android (BroadcastReceivers)
- Service pattern for long-running background processes
- Separation of concerns: capture → upload → server processing → storage → admin UI
d. Key technologies/frameworks
- Android SDK (Java), Gradle, commons-net library
- PHP 7+, Apache/Nginx
- MySQL
- HTML/CSS for web panel UI

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile Client Layer
    subgraph "Mobile Client" 
        style MobileClient fill:#D0E8FF,stroke:#333,stroke-width:1px
        subgraph "UI Layer"
            MainActivity["MainActivity"]:::mobile
            AppSettings["AppSettings"]:::mobile
        end
        subgraph "Background Layer"
            AlarmBR["AlarmBroadcastReceiver"]:::mobile
            CallStateBR["CallStateBroadcastReceiver"]:::mobile
            SMSBR["SMSBroadcastReceiver"]:::mobile
            NetworkBR["NetworkChangeBroadcastReceiver"]:::mobile
            BootBR["OnBootCompletedReceiver"]:::mobile
            MainService["MainService"]:::mobile
            RepeatTask["RepeatTask"]:::mobile
            HelperMethods["HelperMethods"]:::mobile
            CameraCapture["CameraCapture"]:::mobile
        end
        subgraph "Network Layer"
            FileUploader["FileUploader"]:::mobile
            ServerTalkLoopThread["ServerTalkLoopThread"]:::mobile
            WebCommandsExecutor["WebCommandsExecutor"]:::mobile
            SMSExecutor["SMSExecutor"]:::mobile
        end
    end

    %% Server/API Layer
    subgraph "Server/API" 
        style ServerAPI fill:#FFE0B2,stroke:#333,stroke-width:1px
        helperfuncs["helperfuncs.php"]:::api
        authenticate["authenticate.php"]:::api
        getcommands["getcommands.php"]:::api
        setcommands["setcommands.php"]:::api
        setoutput["setoutput.php"]:::api
        outputlist["outputlist.php"]:::api
        getsettings["getsettings.php"]:::api
        setsettings["setsettings.php"]:::api
        clientlist["clientlist.php"]:::api
        displaycalllogs["displaycalllogs.php"]:::api
        displaysmses["displaysmses.php"]:::api
        displaysmsconversation["displaysmsconversation.php"]:::api
        displaycontacts["displaycontacts.php"]:::api
        displayphotos["displayphotos.php"]:::api
        commandlist["commandlist.php"]:::api
        report["report.php"]:::api
        deleteimage["deleteimage.php"]:::api
        index["index.php"]:::api
        mainPage["main.php"]:::api
        logout["logout.php"]:::api
    end

    %% Admin UI Layer
    subgraph "Admin UI"
        style AdminUI fill:#E1BEE7,stroke:#333,stroke-width:1px
        AdminBrowser["Web Browser"]:::ui
    end

    %% Database Layer
    subgraph "Database"
        style Database fill:#C8E6C9,stroke:#333,stroke-width:1px
        MySQL["MySQL: phonemonitor"]:::db
    end

    %% Data Flows - Mobile Client
    AlarmBR -->|triggers| MainService
    CallStateBR -->|triggers| MainService
    SMSBR -->|triggers| MainService
    NetworkBR -->|triggers| MainService
    BootBR -->|triggers| MainService
    MainService -->|schedules| RepeatTask
    RepeatTask -->|uses| HelperMethods
    HelperMethods -->|captures| CameraCapture
    HelperMethods -->|calls| FileUploader
    FileUploader -->|HTTP POST| setoutput
    ServerTalkLoopThread -->|HTTP GET| getcommands
    getcommands -->|commands| WebCommandsExecutor
    getcommands -->|commands| SMSExecutor

    %% Data Flows - Admin UI to Server/API to DB
    AdminBrowser -->|login| authenticate
    authenticate -->|validates via| helperfuncs
    authenticate -->|redirects to| mainPage
    AdminBrowser -->|requests| clientlist
    AdminBrowser -->|views| displaycalllogs
    AdminBrowser -->|views| displaysmses
    AdminBrowser -->|views| displaysmsconversation
    AdminBrowser -->|views| displaycontacts
    AdminBrowser -->|views| displayphotos
    AdminBrowser -->|views| commandlist
    AdminBrowser -->|views| report
    AdminBrowser -->|issues delete| deleteimage
    AdminBrowser -->|sets| setcommands
    AdminBrowser -->|gets| getsettings
    AdminBrowser -->|sets| setsettings
    AdminBrowser -->|lists| outputlist
    AdminBrowser -->|logout| logout
    authenticate --> helperfuncs
    mainPage --> helperfuncs
    clientlist --> helperfuncs
    displaycalllogs --> helperfuncs
    displaysmses --> helperfuncs
    displaysmsconversation --> helperfuncs
    displaycontacts --> helperfuncs
    displayphotos --> helperfuncs
    commandlist --> helperfuncs
    report --> helperfuncs
    deleteimage --> helperfuncs
    setcommands --> helperfuncs
    getsettings --> helperfuncs
    setsettings --> helperfuncs
    outputlist --> helperfuncs

    %% API Layer to Database
    helperfuncs -->|queries| MySQL

    %% Client API calls to helper and DB
    setoutput --> helperfuncs
    getcommands --> helperfuncs

    %% Click Events - Android Components
    click MainActivity "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/MainActivity.java"
    click AppSettings "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/AppSettings.java"
    click AlarmBR "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/AlarmBroadcastReceiver.java"
    click CallStateBR "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/CallStateBroadcastReceiver.java"
    click SMSBR "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/SMSBroadcastReceiver.java"
    click NetworkBR "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/NetworkChangeBroadcastReceiver.java"
    click BootBR "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/OnBootCompletedReceiver.java"
    click MainService "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/MainService.java"
    click RepeatTask "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/RepeatTask.java"
    click HelperMethods "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/HelperMethods.java"
    click CameraCapture "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/CameraCapture.java"
    click FileUploader "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/FileUploader.java"
    click ServerTalkLoopThread "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/ServerTalkLoopThread.java"
    click WebCommandsExecutor "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/WebCommandsExecutor.java"
    click SMSExecutor "https://github.com/globalpolicy/phonemonitor/blob/master/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/SMSExecutor.java"

    %% Click Events - Webpanel API Layer
    click helperfuncs "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/helperfuncs.php"
    click authenticate "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/authenticate.php"
    click getcommands "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/getcommands.php"
    click setcommands "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/setcommands.php"
    click setoutput "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/setoutput.php"
    click outputlist "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/outputlist.php"
    click getsettings "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/getsettings.php"
    click setsettings "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/setsettings.php"
    click clientlist "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/clientlist.php"
    click displaycalllogs "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/displaycalllogs.php"
    click displaysmses "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/displaysmses.php"
    click displaysmsconversation "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/displaysmsconversation.php"
    click displaycontacts "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/displaycontacts.php"
    click displayphotos "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/displayphotos.php"
    click commandlist "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/commandlist.php"
    click report "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/report.php"
    click deleteimage "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/deleteimage.php"
    click index "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/index.php"
    click mainPage "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/main.php"
    click logout "https://github.com/globalpolicy/phonemonitor/blob/master/Webpanel/logout.php"

    %% Styles
    classDef mobile fill:#BBDEFB,stroke:#1E88E5,color:#000
    classDef api fill:#FFE0B2,stroke:#FB8C00,color:#000
    classDef db fill:#C8E6C9,stroke:#43A047,color:#000
    classDef ui fill:#E1BEE7,stroke:#8E24AA,color:#000
    class ServerAPI,MobileClient,AdminUI,Database fill-opacity:0.3
```
