Internal alpha — MicroClub USTHB devs only. This guide is the working agreement while the project is private. A public-facing version will replace it before the v1.0 release.
Anyone with write access to MicroClub-USTHB/mctf-cli. If you're a challenge author looking for how to write a challenge, you want docs/spec/challenge-manifest.md, not this file.
- Go 1.23+
- GNU make (any recent version)
- git
- Python 3.10+ with
pyyamlandjsonschema(only needed if you run the script-based sanity checks locally — CI runs them either way) - A working Docker setup for any deploy/build commands (none required for
validateorgenerate)
git clone git@github.com:MicroClub-USTHB/mctf-cli.git
cd mctf-cli
make build
./mctf -C examples/sample-event validate
go test ./...If make build fails on a fresh checkout, run go mod download first.
| Path | What it's for |
|---|---|
cmd/ |
Cobra command definitions. One file per command; flags live next to the command. Keep cmd/ thin — argument parsing and human/JSON output only. |
internal/build/ |
Plans and executes container image builds (docker build / docker push) for deployable challenges. |
internal/challenge/ |
Per-challenge manifest loader, filesystem discovery, archetype derivation (ArchetypeStatic, ArchetypeService, ArchetypeInstanced). |
internal/config/ |
mctf.config.yml loader + typed Config struct. Schema-validated on load. |
internal/deploy/ |
Plans and executes per-challenge docker compose runs. Covers docker and SSH deploy modes, GitOps state sync, and rollback on failure. |
internal/doctor/ |
Preflight checks against the host environment (port availability, Docker daemon, DNS resolution, disk space, storage driver). |
internal/generate/ |
Deterministic emitters for all derived files (CTFd manifest, instance.toml, CSV, index.json, Prometheus scrape config). Output must be byte-identical across runs. |
internal/git/ |
Thin shell wrapper around git for state-sync operations used by the deploy rollback system. |
internal/info/ |
Human- and machine-readable event summaries (mctf info). Renders category/archetype/difficulty breakdowns. |
internal/ingress/ |
Generates routing config for the deploy mode's reverse proxy (currently Traefik dynamic config). |
internal/instancer/ |
Manages per-team challenge instances: lifecycle planning (PlanSpawn), store persistence, HTTP daemon, reaper. Mints per-team dynamic flags at spawn time. |
internal/jsonschema/ |
Thin wrapper around santhosh-tekuri/jsonschema/v5 with MCTF-specific error formatting. |
internal/notify/ |
Posts deploy/build outcome messages to optional notification channels (Slack, webhook). |
internal/platform/ctfd/ |
Typed REST client for the CTFd API. Scope: just the endpoints needed by mctf platform sync (challenges, flags, hints, files, visibility). |
internal/scaffold/ |
Renders embedded Go templates onto the filesystem for mctf init. |
internal/schemas/ |
Embedded copy of the JSON Schemas. Synced from schema/ by make schemas — never edit directly. |
internal/solve/ |
Runs a challenge's solution script and verifies the flag. Supports --against-instance to target a live per-team instance. |
internal/status/ |
Reports the runtime state of an event's deployable challenges (container health, port bindings). |
internal/validate/ |
Cross-cutting checks beyond schema: uniqueness, flag leak guard, capability allowlists, healthcheck rules, archetype consistency. |
schema/ |
The canonical JSON Schemas. Edit these when the spec changes. |
docs/spec/ |
The spec itself. Moves with the schemas and code. |
examples/sample-event/ |
Reference event that exercises every code path. CI runs validate and generate --check against it on every push. |
scripts/ |
Python sanity-check validators (used by CI to catch schema drift). |
- One PR per concern. Validation rule changes, generator changes, CLI surface changes, and refactors go in separate PRs. Reviewers can't sign off on a 30-file diff that does five things.
- The spec moves with the code. Any change that affects on-disk file shapes touches:
- the relevant JSON Schema in
schema/, - the relevant doc in
docs/spec/, - the embedded copy (
make schemas), - tests that exercise the new shape. PRs that update one without the others get bounced.
- the relevant JSON Schema in
- Don't edit
internal/schemas/*.jsondirectly. Editschema/*.jsonand runmake schemas. The Makefile detects drift and CI catches it either way. - CI must be green. Both the
goandschemasjobs.mctf generate --checkon the sample event has to pass. - No new commands without spec coverage. Every new CLI verb lands with its semantics documented under
docs/spec/. Internal helpers are exempt; user-facing commands are not.
Two cases:
- Edit
schema/challenge.schema.json(or the relevant schema). - Run
make schemasto sync the embedded copy. - Document the rule under
docs/spec/validation.mdwith a stable rule ID. Schema-level rules useS###IDs. - Add or update an example under
examples/sample-event/that exercises the rule. - Run
python3 scripts/validate-examples.pyto confirm sources still validate.
- Add the check to
internal/validate/checks.go. User.Errorffor hard-fails,r.Warnffor warnings,r.Infoffor nudges. Keep the rule ID consistent withdocs/spec/validation.md. - Document the rule in
docs/spec/validation.md(rule ID + rationale). - Add a unit test in
internal/validate/that constructs a minimal[]*challenge.Challengetriggering the rule. - Update
examples/sample-event/if the rule is new enough that no existing fixture covers it.
- New file under
cmd/<verb>.go. Cobra command + flags + aRunEthat delegates tointernal/.... - Register the command in its
init()viarootCmd.AddCommand(...). - Real logic goes in
internal/<area>/. Keepcmd/thin — it's just argument parsing and human/JSON output. - If the command consumes the on-disk contract, document the data flow in
docs/spec/derived-files.md(or a new doc). - Add an end-to-end test if practical: drive
cmd.Execute()against a copy ofexamples/sample-event/in a tempdir.
- Add the schema at
schema/<name>.schema.json. JSON Schema 2020-12. - Add the generator at
internal/generate/<name>.go. Output must be byte-deterministic — no timestamps, no map iteration, sort lists explicitly. - Wire it into
Plan()ininternal/generate/generate.go. - Document the format under
docs/spec/derived-files.mdwith an example and the input → output mapping table. - Add a Python sanity check in
scripts/validate-generated.pyso CI catches schema drift in generated output.
go test ./...runs the unit tests. Add new tests next to the package they cover.- Tests should not require network, Docker, or a running CTFd. If you need fixtures, put them under
internal/<pkg>/testdata/. - For interactive prompts (e.g.,
cmd/init.go), inject test input via thepromptInvariable — seecmd/init_test.gofor the pattern. - The sample event under
examples/sample-event/is the integration fixture; CI uses it directly.
- Branch off
develop. Name your branch<area>/<short-description>— examples:validate/duplicate-port-check,generate/csv-utf8,cmd/init-skeleton. - Open the PR against
develop. Request review from at least one other member. - Squash-merge by default unless the branch contains intentionally separate logical commits.
- Never push directly to
mainordeveloponce branch protection is enabled.
Conventional-commits style, one-line subject + optional body:
feat(generate): emit hints in CTFd manifest output
Pulls challenge.hints[] into the auto-generated CTFd manifest under the
"hints" key. Manifests without hints stay omitted from the output.
Common scopes: validate, generate, config, challenge, cmd, schema, docs, ci, chore, build, deploy, doctor, instancer, platform, solve, ingress, notify, status, info.
gofmt+golangci-lint run ./...clean. Rungolangci-lint run ./...locally before pushing — CI enforces it.- Errors wrap with
fmt.Errorf("...: %w", err). - Comments explain why, not what. If you have to explain what the code does, the code probably needs to change instead.
- No trailing summary blocks at the top of files (no
// Package X does Y, then Z, then W.paragraphs). Keep package docs to one short paragraph. - Public types/functions get doc comments; package-private ones only when behavior isn't obvious.
GitHub Actions runs three jobs on every push and PR:
lint—golangci-lint run ./.... Must be clean before anything else.go—go vet,go test -race,make build,mctf validate,mctf generate --checkagainst the sample event.schemas— Python sanity checks: source manifests vschallenge.schema.json, generated files vs their schemas.
All three must be green. If you can't get them green locally, push the WIP branch and let CI tell you why — that's faster than guessing.
- Read the spec/doc changes first. The doc tells you what the code is supposed to do.
- Pull the branch, run
make build && ./mctf -C examples/sample-event validate && ./mctf -C examples/sample-event generate --check. If those don't pass, the PR isn't ready. - For new validation rules: think of three challenges that shouldn't trigger the rule. The rule should be specific enough to catch real bugs without false positives.
- For new generators: think about what happens on a re-run. Output must be idempotent.
Pre-v0.1, releases are git tags only — no published artifacts. Tag format v0.0.<N>. Use make build to produce a binary locally.
Once v0.1 ships, goreleaser takes over for cross-compiled binaries.
If something here is wrong, unclear, or out of date — open a PR fixing it. This file is part of the spec.