How cognisutra/cdocsign works
Purpose and Runtime
CDocsSign is a lightweight PHP e-signature SaaS: users upload PDFs, configure recipients, collect public signatures, and produce signed PDFs with audit certificates. It runs under PHP 8.1+ (README targets 8.5) behind Apache/Nginx rewrite rules or PHP’s built-in server, with MySQL/MariaDB, PDO, and GD. Primary web root and route handlers are in public/; shared application logic is in src/.
Paths: public/index.php, public/.htaccess, src/db.php
Request Routing and Role Boundaries
Each PHP page is a route/controller. Public routes cover onboarding, public signing, and tracking; authenticated workspace routes manage a customer’s documents; administrator routes manage the whole platform. URL rewrite rules support clean/admin aliases, while physical admin wrappers preserve /admin/... paths. Session-based role guards separate user and admin access, including admin impersonation.
Paths: public/sign.php, public/home.php, public/admin.php, src/helpers.php, src/auth.php
Identity, Sessions, and Notifications
Authentication supports password login, email OTP, password reset, and distinct admin login. Core auth logic establishes sessions and applies RBAC; OTP and reset flows are separate service concerns. Mail dispatch uses SMTP or a Resend HTTP API fallback, with local logging during development. CSRF checks and password hashing are shared security controls.
Paths: public/login.php, public/admin_login.php, public/verify.php, src/auth.php, src/otp.php, src/mailer.php
Envelope Lifecycle
An envelope is the central aggregate: it belongs to a user, references an uploaded PDF, has recipients/tokens, status, expiry/reminders, and optional final signed output. Creation accepts document upload and recipient mapping; public signer links use recipient tokens; signer actions advance recipient/envelope state. Templates provide reusable document setup, while reminder processing is a background/cron-oriented service.
Paths: public/new_envelope.php, public/envelope.php, public/sign.php, src/envelope.php, src/template.php, src/send_reminders.php
Signing, PDF Assembly, and Protected Files
The signing page captures drawn or typed signatures in the browser. Signature assets and PDFs are stored outside the public web root; downloads are mediated through an authorization/token-checking stream endpoint. Once recipients complete, the PDF service uses vendored FPDF/FPDI to import the original document, place signatures, and append an audit certificate.
Paths: public/sign.php, public/file.php, src/pdf.php, lib/fpdf/fpdf.php, lib/fpdi-src/Fpdi.php
Persistence and Audit Boundary
MySQL/MariaDB is the system of record. The relational schema models users/admins, envelopes, recipients, audit events, templates, versions, resets, payments, login history, and settings, with InnoDB foreign keys. PDO prepared queries isolate persistence access. Every envelope transition is recorded as an audit event, supporting operational views and PDF certification.
Paths: schema.sql, schema_upgrade.sql, src/db.php, src/audit.php
Administration, Plans, and Operations
The admin console provides cross-tenant user, envelope, template, audit, analytics, finance, and settings views. Customer billing/upgrade pages expose plans and Razorpay checkout simulation; payments are persisted for reporting. System settings control maintenance, quotas, and upload limits, forming an operational control plane rather than customer workspace behavior.
Paths: public/dashboard.php, public/users.php, public/audit_logs.php, public/settings.php, public/billing.php, public/upgrade.php
Main entry points: envelope.php Envelope lifecycle · db.php PDO access layer · auth.php Auth & RBAC · index.php Front controller & rewrites
Components 20
Web routes
PHP page controllers and browser-facing flows.
- Front controller & rewrites · Routes clean URLs to page controllers.
public/index.php - Login & verification · Customer login, admin login, and OTP verification pages.
public/login.php - Workspace routes · Authenticated customers create and manage envelopes.
public/home.php - Envelope creation · Accepts PDFs and recipient configuration.
public/new_envelope.php - Public signing · Captures drawn or typed recipient signatures.
public/sign.php - Protected download · Streams files after authorization or token checks.
public/file.php
Application services
Shared domain, security, and delivery logic.
- Auth & RBAC · Sessions, role guards, impersonation, CSRF, and password security.
src/auth.php - OTP & reset flow · Manages email OTP and password recovery.
src/otp.php - Mail delivery · Uses SMTP, Resend fallback, or local logging.
src/mailer.php - Envelope lifecycle · Manages recipients, tokens, status, expiry, and completion.
src/envelope.php - Templates · Provides reusable document setup.
src/template.php - PDF assembly · Places signatures and appends audit certificates.
src/pdf.php - Audit trail · Records envelope transitions for operations and certification.
src/audit.php - FPDF / FPDI · Imports original PDFs for final document generation.
lib/fpdi-src/Fpdi.php
Persistence and files
System-of-record data and protected artifacts.
- MySQL / MariaDB · System of record for tenants, envelopes, recipients, payments, and settings.
schema.sql - PDO access layer · Prepared-query boundary for relational persistence.
src/db.php - Protected PDFs & signatures · Artifacts are stored outside the public web root.
Administration and operations
Cross-tenant control, billing, and scheduled work.
- Admin console · Cross-tenant users, envelopes, audits, analytics, and settings.
public/admin.php - Plans & payments · Plan upgrades and Razorpay checkout simulation.
public/billing.php - Reminder processor · Sends reminders for pending envelopes.
src/send_reminders.php
Connections 27
- Front controller & rewrites → Login & verification: routes
- Front controller & rewrites → Workspace routes: routes
- Front controller & rewrites → Public signing: public signer link
- Login & verification → Auth & RBAC: authenticates
- Login & verification → OTP & reset flow: verifies / resets
- OTP & reset flow → Mail delivery: sends codes
- Workspace routes → Auth & RBAC: user guard
- Workspace routes → Envelope lifecycle: manages
- Envelope creation → Envelope lifecycle: creates
- Envelope creation → Protected PDFs & signatures: stores upload
- Envelope lifecycle → Templates: uses setup
- Public signing → Envelope lifecycle: token-based action
- Public signing → Protected PDFs & signatures: stores signature
- Envelope lifecycle → PDF assembly: on completion
- PDF assembly → FPDF / FPDI: imports PDF
- PDF assembly → Protected PDFs & signatures: writes signed PDF
- Envelope lifecycle → Audit trail: records transitions
- Protected download → Auth & RBAC: authorizes
- Protected download → Protected PDFs & signatures: streams
- Envelope lifecycle → PDO access layer: persists
- Audit trail → PDO access layer: persists events
- PDO access layer → MySQL / MariaDB: prepared queries
- Admin console → Auth & RBAC: admin guard
- Admin console → PDO access layer: operates across tenants
- Plans & payments → PDO access layer: records payments
- Reminder processor → Envelope lifecycle: finds pending work
- Reminder processor → Mail delivery: sends reminders