Loading...
Loading...
Senior/Lead Developer Bun.js + Docker dengan pengalaman 20 tahun. Skill ini digunakan ketika: (1) Membuat project Bun.js baru dengan Docker, (2) Code review dan refactoring untuk clean code, (3) Debugging complex issues, (4) Optimisasi performa dan scalability, (5) Arsitektur aplikasi production-ready, (6) Memilih library yang tepat dan terpercaya, (7) Setup CI/CD dan deployment. Trigger keywords: "bun", "bunjs", "bun.js", "docker", "typescript backend", "clean code", "scalable", "maintainable", "debugging", "performance".
npx skill4agent add modra40/claude-codex-skills-directory bunjs-docker-mastery"Simplicity is the ultimate sophistication." — Leonardo da Vinci
// ❌ Over-engineering
class UserServiceFactoryAbstractSingletonProxyDecorator { ... }
// ✅ Simple & Clear
const userService = { create, update, delete, findById }any# Gunakan script init
./scripts/init-project.sh my-app
# Atau manual
bun init
bun add hono zod drizzle-orm pino
bun add -d @types/bun vitestsrc/
├── index.ts # Entry point ONLY (max 20 lines)
├── app.ts # App setup & middleware registration
├── config/
│ ├── index.ts # Export semua config
│ ├── env.ts # Environment validation dengan Zod
│ └── database.ts # Database config
├── routes/
│ ├── index.ts # Route aggregator
│ ├── user.route.ts # User routes
│ └── auth.route.ts # Auth routes
├── controllers/ # HTTP layer ONLY
├── services/ # Business logic
├── repositories/ # Data access layer
├── middlewares/
│ ├── auth.ts # Authentication
│ ├── validate.ts # Request validation
│ └── error.ts # Error handler
├── utils/
│ ├── response.ts # Standard response helper
│ ├── logger.ts # Pino logger setup
│ └── errors.ts # Custom error classes
└── types/
├── index.d.ts # Global types
└── api.types.ts # API request/response types// src/index.ts - HANYA INI
import { app } from "./app"
import { env } from "./config/env"
import { logger } from "./utils/logger"
const server = Bun.serve({
port: env.PORT,
fetch: app.fetch,
})
logger.info(`🚀 Server running on ${server.url}`)// src/config/env.ts
import { z } from "zod"
const envSchema = z.object({
NODE_ENV: z.enum(["development", "production", "test"]).default("development"),
PORT: z.coerce.number().default(3000),
DATABASE_URL: z.string().url(),
JWT_SECRET: z.string().min(32),
REDIS_URL: z.string().url().optional(),
})
export const env = envSchema.parse(process.env)
export type Env = z.infer<typeof envSchema>HTTP Request → Controller → Service → Repository → Database
↓ ↓ ↓
Validation Business Data Access
Logic (Drizzle)// src/utils/errors.ts
export class AppError extends Error {
constructor(
public message: string,
public statusCode: number = 500,
public code: string = "INTERNAL_ERROR"
) {
super(message)
Error.captureStackTrace(this, this.constructor)
}
}
export class NotFoundError extends AppError {
constructor(resource: string) {
super(`${resource} not found`, 404, "NOT_FOUND")
}
}
export class ValidationError extends AppError {
constructor(message: string) {
super(message, 400, "VALIDATION_ERROR")
}
}// src/utils/response.ts
export const ok = <T>(data: T) => ({ success: true, data })
export const created = <T>(data: T) => ({ success: true, data })
export const error = (message: string, code: string) => ({
success: false,
error: { message, code }
})# Build stage
FROM oven/bun:1-alpine AS builder
WORKDIR /app
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile --production=false
COPY . .
RUN bun run build
# Production stage
FROM oven/bun:1-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
# Security: Non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S bunjs -u 1001
USER bunjs
COPY /app/dist ./dist
COPY /app/node_modules ./node_modules
COPY /app/package.json ./
EXPOSE 3000
HEALTHCHECK \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
CMD ["bun", "run", "dist/index.js"]assets/project-template/docker/docker-compose.yml| Issue | Penyebab | Solusi |
|---|---|---|
| Memory leak | Uncleared intervals/listeners | Cleanup di graceful shutdown |
| Connection pool exhausted | Tidak release connection | Gunakan |
| Race condition | Async tanpa proper await | Promise.all dengan error handling |
| Uncaught Promise rejection | Missing try-catch | Global error handler |
// Bun native debugger
bun --inspect src/index.ts
// Memory profiling
bun --smol src/index.ts // Low memory mode
// Trace async operations
process.on("unhandledRejection", (reason, promise) => {
logger.error({ reason, promise }, "Unhandled Rejection")
})scripts/init-project.shscripts/healthcheck.tsassets/project-template//health