Skip to content

feat(cli): add --api flavor to autumn new for JSON-first projects#1847

Merged
madmax983 merged 2 commits into
trunk-devfrom
wave11-1390-autumn-new-api
Jul 13, 2026
Merged

feat(cli): add --api flavor to autumn new for JSON-first projects#1847
madmax983 merged 2 commits into
trunk-devfrom
wave11-1390-autumn-new-api

Conversation

@madmax983

Copy link
Copy Markdown
Owner

Before / After

Beforeautumn new myapi produces exactly one skeleton: a fullstack HTML app wired for Tailwind. To turn it into a JSON API you hand-delete ~5 files/sections: tailwind.config.js, input.css, the CSS-compilation step in build.rs, the maud layout() + HTML routes in main.rs, and the stylesheet <link>.

Afterautumn new myapi --api produces a JSON-first skeleton with zero HTML/CSS/Tailwind artifacts. The first cargo run serves JSON and you delete zero files to reach a clean starting point.

How

The --api flag selects a separate, lean template set rather than rewriting the existing one, so the default path is untouched:

  • New templates in autumn-cli/src/templates/:
    • main.api.rs.tmplJson handlers registered via routes[], keeps migrations wiring, no maud/HTML.
    • Cargo.api.toml.tmpl — no maud dependency, lean feature set.
    • Dockerfile.api.tmpl — no Tailwind/CSS build step.
    • build.api.rs.tmpl — build/git provenance only, no CSS compile.
  • autumn-cli/src/new.rs — adds a with_api option; --api conflicts with --daemon/--bundled-pg; conditional template selection; skips static/, input.css, tailwind.config.js, and vendored assets; API branch in render_cargo_toml; i18n composition plus README/summary adjustments for the API flavor.
  • autumn-cli/src/main.rs — threads the --api clap flag through dispatch.
  • autumn-cli/tests/integration/api_scaffold.rs (registered in mod.rs) — conformance tests.

Acceptance criteria

  • autumn new myapi --api succeeds; the generated project compiles and cargo run serves a sample route returning HTTP 200 with Content-Type: application/json. — Generated app cargo-checks clean against patched autumn-web; runtime proof: GET / returns HTTP 200 with Content-Type: application/json.
  • The generated --api project contains zero HTML/CSS/Tailwind artifacts (no tailwind.config.js, input.css, CSS build.rs step, maud::html!/layout(), or stylesheet <link>); grep for tailwind, input.css, maud::html returns zero matches. — Grep across the generated --api tree returns zero matches for all three.
  • The --api main.rs defines at least one handler returning Json and registers it via routes[]. — main.api.rs.tmpl emits Json handlers wired through routes[].
  • The --api autumn.toml omits the asset/CSS config blocks the fullstack template includes. — Cargo.api.toml.tmpl drops the maud dep and asset/CSS blocks; API branch in render_cargo_toml.
  • The --api Dockerfile has no CSS/asset build step. — Dockerfile.api.tmpl omits the Tailwind/CSS step.
  • Omitting --api produces today's fullstack project unchanged (byte-for-byte). — Default (no-flag) output verified byte-for-byte unchanged.
  • --with-i18n and --with-seed compose correctly with --api. — i18n composition handled in new.rs; covered by conformance tests.
  • A CLI test asserts the --api generated project carries no HTML/CSS template artifacts. — api_scaffold.rs asserts absence of HTML/CSS/Tailwind artifacts.

Testing

  • cargo fmt --all -- --check — clean.
  • cargo clippy -p autumn-cli --all-targets -- -D warnings — clean.
  • cargo build -p autumn-cli — builds.
  • Generated --api app cargo-checks clean with patched autumn-web.
  • Runtime proof: GET / returns HTTP 200 with Content-Type: application/json.
  • Grep for tailwind / input.css / maud::html across the generated --api tree returns zero matches.
  • Default (no-flag) output verified byte-for-byte unchanged.
  • New tests: 6 fast + 1 #[ignore] cargo-check test all pass; full cli_tests suite: 157 passed.

Out of scope

Per the issue, OpenAPI auto-wiring (openapi.rs) and the MCP tool surface are deliberately excluded — desirable follow-ups, not part of this slice.

Closes #1390


Generated by Claude Code

`autumn new <name> --api` emits a lean, JSON-first project skeleton with
zero HTML/CSS/Tailwind artifacts. Handlers return `Json<...>` and register
via `routes![]`; the `maud` dependency and autumn-web's view features
(maud/htmx/tailwind) are dropped via `default-features = false`, while `db`
and migrations are kept so database features still work.

The API flavor skips the Tailwind/CSS build step, `input.css`,
`tailwind.config.js`, and the vendored htmx/JS static assets, and uses
dedicated `main`, `Cargo.toml`, `Dockerfile`, and `build.rs` templates so
the default fullstack scaffold is unchanged. `--api` composes with
`--with-i18n` and `--with-seed`, and is rejected together with the daemon
flavors (`--daemon`/`--bundled-pg`), whose feature sets conflict.

Adds a CLI conformance test asserting the generated `--api` tree carries no
HTML/CSS template artifacts and has a Json handler + `routes![]`, plus an
ignored cargo-check test that compiles the generated API app.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@madmax983 madmax983 marked this pull request as ready for review July 13, 2026 06:49
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 339a692f36

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


COPY --from=builder /app/target/release/{{project_name}} /usr/local/bin/{{project_name}}
COPY --from=builder /app/autumn.toml /app/autumn.toml
COPY --from=builder /app/migrations /app/migrations

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Copy i18n locales into API images

When a project is scaffolded with autumn new <app> --api --with-i18n, inject_i18n_api makes src/main.rs call .i18n_auto(), and this Dockerfile builds without the embed-assets feature, so the app falls back to loading /app/i18n/en.ftl at startup. This copy block never carries the i18n/ sidecar into the runtime image (and the builder stage does not copy it either), so that generated Docker image panics on startup with the default locale missing.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Confirmed — the finding is correct and now fixed in c8ec284. The --api --with-i18n Docker image never copied the i18n/ sidecar, so .i18n_auto() panicked at startup on the missing /app/i18n/en.ftl. The API Dockerfile now copies i18n/ into both the builder stage (COPY i18n ./i18n) and the runtime stage (COPY --from=builder /app/i18n /app/i18n), gated on --with-i18n via anchor injection — an unconditional COPY would break docker build for non-i18n projects. Covered by two new conformance tests.

One correction: this isn't --api-specific. The default fullstack Dockerfile.tmpl has the identical pre-existing omission (autumn new app --with-i18n without --api panics in Docker the same way). Fixing the fullstack template is out of scope for #1390, so it's tracked as a separate follow-up: #1865.


Generated by Claude Code

@madmax983 madmax983 merged commit 2ccd442 into trunk-dev Jul 13, 2026
37 checks passed
@madmax983 madmax983 deleted the wave11-1390-autumn-new-api branch July 13, 2026 14:02
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.05%. Comparing base (14e6518) to head (c8ec284).
⚠️ Report is 40 commits behind head on trunk-dev.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##           trunk-dev    #1847      +/-   ##
=============================================
+ Coverage      86.82%   87.05%   +0.22%     
=============================================
  Files            273      276       +3     
  Lines         202424   207776    +5352     
=============================================
+ Hits          175761   180883    +5122     
- Misses         26663    26893     +230     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an --api flavor to autumn new for lean JSON-first projects

2 participants