# bagpotato/loglens architecture

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

- Interactive diagram: https://gitdiagram.com/bagpotato/loglens
- Repository: https://github.com/bagpotato/loglens

## Overview

LogLens collects server logs, ranks events by deterministic severity, and provides searchable history, live tailing, AI explanations/chat, and critical-event phone alerts. The principal path is monitored host → Loki ingestion → API query and classification → web/mobile UI; AI and alerts are additional branches. Edges are limited to README-documented relationships and sampled source calls; unsampled wiring is omitted or shown only where explicitly documented.

Main entry points: [`backend/crates/api/src/main.rs`](https://github.com/bagpotato/loglens/blob/master/backend/crates/api/src/main.rs) (API server), [`frontend/src/main.tsx`](https://github.com/bagpotato/loglens/blob/master/frontend/src/main.tsx) (LogLens web app), [`backend/crates/api/src/routes`](https://github.com/bagpotato/loglens/tree/master/backend/crates/api/src/routes) (HTTP routes), [`backend/crates/loki/src/query.rs`](https://github.com/bagpotato/loglens/blob/master/backend/crates/loki/src/query.rs) (Loki adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Log ingestion"]
  node_vector["Vector agent"]
end

subgraph group_backend["Backend services"]
  node_api["API server<br/>[main.rs]"]
  node_routes["HTTP routes"]
  node_log_query["Log query service<br/>[query.rs]"]
  node_loki_store["Loki adapter<br/>[query.rs]"]
  node_loki_client["Loki HTTP client<br/>[client.rs]"]
  node_severity["Severity ranking<br/>[classifier.rs]"]
  node_auth["Authentication<br/>[login.rs]"]
  node_ai["AI workflows<br/>[query_planner.rs]"]
  node_ai_providers["AI providers<br/>[mod.rs]"]
  node_alerts["Critical alerts<br/>[poller.rs]"]
  node_storage[("State storage")]
end

subgraph group_client["Web and mobile UI"]
  node_web["LogLens web app<br/>[main.tsx]"]
  node_log_ui["Search and live logs"]
  node_overview["Severity overview"]
  node_chat_ui["AI chat and explain"]
  node_auth_ui["Sign-in UI"]
  node_mobile["Android app shell<br/>[app.rs]"]
end

subgraph group_integrations["External services"]
  node_loki[("Loki log store")]
  node_provider["AI provider service"]
  node_ntfy["ntfy notifications"]
end

node_host(("Monitored servers"))
node_phone(("Phone user"))

node_host -->|"emits logs"| node_vector
node_vector -->|"pushes logs"| node_loki
node_loki -->|"serves queries"| node_loki_store
node_api -->|"registers routes"| node_routes
node_routes -->|"queries logs"| node_log_query
node_log_query -->|"loads entries"| node_loki_store
node_loki_store -->|"requests data"| node_loki_client
node_loki_store -->|"queries and tails"| node_loki
node_api -.->|"ranks events"| node_severity
node_routes -.->|"authenticates requests"| node_auth
node_routes -.->|"handles AI requests"| node_ai
node_ai -.->|"completes prompts"| node_ai_providers
node_ai_providers -->|"sends requests"| node_provider
node_api -.->|"polls critical events"| node_alerts
node_alerts -->|"sends notifications"| node_ntfy
node_ntfy -->|"notifies user"| node_phone
node_auth -.->|"persists account state"| node_storage
node_web -->|"routes to logs"| node_log_ui
node_web -->|"routes to overview"| node_overview
node_web -->|"routes to chat"| node_chat_ui
node_web -->|"routes to sign-in"| node_auth_ui
node_log_ui -->|"requests logs"| node_api
node_overview -->|"requests summaries"| node_api
node_chat_ui -->|"streams AI answers"| node_api
node_auth_ui -->|"signs in"| node_api
node_mobile -->|"packages same frontend"| node_web

click node_api "https://github.com/bagpotato/loglens/blob/master/backend/crates/api/src/main.rs"
click node_routes "https://github.com/bagpotato/loglens/tree/master/backend/crates/api/src/routes"
click node_log_query "https://github.com/bagpotato/loglens/blob/master/backend/crates/api/src/query.rs"
click node_loki_store "https://github.com/bagpotato/loglens/blob/master/backend/crates/loki/src/query.rs"
click node_loki_client "https://github.com/bagpotato/loglens/blob/master/backend/crates/loki/src/client.rs"
click node_severity "https://github.com/bagpotato/loglens/blob/master/backend/crates/severity/src/classifier.rs"
click node_auth "https://github.com/bagpotato/loglens/blob/master/backend/crates/auth/src/login.rs"
click node_ai "https://github.com/bagpotato/loglens/blob/master/backend/crates/ai/src/query_planner.rs"
click node_ai_providers "https://github.com/bagpotato/loglens/blob/master/backend/crates/ai/src/providers/mod.rs"
click node_alerts "https://github.com/bagpotato/loglens/blob/master/backend/crates/alerts/src/poller.rs"
click node_storage "https://github.com/bagpotato/loglens/tree/master/backend/crates/storage/src"
click node_web "https://github.com/bagpotato/loglens/blob/master/frontend/src/main.tsx"
click node_log_ui "https://github.com/bagpotato/loglens/tree/master/frontend/src/features/logs"
click node_overview "https://github.com/bagpotato/loglens/tree/master/frontend/src/features/overview"
click node_chat_ui "https://github.com/bagpotato/loglens/tree/master/frontend/src/features/ai"
click node_auth_ui "https://github.com/bagpotato/loglens/tree/master/frontend/src/features/auth"
click node_mobile "https://github.com/bagpotato/loglens/blob/master/mobile/src-tauri/src/app.rs"

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_vector,node_phone toneBlue
class node_api,node_routes,node_log_query,node_loki_store,node_loki_client,node_severity,node_auth,node_ai,node_ai_providers,node_alerts,node_storage toneAmber
class node_web,node_log_ui,node_overview,node_chat_ui,node_auth_ui,node_mobile,node_host toneMint
class node_loki,node_provider,node_ntfy toneRose
```

## Components

### Log ingestion

- **Vector agent**

### Backend services

- [API server](https://github.com/bagpotato/loglens/blob/master/backend/crates/api/src/main.rs): `backend/crates/api/src/main.rs`
- [HTTP routes](https://github.com/bagpotato/loglens/tree/master/backend/crates/api/src/routes): `backend/crates/api/src/routes`
- [Log query service](https://github.com/bagpotato/loglens/blob/master/backend/crates/api/src/query.rs): `backend/crates/api/src/query.rs`
- [Loki adapter](https://github.com/bagpotato/loglens/blob/master/backend/crates/loki/src/query.rs): `backend/crates/loki/src/query.rs`
- [Loki HTTP client](https://github.com/bagpotato/loglens/blob/master/backend/crates/loki/src/client.rs): `backend/crates/loki/src/client.rs`
- [Severity ranking](https://github.com/bagpotato/loglens/blob/master/backend/crates/severity/src/classifier.rs): `backend/crates/severity/src/classifier.rs`
- [Authentication](https://github.com/bagpotato/loglens/blob/master/backend/crates/auth/src/login.rs): `backend/crates/auth/src/login.rs`
- [AI workflows](https://github.com/bagpotato/loglens/blob/master/backend/crates/ai/src/query_planner.rs): `backend/crates/ai/src/query_planner.rs`
- [AI providers](https://github.com/bagpotato/loglens/blob/master/backend/crates/ai/src/providers/mod.rs): `backend/crates/ai/src/providers/mod.rs`
- [Critical alerts](https://github.com/bagpotato/loglens/blob/master/backend/crates/alerts/src/poller.rs): `backend/crates/alerts/src/poller.rs`
- [State storage](https://github.com/bagpotato/loglens/tree/master/backend/crates/storage/src): `backend/crates/storage/src`

### Web and mobile UI

- [LogLens web app](https://github.com/bagpotato/loglens/blob/master/frontend/src/main.tsx): `frontend/src/main.tsx`
- [Search and live logs](https://github.com/bagpotato/loglens/tree/master/frontend/src/features/logs): `frontend/src/features/logs`
- [Severity overview](https://github.com/bagpotato/loglens/tree/master/frontend/src/features/overview): `frontend/src/features/overview`
- [AI chat and explain](https://github.com/bagpotato/loglens/tree/master/frontend/src/features/ai): `frontend/src/features/ai`
- [Sign-in UI](https://github.com/bagpotato/loglens/tree/master/frontend/src/features/auth): `frontend/src/features/auth`
- [Android app shell](https://github.com/bagpotato/loglens/blob/master/mobile/src-tauri/src/app.rs): `mobile/src-tauri/src/app.rs`

### External services

- **Loki log store**
- **AI provider service**
- **ntfy notifications**

### Other components

- **Monitored servers**
- **Phone user**

## Connections

- Monitored servers → Vector agent: emits logs
- Vector agent → Loki log store: pushes logs
- Loki log store → Loki adapter: serves queries
- API server → HTTP routes: registers routes
- HTTP routes → Log query service: queries logs (evidence: `backend/crates/api/src/query.rs`)
- Log query service → Loki adapter: loads entries (evidence: `backend/crates/api/src/query.rs`)
- Loki adapter → Loki HTTP client: requests data (evidence: `backend/crates/loki/src/query.rs`)
- Loki adapter → Loki log store: queries and tails
- API server → Severity ranking: ranks events
- HTTP routes → Authentication: authenticates requests
- HTTP routes → AI workflows: handles AI requests
- AI workflows → AI providers: completes prompts
- AI providers → AI provider service: sends requests
- API server → Critical alerts: polls critical events
- Critical alerts → ntfy notifications: sends notifications
- ntfy notifications → Phone user: notifies user
- Authentication → State storage: persists account state
- LogLens web app → Search and live logs: routes to logs
- LogLens web app → Severity overview: routes to overview
- LogLens web app → AI chat and explain: routes to chat
- LogLens web app → Sign-in UI: routes to sign-in
- Search and live logs → API server: requests logs
- Severity overview → API server: requests summaries
- AI chat and explain → API server: streams AI answers
- Sign-in UI → API server: signs in
- Android app shell → LogLens web app: packages same frontend
