$ show zfogg/ascii-chat
ascii-chat is a production-grade terminal-based video conferencing application that converts live video and audio streams into real-time ASCII art rendered in the terminal. It operates in multiple modes: server (multi-client host), client (connect to server), mirror (local preview), discovery (peer-to-peer session participant), and discovery-service (session registry and NAT traversal relay). The system uses a custom binary protocol (ACIP) over TCP/WebSocket/WebRTC, with end-to-end encryption (Ed25519 + X25519 + XSalsa20-Poly1305) and support for SSH/GPG key authentication. A companion web client compiled via WebAssembly mirrors functionality in the browser. The codebase includes a standalone reusable C library (libasciichat) with a comprehensive platform abstraction layer (POSIX/Windows/WASM), a declarative options registry that auto-generates man pages and shell completions, SIMD-accelerated ASCII rendering (AVX2, NEON, SVE, SSE2), lock-free data structures, and a sophisticated logging system with crash-safe mmap output. The architecture is modular and cross-platform, with extensive unit, integration, and E2E test coverage across Linux, macOS, Windows, and WebAssembly targets.
The LLM identified 6 files worth highlighting for reuse:
A comprehensive platform abstraction layer (mutex, condvar, rwlock, socket, pipe, memory, string, filesystem, process, signal, terminal, threads) with separate POSIX, Windows, macOS, Linux, and WASM implementations. Each primitive exposes a consistent API under `platform_*` functions, with debug-only tracking of lock acquisition, deadlock detection, and named atomic variables. This layer is project-agnostic and could be extracted into a standalone portability library for any C project targeting multiple operating systems.
A declarative options registry system where all CLI options, environment variables, and configuration file settings are defined centrally via a metadata array. The system automatically generates man pages (groff), shell completions (bash, fish, zsh, PowerShell), help text, and validation logic. Options support mode-aware defaults, custom parsers, dependencies, and RCU-based lock-free reads. This pattern demonstrates advanced macro-free metaprogramming in C and eliminates the need for manual synchronization between option definitions and their documentation.
A lock-free buffer pool using a Treiber stack with atomic compare-and-swap. Pre-allocates fixed-size buffers to avoid malloc/free in hot paths (audio/video frames). Supports global pool with lazy shrink and thread-safe usage counters. The implementation is self-contained with only atomic.h and common.h dependencies, making it reusable for any application requiring low-latency buffer allocation.
A bespoke source-level transformation tool that provides a Go-like `defer` statement for C code. The tool runs as a pre-compilation step, rewriting `defer { ... }` blocks into cleanup code that executes when the current scope exits. This is a non-obvious solution for C's lack of RAII, implemented via AST manipulation. The pattern is reusable across C projects where automatic resource management is desired without switching to C++.
A lock-free, crash-safe logging backend that writes log entries directly to a memory-mapped file using atomic position updates. No flush thread or mutex is required; the write pointer is updated atomically after a complete log line is written. If the process crashes, the mmap file retains all committed entries. This component solves the common problem of reliable logging in crash-prone environments with zero allocation overhead and is fully self-contained.
An AVX2-optimized monochrome ASCII character selection function that converts a 32x32-block of grayscale pixels to a terminal character using the cube-root perceptual luminance formula. Uses SIMD integer arithmetic and table lookups, achieving 2-4x speedup over scalar. The algorithm is generalizable to any grayscale-to-ASCII mapping and demonstrates advanced SIMD programming in C with intrinsics. Similar implementations exist for SSE2, SSSE3, NEON, and SVE, all sharing a common interface ready for extraction.