Home

Cloudflare experiment ports most of Next.js API 'in one week' with AI

A Cloudflare engineer says he has implemented 94 percent of the Next.js API by directing Anthropic's Claude, spending about $1,100 on tokens.

The purpose of the experimental project was not to show off AI coding, but to address an issue with Next.js, the popular React-based framework sponsored by Vercel.

According to Cloudflare engineering director Steve Faulkner, the Next.js tooling is "entirely bespoke... If you want to deploy it to Cloudflare, Netlify, or AWS Lambda, you have to take that build output and reshape it into something the target platform can actually run."

The Next.js team is addressing this following numerous complaints that deploying the framework with full features on platforms other than Vercel is too difficult, with a feature in progress called deployment adapters.

"Vercel will use the same adapter API as every other partner," the company said when introducing the planned feature last year.

Faulkner said these adapters, which remain an "early effort," are insufficient because the framework still uses a bespoke toolchain based on Turbopack, the Vercel-sponsored bundling tool. Another issue is that during development it is hard to use platform-specific APIs such as Cloudflare's KV data storage because the development runtime does not support them without workarounds.

A project called OpenNext, sponsored by SST (Serverless Stack from Anomaly Innovations), Cloudflare, and Netlify, already exists to convert Next.js build output for running outside Vercel. Faulkner said the OpenNext approach proved to be a "difficult and fragile process" thanks to unpredictable changes between Next.js versions.

As a new experiment, Cloudflare created Vinext, open source and available on GitHub, using the Vite build tool in place of Turbopack. Almost all the code was written by AI, Faulkner said, starting with a plan.

"I spent a couple of hours going back and forth with Claude in OpenCode to define the architecture: what to build, in what order, which abstractions to use." OpenCode is an open source AI coding agent. He then asked the AI to implement the Next.js API piece by piece, using the existing Next.js test suite to identify issues before merging the code.

Faulkner said that although AI wrote the code, the human element was critical and he "had to course-correct regularly."

The result comes with a bunch of warnings. No human has reviewed the code or the README states, and the project is under heavy development.

Another snag is that the only current deployment target is Cloudflare Workers. Faulkner promises that not much of Vinext is Cloudflare-specific, that a proof of concept already runs on Vercel, and that other deployment targets are planned.

Last month, Cloudflare posted about another AI coding project, implementing a Matrix server on its Workers platform, but ran into criticism. Matrix project lead Matthew Hodgson said "the post severely overclaimed the scope of the project... the code doesn't yet constitute a functional Matrix server, let alone a production-grade one which you should consider deploying."

Nevertheless, Vinext appears to have more promise, with a build time up to 4.4 times faster than Next.js 16 with Turbopack, and a client bundle size that is around 56 percent smaller.

According to Faulkner, the project is a particularly good fit for AI because it has an extensive test suite from which he ported tests directly. The project used Vite's existing plugin for React Server Components, a key feature of Next.js. Further, the popularity of Next.js means that a large amount of documentation, code, and discussion around the framework is out there for AI crawlers to find.

This experiment may have repercussions. The notion of using AI to code a reimplementation of a widely used API could be attractive in other scenarios where lock-in exists.

Another aspect is a rethinking of how code is architected. According to Faulkner, most software abstractions exist to assist human understanding, to reduce the complexity of the code. AI has the potential to remove intermediate frameworks because "it can hold the whole system in context." A further implication is the creation of software projects that no human can understand – which is a problem given the non-deterministic nature of generative AI and its capacity for hallucination.

The project also tends to bear out the case made in a recent workshop for test-driven development as ideal for AI coding.®

Source: The register

Previous

Next