How nihalxkumar/zingat works
Project type and purpose
• From the file tree and README, Zingat is a Rust-based pastebin application that offers both:
• A web interface (HTTP server) for end-users to create and view “clips”
• A command-line client (CLI) for programmatic interactions
• Features include password protection, clip expiry, hit counting (batched), and templating for HTML pages.
File structure
• src/bin
• httpd.rs → The Rocket-based HTTP server entrypoint
• clipclient.rs → The CLI client entrypoint
• src/lib
• domain → Core business objects (Clip, fields like content, shortcode, expires, password, etc.)
• data → Data-access layer (SQLX queries, models, migrations under “migrations/”)
• service → Application logic (actions, ask abstractions)
• web → Web layer (API handlers, HTTP context, forms, renderer, hit counter)
• templates/ & static/ → Handlebars templates and CSS served by the web server
• migrations/ → SQL scripts for database schema
• Cargo.toml, .env, data.db → Configuration, environment, and SQLite database
README for additional insights
• Tech stack: Rust, SQLX, Rocket, Tokio
• Performance optimization: asynchronous hit-count batching on separate Tokio threads
• Two modes of operation: Web and CLI
Main components and interactions
a. Components
1. HTTP Server (Rocket + Tokio runtime)
2. CLI Client (tokio + SQLX)
3. Service Layer (business logic)
4. Data Layer (SQLX, SQLite, migrations)
5. Domain Layer (Clip entity, validation)
6. Templates & Static Assets (Handlebars, CSS)
7. Background Worker Threads (batching hit counts)
b. Relationships & Data Flow
• HTTP Server → Web Layer → Service Layer → Data Layer → SQLite DB
• CLI Client → Service Layer → Data Layer → SQLite DB
• Service Layer dispatches clip hits to a background worker (Tokio task) for batching
• Web Layer renders templates/static via the renderer component
c. Architectural patterns
• Layered architecture: Presentation (web/CLI) → Service → Data → Database
• Domain-driven design: strict separation of domain types (Clip, fields)
• Repository pattern in data layer (query.rs, model.rs)
• Asynchronous batching (Tokio tasks) for performance
d. Key technologies
• Rocket – HTTP routing & request handling
• Tokio – async runtime for HTTP server & background workers
• SQLX – compile-time checked SQL and migrations
• Handlebars (via templates/) – HTML rendering
• SQLite (data.db) – persistent storage