Development
Setup Pengembangan
Panduan langkah demi langkah untuk pengembangan lokal dengan Docker Compose
Prasyarat
Install ini sebelum melanjutkan:
| Tool | Command | Cek |
|---|---|---|
| Java 21 | brew install openjdk@21 | java -version |
| Rust 1.85+ | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh | rustc --version |
| Node.js 22+ | brew install node | node -v |
| Docker | Docker Desktop | docker -v |
| bun | curl -fsSL https://bun.sh/install | bash | bun -v |
Environment Variables
Setiap service memerlukan environment variables spesifik.
Java Backend (yomu-backend-java)
Buat .env di yomu-backend-java/:
# Database (Docker Compose)
DATABASE_URL=jdbc:postgresql://localhost:5432/yomu_local?user=yomu_user&password=yomu_pass
# Auth
JWT_SECRET=your-super-secret-jwt-key-change-in-production
INTERNAL_API_KEY=internal-api-key-for-rust-sync
RUST_ENGINE_BASE_URL=http://localhost:8081
# Google OAuth (optional)
GOOGLE_OAUTH_CLIENT_ID=your-client-id
GOOGLE_OAUTH_CLIENT_SECRET=your-client-secretRust Backend (yomu-backend-rust)
Buat .env di yomu-backend-rust/:
# Database
DATABASE_URL=postgres://yomu_user:yomu_pass@localhost:5432/yomu_local
# Redis
REDIS_URL=redis://localhost:6379
# Java backend (outbox sync)
JAVA_CORE_URL=http://localhost:8080
JAVA_CORE_API_KEY=internal-api-key-for-rust-sync
# Logging
RUST_LOG=infoFrontend (yomu-frontend)
Buat .env.local di yomu-frontend/:
# API URLs
CORE_API_BASE_URL=http://localhost:8080/api
RUST_ENGINE_URL=http://localhost:8081/api
# Auth
AUTH_COOKIE_SECURE=false
NEXT_PUBLIC_GOOGLE_CLIENT_ID=your-client-id
# Debug
NEXT_PUBLIC_DEBUG=trueSetup Langkah demi Langkah
Langkah 1: Clone dan Install Dependencies
# Clone repository (jika belum dilakukan)
# git clone https://github.com/yourorg/yomu.git
# Java backend
cd yomu-backend-java
./gradlew build
# Rust backend
cd ../yomu-backend-rust
cargo build
# Frontend
cd ../yomu-frontend
bun installLangkah 2: Mulai Infrastructure (PostgreSQL + Redis)
Ketiga service menggunakan infrastruktur Docker Compose yang sama.
cd yomu-backend-rust
docker compose -f docker-compose.dev.yml build
docker compose -f docker-compose.dev.yml up -dVerifikasi container berjalan:
docker compose -f docker-compose.dev.yml psOutput yang diharapkan:
Name Command State Ports
--------------------------------------------------------------------------------------
yomu-postgres docker-entrypoint.sh postgres Up 0.0.0.0:5432->5432/tcp
yomu-redis redis-server --appendonly ... Up 0.0.0.0:6379->6379/tcpTunggu 5-10 detik agar PostgreSQL siap, lalu verifikasi konektivitas:
# Test PostgreSQL
psql -h localhost -U yomu_user -d yomu_local -c "SELECT 1"
# Test Redis
redis-cli -h localhost pingLangkah 3: Jalankan Rust Migrations
cd yomu-backend-rust
cargo sqlx database create
cargo sqlx migrate runVerifikasi:
cargo sqlx migrate statusLangkah 4: Mulai Java Backend
cd yomu-backend-java
./gradlew bootRunOutput yang diharapkan:
Started Application in X.XXX secondsVerifikasi:
curl http://localhost:8080/healthExpected response:
{"success":true,"message":"OK","data":{"status":"UP"}}Langkah 5: Mulai Rust Backend
cd yomu-backend-rust
cargo runOutput yang diharapkan:
Listening on http://0.0.0.0:8081Verifikasi:
curl http://localhost:8081/healthExpected response:
{"success":true,"message":"OK","data":{}}Langkah 6: Mulai Frontend
cd yomu-frontend
bun run devOutput yang diharapkan:
Local: http://localhost:3000Verifikasi: Buka http://localhost:3000 di browser.
Docker Compose Quick Start
Jalankan semua service dengan satu perintah:
# Build semua images
cd yomu-backend-rust
docker compose -f docker-compose.dev.yml build
# Mulai semua services
docker compose -f docker-compose.dev.yml up -d
# Lihat logs
docker compose -f docker-compose.dev.yml logs -fTesting Commands
Java Backend
cd yomu-backend-java
# Jalankan semua tests
./gradlew test
# Jalankan test class spesifik
./gradlew test --tests "yomu.auth.AuthenticationControllerTest"
# Jalankan dengan coverage
./gradlew test jacocoTestReportRust Backend
cd yomu-backend-rust
# Jalankan semua tests
cargo test
# Jalankan test module spesifik
cargo test --package gamification --lib modules::gamification::tests
# Jalankan dengan coverage (memerlukan grcov)
cargo tarpaulin
# Jalankan nextest (lebih lambat tapi parallel)
cargo nextest runFrontend
cd yomu-frontend
# Build untuk produksi
bun run build
# Jalankan type check
bun run typecheck
# Jalankan lint (ESLint)
bun run lintMasalah Umum dan Perbaikan
Masalah 1: Port Sudah Digunakan
Error: Cannot start service java: Bind failed for port 8080Perbaikan:
# Temukan proses yang menggunakan port 8080
lsof -i :8080
# Hentikan
kill -9 <PID>
# Atau ubah port di docker-compose.dev.ymlMasalah 2: Error Migrasi SQLx Rust
error: configuration file not foundPerbaikan:
# Pastikan .sqlx/config.json ada
cd yomu-backend-rust
cargo sqlx migrate setupMasalah 3: Frontend Tidak Bisa Terhubung ke BFF
Error: Network error while fetching /api/v1/...Perbaikan:
# Pastikan variabel NEXT_PUBLIC_* sudah diatur dengan benar di .env.local
# Restart frontend setelah perubahan .env
bun run devMasalah 4: Koneksi PostgreSQL Ditolak
ERROR: database "yomu_local" is not accepting connectionsPerbaikan:
# Tunggu PostgreSQL siap
sleep 10
# Atau periksa logs PostgreSQL
docker compose -f docker-compose.dev.yml logs postgresDiagram Setup Pengembangan Lokal Lengkap
Development Cheat Sheet
| Tugas | Command |
|---|---|
| Mulai semua services | cd yomu-backend-rust && docker compose -f docker-compose.dev.yml up -d |
| Mulai Java backend | cd yomu-backend-java && ./gradlew bootRun |
| Mulai Rust backend | cd yomu-backend-rust && cargo run |
| Mulai frontend | cd yomu-frontend && bun run dev |
| Jalankan Java tests | cd yomu-backend-java && ./gradlew test |
| Jalankan Rust tests | cd yomu-backend-rust && cargo test |
| Format Rust | cd yomu-backend-rust && cargo fmt |
| Lint Rust | cd yomu-backend-rust && cargo clippy |
| Build frontend | cd yomu-frontend && bun run build |
Langkah Selanjutnya
Setelah setup selesai:
- Keputusan Desain — Pelajari tentang Architecture dan pilihan teknologi
- Panduan Pengembangan — Gambaran umum pengembangan lokal
- API Reference — Endpoint API detail (segera hadir)