> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kit-rs.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Development

> Development workflow and tools for building Kit applications

This guide covers the development workflow for building Kit applications, including the dev server, hot reloading, and useful commands.

## Development Server

Start the development server with:

```bash theme={null}
kit serve
```

This starts:

* **Backend server** on `http://localhost:8080`
* **Vite dev server** on `http://localhost:5173` (for frontend assets)

### Backend Only Mode

If you only need the Rust backend (no frontend):

```bash theme={null}
kit serve --backend-only
```

### Custom Ports

Configure ports using environment variables:

```env theme={null}
# .env
PORT=3000
VITE_DEV_SERVER=http://localhost:5174
```

## Project Structure

A typical Kit project structure:

```
my-app/
├── src/
│   ├── main.rs           # Application entry point
│   ├── routes.rs         # Route definitions
│   ├── controllers/      # Request handlers
│   ├── models/           # Database entities
│   ├── actions/          # Business logic
│   └── middleware/       # Custom middleware
├── frontend/
│   ├── src/
│   │   ├── main.tsx      # Frontend entry
│   │   └── pages/        # React components
│   ├── package.json
│   └── vite.config.ts
├── migrations/           # Database migrations
├── .env                  # Environment config
└── Cargo.toml
```

## Development Workflow

### 1. Make Changes

Edit your Rust code in `src/` or React code in `frontend/src/`.

### 2. Automatic Recompilation

Kit watches for changes:

* **Rust changes**: Recompiles automatically
* **React changes**: Hot module replacement (instant updates)

### 3. Test Your Changes

Visit `http://localhost:8080` to see your changes.

## Database Development

### Running Migrations

```bash theme={null}
# Run all pending migrations
kit migrate

# Check migration status
kit migrate:status

# Rollback last migration
kit migrate:rollback
```

### Syncing Entities

After modifying migrations, regenerate entity files:

```bash theme={null}
kit db:sync
```

### Fresh Database

Reset and re-run all migrations:

```bash theme={null}
kit migrate:fresh
```

## Code Generation

Kit provides generators to scaffold common components:

```bash theme={null}
# Create a controller
kit make:controller users

# Create a model
kit make:model User

# Create a migration
kit make:migration create_posts_table

# Create a page component
kit make:page Home

# Generate TypeScript types
kit generate-types
```

## Environment Configuration

Configure your app using `.env`:

```env theme={null}
# Server
PORT=8080

# Database
DATABASE_URL=sqlite:./database.db

# Inertia/Frontend
INERTIA_DEVELOPMENT=true
VITE_DEV_SERVER=http://localhost:5173
```

## Debugging

### Logging

Kit uses Rust's standard logging. Enable debug output:

```bash theme={null}
RUST_LOG=debug kit serve
```

### Database Queries

Enable SQL query logging:

```env theme={null}
RUST_LOG=sea_orm=debug kit serve
```

## Testing

Run your test suite:

```bash theme={null}
cargo test
```

### Frontend Tests

```bash theme={null}
cd frontend
npm test
```

## Building for Production

### Build the Backend

```bash theme={null}
cargo build --release
```

### Build the Frontend

```bash theme={null}
cd frontend
npm run build
```

### Run Production Server

```bash theme={null}
INERTIA_DEVELOPMENT=false ./target/release/your-app
```

## Useful Commands

| Command                      | Description         |
| ---------------------------- | ------------------- |
| `kit serve`                  | Start dev server    |
| `kit serve --backend-only`   | Start without Vite  |
| `kit migrate`                | Run migrations      |
| `kit migrate:fresh`          | Reset database      |
| `kit db:sync`                | Regenerate entities |
| `kit make:controller <name>` | Create controller   |
| `kit make:model <name>`      | Create model        |
| `kit generate-types`         | Generate TS types   |
| `cargo build --release`      | Production build    |
