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
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
NODE_ENV="development"

APP_NAME="Elysia APP"
APP_PORT=3000
APP_URL="http://localhost:3000"
APP_ENV="development"
APP_TIMEZONE="UTC"
APP_KEY="your-app-key"
APP_JWT_SECRET="your-jwt-secret"
Expand Down
69 changes: 63 additions & 6 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,76 @@ return await UserRepository().UserInformation(user.id);

### Import Organization

Use absolute imports with path aliases configured in tsconfig.json:
Use absolute imports with granular path aliases configured in tsconfig.json. Each directory in `src/libs` has its own dedicated alias:

```typescript
import { UserRepository, Hash, BadRequestError } from "@libs";
import { BadRequestError, UnauthorizedError } from "@errors";
import { db, users, userRoles } from "@database";
import { UserRepository } from "@repositories";
import { Hash, log } from "@utils";
import { UserInformation, DatatableType } from "@types";
import { StrongPassword } from "@default";
import { AuthPlugin } from "@plugins";
import { eq, and, or } from "drizzle-orm";
```

Group imports in this order:
**Available Path Aliases:**

- `@base` - Base Elysia app configuration
- `@bull` - Queue and worker files
- `@cache` - Cache utilities and constants
- `@config` - Configuration files (AppConfig, DatabaseConfig, etc.)
- `@database` - Database related (db instance, schemas, tables, RedisClient)
- `@default` - Default constants (StrongPassword, paginationLength, etc.)
- `@errors` - Custom error classes
- `@guards` - Authorization guards (RoleGuard, PermissionGuard)
- `@mailer` - Email services and templates
- `@plugins` - Elysia plugins (AuthPlugin, SecurityPlugin, etc.)
- `@repositories` - Repository pattern implementations
- `@types` - TypeScript type definitions and interfaces
- `@utils` - Utility functions (Hash, log, ResponseToolkit, etc.)
- `@modules` - Application modules

**Import Grouping Order:**

1. External libraries (elysia, drizzle-orm, bullmq, etc.)
2. Internal modules from @libs
3. Internal modules from @modules
4. Type imports
2. Granular aliases by category:
- Configuration: `@config`
- Database: `@database`
- Errors: `@errors`
- Types: `@types`
- Repositories: `@repositories`
- Utils: `@utils`
- Others as needed
3. Relative imports (if absolutely necessary)
4. Type-only imports

**Examples:**

```typescript
// Module service example
import { BadRequestError } from "@errors";
import { db, emailVerifications, users } from "@database";
import { ForgotPasswordRepository, UserRepository } from "@repositories";
import { Hash, log } from "@utils";
import { UserInformation } from "@types";
import { AuthMailService } from "@mailer";
import { eq } from "drizzle-orm";

// Module index example
import { AuthPlugin } from "@plugins";
import { JWT_CONFIG } from "@config";
import { CommonResponseSchemas, ResponseToolkit } from "@utils";
import { UserInformation } from "@types";
import Elysia from "elysia";

// Repository example
import { BadRequestError, UnauthorizedError } from "@errors";
import { db, DbTransaction, userRoles, users } from "@database";
import { Hash } from "@utils";
import { defaultSort } from "@default";
import { DatatableType, PaginationResponse, UserInformation } from "@types";
```

### File Naming

Expand Down
40 changes: 4 additions & 36 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,11 @@ jobs:
with:
bun-version: latest

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: "22"

- name: Install dependencies (Bun)
run: bun install

- name: Install drizzle-kit (Node + npx)
run: npm install drizzle-kit
run: bun add -g drizzle-kit

- name: Lint
run: bun run lint
Expand All @@ -81,15 +76,12 @@ jobs:
run: bun run format

- name: Drizzle Generate
run: npx drizzle-kit generate --config=drizzle.config.ts
run: bunx drizzle-kit generate --config=drizzle.config.ts

- name: Drizzle Migrate
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/elysia_db
# REDIS_HOST: localhost
# REDIS_PORT: 6379
# REDIS_PASSWORD: password123
run: npx drizzle-kit migrate --config=drizzle.config.ts
run: bunx drizzle-kit migrate --config=drizzle.config.ts

- name: Clickhouse Migrate
env:
Expand All @@ -102,28 +94,4 @@ jobs:
run: bun run migrate:clickhouse:status

- name: Build
run: bun run build:all

# docker-compose-up:
# needs: build-and-lint
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v4

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3

# - name: Install Docker Compose
# run: |
# sudo apt-get update
# sudo apt-get install -y docker-compose

# - name: Docker Compose Up
# run: docker-compose up -d

# - name: Wait for services to be healthy
# run: |
# docker-compose ps
# sleep 20
# docker-compose ps
run: bun run build
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ yarn-error.log*
**/*.tgz
**/*.log
package-lock.json
**/*.bun
**/*.bun

/dist
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ RUN bun install --production --ignore-scripts
COPY . .

# Build the app (if needed)
RUN bun run build:all
RUN bun run build

EXPOSE 3000

CMD ["bun", "run", "start:all"]
CMD ["bun", "run", "start"]
81 changes: 17 additions & 64 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
.PHONY: help dev build start lint lint-fix format seed db-generate db-migrate db-push db-pull db-studio db-drop dev-worker build-worker start-worker dev-server build-server start-server dev-all build-all start-all
.PHONY: help lint lint-fix format seed db-generate db-migrate db-push db-pull db-studio db-drop dev build start

# Default target
help:
@echo "Available commands:"
@echo " Development:"
@echo " dev-api - Start API development server with hot reload"
@echo " build-api - Build the API application"
@echo " start-api - Start the API production server"
@echo " dev-server - Start SERVER development server with hot reload"
@echo " build-server - Build the SERVER application"
@echo " start-server - Start the SERVER production server"
@echo " dev-worker - Start WORKER development with hot reload"
@echo " build-worker - Build the WORKER application"
@echo " start-worker - Start the WORKER production service"
@echo " dev-all - Run server and worker in dev mode concurrently"
@echo " build-all - Build server and worker concurrently"
@echo " start-all - Run server and worker in production concurrently"
@echo " dev - Start development server with hot reload"
@echo " build - Build the application"
@echo " start - Start the production server"
@echo " lint - Run ESLint"
@echo " lint-fix - Fix linting issues automatically"
@echo " format - Format code with Prettier"
Expand All @@ -34,32 +25,14 @@ help:
@echo " migrate-clickhouse-status - Check status of ClickHouse migrations"

# Development commands
dev-api:
bun run dev:api
dev:
bun run dev

build-api:
bun run build:api
build:
bun run build

start-api:
bun run start:api

dev-server:
bun run dev:server

build-server:
bun run build:server

start-server:
bun run start:server

dev-worker:
bun run dev:worker

build-worker:
bun run build:worker

start-worker:
bun run start:worker
start:
bun run start

lint:
bun run lint
Expand All @@ -71,7 +44,7 @@ format:
bun run format

db-seed:
bun run infra/seed/index.ts
bun run ./src/libs/database/postgres/seed/index.ts

migrate-clickhouse:
bun run migrate:clickhouse
Expand All @@ -98,32 +71,12 @@ db-studio:
db-drop:
bunx drizzle-kit drop

# db-generate:
# npx drizzle-kit generate

# db-migrate:
# npx drizzle-kit migrate

# db-push:
# npx drizzle-kit push

# db-pull:
# npx drizzle-kit introspect

# db-studio:
# npx drizzle-kit studio

# db-drop:
# npx drizzle-kit drop

dev-all:
bun run dev:all

build-all:
bun run build:all

start-all:
bun run start:all
deploy-prepare:
@echo "Preparing deployment..."
bun install
bunx drizzle-kit migrate
bun run build
@echo "Deployment package is ready!"

# Combined commands for common workflows
fresh: db-drop db-push seed
Expand Down
Loading