How kshitijjain21/certification-tool-cli works
Project Type and Purpose
• This is a CLI tool built in Python (with Poetry for dependency management) which acts as a front-end for interacting with a Test Harness backend.
• The main purpose is to allow users to run tests, query test execution history, manage projects (create, list, delete, update), and interact with the Test Harness API.
• It also includes an auto-generated API client (using fastapi_client) to communicate with the backend and a client generator module that can produce client code based on OpenAPI specifications.
File Structure for Architectural Clues
• The “app” directory is the core of the CLI tool:
• app/main.py serves as the CLI’s entry point.
• app/commands contains different Click-based command implementations (e.g., available-tests, run-tests, test-run-execution-history).
• app/api_lib_autogen holds the auto-generated API client code (with subdirectories for API endpoints, documentation, models, and exceptions) that wraps the Test Harness API.
• Other modules in “app” (like config.py, async_cmd.py, and modules under app/test_run such as logging and websocket) indicate responsibilities for configuration, asynchronous command execution, and managing test-run details.
• Outside “app”, the client_generator folder is dedicated to generating client code (has Dockerfiles, examples, and mustache templates) showing integration with the OpenAPI specifications.
• Additional files (openapi.json, config.json.example, Dockerfile, scripts folder) indicate support for automated client generation, linting, formatting, and deployment support.
Key Components and Their Relationships
• CLI Entry Point:
• The CLI entry is triggered via a shell script (cli.sh) that calls the app/main.py.
• Command Processing Layer:
• Under app/commands, different commands are implemented using the Click framework. These commands collect user input/options and then dispatch actions.
• API Client Layer:
• Within app/api_lib_autogen, the auto-generated API client (including various endpoints like devices_api, projects_api, etc.) abstracts the interaction with the external Test Harness API.
• This component is a major interface between the CLI commands and the remote backend.
• Configuration:
• The config.py, and config.json (template provided), manage settings such as the hostname for the Test Harness.
• Test-Run Manager:
• The app/test_run component manages aspects of test execution (logging, websocket communications, prompt handling).
• Client Generator:
• The client_generator folder provides tooling to generate client libraries from an OpenAPI specification. It is designed for extendibility and maintenance of clients for the Test Harness API.
• DevOps / Environment Tools:
• Dev container configurations (.devcontainer), Dockerfiles, GitHub workflows, and scripts show that containerized development and CI/CD are part of the design.
Architectural Patterns and Design Principles
• Layered Architecture:
• Each “layer” (CLI interface, business/command logic, API client integration, asynchronous test run handling) plays a well-defined role.
• Modularity and Separation of Concerns:
• Commands are modularized under app/commands.
• API communication is separated into the api_lib_autogen.
• Client generation is encapsulated in its own folder.
• Auto-Generation and Integration:
• The auto-generated API client demonstrates an integration pattern, reducing manual API wrapper code and ensuring consistency with the backend’s OpenAPI spec.
• Containerization:
• Docker and a VS Code dev-container ensure consistent development/deployment environments.