How hanchuanchuan/inception works
Project type and purpose
• This is an open-source SQL auditing and execution tool (“Inception”) built as a fork of MySQL 5.6.10.
• It embeds the real MySQL parser and execution path (with storage engines stripped out) to analyze, enforce rules on, execute or roll back arbitrary SQL statements.
• Offers two user-facing fronts: a command-line shell (client) and a web UI.
High-level architecture and main components
a. Presentation layer
– CLI client: located under /client, compiled into inception binary.
– Web UI: a lightweight HTTP server front (not shown in this tree, but part of higher-level docs) that calls the same engine APIs.
b. Core engine
– Embedded server library (/libmysqld): hosts the modified MySQL server core in process.
– Parser & analyzer (/sql): MySQL’s SQL parser, optimizer stubs, rule-engine hooks.
– Rule engine & checker: custom validation modules inserted into the parse/optimize path.
– Rollback generator: produces inverse SQL statements based on DML analysis.
c. Client library
– /libmysql: client-side API used by both the CLI and the web UI to talk to the embedded engine or remote servers.
d. I/O abstraction
– /vio: abstracts sockets, SSL, pipes for communication with back-end MySQL servers.
– /libevent: event loop for nonblocking I/O (used by both CLI readline and optional network modules).
e. External services
– Upstream MySQL instances: Inception connects over TCP/SSL to target production servers, forwards approved statements, and captures results/metadata.
Relationships and data flow
1. User → CLI or Web UI (HTTP).
2. UI calls libmysql/libmysqld interfaces → passes raw SQL.
3. Core engine (embedded server) invokes parser → rule engine → if violation, returns error.
4. If approved or in “execute” mode: engine forwards SQL to external MySQL over vio/libevent.
5. Results and binlog events are captured; rollback SQL is generated and stored (in memory or log files).
6. UI presents execution outcome and rollback script.
Important architectural patterns
• Modular monolith in C/C++: separates client, engine, I/O, utilities into libraries.
• Plugin–style services: /include/mysql/... and /mysys, /service_*.h define service interfaces for authentication, thread scheduling, audit.
• Build configurability via CMake: each component (client, libmysql, libmysqld, libevent, vio, testing, packaging) is a CMake target.
Technologies and frameworks
• CMake (configuration & cross-platform build)
• libevent (event notifications)
• Embedded MySQL server core (parser + optimizer stubs)
• Custom rule engine modules in /sql
• Readline/libedit (/cmd-line-utils/libedit) for interactive shell
• Packaging scripts for MSI, RPM, Solaris
• Clear component boundaries and labels
• Notes on key interactions (e.g., “SQL parse → validate → execute/rollback”)
• Reference to major directories as documentation call-outs (e.g., /sql, /client, /libmysqld)