# fchfaz/cosmos architecture

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

- Interactive diagram: https://gitdiagram.com/fchfaz/cosmos
- Repository: https://github.com/fchfaz/cosmos

## Overview

Jarvis is a personal assistant with a laptop-hosted server and Android notification relays. The main workflow is device notification ingestion into a filtered, deduplicated inbox, or owner chat through Telegram/PWA; the assistant routes requests to skills, with approval required for external write actions. Email polling, Instagram DM access, notes, system actions, and offline/local/cloud language-model modes are additional product capabilities. Several central modules and the PWA are represented from README or SOURCE INDEX evidence because their implementations were not excerpted; uncertain internal links are omitted.

Main entry points: [`core/context.py`](https://github.com/fchfaz/cosmos/blob/main/core/context.py) (Runtime context), [`core/main.py`](https://github.com/fchfaz/cosmos/blob/main/core/main.py) (HTTP server), [`core/brain.py`](https://github.com/fchfaz/cosmos/blob/main/core/brain.py) (Request brain), [`core/approval.py`](https://github.com/fchfaz/cosmos/blob/main/core/approval.py) (Approval manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Interfaces and devices"]
  node_server["HTTP server<br/>[main.py]"]
  node_telegram["Telegram bot<br/>[telegram_bot.py]"]
  node_pwa["PWA<br/>[index.html]"]
  node_termux["Termux relay<br/>[relay.sh]"]
  node_kotlin["Kotlin relay<br/>[RelayService.kt]"]
end

subgraph group_orchestration["Assistant core"]
  node_context["Runtime context<br/>[context.py]"]
  node_brain["Request brain<br/>[brain.py]"]
  node_registry["Skill registry<br/>[registry.py]"]
  node_llm["LLM router<br/>[llm.py]"]
  node_approval["Approval manager<br/>[approval.py]"]
end

subgraph group_skills["Assistant capabilities"]
  node_base["Skill contract<br/>[base.py]"]
  node_notif["Notification inbox<br/>[notif_skill.py]"]
  node_email["Gmail skill<br/>[email_skill.py]"]
  node_instagram["Instagram DM<br/>[instagram_skill.py]"]
  node_notes["Notes skill<br/>[notes_skill.py]"]
  node_system["System skill<br/>[system_skill.py]"]
end

subgraph group_state["Persistence and safety"]
  node_db[("SQLite database<br/>[db.py]")]
  node_bus["Event bus<br/>[bus.py]"]
  node_safety["Safety filters<br/>[safety.py]"]
  node_settings["Settings<br/>[config.py]"]
end

node_owner(("Assistant owner"))
node_phones(("Android devices"))
node_gmail["Gmail API"]
node_meta["Meta Graph API"]
node_llmservice["LLM services"]

node_owner -->|"sends requests"| node_server
node_owner -->|"chats"| node_telegram
node_owner -->|"uses"| node_pwa
node_phones -->|"runs relay"| node_termux
node_phones -->|"runs relay"| node_kotlin
node_termux -->|"posts notifications"| node_server
node_kotlin -->|"posts notifications"| node_server
node_server -->|"creates"| node_context
node_server -->|"routes chat"| node_brain
node_server -->|"starts"| node_telegram
node_context -->|"creates"| node_db
node_context -->|"creates"| node_bus
node_context -->|"creates"| node_llm
node_context -->|"creates"| node_registry
node_context -->|"creates"| node_approval
node_context -->|"creates"| node_brain
node_context -->|"uses"| node_settings
node_context -->|"subscribes handlers"| node_bus
node_brain -->|"uses"| node_safety
node_brain -.->|"uses"| node_llm
node_brain -.->|"dispatches actions"| node_registry
node_registry -->|"loads plugins"| node_base
node_telegram -->|"calls skills"| node_registry
node_telegram -->|"decides approvals"| node_approval
node_server -->|"handles decisions"| node_approval
node_server -.->|"ingests notifications"| node_notif
node_notif -->|"publishes events"| node_bus
node_notif -->|"reads dedup and events"| node_db
node_bus -->|"stores events"| node_db
node_email -->|"reads and sends"| node_gmail
node_instagram -->|"uses Graph API"| node_meta
node_instagram -->|"reads notification events"| node_db
node_email -->|"requires approval"| node_approval
node_instagram -->|"requires approval"| node_approval
node_llm -.->|"calls configured model"| node_llmservice
node_pwa -.->|"uses API"| node_server

click node_server "https://github.com/fchfaz/cosmos/blob/main/core/main.py"
click node_telegram "https://github.com/fchfaz/cosmos/blob/main/interfaces/telegram_bot.py"
click node_pwa "https://github.com/fchfaz/cosmos/blob/main/interfaces/web/index.html"
click node_termux "https://github.com/fchfaz/cosmos/blob/main/android/termux/relay.sh"
click node_kotlin "https://github.com/fchfaz/cosmos/blob/main/android/NotificationRelay/app/src/main/java/id/jarvis/relay/RelayService.kt"
click node_context "https://github.com/fchfaz/cosmos/blob/main/core/context.py"
click node_brain "https://github.com/fchfaz/cosmos/blob/main/core/brain.py"
click node_registry "https://github.com/fchfaz/cosmos/blob/main/core/registry.py"
click node_llm "https://github.com/fchfaz/cosmos/blob/main/core/llm.py"
click node_approval "https://github.com/fchfaz/cosmos/blob/main/core/approval.py"
click node_base "https://github.com/fchfaz/cosmos/blob/main/skills/base.py"
click node_notif "https://github.com/fchfaz/cosmos/blob/main/skills/notif_skill.py"
click node_email "https://github.com/fchfaz/cosmos/blob/main/skills/email_skill.py"
click node_instagram "https://github.com/fchfaz/cosmos/blob/main/skills/instagram_skill.py"
click node_notes "https://github.com/fchfaz/cosmos/blob/main/skills/notes_skill.py"
click node_system "https://github.com/fchfaz/cosmos/blob/main/skills/system_skill.py"
click node_db "https://github.com/fchfaz/cosmos/blob/main/core/db.py"
click node_bus "https://github.com/fchfaz/cosmos/blob/main/core/bus.py"
click node_safety "https://github.com/fchfaz/cosmos/blob/main/core/safety.py"
click node_settings "https://github.com/fchfaz/cosmos/blob/main/core/config.py"

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_server,node_telegram,node_pwa,node_termux,node_kotlin toneBlue
class node_context,node_brain,node_registry,node_llm,node_approval toneAmber
class node_base,node_notif,node_email,node_instagram,node_notes,node_system,node_gmail,node_meta toneMint
class node_db,node_bus,node_safety,node_settings toneRose
class node_owner,node_phones,node_llmservice toneIndigo
```

## Components

### Interfaces and devices

- [HTTP server](https://github.com/fchfaz/cosmos/blob/main/core/main.py): `core/main.py`
- [Telegram bot](https://github.com/fchfaz/cosmos/blob/main/interfaces/telegram_bot.py): `interfaces/telegram_bot.py`
- [PWA](https://github.com/fchfaz/cosmos/blob/main/interfaces/web/index.html): `interfaces/web/index.html`
- [Termux relay](https://github.com/fchfaz/cosmos/blob/main/android/termux/relay.sh): `android/termux/relay.sh`
- [Kotlin relay](https://github.com/fchfaz/cosmos/blob/main/android/NotificationRelay/app/src/main/java/id/jarvis/relay/RelayService.kt): `android/NotificationRelay/app/src/main/java/id/jarvis/relay/RelayService.kt`

### Assistant core

- [Runtime context](https://github.com/fchfaz/cosmos/blob/main/core/context.py): `core/context.py`
- [Request brain](https://github.com/fchfaz/cosmos/blob/main/core/brain.py): `core/brain.py`
- [Skill registry](https://github.com/fchfaz/cosmos/blob/main/core/registry.py): `core/registry.py`
- [LLM router](https://github.com/fchfaz/cosmos/blob/main/core/llm.py): `core/llm.py`
- [Approval manager](https://github.com/fchfaz/cosmos/blob/main/core/approval.py): `core/approval.py`

### Assistant capabilities

- [Skill contract](https://github.com/fchfaz/cosmos/blob/main/skills/base.py): `skills/base.py`
- [Notification inbox](https://github.com/fchfaz/cosmos/blob/main/skills/notif_skill.py): `skills/notif_skill.py`
- [Gmail skill](https://github.com/fchfaz/cosmos/blob/main/skills/email_skill.py): `skills/email_skill.py`
- [Instagram DM](https://github.com/fchfaz/cosmos/blob/main/skills/instagram_skill.py): `skills/instagram_skill.py`
- [Notes skill](https://github.com/fchfaz/cosmos/blob/main/skills/notes_skill.py): `skills/notes_skill.py`
- [System skill](https://github.com/fchfaz/cosmos/blob/main/skills/system_skill.py): `skills/system_skill.py`

### Persistence and safety

- [SQLite database](https://github.com/fchfaz/cosmos/blob/main/core/db.py): `core/db.py`
- [Event bus](https://github.com/fchfaz/cosmos/blob/main/core/bus.py): `core/bus.py`
- [Safety filters](https://github.com/fchfaz/cosmos/blob/main/core/safety.py): `core/safety.py`
- [Settings](https://github.com/fchfaz/cosmos/blob/main/core/config.py): `core/config.py`

### Other components

- **Assistant owner**
- **Android devices**
- **Gmail API**
- **Meta Graph API**
- **LLM services**

## Connections

- Assistant owner → HTTP server: sends requests (evidence: `README.md`)
- Assistant owner → Telegram bot: chats (evidence: `README.md`)
- Assistant owner → PWA: uses (evidence: `README.md`)
- Android devices → Termux relay: runs relay (evidence: `README.md`)
- Android devices → Kotlin relay: runs relay (evidence: `README.md`)
- Termux relay → HTTP server: posts notifications (evidence: `README.md`)
- Kotlin relay → HTTP server: posts notifications (evidence: `README.md`)
- HTTP server → Runtime context: creates (evidence: `core/main.py`)
- HTTP server → Request brain: routes chat (evidence: `core/main.py`)
- HTTP server → Telegram bot: starts (evidence: `core/main.py`)
- Runtime context → SQLite database: creates (evidence: `core/context.py`)
- Runtime context → Event bus: creates (evidence: `core/context.py`)
- Runtime context → LLM router: creates (evidence: `core/context.py`)
- Runtime context → Skill registry: creates (evidence: `core/context.py`)
- Runtime context → Approval manager: creates (evidence: `core/context.py`)
- Runtime context → Request brain: creates (evidence: `core/context.py`)
- Runtime context → Settings: uses (evidence: `core/context.py`)
- Runtime context → Event bus: subscribes handlers (evidence: `core/context.py`)
- Request brain → Safety filters: uses (evidence: `core/brain.py`)
- Request brain → LLM router: uses
- Request brain → Skill registry: dispatches actions
- Skill registry → Skill contract: loads plugins (evidence: `core/registry.py`)
- Telegram bot → Skill registry: calls skills (evidence: `interfaces/telegram_bot.py`)
- Telegram bot → Approval manager: decides approvals (evidence: `interfaces/telegram_bot.py`)
- HTTP server → Approval manager: handles decisions (evidence: `core/main.py`)
- HTTP server → Notification inbox: ingests notifications
- Notification inbox → Event bus: publishes events (evidence: `skills/notif_skill.py`)
- Notification inbox → SQLite database: reads dedup and events (evidence: `skills/notif_skill.py`)
- Event bus → SQLite database: stores events (evidence: `core/bus.py`)
- Gmail skill → Gmail API: reads and sends (evidence: `README.md`)
- Instagram DM → Meta Graph API: uses Graph API (evidence: `skills/instagram_skill.py`)
- Instagram DM → SQLite database: reads notification events (evidence: `skills/instagram_skill.py`)
- Gmail skill → Approval manager: requires approval (evidence: `README.md`)
- Instagram DM → Approval manager: requires approval (evidence: `README.md`)
- LLM router → LLM services: calls configured model
- PWA → HTTP server: uses API
