RESTful API Backend untuk sistem manajemen pengumpulan sampah Gerobaks - Menghubungkan pengguna dengan mitra pengumpul sampah secara efisien.
| Resource | URL |
|---|---|
| π Production API | https://gerobaks.dumeg.com |
| π Swagger API Docs | https://gerobaks.dumeg.com/api/documentation |
| π Sentry Dashboard | https://sentry.io/gerobaks |
| π Changelog | GitHub Commits |
| π Issue Tracker | GitHub Issues |
| π¨βπ» Developer | @fk0u |
| π Repository | https://github.com/fk0u/gerobackend |
- π Authentication & Authorization - Laravel Sanctum with role-based access control
- οΏ½ Schedule Management - Complete CRUD with mobile app format support
- π Real-time Tracking - GPS tracking for mitra location
- π° Payment & Balance System - Top-up, withdrawal, and transaction history
- β Rating & Feedback - User rating and feedback system
- π¬ Chat System - Real-time messaging between users and mitra
- π Notifications - Push notifications for schedule updates
- π Dashboard Analytics - Comprehensive statistics for users and mitra
- π« Subscription Management - Multiple subscription plans
- π¨βπΌ Admin Panel - Complete admin management features
Sentry sudah terintegrasi untuk monitoring error di production secara real-time.
composer require sentry/sentry-laravel
php artisan sentry:publish --dsnTambahkan ke .env production:
# Sentry Configuration
SENTRY_LARAVEL_DSN=https://[your-key]@[region].ingest.sentry.io/[project-id]
SENTRY_TRACES_SAMPLE_RATE=1.0
SENTRY_ENVIRONMENT=production
SENTRY_RELEASE=[email protected]Cara mendapatkan DSN:
- Login ke sentry.io
- Create project "gerobaks-backend" (Laravel PHP)
- Copy DSN dari Settings β Client Keys (DSN)
- Paste ke
.envproduction
File konfigurasi sudah include:
<?php
return [
'dsn' => env('SENTRY_LARAVEL_DSN'),
'environment' => env('SENTRY_ENVIRONMENT', env('APP_ENV', 'production')),
'release' => env('SENTRY_RELEASE'),
'sample_rate' => (float) env('SENTRY_TRACES_SAMPLE_RATE', 1.0),
'traces_sample_rate' => (float) env('SENTRY_TRACES_SAMPLE_RATE', 1.0),
'send_default_pii' => false, // Jangan kirim data personal
'breadcrumbs' => [
'logs' => true,
'sql_queries' => true,
'sql_bindings' => true,
'queue_info' => true,
'command_info' => true,
],
'integrations' => [
\Sentry\Laravel\Integration::class,
],
'before_send' => function (\Sentry\Event $event): ?\Sentry\Event {
// Filter error yang tidak perlu dilaporkan
if (str_contains($event->getMessage() ?? '', 'TokenMismatchException')) {
return null;
}
return $event;
},
];Test apakah Sentry sudah terkoneksi:
php artisan sentry:testAtau test manual dengan melempar exception:
Route::get('/sentry-test', function () {
throw new Exception('Sentry test exception dari production!');
});Akses https://gerobaks.dumeg.com/sentry-test β error akan muncul di Sentry dashboard.
Dashboard URL: https://sentry.io/organizations/gerobaks/projects/
Fitur yang bisa dipantau:
- π Issues - Error grouping dengan stacktrace lengkap
- π Performance - API response time & slow queries
- π Releases - Track error per deployment
- π€ User Context - Error yang dialami user tertentu (tanpa PII)
- π Alerts - Email/Slack notification untuk error critical
Alert Setup:
- Buka project di Sentry
- Settings β Alerts β Create Alert Rule
- Contoh rule:
- Name: Critical API Errors
- Conditions: When error count > 10 in 5 minutes
- Actions: Send email to [email protected]
Track custom events di code:
use Sentry\Laravel\Facades\Sentry;
// Capture exception dengan context
try {
$schedule = Schedule::create($data);
} catch (\Exception $e) {
Sentry::captureException($e, [
'tags' => ['component' => 'schedule-create'],
'extra' => [
'user_id' => auth()->id(),
'mitra_id' => $data['mitra_id'] ?? null,
],
]);
throw $e;
}
// Capture custom message
Sentry::captureMessage('Schedule bulk import failed', [
'level' => 'warning',
'extra' => ['count' => $failedCount],
]);Track slow API endpoints:
// config/sentry.php
'traces_sample_rate' => 0.2, // Sample 20% requests untuk performanceSentry akan otomatis track:
- Database query performance
- HTTP request duration
- External API calls
- Job queue processing time
API Documentation sudah terintegrasi dengan GitHub untuk menampilkan changelog terbaru.
Buka https://gerobaks.dumeg.com/api/documentation
Tab Changelog menampilkan:
- π Commit terbaru dari repository
- π¨βπ» Author & timestamp
- π Commit message
- π Link ke GitHub commit detail
File konfigurasi di config/l5-swagger.php:
'changelog' => [
'enabled' => env('SWAGGER_CHANGELOG_ENABLED', true),
'github_repo' => env('GITHUB_REPO', 'fk0u/gerobackend'),
'github_token' => env('GITHUB_TOKEN', null), // Optional untuk public repo
'cache_ttl' => env('CHANGELOG_CACHE_TTL', 3600), // Cache 1 jam
'limit' => env('CHANGELOG_LIMIT', 20), // Tampilkan 20 commit terakhir
],Environment Variables (.env):
# GitHub Changelog Configuration
SWAGGER_CHANGELOG_ENABLED=true
GITHUB_REPO=fk0u/gerobackend
GITHUB_TOKEN= # Opsional, untuk private repo atau rate limit lebih tinggi
CHANGELOG_CACHE_TTL=3600
CHANGELOG_LIMIT=20Untuk private repository atau rate limit lebih tinggi:
- Buka GitHub Settings β Developer Settings β Personal Access Tokens
- Generate new token (classic)
- Permissions:
repo(untuk private) ataupublic_repo(untuk public) - Copy token dan paste ke
.env:
GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFile app/Http/Controllers/Api/ChangelogController.php handle fetching commits:
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
class ChangelogController extends Controller
{
public function index(Request $request)
{
$repo = config('l5-swagger.changelog.github_repo');
$token = config('l5-swagger.changelog.github_token');
$limit = $request->get('limit', config('l5-swagger.changelog.limit', 20));
$cacheKey = "github_changelog_{$repo}_{$limit}";
$cacheTtl = config('l5-swagger.changelog.cache_ttl', 3600);
$commits = Cache::remember($cacheKey, $cacheTtl, function () use ($repo, $token, $limit) {
$url = "https://api.github.com/repos/{$repo}/commits?per_page={$limit}";
$response = Http::withHeaders([
'Accept' => 'application/vnd.github.v3+json',
'Authorization' => $token ? "token {$token}" : null,
])->get($url);
if (!$response->successful()) {
return [];
}
return collect($response->json())->map(function ($commit) {
return [
'sha' => substr($commit['sha'], 0, 7),
'message' => $commit['commit']['message'],
'author' => $commit['commit']['author']['name'],
'email' => $commit['commit']['author']['email'],
'date' => $commit['commit']['author']['date'],
'url' => $commit['html_url'],
];
});
});
return response()->json([
'success' => true,
'data' => [
'repository' => $repo,
'commits' => $commits,
'total' => $commits->count(),
],
]);
}
public function clearCache()
{
Cache::flush();
return response()->json([
'success' => true,
'message' => 'Changelog cache cleared successfully',
]);
}
}Route (routes/api.php):
Route::get('/changelog', [ChangelogController::class, 'index']);
Route::post('/changelog/clear-cache', [ChangelogController::class, 'clearCache'])->middleware('auth:sanctum');File resources/views/vendor/l5-swagger/index.blade.php sudah include tab Changelog:
<!-- Changelog Tab -->
<div id="changelog-tab" class="tab-pane">
<h3>π Latest Changes</h3>
<div id="changelog-container">
<p>Loading changelog from GitHub...</p>
</div>
</div>
<script>
// Fetch changelog dari API
fetch("/api/changelog")
.then((res) => res.json())
.then((data) => {
const container = document.getElementById("changelog-container");
if (!data.success || !data.data.commits.length) {
container.innerHTML = "<p>No commits found.</p>";
return;
}
const commitsHtml = data.data.commits
.map(
(commit) => `
<div class="commit-item">
<div class="commit-header">
<span class="commit-sha">${commit.sha}</span>
<span class="commit-date">${new Date(
commit.date
).toLocaleDateString()}</span>
</div>
<div class="commit-message">${commit.message}</div>
<div class="commit-meta">
<span class="commit-author">π€ ${commit.author}</span>
<a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%3Cspan+class%3D"pl-s1">${commit.url}" target="_blank">View on GitHub β</a>
</div>
</div>
`
)
.join("");
container.innerHTML = commitsHtml;
})
.catch((err) => {
console.error("Failed to load changelog:", err);
document.getElementById("changelog-container").innerHTML =
'<p class="error">Failed to load changelog. Check console for details.</p>';
});
</script>Jika changelog tidak update:
# Via artisan
php artisan cache:clear
# Via API (dengan auth)
curl -X POST https://gerobaks.dumeg.com/api/changelog/clear-cache \
-H "Authorization: Bearer YOUR_TOKEN"GitHub API rate limit:
- Without token: 60 requests/hour
- With token: 5000 requests/hour
Cache TTL default 1 jam sudah cukup untuk menghindari rate limit.
- PHP >= 8.1
- Composer
- MySQL >= 8.0
- Laravel 10.x
- Clone the repository
git clone https://github.com/fk0u/gerobackend.git
cd gerobackend- Install dependencies
composer install- Environment setup
cp .env.example .env
php artisan key:generate- Configure database (edit
.env)
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=gerobaks
DB_USERNAME=root
DB_PASSWORD=- Run migrations and seeders
php artisan migrate --seed- Start development server
php artisan serveAPI akan berjalan di http://127.0.0.1:8000
POST /api/register- Register new userPOST /api/login- Login and get tokenGET /api/auth/me- Get current userPOST /api/auth/logout- Logout
GET /api/schedules- Get all schedulesPOST /api/schedules- Create schedule (mitra/admin)POST /api/schedules/mobile- Create schedule (end_user)PATCH /api/schedules/{id}- Update schedulePOST /api/schedules/{id}/complete- Complete schedulePOST /api/schedules/{id}/cancel- Cancel schedule
GET /api/tracking- Get tracking dataPOST /api/tracking- Create tracking pointGET /api/tracking/schedule/{id}- Get tracking by schedule
π See full documentation: API_DOCUMENTATION_COMPLETE.md
Email: [email protected]
Password: password123
Role: end_user
Email: [email protected]
Password: mitra123
Role: mitra
Email: [email protected]
Password: admin123
Role: admin
- Complete API Documentation: API_DOCUMENTATION_COMPLETE.md
- Deployment Guide: DEPLOYMENT.md
- Database ERD: ERD_COMPLIANCE_SUMMARY.md
- API Changelog: CHANGELOG.md
curl http://127.0.0.1:8000/api/healthcurl -X POST http://127.0.0.1:8000/api/login \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "password123"
}'php artisan test| Method | Endpoint | Deskripsi | Role |
|---|---|---|---|
| POST | /api/login |
Login dan mendapat token | Semua |
| POST | /api/logout |
Cabut token aktif | Authenticated |
| GET | /api/profile |
Profil user yang login | Semua |
| GET | /api/schedules |
Daftar jadwal pengambilan | end_user, mitra |
| GET | /api/orders |
Riwayat order dengan pagination | end_user |
| POST | /api/orders/{order}/cancel |
Batalkan order | end_user |
| GET | /api/tracking/{order} |
Posisi armada real-time | end_user |
| GET | /api/balance/summary |
Ringkasan saldo & poin | end_user |
| GET | /api/balance/ledger |
Riwayat transaksi saldo | end_user |
| GET | /api/notifications |
Feed notifikasi | Semua |
| POST | /api/notifications/{id}/read |
Tandai notifikasi dibaca | Semua |
| GET | /api/chats |
Daftar percakapan | end_user, mitra |
| POST | /api/chats |
Kirim pesan baru | end_user, mitra |
| POST | /api/payments/{order}/confirm |
Konfirmasi pembayaran | admin |
| POST | /api/ratings |
Kirim rating layanan | end_user |
Detail lengkap lihat file route
routes/api.phpdan masing-masing controller diapp/Http/Controllers/Api/.
| Role | Password | |
|---|---|---|
| Admin | [email protected] |
password |
| Mitra | [email protected] |
password |
| End User | [email protected] |
password |
Ubah kredensial sebelum produksi. Seeder dibuat untuk pengujian lokal.
php artisan optimize: Membersihkan cache konfigurasi & routephp artisan storage:link: Membuat symlink storage (bila butuh upload)php artisan make:module ...: Gunakan blueprint internal (lihatREADME-dev.mdbila ada)php artisan tinker: Eksperimen cepat dengan data
- Sentry Laravel SDK aktif pada channel log
stack(single,sentry). PastikanSENTRY_LARAVEL_DSNterisi pada.envproduksi. - Variabel
SENTRY_TRACES_SAMPLE_RATEdefault1.0untuk staging sehingga request dari aplikasi mobile tercatat lengkap. Turunkan nilainya (0.2β0.3) bila beban produksi meningkat. - Ganti
SENTRY_SEND_DEFAULT_PIIkefalsejika deployment tertentu tidak boleh mengirim data PII (email/IP) ke Sentry. - Gunakan tombol "Ping" dan "Use Server" di halaman dokumentasi internal (Blade
docs/index.blade.php) untuk menguji health check API sebelum rilis mobile.
php artisan test # Menjalankan seluruh test suite
php artisan test --filter=OrderTestTambahkan test baru di folder tests/Feature untuk flow API dan tests/Unit untuk logika helper.
Deployment ke cPanel bisa selesai dalam ~20 menit!
# Windows
cd backend
deploy-prepare.bat
# Linux/Mac
chmod +x deploy-prepare.sh
./deploy-prepare.sh- Login ke cPanel: https://gerobaks.dumeg.com:2083
- File Manager β Upload ZIP yang di-generate
- Extract di
public_html/
# Via SSH (Recommended)
ssh [email protected]
cd public_html/backend
chmod +x deploy-server.sh
./deploy-server.shcurl https://gerobaks.dumeg.com/api/health
# Expected: {"status":"ok"}Kami menyediakan dokumentasi deployment yang lengkap dan terstruktur:
| File | Description | When to Use |
|---|---|---|
| START_HERE.md | πΊοΈ Navigator & decision tree | Bingung mulai dari mana |
| QUICKSTART-CPANEL.md | β‘ Quick deployment guide (~20 min) | First-time deployment |
| DEPLOYMENT.md | π Complete reference (400+ lines) | Troubleshooting & details |
| DEPLOYMENT_FILES_SUMMARY.md | π¦ File list & explanation | Overview semua tools |
| API_CREDENTIALS.md | π Test accounts & credentials | Butuh login info |
| BACKEND_API_VERIFICATION.md | β Test results & procedures | Verify API working |
| Script | Platform | Purpose |
|---|---|---|
deploy-prepare.sh |
Linux/Mac | Local preparation & packaging |
deploy-prepare.bat |
Windows | Local preparation & packaging |
deploy-server.sh |
Server (SSH) | Server-side deployment |
Verify API functionality before production:
php test_api_comprehensive.php # Test all endpoints
php test_cors.php # Verify CORS headers
php test_login.php # Quick login test- Set
APP_ENV=productiondanAPP_DEBUG=false - Database MySQL configured (tidak pakai SQLite)
- SSL certificate active (HTTPS)
- Run migrations:
php artisan migrate --force - Run seeders:
php artisan db:seed --force - Optimize caches:
php artisan config:cache && route:cache - Set permissions:
chmod -R 755 storage bootstrap/cache - Test endpoints: All return JSON dengan CORS headers
- Update Flutter app: Change
apiBaseUrlto production URL - Monitor logs:
tail -f storage/logs/laravel.log
- API Base: https://gerobaks.dumeg.com
- API Docs: https://gerobaks.dumeg.com/docs
- Health Check: https://gerobaks.dumeg.com/api/health
- cPanel: https://gerobaks.dumeg.com:2083
| Issue | Quick Fix |
|---|---|
| 500 Error | php artisan config:clear |
| Database Error | Check .env credentials |
| Permission Error | chmod -R 755 storage bootstrap/cache |
| CORS Error | Already fixed in middleware, clear cache |
| 404 on /api/* | Check .htaccess, enable mod_rewrite |
Need detailed help? β Read DEPLOYMENT.md Troubleshooting section
- Branch utama:
main - Ikuti konvensi commit conventional (
feat:,fix:) - PR harus menyertakan test bila menyentuh business logic
- Jalankan
php artisan testsebelum push
- Engineering Lead: [email protected]
- Product: [email protected]
- Support Teknis: [email protected]
π΄ CLOSED SOURCE LICENSE
Seluruh kode sumber, aset, dan dokumentasi adalah milik eksklusif Gerobaks.
Dilarang untuk:
- Mendistribusikan atau mempublikasikan ulang kode
- Melakukan reverse engineering
- Membuat karya turunan tanpa izin
- Menggunakan untuk kepentingan komersial tanpa persetujuan tertulis
Permintaan kerjasama dan perizinan: [email protected]
π± Gerobaks API β Mendukung ekosistem pengelolaan sampah yang bersih dan berkelanjutan. π±