How mondoohq/cnquery works
• CLI / Command Interface – The “apps/cnquery” and “cli” directories contain the core command implementations. This is where user commands (run, shell, scan) and query input are handled.
• Query Engine – Look at directories such as “mql”, “mqlc”, “internal”, and “explorer”. These hold the logic for parsing, processing, and executing MQL queries against the infrastructure.
• Providers / Plugin System – The “providers” directory (which is huge and subdivided into many subdirectories for AWS, Azure, Google, Kubernetes, etc.) indicates that providers are modular components. This layer abstracts the connections to external resources and APIs.
• Data Aggregation and Processing – Components like “internal/workerpool” and portions of “llx” (which appear to handle data types, bundling, and transformation) suggest an aggregation layer that collects and processes data from multiple sources.
• SDK and Shared Libraries – The “providers-sdk” and “shared” directories indicate additional reusable libraries, common interface definitions (including gRPC protos) and utilities.
• SBOM and Packaging – The “sbom” directory manages software bill of materials generation, suggesting that the tool also tracks its own dependencies and outputs formal artifact descriptions.
• Logging, Configuration, and Utilities – Throughout the file tree you see “logger”, “cli/config”, “utils”, and “types” that are used for logging, configuration management, error handling, and utility functions.
Interactions and Data Flow
• The CLI passes query strings and parameters to the Query Engine, which parses the provided MQL queries (using modules from “mql” and “mqlc”).
• Each provider works via its connection code (often in a “connection” subdirectory) to query external systems such as cloud APIs, Kubernetes clusters, etc.
• The providers return structured resource data back to the Query Engine, which aggregates and processes the data.
• The output is then formatted via reporting functionalities (in “cli/reporter”) and printed to the console or outputted in JSON (or other formats).
• Optionally, the SBOM subsystem gathers metadata and dependencies during builds or runs.
• Throughout these flows, logging and error management (via “logger” and “cli/errors”) capture key events.
Architectural Patterns
• Plugin-based architecture: Each provider is a loosely coupled module that implements a common interface, allowing the system to support “over 850 resources” across different services.
• Layered design: The separation between CLI, Query Engine, and Provider integration forms distinct layers (presentation, processing, integration).
• Use of worker pools and concurrency: The “internal/workerpool” indicates that queries and provider calls may run concurrently to speed execution.
• Extensive use of shared protocols: Protobuf definitions in “shared/proto” and in provider-specific directories indicate that inter-component communications and (possibly) remote procedure calls are standardized.
Technologies and Frameworks
• The project is implemented in Go and uses Docker (as evidenced by multiple Dockerfiles and devcontainer configurations).
• It utilizes GitHub Actions (under the “.github” directory) for CI/CD and linting.
• The communication between components is supported by gRPC in shared/proto.
• The tool interacts natively with numerous external systems (cloud APIs, container systems, etc.) using provider-specific libraries and protocols.
Detailing Essential Architectural Elements
• Plugin architecture clearly: show a common interface between the Query Engine and Provider modules that standardize how queries are sent and responses are returned.
• Configuration and logging components as cross-cutting concerns that interact with almost all modules.
• Optionally, add annotations such as “query parsing,” “data aggregation,” and “reporting” to clarify subsystem responsibilities.