> [Agent navigation index](/llms.txt)

# Server configuration

A full-stack Brix application has three server-facing files. `src/brix.ts` holds browser-safe contracts and configuration. `src/brix.server.ts` calls `defineBrixServer(brix, options)` to attach server-only concerns: environment, authentication, caching, security policy, middleware, logging, and integrations. `src/app.ts` calls `createBrixApp(brixServer)` to assemble the Hono application that the generated production entry serves with your discovered routes.

Managed React applications are browser-only and have no Brix server; see [application types](/docs/react.md).

## Recommended path

1. [Assemble the server](/docs/server-foundations.md) and confirm a discovered route runs through the production app.
1. [Add authentication and security policy](/docs/server-auth-security.md) if any route is private, accepts mutations, or is called from another origin.
   Applications that sign in through brix-auth [use its framework-owned policy](/docs/server-brix-auth.md).
1. [Add middleware, errors, and observability](/docs/server-runtime.md) after the request boundary works.
1. [Choose a deployment target](/docs/deployment.md) only after local route tests and `brix verify` pass.

## What happens on every request

`createBrixApp` installs infrastructure in a fixed order. Application options plug into specific steps; they cannot be reordered:

1. **Request ID.** A valid incoming `x-request-id` is reused, otherwise Brix generates one, and it is returned on the response.
1. **Environment.** When `env` is configured, the platform's environment snapshot is parsed. A failure returns a sanitized 500 and skips everything below except security headers.
1. **Logging and timing.** The request logger, `c.timings`, and the `request.start` record begin.
1. **Security headers and CSP.** Default secure headers and a fresh CSP nonce are applied to every response; Markdown and plain-text responses get a script-free policy without the nonce.
1. **Cross-origin mutation guard.** Cross-origin browser `POST`, `PUT`, `PATCH`, and `DELETE` requests receive 403.
1. **Built-in assets.** Production builds serve generated assets and `public/` files before any route.
1. **Locale, then translations.** `resolveLocale` and the translation loader run.
1. **Application middleware.** Your `middleware` array runs in order.
1. **Routes.** Integration and OpenAPI routes, then discovered routes. Each route applies its own body limit, authentication, and route middleware before the handler or loader.

Responses also carry `X-App-Version` when a release version is known; see [application version](/docs/api-documentation.md#application-version).
