How d99kris/nchat works
Project Type and Purpose
• nchat is a terminal-based, full-stack chat client supporting Telegram and WhatsApp.
• It’s implemented primarily in C++ (UI, core engine, protocol wrappers) with parts in Go (WhatsApp via whatsmeow).
• Key purpose: provide a lightweight ncurses UI, handle message serialization, protocol abstraction (Telegram via tdlib, WhatsApp via whatsmeow), local caching, configuration and theming.
File Structure
• Top level:
• CMakeLists.txt, make.sh, build scripts, workflows (.github)
• src/ – main.cpp and dozens of u*.cpp/h for ncurses UI (views, controllers, dialogs).
• lib/ – protocol modules and common utilities:
– lib/common + lib/duchat + lib/ncutil: shared data structures, serialization, caching, logging, file utilities, thread primitives.
– lib/tgchat: C++ wrapper around tdlib (ext/td) for Telegram API.
– lib/wmchat: Go wrapper around whatsmeow (ext/whatsmeow) for WhatsApp API.
• ext/ – embedded third-party libs: apathy, cereal, clip, sqlite_modern_cpp, tdlib source, whatsmeow source.
• themes/, utils/, dev/, doc/: configuration templates, update scripts, documentation.
• Architectural pattern: MVC/MVP—UI views/controllers in src/ talk to core “Model” in lib/, which interfaces with protocol engines.
README for Insights
• Describes UI commands, configuration files, themes, build/dependencies.
• Lists third-party libraries and update scripts.
• Mentions cache (SQLite) and serialization (cereal).
• Confirms two protocol pipelines: Telegram and WhatsApp.
Main Components and Their Interactions
a. Components
• UI Layer (ncurses) [src/]: screens, dialogs, input handling, theming.
• Controller/Model Layer [src/uicontroller.cpp, lib/*]: translates UI actions into chat operations.
• Protocol Adapters:
• Telegram Module [lib/tgchat + ext/tdlib]: authentication, message send/receive via tdlib.
• WhatsApp Module [lib/wmchat + ext/whatsmeow]: similar role in Go.
• Utility Library [lib/ncutil, lib/common]: configuration, file I/O, caching, logging, synchronization.
• Data Layer (cache) [sqlite_modern_cpp]: local message history, settings, profiles.
• Serialization [ext/cereal]: encode/decode messages, settings.
• Clipboard Integration [ext/clip].
• Build & Deployment (CMake, make.sh).
b. Relationships / Data Flow
• UI → Controller → Protocol Adapter → External Library → Network (Telegram/WhatsApp servers).
• Incoming network events → Library → Adapter → Model → UI update.
• Model ↔ Data Layer (SQLite cache via sqlite_modern_cpp).
• Model → Serialization (cereal) for config, history export.
• UI → Clipboard (clip) for copy/paste.
c. Patterns / Principles
• MVC/MVP: separation of UI (views/controllers) from business logic (models, protocol adapters).
• Layered architecture: UI, Core, Protocol, Data, External.
• Plugin-like protocol adapters for extensibility.
• Dependency injection via shared lib/ncutil utilities.
• CMake-driven modular build.
d. Technologies / Frameworks
• ncurses (UI)
• C++17, Go
• CMake, make.sh, help2man
• SQLite (sqlite_modern_cpp)
• third-party: cereal (serialization), clip (clipboard), apathy (logging), tdlib, whatsmeow
Detailed Capture
• Update scripts (utils/tdlib-update, whatsmeow-update) linked to ext/tdlib and ext/whatsmeow.
• Build flow: CMakeLists → compiles modules → links into nchat binary (and Go binary for WhatsApp).