# Development Setup

## Prerequisites

- [Bun](https://bun.sh) v1.1+
- PostgreSQL 16
- Valkey 8 (or Redis 7+)

## Installation

```bash
git clone <repo-url> && cd lunarfront
bun install
```

## Environment

Create a `.env` file in the project root:

```env
DATABASE_URL=postgresql://lunarfront:lunarfront@localhost:5432/lunarfront
REDIS_URL=redis://localhost:6379
JWT_SECRET=your-secret-here
NODE_ENV=development
```

### All Environment Variables

| Variable | Default | Description |
|----------|---------|-------------|
| `DATABASE_URL` | `postgresql://lunarfront:lunarfront@localhost:5432/lunarfront` | PostgreSQL connection string |
| `REDIS_URL` | `redis://localhost:6379` | Valkey/Redis connection string |
| `JWT_SECRET` | (auto-generated in dev) | Secret for signing JWTs. **Required in production.** |
| `PORT` | `8000` | Backend API port |
| `HOST` | `0.0.0.0` | Backend bind address |
| `NODE_ENV` | — | `development`, `test`, or `production` |
| `LOG_LEVEL` | `info` | Pino log level (`debug`, `info`, `warn`, `error`, `silent`) |
| `LOG_FILE` | — | Path to log file (production only, also logs to stdout) |
| `STORAGE_PROVIDER` | `local` | File storage provider (`local` or `s3`) |
| `STORAGE_LOCAL_PATH` | `./data/files` | Local file storage directory |
| `CORS_ORIGINS` | `*` (dev) | Comma-separated allowed origins |
| `APP_URL` | `http://localhost:5173` | Frontend URL (used in password reset links) |

## Database

```bash
# Create the database
createdb lunarfront

# Run migrations
cd packages/backend
source ../.env  # or source .env from project root
bunx drizzle-kit migrate
```

## Running

```bash
# From project root — starts all packages
bun run dev

# Or individually:
cd packages/backend && source .env && bun run dev   # API on :8000
cd packages/admin && bun run dev                     # UI on :5173
```

## Testing

```bash
# API integration tests (starts a backend, seeds DB, runs HTTP tests)
cd packages/backend
source .env
bun run api-test

# Filter by suite or tag
bun run api-test --suite accounts
bun run api-test --tag crud

# Unit tests
bun run test
```

## Useful Commands

```bash
bun run lint      # ESLint across all packages
bun run format    # Prettier write
bun run build     # Build all packages
```
