create-ely 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/package.json +60 -0
  4. package/src/index.ts +187 -0
  5. package/templates/monorepo/README.md +75 -0
  6. package/templates/monorepo/apps/backend/.cursor/mcp.json +8 -0
  7. package/templates/monorepo/apps/backend/.dockerignore +60 -0
  8. package/templates/monorepo/apps/backend/.env.example +19 -0
  9. package/templates/monorepo/apps/backend/.github/workflows/lint.yml +31 -0
  10. package/templates/monorepo/apps/backend/.github/workflows/tests.yml +36 -0
  11. package/templates/monorepo/apps/backend/AGENTS.md +79 -0
  12. package/templates/monorepo/apps/backend/CHANGELOG.md +190 -0
  13. package/templates/monorepo/apps/backend/CLAUDE.md +149 -0
  14. package/templates/monorepo/apps/backend/Dockerfile +35 -0
  15. package/templates/monorepo/apps/backend/LICENSE +21 -0
  16. package/templates/monorepo/apps/backend/README.md +274 -0
  17. package/templates/monorepo/apps/backend/biome.json +58 -0
  18. package/templates/monorepo/apps/backend/bun.lock +303 -0
  19. package/templates/monorepo/apps/backend/docker-compose.yml +37 -0
  20. package/templates/monorepo/apps/backend/drizzle.config.ts +14 -0
  21. package/templates/monorepo/apps/backend/package.json +42 -0
  22. package/templates/monorepo/apps/backend/src/common/config.ts +29 -0
  23. package/templates/monorepo/apps/backend/src/common/logger.ts +18 -0
  24. package/templates/monorepo/apps/backend/src/db/index.ts +31 -0
  25. package/templates/monorepo/apps/backend/src/db/migrations/20251111132328_curly_spectrum.sql +8 -0
  26. package/templates/monorepo/apps/backend/src/db/migrations/meta/20251111132328_snapshot.json +70 -0
  27. package/templates/monorepo/apps/backend/src/db/migrations/meta/_journal.json +13 -0
  28. package/templates/monorepo/apps/backend/src/db/schema/users.ts +39 -0
  29. package/templates/monorepo/apps/backend/src/main.ts +67 -0
  30. package/templates/monorepo/apps/backend/src/middleware/error-handler.ts +36 -0
  31. package/templates/monorepo/apps/backend/src/modules/users/index.ts +61 -0
  32. package/templates/monorepo/apps/backend/src/modules/users/model.ts +48 -0
  33. package/templates/monorepo/apps/backend/src/modules/users/service.ts +46 -0
  34. package/templates/monorepo/apps/backend/src/tests/users.test.ts +102 -0
  35. package/templates/monorepo/apps/backend/src/util/graceful-shutdown.ts +37 -0
  36. package/templates/monorepo/apps/backend/tsconfig.json +35 -0
  37. package/templates/monorepo/apps/backend-biome.json.template +14 -0
  38. package/templates/monorepo/apps/frontend/.env.example +1 -0
  39. package/templates/monorepo/apps/frontend/README.md +59 -0
  40. package/templates/monorepo/apps/frontend/biome.json +16 -0
  41. package/templates/monorepo/apps/frontend/components.json +21 -0
  42. package/templates/monorepo/apps/frontend/index.html +15 -0
  43. package/templates/monorepo/apps/frontend/package.json +48 -0
  44. package/templates/monorepo/apps/frontend/public/favicon.ico +0 -0
  45. package/templates/monorepo/apps/frontend/src/assets/fonts/.gitkeep +0 -0
  46. package/templates/monorepo/apps/frontend/src/assets/images/.gitkeep +0 -0
  47. package/templates/monorepo/apps/frontend/src/features/layout/Header.tsx +73 -0
  48. package/templates/monorepo/apps/frontend/src/main.tsx +36 -0
  49. package/templates/monorepo/apps/frontend/src/routeTree.gen.ts +95 -0
  50. package/templates/monorepo/apps/frontend/src/routes/__root.tsx +25 -0
  51. package/templates/monorepo/apps/frontend/src/routes/index.tsx +34 -0
  52. package/templates/monorepo/apps/frontend/src/routes/users/index.tsx +79 -0
  53. package/templates/monorepo/apps/frontend/src/routes/users/new.tsx +148 -0
  54. package/templates/monorepo/apps/frontend/src/shared/api/client.ts +6 -0
  55. package/templates/monorepo/apps/frontend/src/shared/components/.gitkeep +0 -0
  56. package/templates/monorepo/apps/frontend/src/shared/constants/.gitkeep +0 -0
  57. package/templates/monorepo/apps/frontend/src/shared/hooks/.gitkeep +0 -0
  58. package/templates/monorepo/apps/frontend/src/shared/types/.gitkeep +0 -0
  59. package/templates/monorepo/apps/frontend/src/shared/utils/utils.ts +6 -0
  60. package/templates/monorepo/apps/frontend/src/styles.css +138 -0
  61. package/templates/monorepo/apps/frontend/src/vite-env.d.ts +13 -0
  62. package/templates/monorepo/apps/frontend/tsconfig.json +27 -0
  63. package/templates/monorepo/apps/frontend/vite.config.ts +27 -0
  64. package/templates/monorepo/biome.json +65 -0
  65. package/templates/monorepo/bun.lock +1044 -0
  66. package/templates/monorepo/package.json +13 -0
@@ -0,0 +1,190 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.4.5] - 2026-01-03
11
+
12
+ ### Changed
13
+
14
+ - Updated dependencies to the latest version
15
+
16
+ ## [0.4.4] - 2025-12-25
17
+
18
+ ### Added
19
+
20
+ - Added `CLAUDE.md` with comprehensive development guidelines for AI-assisted development
21
+ - Added `ENABLE_OPENAPI` environment variable to control OpenAPI documentation availability
22
+ - Added new `src/middleware/error-handler.ts` for centralized error handling
23
+ - Added startup logging to indicate OpenAPI documentation availability status
24
+
25
+ ### Changed
26
+
27
+ - Extracted global error handler into separate middleware file (`src/middleware/error-handler.ts`)
28
+ - Enhanced error logging in users module to log all caught errors before returning responses
29
+ - Updated `src/common/logger.ts` to use raw `pino` instead of elysia-logger wrapper
30
+ - Updated OpenAPI integration to respect `ENABLE_OPENAPI` configuration
31
+ - Updated `.env.example` with `ENABLE_OPENAPI` setting and changed default `LOG_LEVEL` to `debug`
32
+ - Updated dependencies: `@elysiajs/openapi` to ^1.4.12, `drizzle-orm` to ^0.45.1, `elysia` to ^1.4.19
33
+ - Cleaned up `src/main.ts` by moving error handling logic to dedicated middleware
34
+
35
+ ### Removed
36
+
37
+ - Removed `@bogeychan/elysia-logger` dependency in favor of raw Pino integration
38
+
39
+ ## [0.4.3] - 2025-12-15
40
+
41
+ ### Changed
42
+
43
+ - Improved `README.md` with up-to-date docs
44
+ - Fixed database variable value in `.env.example` to work with `docker-compose.yml` deployment out of the box
45
+ - Updated Elysia to the latest `1.4.19` version
46
+
47
+ ## [0.4.2] - 2025-12-06
48
+
49
+ ### Added
50
+
51
+ - Added database migration error handling
52
+ - Added automatic database migrations on server startup
53
+
54
+ ### Changed
55
+
56
+ - Updated dependencies to the latest version
57
+ - Changed the way server starts to be more robust
58
+
59
+ ## [0.4.1] - 2025-12-03
60
+
61
+ ### Changed
62
+
63
+ - Updated dependencies to the latest version
64
+ - Updated error handling to be more robust
65
+ - Updated ci workflows to use action environment variables instead of test environment
66
+
67
+ ### Fixed
68
+
69
+ - Fixed error logging to not expose sensitive request information
70
+
71
+ ## [0.3.1] - 2025-12-01
72
+
73
+ ### Changed
74
+
75
+ - Updated graceful shutdown functionality to be more robust
76
+ - Updated dependencies to the latest version
77
+
78
+ ### Added
79
+
80
+ - Added `@types/pg` to dev dependencies for type safety
81
+
82
+ ## [0.3.0] - 2025-11-27
83
+
84
+ ### Changed
85
+
86
+ - Updated logger integration to use plugin-based approach at root app level
87
+ - Improved app initialization and launch process with proper signal handling (SIGINT/SIGTERM)
88
+ - Enhanced error logging with structured HTTP request context
89
+ - Improved error handling in the users module
90
+
91
+ ## [0.2.4] - 2025-11-20
92
+
93
+ ### Fixed
94
+
95
+ - Fixed `README.md` to use correct workflow name
96
+
97
+ ## [0.2.2] - 2025-11-20
98
+
99
+ ### Fixed
100
+
101
+ - Fixed workflows to use environment variables
102
+
103
+ ## [0.2.0] - 2025-11-20
104
+
105
+ ### Added
106
+
107
+ - Added local MCP server configuration
108
+ - Added CI lint workflow
109
+ - Added Biome-based formatting/linting
110
+ - Added VS Code recommendations/settings included
111
+ - Added project guidelines and updated changelog
112
+
113
+ ### Fixed
114
+
115
+ - Improved user-creation error handling with clearer 422 responses and more robust failure checks
116
+
117
+ ### Changed
118
+
119
+ - Updated dependencies to the latest version
120
+ - Updated tests for consistent formatting and interaction patterns
121
+
122
+ ## [0.1.6] - 2025-11-11
123
+
124
+ ### Changed
125
+
126
+ - Dependencies updated to the latest version
127
+ - Fixed the way we define models
128
+ - Moved database-related files to `src/db`
129
+ - Moved common files to `src/common`
130
+ - Removed aliases from `tsconfig.json` as it may interfere with monorepo setups
131
+
132
+ ### Added
133
+
134
+ - Added `timestamp` prefix to migrations
135
+
136
+ ## [0.1.5] - 2025-09-30
137
+
138
+ ### Changed
139
+
140
+ - Updated dependencies to the latest version
141
+ - Updated the way we use logger
142
+ - Improved `openapi` documentation
143
+
144
+ ## [0.1.4] - 2025-09-16
145
+
146
+ ### Changed
147
+
148
+ - Updated packages to the latest version
149
+ - Improved `Dockerfile`
150
+
151
+ ## [0.1.2] - 2025-09-14
152
+
153
+ ### Added
154
+
155
+ - Added test directory to `bunfig.toml`
156
+ - Added users test file
157
+
158
+ ### Fixed
159
+
160
+ - Fixed `LOG_LEVEL` type in `config.ts`
161
+ - Fixed mistaken comment in `users/index.ts`
162
+
163
+ ### Changed
164
+
165
+ - Updated `README.md` with testing information and some badges
166
+
167
+ ## [0.1.1] - 2025-09-14
168
+
169
+ ### Changed
170
+
171
+ - Removed invalid parameters from `bunfig.toml` and disabled telemetry
172
+
173
+ ## [0.1.0] - 2025-09-14
174
+
175
+ ### Added
176
+
177
+ - Elysia web framework with TypeScript and Bun runtime
178
+ - PostgreSQL database with Drizzle ORM
179
+ - User management API endpoints
180
+ - OpenAPI documentation generation
181
+ - Docker and Docker Compose configuration
182
+ - Database migration system
183
+ - Pino logger with development pretty printing
184
+ - Environment variable validation with Envalid
185
+ - Hot reload development server
186
+ - Initial users table schema
187
+
188
+ ### Changed
189
+
190
+ - Updated OpenAPI documentation URLs from `/swagger` to `/openapi`
@@ -0,0 +1,149 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Development Commands
6
+
7
+ ```bash
8
+ # Dependencies
9
+ bun install # Install dependencies
10
+
11
+ # Development
12
+ bun run dev # Start dev server with hot reload
13
+ bun run start # Start production server
14
+ bun run build # Build optimized binary
15
+
16
+ # Database (Drizzle ORM)
17
+ bun run db:generate # Generate migration after schema changes
18
+ bun run db:migrate # Apply pending migrations
19
+ bun run db:studio # Open Drizzle Studio GUI
20
+
21
+ # Code Quality
22
+ bun run lint # Check for lint errors
23
+ bun run lint:fix # Auto-fix lint issues
24
+ bun run format # Format code with Biome
25
+
26
+ # Testing
27
+ bun test # Run all tests
28
+ bun test --coverage # Run tests with coverage report
29
+
30
+ # Docker
31
+ docker-compose up -d # Start all services (app + postgres)
32
+ docker-compose up -d elysia-boilerplate-postgres # PostgreSQL only
33
+ docker-compose logs -f # View logs
34
+ docker-compose down # Stop all services
35
+ ```
36
+
37
+ ## Architecture Overview
38
+
39
+ ### Request Flow
40
+ 1. Request enters through `src/main.ts` (root Elysia app)
41
+ 2. Global middleware applied: CORS, error handling, OpenAPI
42
+ 3. Routed to module in `src/modules/` (e.g., `/users` → `src/modules/users/`)
43
+ 4. Module structure: `index.ts` (routes) → `service.ts` (business logic) → database
44
+
45
+ ### Logger Architecture (CRITICAL)
46
+ The logger is initialized **once** in `src/main.ts` using `.use(log.into({...}))`. To avoid duplicate logs:
47
+ - **DO NOT** use logger from Elysia context (`ctx.log`) in submodules
48
+ - **ALWAYS** import logger directly: `import { log } from 'src/common/logger'`
49
+ - Create child loggers for modules: `const log = logger.child({ name: 'module-name' })`
50
+
51
+ Example from `src/modules/users/index.ts`:
52
+ ```typescript
53
+ import { log as logger } from 'src/common/logger';
54
+ const log = logger.child({ name: 'users' });
55
+ ```
56
+
57
+ ### Module Pattern
58
+ Each module in `src/modules/` follows this structure:
59
+
60
+ 1. **`schema/` in `src/db/schema/`**: Drizzle table definition + validation schemas
61
+ - Define table with `pgTable()`
62
+ - Export `createInsertSchema`, `createSelectSchema`, `createUpdateSchema` from drizzle-typebox
63
+ - Add Elysia field refinements (validation rules)
64
+
65
+ 2. **`model.ts`**: Type definitions and Elysia model plugin
66
+ - Define request/response types using Elysia's `t` (TypeBox)
67
+ - Create namespace (e.g., `UsersModel`) with typed DTOs
68
+ - Export Elysia plugin with `.model()` to register schemas
69
+
70
+ 3. **`service.ts`**: Business logic and database operations
71
+ - Pure functions that interact with database
72
+ - No HTTP concerns (status codes, headers, etc.)
73
+
74
+ 4. **`index.ts`**: Route definitions (Elysia controller)
75
+ - Define routes with `.get()`, `.post()`, etc.
76
+ - Reference models by string: `body: 'users.createRequest'`
77
+ - Handle errors and return proper HTTP status codes
78
+ - OpenAPI documentation in `detail` field
79
+
80
+ ### Database Schema Pattern
81
+ When creating/modifying tables in `src/db/schema/`:
82
+
83
+ ```typescript
84
+ // 1. Define table
85
+ export const users = pgTable('users', {
86
+ id: uuid('id').primaryKey().$defaultFn(() => Bun.randomUUIDv7()),
87
+ // ... fields
88
+ });
89
+
90
+ // 2. Define validation refinements for Elysia
91
+ const fieldRefinements = {
92
+ name: t.String({ minLength: 1, maxLength: 255 }),
93
+ };
94
+
95
+ // 3. Create schemas (avoid infinite type instantiation)
96
+ const _userCreate = createInsertSchema(users, fieldRefinements);
97
+ const _userSelect = createSelectSchema(users, fieldRefinements);
98
+ const _userUpdate = createUpdateSchema(users, fieldRefinements);
99
+
100
+ // 4. Export with explicit types
101
+ export const userCreate = _userCreate;
102
+ export const userSelect = _userSelect;
103
+ export const userUpdate = _userUpdate;
104
+ ```
105
+
106
+ After schema changes, run `bun run db:generate` to create migration.
107
+
108
+ ### Environment Configuration
109
+ - All env vars validated in `src/common/config.ts` using Envalid
110
+ - **NEVER** use `process.env` or `Bun.env` directly in application code
111
+ - Always import: `import config from 'src/common/config'`
112
+ - Available config: `NODE_ENV`, `LOG_LEVEL`, `SERVER_HOSTNAME`, `SERVER_PORT`, `DATABASE_URL`, `DB_AUTO_MIGRATE`, `ENABLE_OPENAPI`
113
+
114
+ ### Error Handling
115
+ Global error handler in `src/middleware/error-handler.ts`:
116
+ - Elysia's handled errors (status codes) pass through
117
+ - Unhandled errors are logged with context (method, URL, referrer)
118
+ - Clients receive generic "Internal Server Error" (never expose details)
119
+
120
+ ### Bootstrap Process
121
+ `src/main.ts` bootstrap function:
122
+ 1. Run database migrations (if `DB_AUTO_MIGRATE=true`)
123
+ 2. Start HTTP server
124
+ 3. Register graceful shutdown handlers (SIGINT, SIGTERM)
125
+
126
+ If bootstrap fails, app logs fatal error and exits with code 1.
127
+
128
+ ## Branch Strategy
129
+ - `main`: Production releases
130
+ - `develop`: Integration branch (default PR target)
131
+ - `feature/*`: New features
132
+ - GitHub Actions run lint checks on push/PR to `main` and `develop`
133
+
134
+ ## TypeScript Configuration
135
+ - Strict mode enabled (`strict: true`)
136
+ - No unchecked indexed access (`noUncheckedIndexedAccess: true`)
137
+ - Module resolution: `bundler` (Bun-specific)
138
+ - Base URL set to `.` for absolute imports from project root
139
+
140
+ ## Testing
141
+ - Test files in `src/tests/` named `*.test.ts`
142
+ - Use Bun's built-in test runner
143
+ - All new features require tests
144
+
145
+ ## Code Style
146
+ - Linter: Biome (config in `biome.json`)
147
+ - Run `bun run lint:fix` before committing
148
+ - No `any` types unless absolutely necessary
149
+ - Use explicit imports (no `import *`)
@@ -0,0 +1,35 @@
1
+ # Build stage
2
+ FROM oven/bun:1.3.2-alpine AS builder
3
+
4
+ WORKDIR /app
5
+
6
+ # Copy package files
7
+ COPY package.json bun.lock ./
8
+
9
+ # Install dependencies
10
+ RUN bun install
11
+
12
+ # Copy source files
13
+ COPY src ./src
14
+ COPY drizzle.config.ts ./
15
+ COPY tsconfig.json ./
16
+
17
+ # Build the application for Linux
18
+ RUN bun build --compile --minify-whitespace --minify-syntax --outfile build/server src/main.ts
19
+
20
+ # Final stage - ultra-minimal runtime using alpine-glibc (16MB base)
21
+ FROM frolvlad/alpine-glibc
22
+
23
+ # Install only essential C++ runtime libraries (minimal overhead)
24
+ RUN apk --no-cache add libstdc++ libgcc
25
+
26
+ # Copy the compiled binary directly from builder stage
27
+ COPY --from=builder /app/build/server /server
28
+
29
+ # Make the binary executable
30
+ RUN chmod +x /server
31
+
32
+ EXPOSE 3000
33
+
34
+ # Use the compressed binary
35
+ CMD ["/server"]
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Elysia Boilerplate
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,274 @@
1
+ # Elysia Boilerplate
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![Bun](https://img.shields.io/badge/Bun-000?logo=bun&logoColor=fff)](https://bun.sh)
5
+ [![Postgres](https://img.shields.io/badge/Postgres-%23316192.svg?logo=postgresql&logoColor=white)](https://www.postgresql.org)
6
+ [![Drizzle](https://img.shields.io/badge/Drizzle-C5F74F?logo=drizzle&logoColor=000)](https://orm.drizzle.team)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?logo=typescript&logoColor=white)](https://www.typescriptlang.org)
8
+ [![Docker](https://img.shields.io/badge/Docker-2496ED?logo=docker&logoColor=white)](https://www.docker.com)
9
+ [![Tests](https://github.com/truehazker/elysia-boilerplate/actions/workflows/tests.yml/badge.svg)](https://github.com/truehazker/elysia-boilerplate/actions/workflows/tests.yml)
10
+ [![Lint](https://github.com/truehazker/elysia-boilerplate/actions/workflows/lint.yml/badge.svg)](https://github.com/truehazker/elysia-boilerplate/actions/workflows/lint.yml)
11
+
12
+ A modern, production-ready boilerplate for building APIs with Elysia, Bun runtime, and PostgreSQL.
13
+
14
+ ## Features
15
+
16
+ - **Elysia** - Fast and ergonomic web framework
17
+ - **Bun** - Ultra-fast JavaScript runtime and package manager
18
+ - **PostgreSQL** - Robust relational database
19
+ - **Drizzle ORM** - Type-safe SQL ORM with excellent TypeScript support
20
+ - **Pino Logger** - High-performance JSON logger
21
+ - **OpenAPI** - Automatic API documentation generation
22
+ - **Environment Configuration** - Type-safe environment variable validation with Envalid
23
+ - **Modular Architecture** - Clean, organized code structure
24
+
25
+ ## Prerequisites
26
+
27
+ - [Bun](https://bun.sh) (latest version)
28
+
29
+ ## Installation
30
+
31
+ 1. **Clone the repository**
32
+
33
+ ```bash
34
+ git clone <repository-url>
35
+ cd elysia-boilerplate
36
+ ```
37
+
38
+ 2. **Install dependencies**
39
+
40
+ ```bash
41
+ bun install
42
+ ```
43
+
44
+ 3. **Set up PostgreSQL**
45
+
46
+ **Recommended approach**: The easiest way to get started is to use the provided Docker Compose setup, which will start PostgreSQL instantly:
47
+
48
+ ```bash
49
+ docker-compose up -d elysia-boilerplate-postgres
50
+ ```
51
+
52
+ **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.
53
+
54
+ 4. **Create and configure environment variables**
55
+
56
+ ```bash
57
+ cp .env.example .env
58
+ ```
59
+
60
+ **Important**: You must create a `.env` file from the provided `.env.example` template and update it with your PostgreSQL connection details:
61
+
62
+ ```env
63
+ NODE_ENV=development
64
+ LOG_LEVEL=info
65
+ SERVER_HOSTNAME=localhost
66
+ SERVER_PORT=3000
67
+ DATABASE_URL=postgresql://username:password@localhost:5432/your_database_name
68
+ ```
69
+
70
+ 5. **Run database migrations**
71
+
72
+ ```bash
73
+ bun run db:migrate
74
+ ```
75
+
76
+ ## Development
77
+
78
+ Start the development server with hot reload:
79
+
80
+ ```bash
81
+ bun run dev
82
+ ```
83
+
84
+ The server will start at `http://localhost:3000` (or your configured port).
85
+
86
+ ## Available Scripts
87
+
88
+ | Command | Description |
89
+ |---------|-------------|
90
+ | `bun run dev` | Start development server with hot reload |
91
+ | `bun run start` | Start production server |
92
+ | `bun run build` | Build the application for production |
93
+ | `bun run db:generate` | Generate a new database migration |
94
+ | `bun run db:migrate` | Apply pending migrations to the database |
95
+ | `bun run db:studio` | Open Drizzle Studio for database management |
96
+ | `docker-compose up -d` | Start the entire stack with Docker Compose |
97
+ | `docker-compose down` | Stop all Docker services |
98
+ | `docker-compose logs -f` | View logs from all services |
99
+
100
+ ## Testing
101
+
102
+ This project includes a testing setup using Bun's built-in test runner. Tests are located in the `src/tests/` folder.
103
+
104
+ ### Running Tests
105
+
106
+ To run all tests:
107
+
108
+ ```bash
109
+ bun test
110
+ ```
111
+
112
+ To run tests with coverage:
113
+
114
+ ```bash
115
+ bun test --coverage
116
+ ```
117
+
118
+ ### Adding Tests
119
+
120
+ Add your test files to the `src/tests/` folder. Test files should follow the naming convention `*.test.ts`.
121
+
122
+ Example test structure:
123
+
124
+ ```text
125
+ src/tests/
126
+ ├── users.test.ts # User module tests
127
+ ├── auth.test.ts # Authentication tests
128
+ └── api.test.ts # API endpoint tests
129
+ ```
130
+
131
+ ## Project Structure
132
+
133
+ ```text
134
+ src/
135
+ ├── db/ # Database configuration and schema
136
+ │ ├── migrations/ # Database migrations
137
+ │ ├── index.ts # Database connection setup
138
+ │ └── schema/ # Drizzle schema definitions
139
+ ├── common/ # Shared utilities
140
+ │ ├── config.ts # Environment configuration
141
+ │ └── logger.ts # Logger setup
142
+ ├── modules/ # Feature modules
143
+ │ └── users/ # User module example
144
+ │ ├── index.ts # Route definitions
145
+ │ ├── model.ts # Data models
146
+ │ └── service.ts # Business logic
147
+ └── main.ts # Application entry point
148
+ ```
149
+
150
+ ### Important Notes on Logger Usage
151
+
152
+ The logger is initialized in the root application (`src/main.ts`) using `.use(log.into({...}))`. To avoid duplicate logs, submodules should import and use the logger directly from `src/common/logger` rather than relying on Elysia's context. Using the logger from context in submodules will result in duplicate log entries.
153
+
154
+ **Example:**
155
+
156
+ ```typescript
157
+ // ✅ Correct: Import logger directly
158
+ import { log } from 'src/common/logger';
159
+
160
+ // ❌ Incorrect: Using logger from Elysia context in submodules
161
+ // This will cause duplicate logs
162
+ ```
163
+
164
+ ## Configuration
165
+
166
+ The application uses [Envalid](https://github.com/af/envalid) for type-safe environment variable validation. All configuration is centralized in `src/common/config.ts`.
167
+
168
+ ### Environment Variables
169
+
170
+ | Variable | Type | Default | Description |
171
+ |----------|------|---------|-------------|
172
+ | `NODE_ENV` | string | `development` | Application environment |
173
+ | `LOG_LEVEL` | string | `info` | Logging level |
174
+ | `SERVER_HOSTNAME` | string | `localhost` | Server hostname |
175
+ | `SERVER_PORT` | number | `3000` | Server port |
176
+ | `DATABASE_URL` | string | `postgresql://postgres:postgres@localhost:5432/elysia-boilerplate` | PostgreSQL connection URL |
177
+
178
+ ## API Documentation
179
+
180
+ Once the server is running, you can access the interactive API documentation at:
181
+
182
+ - **Scala UI**: `http://localhost:3000/openapi`
183
+ - **OpenAPI JSON**: `http://localhost:3000/openapi/json`
184
+
185
+ ## Database Management
186
+
187
+ ### Generate a new migration
188
+
189
+ ```bash
190
+ bun run db:generate
191
+ ```
192
+
193
+ ### Apply migrations
194
+
195
+ ```bash
196
+ bun run db:migrate
197
+ ```
198
+
199
+ ### Open Drizzle Studio
200
+
201
+ ```bash
202
+ bun run db:studio
203
+ ```
204
+
205
+ ## Docker Deployment
206
+
207
+ This project includes Docker configuration for easy deployment and development.
208
+
209
+ ### Using Docker Compose (Recommended)
210
+
211
+ The easiest way to run the entire stack is with Docker Compose:
212
+
213
+ ```bash
214
+ # Start all services (app + database)
215
+ docker-compose up -d
216
+
217
+ # View logs
218
+ docker-compose logs -f
219
+
220
+ # Stop all services
221
+ docker-compose down
222
+ ```
223
+
224
+ This will start:
225
+
226
+ - **Elysia application** on `http://localhost:3000`
227
+ - **PostgreSQL database** on `localhost:5432`
228
+ - **Automatic database migrations** on startup
229
+
230
+ ### Docker Configuration
231
+
232
+ - **Dockerfile**: Multi-stage build using Bun runtime, compiles TypeScript and creates optimized binary
233
+ - **docker-compose.yml**: Complete stack with PostgreSQL, health checks, and persistent data storage
234
+ - **Environment**: Production-ready configuration with proper networking and restart policies
235
+
236
+ ## Production Deployment
237
+
238
+ 1. **Build the application**
239
+
240
+ ```bash
241
+ bun run build
242
+ ```
243
+
244
+ 2. **Set production environment variables**
245
+
246
+ ```bash
247
+ export NODE_ENV=production
248
+ export DATABASE_URL=your_production_database_url
249
+ # ... other production variables
250
+ ```
251
+
252
+ 3. **Run the application**
253
+
254
+ ```bash
255
+ ./build/server
256
+ ```
257
+
258
+ ## Using Agents
259
+
260
+ This repository features an `AGENTS.md` file that outlines the recommended tools and commands for using agents.
261
+
262
+ You can use cursor, claude, etc. to use agents
263
+
264
+ ## Contributing
265
+
266
+ 1. Fork the repository
267
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
268
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
269
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
270
+ 5. Open a Pull Request
271
+
272
+ ## License
273
+
274
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.