prt_core/lib.rs
1//! # prt-core
2//!
3//! Core library for **prt** — a real-time network port monitor.
4//!
5//! This crate provides the platform-independent logic for scanning, tracking,
6//! enriching, filtering, sorting, and exporting network port information. It is
7//! designed to be consumed by any frontend (TUI, GUI, CLI).
8//!
9//! # Architecture
10//!
11//! ```text
12//! platform::scan_ports()
13//! → Session::refresh()
14//! → scanner::diff_entries() (New / Unchanged / Gone + first_seen)
15//! → enrich: service names, suspicious flags, containers
16//! → retain: drop Gone entries older than 5s
17//! → bandwidth.sample()
18//! → scanner::sort_entries()
19//! → (frontend layer)
20//! → alerts::evaluate()
21//! → scanner::filter_indices()
22//! → UI renders
23//! ```
24//!
25//! # Modules
26//!
27//! - [`model`] — Core data types: [`PortEntry`](model::PortEntry),
28//! [`TrackedEntry`](model::TrackedEntry), [`ViewMode`](model::ViewMode),
29//! [`DetailTab`](model::DetailTab), [`SortState`](model::SortState).
30//! - [`core`] — Business logic: scanning, diffing, filtering, sorting, killing,
31//! session management, alerts, suspicious detection, bandwidth tracking,
32//! container resolution, namespaces, process detail, firewall.
33//! - [`config`] — TOML configuration from `~/.config/prt/` (known port overrides, alert rules).
34//! - [`known_ports`] — Well-known port → service name database (~170 entries + user overrides).
35//! - [`i18n`] — Internationalization: runtime-switchable language support
36//! (English, Russian, Chinese) backed by `AtomicU8`.
37//! - [`platform`] — OS-specific port scanning: macOS (`lsof`), Linux (`/proc`).
38//!
39//! # Example
40//!
41//! ```no_run
42//! use prt_core::core::scanner;
43//! use prt_core::model::ExportFormat;
44//!
45//! let entries = scanner::scan().expect("scan failed");
46//! let json = scanner::export(&entries, ExportFormat::Json).unwrap();
47//! println!("{json}");
48//! ```
49
50pub mod config;
51pub mod core;
52pub mod i18n;
53pub mod known_ports;
54pub mod model;
55pub mod platform;