# Will npx croct init clobber anything in an existing Next.js repo?

Asked by cfraser on 2025-04-17. Tags: cli, setup, nextjs.

Before I run any CLI scaffolding tool on a mature codebase, I like to know
exactly what it intends to touch. Our Next.js repo is three years old, has a
carefully composed `middleware.ts` (auth plus locale detection), and a strict
review process.

So, for `npx croct@latest init` on an existing app:

1. Which files does it create or modify?
2. Does it try to write a middleware file, and what happens to the one we
   already have?
3. How do I verify the integration actually works before merging the branch?

I will read the diff regardless, just want to know what to expect in it.

## 1 answer

### Accepted answer from yusufd (2025-04-17)

Ran this on a similarly aged repo recently, so here is the concrete inventory.
The CLI detects your framework and wires the SDK; on Next.js the diff contains:

- The `@croct/plug-next` dependency in package.json.
- The provider added to your layout.
- A proxy export (Croct's middleware is called proxy) with a matcher that
  excludes `api`, `_next/static`, and similar paths.
- Env vars: `NEXT_PUBLIC_CROCT_APP_ID` and `CROCT_API_KEY`.
- A `croct.json5` config file and generated `slots.d.ts` types.

On your question 2, this is the one spot that needs your judgment rather than
the generator's. Do not let a plain proxy export replace your existing
middleware. Compose them instead:

```ts
import {withCroct} from '@croct/plug-next/proxy';
import {middleware as existing} from './lib/middleware';

export const proxy = withCroct(existing);
```

Your auth and locale logic keeps running, Croct wraps around it. Review that
file most carefully, the rest of the diff is routine codegen.

For verification before merging: run the branch, browse a few pages, then check
the Integration page in the Croct dashboard. It shows a green "Received traffic
in the past 24 hours" badge once requests flow. Green badge plus a clean diff
review and you are done.

#### Reply from cfraser (2025-04-18)

Ran it on a branch. The diff matched your inventory exactly, and the
withCroct composition preserved our middleware chain. Badge went green.
Merging. Thanks for the precise answer.
