# nextgin > Next.js App Router on the frontend. Zero-dependency pure-Go (`net/http`) API and in-process cron engine on the backend. ## Install & Scaffold - Scaffold single-repo self-host app: `npx @nextgin/adapter init my-app` - Scaffold split app (`web/` + `backend/`): `npx @nextgin/adapter init my-app --layout split` - Go module: `go get github.com/Chidi09/nextgin` - Next.js adapter & CLI: `npm install @nextgin/adapter` ## Core Architectural Invariants (for AI Coding Agents) 1. **Zero external Go dependencies in core:** `github.com/Chidi09/nextgin` wraps Go 1.22+ `net/http.ServeMux` (`app.Router.Group`, `GET/POST/PUT/PATCH/DELETE`, `Use`). Use Go 1.22+ `{param}` syntax and `r.PathValue("id")`, never `:param`. 2. **Go owns hot paths & crons:** Put auth, sessions, rate limiting, carts, payments, webhooks, and scheduled jobs in Go. Let Next.js focus on UI, SSR, RSC, and Server Actions. 3. **Crons are authenticated HTTP routes:** `app.Cron(name, schedule, handler)` registers `GET`/`POST /_nextgin/cron/` behind fail-closed bearer auth (`CRON_SECRET` or internal token). Always respect `r.Context().Done()`. 4. **Fail-closed security defaults:** `nextgin.CORS(...)` panics on empty or `*` origins; `nextgin.RequireInternal()` returns 401 when `NEXTGIN_INTERNAL_SECRET` is unset; `nextgin.ReadJSON` caps bodies at 1 MiB and rejects trailing tokens; `nextgin.SetSessionCookie` defaults to `HttpOnly: true`, `Secure: true`, `SameSite: Lax`. 5. **Payment webhooks:** Always use `nextgin.ReadRawBody(w, r, limit)` before verifying HMAC signatures — never pass webhook bodies through `ReadJSON` first. 6. **Streaming-safe self-host:** `TargetSelfhost` keeps `WriteTimeout: 0` so React Suspense and SSE streams are never cut off. 7. **Layered app structure:** Keep `main.go` thin (wiring only) and separate `internal/domain`, `internal/store`, `internal/service`, and `internal/httpapi`. Centralize Next.js fetches in `lib/api.ts`. ## Documentation (Raw Markdown for LLMs) - [Complete Docs Bundle (all guides in one file)](https://next-gin.dev/llms-full.txt): Full single-file markdown corpus for one-shot context ingestion. - [Getting Started](https://next-gin.dev/docs/getting-started.md): Quick start, scaffolding, single-file Go backend, and deployment targets. - [Architecture Patterns](https://next-gin.dev/docs/patterns.md): 3-layer Go backend layout (httpapi, service, store), error mapping, middleware, and Next.js API boundary. - [Cookbook & Best Practices](https://next-gin.dev/docs/cookbook.md): Split topology, Cloudflare Pages + Containers, SQL/sqlc vs ORMs, auth, HMAC webhooks, and CronLocker. - [Deployment Guide](https://next-gin.dev/docs/deployment.md): Deploying to Vercel + Go container, Cloudflare Pages + Containers, Render, Fly.io, or a single VPS. - [Security & Crons](https://next-gin.dev/docs/security-and-crons.md): CORS, RequireInternal, ReadJSON/ReadRawBody limits, RateLimit, session cookies, and in-process crons. - [CLI Reference](https://next-gin.dev/docs/cli-reference.md): Full reference for nextgin init, dev, build, and deploy flags. - [Architecture Specification](https://next-gin.dev/docs/spec.md): Design record, request routing, worker pool internals, and benchmarks. ## Web Pages & Packages - [Homepage](https://next-gin.dev/) - [Documentation Hub](https://next-gin.dev/docs) - [GitHub Repository](https://github.com/Chidi09/nextgin) - [Go Package Docs](https://pkg.go.dev/github.com/Chidi09/nextgin) - [npm Package (@nextgin/adapter)](https://www.npmjs.com/package/@nextgin/adapter)