How checkmarx/ast-cli works
Project Type and Purpose
• Project Type: A standalone, cross‐platform CLI tool written in Go.
• Purpose: Exposes Checkmarx One platform functionality (scans, results, policies, user counts, chat integrations, etc.) via a local binary.
• Key Indicators:
– cmd/main.go entrypoint
– internal/commands/* packages implementing CLI commands
– internal/services/* orchestration of business logic
– internal/wrappers/* HTTP & gRPC clients to remote APIs
File Structure
Top‐level layout:
• cmd – entrypoint & root command
• internal/commands – individual CLI subcommands (scan, auth, project, chat, asca, sca‐realtime, etc.)
• internal/services – core business logic (projects, policies, export)
• internal/wrappers – low‐level API clients (REST, gRPC, mocks for testing)
• internal/params, constants, logger – configuration, flags, environment, logging
• test directories – unit & integration suites
Architectural Pattern:
Layered architecture:
CLI layer → Command layer → Service layer → Wrapper (API) layer → External Checkmarx One platform
README Insights
• Confirms it’s a CLI executable (“Checkmarx CLI is a standalone Checkmarx tool”)
• Lists Go as the language and shows build targets for multiple OS/architectures
Main Components & Relationships
a. Components:
1. CLI Entrypoint (cmd)
2. Command Processor (internal/commands)
3. Business Service Layer (internal/services)
4. API Wrapper Layer (internal/wrappers)
5. Core Utilities & Config (internal/logger, internal/params, internal/constants)
6. External Checkmarx One Platform (REST & gRPC endpoints)
7. Test Harness & Mocks (internal/wrappers/mock, test/integration)
b. Relationships / Data Flows:
• User types command → CLI Entrypoint
• Entrypoint routes to specific Command module
• Command invokes Service(s), passing parsed flags & configuration
• Service calls Wrapper client (HTTP or gRPC) to perform remote operations
• Wrapper returns raw payload → Service transforms → Command prints via Printer util
• All layers use shared Config & Logging components
c. Architectural Patterns & Principles:
• Layered Separation of Concerns (each layer has a single responsibility)
• Dependency Injection via Go interfaces (commands depend on service interfaces, services depend on wrapper interfaces)
• Mockable API clients (wrappers/mock) to facilitate testing
• Platform‐agnostic CLI core with OS‐specific build targets
d. Key Technologies:
• Go modules & packages
• Cobra (or similar) for CLI parsing (inferred from command structure)
• HTTP REST clients (net/http wrappers)
• gRPC clients (internal/wrappers/grpcs)
• Makefile & Dockerfile for builds & CI
• GitHub Actions for CI/CD