Skip to content

Project Structure

Hyacinthe-primus edited this page Nov 12, 2026 · 4 revisions

Project Structure

The repository contains two independent codebases: the Arduino sketch in gatecore-firmware/ and the Rust host tool in gatecore-cli/. The CLI is a library with a thin binary, which keeps the serial and command layers testable without hardware.

GateCore/
├── gatecore-firmware/                  C++ for the ESP32 Arduino core
│   ├── gatecore-firmware.ino           setup() and loop()
│   ├── Config.h                        pins, limits, baud, lockout, timezone
│   ├── DatabaseManager.h/.cpp          PSRAM array, users.bin, selective saves
│   ├── DisplayManager.h/.cpp           LCD screens
│   ├── RFIDManager.h/.cpp              PN532 over hardware SPI
│   ├── SerialProtocol.h/.cpp           JSON lines and raw bulk transfers
│   ├── NetworkManager.h/.cpp           Wi-Fi, NTP, timezone in NVS
│   ├── BuzzerManager.h/.cpp            passive buzzer sequences
│   ├── SystemController.h/.cpp         state machine and command handlers
│   ├── ImportProfiler.h/.cpp           import timing, not stable API
│   ├── SyncProfiler.h/.cpp             sync timing
│   ├── MicroTimer.h                    microsecond timing helper
│   ├── partitions.csv                  16 MB layout, 12 MB LittleFS, coredump
│   ├── uploader.ps1                    compile/upload/monitor on Windows
│   └── uploader.sh                     compile/upload/monitor on Linux/macOS
├── gatecore-cli/                       Rust crate "gatecore-cli"
│   ├── Cargo.toml, Cargo.lock          Rust 1.90+, lockfile committed
│   ├── src/
│   │   ├── main.rs                     argument parsing and exit codes
│   │   ├── lib.rs                      module map
│   │   ├── cli.rs                      clap definitions
│   │   ├── commands/                   users, device, scan, bulk, sync
│   │   ├── repl.rs                     interactive shell
│   │   ├── serial.rs                   discovery, framing, retries, raw I/O
│   │   ├── protocol.rs                 typed requests and responses
│   │   ├── convert.rs                  users.bin codec, CRC32, sync entries
│   │   ├── userfile.rs                 JSON, CSV and .bin I/O
│   │   ├── database.rs                 Uid, names, dates, validity
│   │   ├── ui.rs                       messages, tables, progress bars
│   │   ├── sync_stats.rs               timing model for sync --stats
│   │   ├── interrupt.rs                Ctrl+C as a polled flag
│   │   └── error.rs                    error type and exit codes
│   ├── tests/
│   │   ├── device_sim.rs               tests against a firmware simulator
│   │   └── golden/                     byte vectors for the users.bin codec
│   └── samples/                        users_example.csv, users_example.json
├── docs/
│   └── gatecore-firmware-1.1.0-to-1.2.0.diff
├── .github/workflows/
│   ├── gatecore-cli.yml                stable and 1.90 tests, clippy
│   ├── gatecore-firmware.yml           ESP32-S3 compile
│   └── release.yml                     release archives on v* tags
├── CHOICES_AND_MODIFICATIONS.md
├── Wiring.png
├── LICENSE.md
└── README.md

gatecore-cli/usersdata/ and gatecore-cli/backups/ are git-ignored because they can contain badge holders' names. wiki/ is a separate Git repository and is also ignored by the main repository.

CLI layers

Each module only depends on the ones before it in this table. That is what lets the serial protocol and command handlers run against the simulator.

Module Responsibility
error, interrupt Error type and exit codes; Ctrl+C as a flag
convert Record encoding, per-record CRC, database CRC, sync entries
database UID, name and date validation; UserEntry
userfile One loader and writer for JSON, CSV and .bin
protocol Request enum and typed response views
serial Port discovery, framing, retries, raw transfers
ui, sync_stats Output and sync timing
cli, commands, repl Command definitions, handlers, shell

serial::Link is the boundary between the real port and the simulator. The end-to-end tests implement that trait with an in-memory version of the firmware protocol and run the normal command handlers against it.

Tests

cd gatecore-cli
cargo test --locked

There are 51 tests: 38 unit tests and 13 end-to-end tests. The unit tests cover the codec, date and name validation, parsing, protocol serialization and clap rules. The end-to-end tests cover import over both transports, export, sync and its date rules, retries, noise lines, scan events, remove --except, backups, import abort, and offline commands. See Development for the local build commands.

Clone this wiki locally