How okaprinarjaya/opj-ssfrs works
Project type and purpose
• Opj-Ssfrs is a lightweight Node.js–based TCP file‐receive server (no browser UI).
• It provides a custom protocol for chunked/multipart file transfer over TCP, records detailed transfer metadata in MongoDB, and can integrate with a Gearman job server (optional) or execute shell commands after each complete receive.
File structure
• Top-level directories:
• server/ – the TCP server entry point (server.js), utilities (server_utils.js), and configuration (config.js).
• client/ – a reusable client library (Opj_Ssfrc.js) and two test clients (test_client.js, test_client_multipart.js).
• Config files:
• server/config.js – database URI, registered IPs, SSL toggle, Gearman settings.
• CI:
• .github/workflows/dependabot.yml – dependency updates.
• Package manifest:
• package.json – lists Node.js dependencies (e.g., mongodb, gearman, tls).
Key insights from README
• Core features: multipart transfer, post‐receive commands, Gearman job submission, detailed logging, SSL (experimental), IP whitelisting.
• External dependencies: MongoDB (required), Gearman (optional), NodeJS runtime.
Main components and their interactions
a. Clients
• Application or script that uses Opj_Ssfrc.js to open a TCP (or TLS) socket, chunk files, and stream them.
• Two reference binaries: test_client.js (single file) and test_client_multipart.js (chunked).
b. Network layer
• Plain TCP or optional TLS socket.
• Custom protocol framing for start, chunk, end messages.
c. Server core
• server.js listens on configured port, negotiates protocol, handles per‐connection events.
• Delegates parsing and DB writes to server_utils.js.
d. Persistence: MongoDB
• Stores transfer metadata and status (sender IP, file name, size, checksum, timestamps, success/failure).
e. Integration points
• Shell command executor – invoked when a transfer completes.
• Gearman client – pushes a job to Gearman server for async processing (image resize, watermark, SQL import, etc.).
• Gearman workers – external processes that pick up jobs and do the heavy compute.
f. Optional security
• TLS termination inside server if config.ssl = true.
• IP filter against config.registeredIp.
Architectural patterns and design principles
• Event‐driven, nonblocking I/O (Node.js streams + events).
• Modular separation: protocol logic (utils), configuration, integration.
• Pluggable post‐receive handlers (shell or Gearman).
• Fail‐safe logging: every state transition written to DB for replay/retry.
Final advice
• Keep labels concise but unambiguous.