Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions PROJECT_OVERVIEW.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Codewise CLI Project Overview

## What This Project Does

Codewise CLI is a DevOps-focused command-line tool that unifies common workflows used in application delivery.

It provides one command surface for:
- Dockerfile scaffolding and image build operations
- Kubernetes manifest generation and apply/delete operations
- Helm chart scaffolding
- Deployment status/log/history/rollback flows
- Environment profile management
- Data transformation utilities (YAML, JSON, TOML, XML, ENV, Base64)
- Template generation (for example GitHub Actions and Argo app templates)

The goal is to reduce command sprawl and boilerplate when moving from code to deployable workloads.

## How It Is Built

The project is implemented in Go and organized as a Cobra-based CLI.

High-level build path:
- `main.go` is the executable entry point.
- `cmd/` contains CLI command definitions and flag wiring.
- `pkg/` contains implementation logic used by commands.

Build commands:

```bash
go build -o codewise-cli main.go
# or
make build
```

Test commands:

```bash
make test
go test ./... -v
```

## Runtime Connectivity And Control Flow

The internal execution flow is:

1. User runs a CLI command (for example `codewise k8s apply`).
2. Cobra command in `cmd/` parses args and flags.
3. Command handler calls a domain package in `pkg/`.
4. Domain package reads files/config and performs requested action.
5. For deployment workflows, external CLIs/services are invoked where needed.
6. Result is printed to terminal and process exits with success or error code.

Conceptual connectivity map:

```text
Terminal User
-> codewise (binary)
-> cmd/* (Cobra command layer)
-> pkg/* (business logic)
-> Local Filesystem (templates, manifests, config)
-> External Tools (docker, kubectl, helm)
-> Kubernetes API (through kubectl/helm operations)
```

## Project Structure And Responsibilities

- `cmd/`: Command definitions, flags, argument validation, command wiring.
- `pkg/config/`: Configuration load/save defaults.
- `pkg/docker/`: Dockerfile init, validation, image build helpers.
- `pkg/k8s/`: Manifest generation, apply/delete orchestration.
- `pkg/helm/`: Helm chart scaffold generation.
- `pkg/deploy/`: Deploy planning, execution, logs, status, history, rollback.
- `pkg/env/`: Environment create/list/delete behaviors.
- `pkg/encoder/`: Format conversion and Base64 utilities.
- `pkg/generator/`: Project and template generation logic.
- `templates/`: Template source files used by template commands.
- `k8s/` and `helm/`: Generated scaffold outputs.
- `tests/` and `testdata/`: Test cases and fixture inputs/outputs.

## Tech Stack

Primary:
- Go 1.20
- Cobra CLI framework (`github.com/spf13/cobra`)
- YAML support (`gopkg.in/yaml.v3`)
- TOML support (`github.com/BurntSushi/toml`)
- XML mapping support (`github.com/clbanning/mxj/v2`)
- Interactive prompts (`github.com/AlecAivazis/survey/v2`)

Tooling and ecosystem dependencies:
- Docker CLI and daemon for image-related workflows
- kubectl and Kubernetes cluster context for K8s apply/delete workflows
- Helm CLI for chart-related workflows

## How Commands Connect To Domains

- `config` commands map to config domain for defaults and view/init operations.
- `docker` commands map to Docker domain for init/validate/build.
- `k8s` commands map to K8s domain for scaffold/apply/delete.
- `helm` commands map to Helm domain for scaffold init.
- `deploy` commands map to deployment domain for run/plan/status/logs/history/rollback.
- `env` commands map to environment domain for profile lifecycle.
- `encode` maps to transformation domain for file format conversions.
- `template` maps to generator/template domain for predefined scaffold files.

## Development And Contribution Model

Typical change flow:

1. Add or update command wiring under `cmd/`.
2. Implement core logic in `pkg/`.
3. Add or update tests under `tests/` with fixtures in `testdata/`.
4. Validate with `go test ./... -v`.
5. Build with `make build` and run manual smoke commands.

This layering keeps CLI surface concerns separate from business logic and improves testability.
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ Clone the repository:
```bash
git clone https://github.com/aryansharma9917/codewise-cli.git
cd codewise-cli
````
```

Build from source:

```bash
go build -o codewise main.go
make build
# or
go build -o codewise-cli main.go
```

(Optional) install globally:

```bash
sudo mv codewise /usr/local/bin/
sudo mv codewise-cli /usr/local/bin/codewise
```

---
Expand All @@ -56,6 +58,21 @@ General syntax:
codewise <command> [subcommand] [flags]
```

Local development usage (without global install):

```bash
./codewise-cli <command> [subcommand] [flags]
# or
go run . <command> [subcommand] [flags]
```

---

## Documentation

- [Testing runbook](TESTING_RUNBOOK.md) for copy-paste test and smoke commands
- [Project overview](PROJECT_OVERVIEW.md) for architecture, connectivity, build flow, and tech stack

---

## Configuration
Expand Down Expand Up @@ -201,9 +218,11 @@ codewise helm init
.
├── cmd/ # CLI commands
├── pkg/ # Core logic (docker, k8s, helm, config, encode)
├── templates/ # Source templates used by generators
├── helm/ # Generated Helm charts
├── k8s/ # Generated Kubernetes manifests
├── config/ # Configuration helpers
├── tests/ # Automated tests
├── testdata/ # Fixtures used by tests and conversion checks
├── Dockerfile
├── go.mod
└── main.go
Expand Down
178 changes: 178 additions & 0 deletions TESTING_RUNBOOK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# Codewise CLI Testing Runbook

This runbook is designed for direct copy-paste testing from project root.

## 1) Prerequisites

Use these checks to confirm required tooling is available before running any workflow.

```bash
go version
docker --version
kubectl version --client
helm version
```

## 2) Build And Baseline Validation

Build the binary, then verify command wiring and version output.

```bash
make clean
make build
./codewise-cli --help
./codewise-cli version
go run . --help
go run . version
```

## 3) Automated Tests

Run the existing test suites first, then optional race and coverage checks.

```bash
make test
go test ./... -v
go test ./... -race
go test ./... -coverprofile=coverage.out
go tool cover -func=coverage.out
```

## 4) Top-Level Command Surface Check

These commands confirm every top-level command is registered and callable.

```bash
./codewise-cli config --help
./codewise-cli deploy --help
./codewise-cli docker --help
./codewise-cli encode --help
./codewise-cli env --help
./codewise-cli helm --help
./codewise-cli init --help
./codewise-cli k8s --help
./codewise-cli template --help
```

## 5) Config Workflow

This validates local configuration initialization and read-back.

```bash
./codewise-cli config init
./codewise-cli config view
cat ~/.codewise/config.yaml
```

## 6) Encode/Convert Workflow (Fixture-Based)

These commands validate common encode paths using files in `testdata/`.

```bash
./codewise-cli encode -i testdata/sample.yaml -o /tmp/cw_sample_1.json
./codewise-cli encode -i testdata/sample.json -o /tmp/cw_sample_2.yaml --json-to-yaml
./codewise-cli encode -i testdata/sample.env -o /tmp/cw_sample_3.json --env-to-json
./codewise-cli encode -i testdata/sample.txt -o /tmp/cw_sample_4.b64 --base64
./codewise-cli encode -i /tmp/cw_sample_4.b64 -o /tmp/cw_sample_5.txt --base64 --decode
```

Quick output validation for generated artifacts.

```bash
ls -lh /tmp/cw_sample_1.json /tmp/cw_sample_2.yaml /tmp/cw_sample_3.json /tmp/cw_sample_4.b64 /tmp/cw_sample_5.txt
diff -u testdata/sample.txt /tmp/cw_sample_5.txt
```

## 7) Scaffold Generation (Local Safe)

Use this to validate project scaffold generation for Kubernetes and Helm.

```bash
rm -rf helm/chart k8s/app
./codewise-cli helm init
./codewise-cli k8s init
find helm -maxdepth 4 -type f | sort
find k8s -maxdepth 4 -type f | sort
```

## 8) Template Commands

These validate template generation commands.

```bash
./codewise-cli template github-action
./codewise-cli template argo-app
```

## 9) Docker Workflow (Requires Docker Daemon)

Run these if Docker is available and running on your machine.

```bash
./codewise-cli docker init
./codewise-cli docker validate
./codewise-cli docker build
docker images | grep -i codewise
```

## 10) Kubernetes Workflow (Dry-Run First)

Use dry-run for safe validation without applying to the cluster.

```bash
./codewise-cli k8s apply --dry-run
./codewise-cli k8s delete --dry-run
```

## 11) Kubernetes Real Apply (Only On Test Cluster)

Run this section only when your kube context points to a non-production cluster.

```bash
kubectl config current-context
./codewise-cli k8s apply --namespace dev
./codewise-cli deploy status --namespace dev
./codewise-cli deploy logs --namespace dev
./codewise-cli deploy history --namespace dev
./codewise-cli deploy rollback --namespace dev
./codewise-cli k8s delete --namespace dev
```

## 12) Environment Command Validation

Use help checks and simple actions to validate env command behavior.

```bash
./codewise-cli env --help
./codewise-cli env list
./codewise-cli env create dev
./codewise-cli env list
./codewise-cli env delete dev
./codewise-cli env list
```

## 13) Negative Testing

These commands validate error handling and message quality for invalid inputs.

```bash
./codewise-cli encode -i does-not-exist.yaml -o /tmp/out.json
./codewise-cli k8s apply --context definitely-not-real --dry-run
./codewise-cli deploy status --namespace does-not-exist
```

## 14) One-Line Regression Pack

Use this compact command for quick regression checks before pushing changes.

```bash
make build && go test ./... -v && ./codewise-cli encode -i testdata/sample.yaml -o /tmp/reg.json && ./codewise-cli helm init && ./codewise-cli k8s init && ./codewise-cli k8s apply --dry-run
```

## Expected Success Signals

- Build exits with code 0.
- Test commands pass with code 0.
- Encode commands generate output files and decode roundtrip matches input.
- Helm and Kubernetes scaffold files are generated without runtime errors.
- Dry-run commands do not mutate cluster resources and still validate command flow.
1 change: 0 additions & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (

"github.com/aryansharma9917/codewise-cli/pkg/deploy"
"github.com/spf13/cobra"
)
Expand Down
1 change: 0 additions & 1 deletion cmd/docker.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (

"github.com/aryansharma9917/codewise-cli/pkg/docker"
"github.com/spf13/cobra"
)
Expand Down
Loading
Loading