# r-976/parental architecture

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

- Interactive diagram: https://gitdiagram.com/r-976/parental
- Repository: https://github.com/r-976/parental

## Overview

SafeGuard is a parental-monitoring system: parents pair a child Android device, the app gathers device activity and location, and sends telemetry or real-time events to a multi-tenant Flask server for parent/admin dashboards. The server also dispatches remote commands and supports live-media signaling. The graph preserves documented monitoring, media, notifications, and administration capabilities; some implementation details are represented by their exact enclosing directories because those modules were not sampled. Edges are limited to relationships shown by excerpts, the source index, or the README.

Main entry points: [`server/routes`](https://github.com/r-976/parental/tree/main/server/routes) (Monitoring APIs), [`server/socket_server.py`](https://github.com/r-976/parental/blob/main/server/socket_server.py) (Realtime service), [`app/src/main/java/com/safeguard/client/services/DaemonService.kt`](https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/services/DaemonService.kt) (Background daemon), [`server/database.py`](https://github.com/r-976/parental/blob/main/server/database.py) (Database engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Android client"]
  node_daemon["Background daemon<br/>[DaemonService.kt]"]
  node_commands["Command dispatcher"]
  node_location["Location capture<br/>[LocationManager.kt]"]
  node_route["Route tracking"]
  node_boundary["Boundary monitoring"]
  node_devicefeatures["Device monitoring"]
  node_liveclient["Live media client<br/>[WebRtcManager.kt]"]
  node_client_store[("Client telemetry cache")]
  node_route_store[("Route cache")]
end

subgraph group_transport["Server transport"]
  node_api["HTTP client<br/>[ApiClient.kt]"]
  node_socket["Socket client<br/>[SocketManager.kt]"]
end

subgraph group_backend["Server application"]
  node_server["Flask application<br/>[app.py]"]
  node_http_routes["Monitoring APIs"]
  node_command_routes["Command lifecycle<br/>[command_routes.py]"]
  node_socketserver["Realtime service<br/>[socket_server.py]"]
  node_admin["Admin operations<br/>[admin_routes.py]"]
  node_fcm["Push notifications<br/>[fcm.py]"]
end

subgraph group_persistence["Data and security"]
  node_models["Domain records"]
  node_database[("Database engine<br/>[database.py]")]
  node_audit["Activity auditing<br/>[audit.py]"]
  node_auth["Identity and access<br/>[auth_helper.py]"]
  node_device_token["Device authentication<br/>[device_token.py]"]
  node_encryption["Encrypted messaging<br/>[encryption.py]"]
end

subgraph group_dashboard["Parent and admin"]
  node_dashboard_ui["Web dashboard<br/>[main.js]"]
end

node_parent(("Parent or admin"))
node_child(("Child device"))
node_external_push["Push service"]

node_child -->|"runs app"| node_daemon
node_daemon -->|"connects and dispatches"| node_socket
node_socket -->|"dispatches commands"| node_commands
node_daemon -->|"uses capture"| node_location
node_location -->|"stores telemetry"| node_client_store
node_location -->|"uploads location"| node_api
node_daemon -->|"starts tracking"| node_route
node_route -->|"stores route state"| node_route_store
node_route -->|"uploads route data"| node_api
node_route -->|"sends realtime data"| node_socket
node_daemon -->|"starts monitoring"| node_devicefeatures
node_daemon -->|"manages live sessions"| node_liveclient
node_boundary -->|"uses location"| node_location
node_api -.->|"HTTP requests"| node_server
node_socket -.->|"socket events"| node_socketserver
node_parent -->|"uses dashboard"| node_dashboard_ui
node_dashboard_ui -.->|"realtime dashboard"| node_socketserver
node_server -->|"registers routes"| node_http_routes
node_server -->|"initializes realtime"| node_socketserver
node_http_routes -->|"uses records"| node_models
node_http_routes -->|"queries data"| node_database
node_http_routes -->|"checks access"| node_auth
node_http_routes -->|"validates devices"| node_device_token
node_http_routes -->|"records activity"| node_audit
node_server -->|"configures database"| node_database
node_command_routes -->|"queues commands"| node_database
node_socketserver -->|"updates device state"| node_database
node_socketserver -.->|"verifies encrypted packets"| node_encryption
node_socketserver -.->|"handles command data"| node_command_routes
node_admin -->|"checks access"| node_auth
node_admin -->|"records actions"| node_audit
node_admin -->|"manages realtime state"| node_socketserver
node_http_routes -.->|"sends push alerts"| node_fcm
node_fcm -.->|"delivers notifications"| node_external_push
node_database -.->|"persists records"| node_models
node_parent -->|"administers accounts"| node_admin
node_parent -->|"views child activity"| node_http_routes
node_parent -->|"issues commands"| node_command_routes

click node_daemon "https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/services/DaemonService.kt"
click node_commands "https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/managers/CommandDispatcher.kt"
click node_location "https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/managers/LocationManager.kt"
click node_route "https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/managers/RouteTrackingManager.kt"
click node_boundary "https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/services/BoundaryMonitoringService.kt"
click node_devicefeatures "https://github.com/r-976/parental/tree/main/app/src/main/java/com/safeguard/client/managers"
click node_liveclient "https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/webrtc/WebRtcManager.kt"
click node_api "https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/network/ApiClient.kt"
click node_socket "https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/network/SocketManager.kt"
click node_server "https://github.com/r-976/parental/blob/main/server/app.py"
click node_http_routes "https://github.com/r-976/parental/tree/main/server/routes"
click node_command_routes "https://github.com/r-976/parental/blob/main/server/routes/command_routes.py"
click node_socketserver "https://github.com/r-976/parental/blob/main/server/socket_server.py"
click node_dashboard_ui "https://github.com/r-976/parental/blob/main/server/static/js/main.js"
click node_admin "https://github.com/r-976/parental/blob/main/server/routes/admin_routes.py"
click node_models "https://github.com/r-976/parental/tree/main/server/models"
click node_database "https://github.com/r-976/parental/blob/main/server/database.py"
click node_audit "https://github.com/r-976/parental/blob/main/server/utils/audit.py"
click node_auth "https://github.com/r-976/parental/blob/main/server/utils/auth_helper.py"
click node_device_token "https://github.com/r-976/parental/blob/main/server/utils/device_token.py"
click node_encryption "https://github.com/r-976/parental/blob/main/server/encryption.py"
click node_fcm "https://github.com/r-976/parental/blob/main/server/utils/fcm.py"
click node_client_store "https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/database/TelemetryDatabase.kt"
click node_route_store "https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/database/RouteTrackingDatabase.kt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_daemon,node_commands,node_location,node_route,node_boundary,node_devicefeatures,node_liveclient,node_client_store,node_route_store toneBlue
class node_api,node_socket toneAmber
class node_server,node_http_routes,node_command_routes,node_socketserver,node_admin,node_fcm toneMint
class node_models,node_database,node_audit,node_auth,node_device_token,node_encryption toneRose
class node_dashboard_ui,node_parent,node_child,node_external_push toneIndigo
```

## Components

### Android client

- [Background daemon](https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/services/DaemonService.kt): `app/src/main/java/com/safeguard/client/services/DaemonService.kt`
- [Command dispatcher](https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/managers/CommandDispatcher.kt): `app/src/main/java/com/safeguard/client/managers/CommandDispatcher.kt`
- [Location capture](https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/managers/LocationManager.kt): `app/src/main/java/com/safeguard/client/managers/LocationManager.kt`
- [Route tracking](https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/managers/RouteTrackingManager.kt): `app/src/main/java/com/safeguard/client/managers/RouteTrackingManager.kt`
- [Boundary monitoring](https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/services/BoundaryMonitoringService.kt): `app/src/main/java/com/safeguard/client/services/BoundaryMonitoringService.kt`
- [Device monitoring](https://github.com/r-976/parental/tree/main/app/src/main/java/com/safeguard/client/managers): `app/src/main/java/com/safeguard/client/managers`
- [Live media client](https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/webrtc/WebRtcManager.kt): `app/src/main/java/com/safeguard/client/webrtc/WebRtcManager.kt`
- [Client telemetry cache](https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/database/TelemetryDatabase.kt): `app/src/main/java/com/safeguard/client/database/TelemetryDatabase.kt`
- [Route cache](https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/database/RouteTrackingDatabase.kt): `app/src/main/java/com/safeguard/client/database/RouteTrackingDatabase.kt`

### Server transport

- [HTTP client](https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/network/ApiClient.kt): `app/src/main/java/com/safeguard/client/network/ApiClient.kt`
- [Socket client](https://github.com/r-976/parental/blob/main/app/src/main/java/com/safeguard/client/network/SocketManager.kt): `app/src/main/java/com/safeguard/client/network/SocketManager.kt`

### Server application

- [Flask application](https://github.com/r-976/parental/blob/main/server/app.py): `server/app.py`
- [Monitoring APIs](https://github.com/r-976/parental/tree/main/server/routes): `server/routes`
- [Command lifecycle](https://github.com/r-976/parental/blob/main/server/routes/command_routes.py): `server/routes/command_routes.py`
- [Realtime service](https://github.com/r-976/parental/blob/main/server/socket_server.py): `server/socket_server.py`
- [Admin operations](https://github.com/r-976/parental/blob/main/server/routes/admin_routes.py): `server/routes/admin_routes.py`
- [Push notifications](https://github.com/r-976/parental/blob/main/server/utils/fcm.py): `server/utils/fcm.py`

### Data and security

- [Domain records](https://github.com/r-976/parental/tree/main/server/models): `server/models`
- [Database engine](https://github.com/r-976/parental/blob/main/server/database.py): `server/database.py`
- [Activity auditing](https://github.com/r-976/parental/blob/main/server/utils/audit.py): `server/utils/audit.py`
- [Identity and access](https://github.com/r-976/parental/blob/main/server/utils/auth_helper.py): `server/utils/auth_helper.py`
- [Device authentication](https://github.com/r-976/parental/blob/main/server/utils/device_token.py): `server/utils/device_token.py`
- [Encrypted messaging](https://github.com/r-976/parental/blob/main/server/encryption.py): `server/encryption.py`

### Parent and admin

- [Web dashboard](https://github.com/r-976/parental/blob/main/server/static/js/main.js): `server/static/js/main.js`

### Other components

- **Parent or admin**
- **Child device**
- **Push service**

## Connections

- Child device → Background daemon: runs app
- Background daemon → Socket client: connects and dispatches (evidence: `app/src/main/java/com/safeguard/client/services/DaemonService.kt`)
- Socket client → Command dispatcher: dispatches commands (evidence: `app/src/main/java/com/safeguard/client/services/DaemonService.kt`)
- Background daemon → Location capture: uses capture (evidence: `app/src/main/java/com/safeguard/client/services/DaemonService.kt`)
- Location capture → Client telemetry cache: stores telemetry (evidence: `app/src/main/java/com/safeguard/client/managers/LocationManager.kt`)
- Location capture → HTTP client: uploads location (evidence: `app/src/main/java/com/safeguard/client/managers/LocationManager.kt`)
- Background daemon → Route tracking: starts tracking (evidence: `app/src/main/java/com/safeguard/client/services/DaemonService.kt`)
- Route tracking → Route cache: stores route state (evidence: `app/src/main/java/com/safeguard/client/managers/RouteTrackingManager.kt`)
- Route tracking → HTTP client: uploads route data (evidence: `app/src/main/java/com/safeguard/client/managers/RouteTrackingManager.kt`)
- Route tracking → Socket client: sends realtime data (evidence: `app/src/main/java/com/safeguard/client/managers/RouteTrackingManager.kt`)
- Background daemon → Device monitoring: starts monitoring (evidence: `app/src/main/java/com/safeguard/client/services/DaemonService.kt`)
- Background daemon → Live media client: manages live sessions (evidence: `app/src/main/java/com/safeguard/client/services/DaemonService.kt`)
- Boundary monitoring → Location capture: uses location (evidence: `app/src/main/java/com/safeguard/client/services/BoundaryMonitoringService.kt`)
- HTTP client → Flask application: HTTP requests
- Socket client → Realtime service: socket events
- Parent or admin → Web dashboard: uses dashboard
- Web dashboard → Realtime service: realtime dashboard
- Flask application → Monitoring APIs: registers routes (evidence: `server/app.py`)
- Flask application → Realtime service: initializes realtime (evidence: `server/app.py`)
- Monitoring APIs → Domain records: uses records (evidence: `server/routes/location_routes.py`)
- Monitoring APIs → Database engine: queries data (evidence: `server/routes/location_routes.py`)
- Monitoring APIs → Identity and access: checks access (evidence: `server/routes/location_routes.py`)
- Monitoring APIs → Device authentication: validates devices (evidence: `server/routes/location_routes.py`)
- Monitoring APIs → Activity auditing: records activity (evidence: `server/routes/location_routes.py`)
- Flask application → Database engine: configures database (evidence: `server/app.py`)
- Command lifecycle → Database engine: queues commands (evidence: `server/routes/command_routes.py`)
- Realtime service → Database engine: updates device state (evidence: `server/socket_server.py`)
- Realtime service → Encrypted messaging: verifies encrypted packets (evidence: `server/socket_server.py`)
- Realtime service → Command lifecycle: handles command data (evidence: `server/routes/command_routes.py`)
- Admin operations → Identity and access: checks access (evidence: `server/routes/admin_routes.py`)
- Admin operations → Activity auditing: records actions (evidence: `server/routes/admin_routes.py`)
- Admin operations → Realtime service: manages realtime state (evidence: `server/routes/admin_routes.py`)
- Monitoring APIs → Push notifications: sends push alerts (evidence: `server/routes/location_routes.py`)
- Push notifications → Push service: delivers notifications (evidence: `server/utils/fcm.py`)
- Database engine → Domain records: persists records (evidence: `server/database.py`)
- Parent or admin → Admin operations: administers accounts
- Parent or admin → Monitoring APIs: views child activity
- Parent or admin → Command lifecycle: issues commands
