# agg-kantas/rfid-unlocker architecture

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

- Interactive diagram: https://gitdiagram.com/agg-kantas/rfid-unlocker
- Repository: https://github.com/agg-kantas/rfid-unlocker

## Overview

RFID Unlocker scans a card on a Pico, sends its UID as an integer over USB serial, and has a Linux daemon compare that value with an authorized UID before requesting the current session be unlocked. The graph separates the reader driver, scan-and-emit stage, daemon control loop, comparison, and unlock action. The README documents the cross-device serial workflow; source excerpts show the local calls and command. The systemd service file is omitted because it configures deployment rather than implementing the product workflow.

Main entry points: [`daemon/unlocker.py`](https://github.com/agg-kantas/rfid-unlocker/blob/main/daemon/unlocker.py) (Daemon loop), [`pico/main.py`](https://github.com/agg-kantas/rfid-unlocker/blob/main/pico/main.py) (Scan and emit UID), [`pico/mfrc522.py`](https://github.com/agg-kantas/rfid-unlocker/blob/main/pico/mfrc522.py) (MFRC522 driver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pico["Pico scanning"]
  node_driver["MFRC522 driver<br/>[mfrc522.py]"]
  node_scanner["Scan and emit UID<br/>[main.py]"]
end

subgraph group_host["Host daemon"]
  node_daemon_loop["Daemon loop<br/>[unlocker.py]"]
  node_serial_read["Read serial UID<br/>[unlocker.py]"]
  node_compare["Compare authorized UID<br/>[unlocker.py]"]
end

subgraph group_unlock["Session unlock"]
  node_unlock_action["Request session unlock<br/>[unlocker.py]"]
end

node_card(("RFID card"))
node_reader["RC522 reader"]
node_session["Linux login session"]

node_card -->|"tapped at"| node_reader
node_scanner -->|"calls reader API"| node_driver
node_driver -->|"communicates via SPI"| node_reader
node_scanner -->|"sends UID over USB serial"| node_serial_read
node_daemon_loop -->|"reads line"| node_serial_read
node_daemon_loop -->|"calls compare"| node_compare
node_daemon_loop -->|"calls unlock"| node_unlock_action
node_compare -->|"sets authorization state"| node_unlock_action
node_unlock_action -->|"runs loginctl unlock"| node_session

click node_driver "https://github.com/agg-kantas/rfid-unlocker/blob/main/pico/mfrc522.py"
click node_scanner "https://github.com/agg-kantas/rfid-unlocker/blob/main/pico/main.py"
click node_daemon_loop "https://github.com/agg-kantas/rfid-unlocker/blob/main/daemon/unlocker.py"
click node_serial_read "https://github.com/agg-kantas/rfid-unlocker/blob/main/daemon/unlocker.py"
click node_compare "https://github.com/agg-kantas/rfid-unlocker/blob/main/daemon/unlocker.py"
click node_unlock_action "https://github.com/agg-kantas/rfid-unlocker/blob/main/daemon/unlocker.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_driver,node_scanner toneBlue
class node_daemon_loop,node_serial_read,node_compare toneAmber
class node_unlock_action toneMint
class node_card,node_reader,node_session toneIndigo
```

## Components

### Pico scanning

- [MFRC522 driver](https://github.com/agg-kantas/rfid-unlocker/blob/main/pico/mfrc522.py): `pico/mfrc522.py`
- [Scan and emit UID](https://github.com/agg-kantas/rfid-unlocker/blob/main/pico/main.py): `pico/main.py`

### Host daemon

- [Daemon loop](https://github.com/agg-kantas/rfid-unlocker/blob/main/daemon/unlocker.py): `daemon/unlocker.py`
- [Read serial UID](https://github.com/agg-kantas/rfid-unlocker/blob/main/daemon/unlocker.py): `daemon/unlocker.py`
- [Compare authorized UID](https://github.com/agg-kantas/rfid-unlocker/blob/main/daemon/unlocker.py): `daemon/unlocker.py`

### Session unlock

- [Request session unlock](https://github.com/agg-kantas/rfid-unlocker/blob/main/daemon/unlocker.py): `daemon/unlocker.py`

### Other components

- **RFID card**
- **RC522 reader**
- **Linux login session**

## Connections

- RFID card → RC522 reader: tapped at (evidence: `README.md`)
- Scan and emit UID → MFRC522 driver: calls reader API (evidence: `pico/main.py`)
- MFRC522 driver → RC522 reader: communicates via SPI (evidence: `README.md`)
- Scan and emit UID → Read serial UID: sends UID over USB serial (evidence: `README.md`)
- Daemon loop → Read serial UID: reads line (evidence: `daemon/unlocker.py`)
- Daemon loop → Compare authorized UID: calls compare (evidence: `daemon/unlocker.py`)
- Daemon loop → Request session unlock: calls unlock (evidence: `daemon/unlocker.py`)
- Compare authorized UID → Request session unlock: sets authorization state (evidence: `daemon/unlocker.py`)
- Request session unlock → Linux login session: runs loginctl unlock (evidence: `daemon/unlocker.py`)
