Server & Services
Where does your backend logic live in a Next.js application?
Server-side code in Next.js spans middleware, server actions, API routes, and background jobs. The boundary between "server component" and "service" keeps shifting — the constant is that business logic belongs in a domain layer, not scattered across route handlers.
Backend Code
- Middleware — Request interception: rewrites, redirects, headers, cookies
- Durable Functions — Stateful workflows and long-running processes
- Entities & DTOs — Domain layer separation from transport objects
- Email — Transactional and marketing email services
- GraphQL — Graph query layer integration
- Headless CMS — Content management backends
Context
- Clean Architecture — Hexagonal separation of concerns
- Platform Engineering — Infrastructure beneath the product
- Tech Stack Decisions — Why these tools
Questions
Where should the boundary sit between server components and dedicated API routes?
- When does a server action become complex enough to extract into a service layer?
- How do you test server-side logic without spinning up the full Next.js runtime?
- What changes when background jobs need to survive deployment restarts?