Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SERVER_PORT=3000

# Database Configuration
# Replace with your actual PostgreSQL connection details
DATABASE_URL=postgresql://username:password@localhost:5432/elysia-boilerplate
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/elysia-boilerplate

# Enable migrations on server startup
DB_AUTO_MIGRATE=false
66 changes: 32 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,40 @@ A modern, production-ready boilerplate for building APIs with Elysia, Bun runtim
## Prerequisites

- [Bun](https://bun.sh) (latest version)
- [PostgreSQL](https://www.postgresql.org) (12+)

## Installation

1. **Clone the repository**

```bash
git clone <repository-url>
cd elysia-boilerplate
```

2. **Install dependencies**

```bash
bun install
```

3. **Set up PostgreSQL**
- Install and start PostgreSQL on your system
- Create a database for your project
- Note the connection details (host, port, database name, username, password)

**Recommended approach**: The easiest way to get started is to use the provided Docker Compose setup, which will start PostgreSQL instantly:

```bash
docker-compose up -d elysia-boilerplate-postgres
```

**Alternative**: If you prefer to run your own PostgreSQL instance, create a database for your project and note the connection details (host, port, database name, username, password). **Remember to update your `.env` file** with the correct `DATABASE_URL` connection string.

4. **Create and configure environment variables**

```bash
cp .env.example .env
```

**Important**: You must create a `.env` file from the provided `.env.example` template and update it with your PostgreSQL connection details:

```env
NODE_ENV=development
LOG_LEVEL=info
Expand All @@ -60,13 +68,15 @@ A modern, production-ready boilerplate for building APIs with Elysia, Bun runtim
```

5. **Run database migrations**

```bash
bun run db:migrate
```

## Development

Start the development server with hot reload:

```bash
bun run dev
```
Expand Down Expand Up @@ -94,11 +104,13 @@ This project includes a testing setup using Bun's built-in test runner. Tests ar
### Running Tests

To run all tests:

```bash
bun test
```

To run tests with coverage:

```bash
bun test --coverage
```
Expand All @@ -108,16 +120,17 @@ bun test --coverage
Add your test files to the `src/tests/` folder. Test files should follow the naming convention `*.test.ts`.

Example test structure:
```

```text
src/tests/
├── users.test.ts # User module tests
├── auth.test.ts # Authentication tests
└── api.test.ts # API endpoint tests
├── users.test.ts # User module tests
├── auth.test.ts # Authentication tests
└── api.test.ts # API endpoint tests
```

## Project Structure

```
```text
src/
├── db/ # Database configuration and schema
│ ├── migrations/ # Database migrations
Expand Down Expand Up @@ -160,27 +173,31 @@ The application uses [Envalid](https://github.com/af/envalid) for type-safe envi
| `LOG_LEVEL` | string | `info` | Logging level |
| `SERVER_HOSTNAME` | string | `localhost` | Server hostname |
| `SERVER_PORT` | number | `3000` | Server port |
| `DATABASE_URL` | string | - | PostgreSQL connection URL |
| `DATABASE_URL` | string | `postgresql://postgres:postgres@localhost:5432/elysia-boilerplate` | PostgreSQL connection URL |

## API Documentation

Once the server is running, you can access the interactive API documentation at:

- **Scala UI**: `http://localhost:3000/openapi`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Correct OpenAPI documentation UI label.

"Scala UI" is not the correct terminology for OpenAPI/Swagger documentation. This should be "Swagger UI" or "ReDoc" (or the specific UI tool your OpenAPI setup uses).

Apply this diff:

- - **Scala UI**: `http://localhost:3000/openapi`
+ - **Swagger UI**: `http://localhost:3000/openapi`

If the UI is neither Swagger nor ReDoc, verify which tool is configured and update the label accordingly.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- **Scala UI**: `http://localhost:3000/openapi`
- **Swagger UI**: `http://localhost:3000/openapi`
🤖 Prompt for AI Agents
In README.md around line 182, the OpenAPI docs label currently reads "Scala UI"
which is incorrect; update that label to the correct UI name (e.g., "Swagger UI"
or "ReDoc") that your project actually uses and adjust the text accordingly (for
example: replace "Scala UI" with "Swagger UI" if Swagger UI is served at
http://localhost:3000/openapi); if the project uses a different OpenAPI viewer,
verify the configured tool and set the label to that exact name and ensure the
URL remains accurate.

- **OpenAPI JSON**: `http://localhost:3000/openapi/json`

## Database Management

### Generate a new migration

```bash
bun run db:generate
```

### Apply migrations

```bash
bun run db:migrate
```

### Open Drizzle Studio

```bash
bun run db:studio
```
Expand All @@ -205,33 +222,11 @@ docker-compose down
```

This will start:

- **Elysia application** on `http://localhost:3000`
- **PostgreSQL database** on `localhost:5432`
- **Automatic database migrations** on startup

### Manual Docker Build

If you prefer to build and run manually:

```bash
# Build the Docker image
docker build -t elysia-boilerplate .

# Run PostgreSQL
docker run -d --name postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=elysia-boilerplate \
-p 5432:5432 \
postgres:17-alpine

# Run the application
docker run -d --name elysia-app \
-p 3000:3000 \
-e DATABASE_URL=postgresql://postgres:[email protected]:5432/elysia-boilerplate \
elysia-boilerplate
```

### Docker Configuration

- **Dockerfile**: Multi-stage build using Bun runtime, compiles TypeScript and creates optimized binary
Expand All @@ -241,18 +236,21 @@ docker run -d --name elysia-app \
## Production Deployment

1. **Build the application**

```bash
bun run build
```

2. **Set production environment variables**

```bash
export NODE_ENV=production
export DATABASE_URL=your_production_database_url
# ... other production variables
```

3. **Run the application**

```bash
./build/server
```
Expand Down