# vxnavi71/guardian-link architecture

> Architecture diagram of the GitHub repository vxnavi71/guardian-link, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vxnavi71/guardian-link
- Repository: https://github.com/vxnavi71/guardian-link

## Overview

#### Purpose and Entry Points
Guardian Link is a Python-backed web application for monitoring Instagram-related activity and detecting grooming-risk signals. The primary process entry point is `run.py`; application assembly and runtime configuration are centered in `backend/app.py`.

#### Web Application Layer
The backend exposes browser-facing routes for authentication, dashboard access, and monitoring workflows. Routing is separated from app creation:
- `backend/app.py`
- `backend/routes.py`
- `backend/auth.py`

Server-rendered pages use a shared template layout and dashboard view:
- `frontend/templates/base.html`
- `frontend/templates/dashboard.html`
- `frontend/templates/login.html`

#### Authentication and User Boundary
Authentication is a distinct subsystem, likely handling registration, login, session/identity checks, and access control before users reach protected monitoring functions. Its UI boundary is represented by registration and login templates, while backend enforcement resides in:
- `backend/auth.py`
- `frontend/templates/login.html`
- `frontend/templates/register.html`

#### Monitoring and Instagram Integration
Instagram is treated as an external data-source boundary. The application’s Instagram adapter should isolate API acquisition and normalization from route/UI concerns:
- `backend/instagram_api.py`
- `backend/routes.py`

This stage feeds account, conversation, or activity data into the risk-analysis path rather than coupling external API behavior directly to templates.

#### Grooming Detection and ML Analysis
Risk detection is split between grooming-specific logic and a machine-learning model wrapper:
- `backend/grooming_detector.py`
- `backend/ml_model.py`

The expected core flow is: Instagram-derived content enters detector/model analysis, is classified or scored for suspicious grooming behavior, and returns findings for presentation and alerting. Keeping these modules separate supports evolving detection rules independently of model inference.

#### Alerts and Persistence
Detection results can trigger alert handling, while database access is centralized behind a persistence boundary:
- `backend/alerts.py`
- `backend/db.py`
- `backend/mock_data.json`

`mock_data.json` suggests a development/demo data path may exist when live external data or database records are unavailable. Alert generation should consume detector outputs rather than recompute detection logic.

#### Frontend Delivery
The frontend is server-rendered HTML with static CSS and JavaScript enhancements, not a separately listed SPA runtime:
- `frontend/templates/dashboard.html`
- `frontend/static/js/main.js`
- `frontend/static/css/style.css`

The dashboard is the primary visualization/control surface for monitored activity, risk findings, and likely alerts. Browser interactions cross the backend route boundary; they should not communicate directly with Instagram or model internals.

Main entry points: [`backend/routes.py`](https://github.com/vxnavi71/guardian-link/blob/main/backend/routes.py) (Monitoring routes), [`backend/grooming_detector.py`](https://github.com/vxnavi71/guardian-link/blob/main/backend/grooming_detector.py) (Grooming detector), [`backend/app.py`](https://github.com/vxnavi71/guardian-link/blob/main/backend/app.py) (App assembly), [`backend/alerts.py`](https://github.com/vxnavi71/guardian-link/blob/main/backend/alerts.py) (Alert handling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_app["App assembly<br/>application factory<br/>[app.py]"]
  node_routes["Monitoring routes<br/>route handlers<br/>[routes.py]"]
  node_auth["Authentication<br/>identity and access<br/>[auth.py]"]
  node_templates["Page templates<br/>server-rendered views<br/>[base.html]"]
  node_frontend["Dashboard enhancements<br/>CSS and JavaScript<br/>[main.js]"]
end

subgraph group_analysis["Risk analysis"]
  node_detector["Grooming detector<br/>risk rules"]
  node_model["ML model wrapper<br/>model inference<br/>[ml_model.py]"]
  node_alerts["Alert handling<br/>alert service<br/>[alerts.py]"]
end

subgraph group_data["Data and integrations"]
  node_instagram{{"Instagram adapter<br/>external API adapter<br/>[instagram_api.py]"}}
  node_database[("Persistence<br/>database access<br/>[db.py]")]
  node_mock_data["Demo data<br/>development fixture<br/>[mock_data.json]"]
end

node_entry(("Process entry<br/>Python entry point<br/>[run.py]"))
node_browser(("Browser user<br/>client"))

node_entry -->|"starts"| node_app
node_app -->|"registers"| node_routes
node_app -->|"configures"| node_auth
node_browser -->|"requests"| node_routes
node_routes -->|"checks access"| node_auth
node_routes -->|"renders"| node_templates
node_templates -->|"loads"| node_frontend
node_routes -->|"requests activity"| node_instagram
node_instagram -->|"normalized content"| node_detector
node_detector -->|"scores content"| node_model
node_model -->|"risk score"| node_detector
node_detector -->|"findings"| node_alerts
node_routes -->|"retrieves alerts"| node_alerts
node_routes -->|"reads and writes"| node_database
node_alerts -->|"stores alerts"| node_database
node_database -.->|"demo fallback"| node_mock_data

click node_entry "https://github.com/vxnavi71/guardian-link/blob/main/run.py"
click node_app "https://github.com/vxnavi71/guardian-link/blob/main/backend/app.py"
click node_routes "https://github.com/vxnavi71/guardian-link/blob/main/backend/routes.py"
click node_auth "https://github.com/vxnavi71/guardian-link/blob/main/backend/auth.py"
click node_templates "https://github.com/vxnavi71/guardian-link/blob/main/frontend/templates/base.html"
click node_frontend "https://github.com/vxnavi71/guardian-link/blob/main/frontend/static/js/main.js"
click node_instagram "https://github.com/vxnavi71/guardian-link/blob/main/backend/instagram_api.py"
click node_detector "https://github.com/vxnavi71/guardian-link/blob/main/backend/grooming_detector.py"
click node_model "https://github.com/vxnavi71/guardian-link/blob/main/backend/ml_model.py"
click node_alerts "https://github.com/vxnavi71/guardian-link/blob/main/backend/alerts.py"
click node_database "https://github.com/vxnavi71/guardian-link/blob/main/backend/db.py"
click node_mock_data "https://github.com/vxnavi71/guardian-link/blob/main/backend/mock_data.json"

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_app,node_routes,node_auth,node_templates,node_frontend toneBlue
class node_detector,node_model,node_alerts toneAmber
class node_instagram,node_database,node_mock_data toneMint
class node_entry,node_browser toneNeutral
```

## Components

### Web application

- [App assembly](https://github.com/vxnavi71/guardian-link/blob/main/backend/app.py): application factory · Configures the backend runtime. · `backend/app.py`
- [Monitoring routes](https://github.com/vxnavi71/guardian-link/blob/main/backend/routes.py): route handlers · Serves protected monitoring workflows. · `backend/routes.py`
- [Authentication](https://github.com/vxnavi71/guardian-link/blob/main/backend/auth.py): identity and access · Enforces user access before monitoring actions. · `backend/auth.py`
- [Page templates](https://github.com/vxnavi71/guardian-link/blob/main/frontend/templates/base.html): server-rendered views · Shared layout plus login and dashboard pages. · `frontend/templates/base.html`
- [Dashboard enhancements](https://github.com/vxnavi71/guardian-link/blob/main/frontend/static/js/main.js): CSS and JavaScript · Browser-side dashboard presentation and interactions. · `frontend/static/js/main.js`

### Risk analysis

- [Grooming detector](https://github.com/vxnavi71/guardian-link/blob/main/backend/grooming_detector.py): risk rules · Coordinates grooming-specific signal detection. · `backend/grooming_detector.py`
- [ML model wrapper](https://github.com/vxnavi71/guardian-link/blob/main/backend/ml_model.py): model inference · Classifies or scores suspicious content. · `backend/ml_model.py`
- [Alert handling](https://github.com/vxnavi71/guardian-link/blob/main/backend/alerts.py): alert service · Creates alerts from detection findings. · `backend/alerts.py`

### Data and integrations

- [Instagram adapter](https://github.com/vxnavi71/guardian-link/blob/main/backend/instagram_api.py): external API adapter · Acquires and normalizes Instagram activity. · `backend/instagram_api.py`
- [Persistence](https://github.com/vxnavi71/guardian-link/blob/main/backend/db.py): database access · Centralized application data boundary. · `backend/db.py`
- [Demo data](https://github.com/vxnavi71/guardian-link/blob/main/backend/mock_data.json): development fixture · Fallback data for demo or unavailable live sources. · `backend/mock_data.json`

### Other components

- [Process entry](https://github.com/vxnavi71/guardian-link/blob/main/run.py): Python entry point · `run.py`
- **Browser user**: client

## Connections

- Process entry → App assembly: starts
- App assembly → Monitoring routes: registers
- App assembly → Authentication: configures
- Browser user → Monitoring routes: requests
- Monitoring routes → Authentication: checks access
- Monitoring routes → Page templates: renders
- Page templates → Dashboard enhancements: loads
- Monitoring routes → Instagram adapter: requests activity
- Instagram adapter → Grooming detector: normalized content
- Grooming detector → ML model wrapper: scores content
- ML model wrapper → Grooming detector: risk score
- Grooming detector → Alert handling: findings
- Monitoring routes → Alert handling: retrieves alerts
- Monitoring routes → Persistence: reads and writes
- Alert handling → Persistence: stores alerts
- Persistence → Demo data: demo fallback
