Skip to content

About

Fondasi API Gateway untuk ekosistem UMKM.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

20 Commits

Folders and files

Repository files navigation

API Integrator Gateway

Menyediakan spesifikasi produk untuk modul API Integrator yang menjadi pintu masuk semua komunikasi antar aplikasi dalam ekosistem UMKM. API Integrator memastikan routing, keamanan, validasi, logging, dan standarisasi semua request sebelum diteruskan ke SmartBank atau layanan lain.

Kebutuhan

  • Docker Desktop dengan Docker Compose v2; atau
  • Node.js 24 LTS dan npm 11; serta
  • Go 1.26.4 atau lebih baru; dan
  • MySQL Community Server 9.7 untuk setup tanpa Docker.

Setup tercepat dengan Docker

Salin konfigurasi contoh:

Copy-Item .env.example .env

Jalankan seluruh layanan:

docker compose up --build

Layanan yang tersedia:

  • Frontend: http://localhost:5173
  • Frontend login: http://localhost:5173/login
  • Backend health check: http://localhost:8080/health
  • Backend landing content: http://localhost:8080/landing
  • Backend login: POST http://localhost:8080/auth/login
  • Backend current user: GET http://localhost:8080/auth/me
  • Backend notifications: GET http://localhost:8080/notifications
  • Backend mark notifications read: POST http://localhost:8080/notifications/read
  • Backend gateway payment: POST http://localhost:8080/gateway/payment
  • Backend gateway SmartBank: POST http://localhost:8080/gateway/smartbank
  • Backend gateway Marketplace: POST http://localhost:8080/gateway/marketplace
  • Backend gateway LogistiKita: POST http://localhost:8080/gateway/logistics
  • Backend gateway SupplierHub: POST http://localhost:8080/gateway/supplier
  • MySQL: localhost:3306 secara default

Hentikan layanan dengan docker compose down. Data MySQL dipertahankan pada named volume mysql_data. Gunakan docker compose down --volumes hanya jika data lokal memang ingin dihapus.

Nilai pada .env.example hanya untuk development. Ubah password dan jangan commit file .env. Jika port MySQL host sudah digunakan, ubah MYSQL_HOST_PORT pada .env; port internal DB_PORT tetap 3306. Seed user hanya ditujukan untuk development dan otomatis ditolak ketika APP_ENV=production.

Setup lokal tanpa Docker

Frontend

Set-Location frontend
npm.cmd ci
npm.cmd run dev

Gunakan npm.cmd bila PowerShell menolak menjalankan npm.ps1 karena execution policy.

Backend

Pastikan MySQL sudah aktif, lalu siapkan environment:

$env:APP_ENV = "development"
$env:BACKEND_PORT = "8080"
$env:DB_HOST = "localhost"
$env:DB_PORT = "3306"
$env:DB_NAME = "api_integrator"
$env:DB_USER = "gateway"
$env:DB_PASSWORD = "your-local-password"
$env:JWT_SECRET = "minimum-32-character-secret-change-this"
$env:JWT_TTL = "1h"
$env:JWT_ISSUER = "api-integrator-gateway"
$env:SEED_USERS_ENABLED = "false"
$env:GATEWAY_SMARTBANK_URL = ""
$env:GATEWAY_MARKETPLACE_URL = ""
$env:GATEWAY_LOGISTICS_URL = ""
$env:GATEWAY_SUPPLIERHUB_URL = ""

Set-Location backend
go run ./cmd/server

Backend membuka koneksi MySQL dan menjalankan migration Goose saat startup. Jika seed diaktifkan, seluruh username/password seed wajib tersedia melalui environment variables yang dicontohkan pada .env.example.

Landing page Sprint 2

Landing page dapat diakses tanpa login dan menyediakan:

  • Penjelasan layanan dan manfaat API Integrator.
  • Alur request dari aplikasi menuju gateway dan layanan tujuan.
  • Peran SmartBank, Marketplace, POS, SupplierHub, LogistiKita, UMKM Insight, dan API Gateway.
  • Use case integrasi, FAQ, serta tautan ke repositori.
  • Navigasi responsif dengan dukungan keyboard dan mobile menu.

CTA login membuka halaman autentikasi Sprint 4. Landing page tetap dapat diakses tanpa sesi.

Authentication backend Sprint 3

Login menggunakan kombinasi username, password, dan app_name:

POST /auth/login
Content-Type: application/json

{
  "username": "admin",
  "password": "admin-development-password",
  "app_name": "API Gateway"
}

Response sukses berisi JWT HS256, role, aplikasi, dashboard tujuan, dan waktu kedaluwarsa. Token memuat sub, username, role, app_name, iss, iat, nbf, dan exp.

Validasi token:

GET /auth/me
Authorization: Bearer <token>

Role yang tersedia:

  • admin_gateway → /dashboard/admin
  • app_user → /dashboard/user
  • monitoring_user → /dashboard/monitoring

POST /auth/logout tidak tersedia karena token bersifat stateless. Sprint 4 melakukan logout dengan menghapus token di sisi frontend.

Authentication frontend Sprint 4

Frontend menyediakan route:

  • /login untuk autentikasi.
  • /dashboard/admin untuk admin_gateway.
  • /dashboard/user untuk app_user.
  • /dashboard/monitoring untuk monitoring_user.

Login meminta username, password, dan aplikasi. JWT disimpan sebagai satu item access_token pada localStorage, dipasang sebagai Bearer token oleh Axios, dan diverifikasi kembali melalui GET /auth/me ketika halaman dimuat ulang. Response 401, token kedaluwarsa, dan logout akan menghapus token lokal. Pengguna yang mencoba membuka dashboard role lain diarahkan ke dashboard milik role mereka.

Kredensial seed development:

Role Username Password Aplikasi
admin_gateway admin admin-development-password API Gateway
app_user marketplace marketplace-development-password Marketplace
monitoring_user insight insight-development-password UMKM Insight

Kredensial tersebut hanya untuk development dan harus diganti pada environment bersama. Dashboard Sprint 4 masih berupa placeholder; data operasional admin dan user dijadwalkan pada sprint dashboard berikutnya.

Notifications Sprint 9

Endpoint notifikasi memakai JWT Bearer token dan table notifications dari Sprint 5. Role visibility:

  • admin_gateway: melihat semua notifikasi.
  • monitoring_user: melihat semua notifikasi.
  • app_user: hanya melihat notifikasi milik app_name pada token.

GET /notifications?page=1&limit=10 mengembalikan notifikasi terbaru, unread count, dan metadata pagination. limit default 10 dan maksimum 50.

{
  "status": "success",
  "data": {
    "notifications": [
      {
        "id": 1,
        "created_at": "2026-06-21T00:00:00Z",
        "app_name": "Marketplace",
        "type": "api_inactive",
        "message": "API Marketplace tidak aktif selama lebih dari 1 minggu.",
        "is_read": false
      }
    ],
    "unread_count": 1,
    "page": 1,
    "limit": 10
  }
}

POST /notifications/read menerima salah satu body berikut:

{ "notification_id": 1 }
{ "all": true }

Response sukses:

{
  "status": "success",
  "data": {
    "unread_count": 0
  }
}

Backend scheduler membuat alert saat startup lalu setiap 5 menit untuk api_inactive, error_rate, dan response_time. Alert didedup berdasarkan app_name + type selama 24 jam.

Gateway routing Sprint 11

Endpoint gateway memakai JWT Bearer token dan mencatat setiap request valid ke table request_logs. Role admin_gateway dan app_user dapat memanggil endpoint gateway; monitoring_user mendapat 403 forbidden.

Upstream service dikonfigurasi lewat GATEWAY_SMARTBANK_URL, GATEWAY_MARKETPLACE_URL, GATEWAY_LOGISTICS_URL, dan GATEWAY_SUPPLIERHUB_URL. Nilai kosong berarti request diterima untuk development smoke test, tetapi tidak diteruskan keluar (forwarded=false, upstream=not_configured).

Endpoint yang tersedia:

  • POST /gateway/payment dengan body { from_app, from_user, to_user, amount, metadata, service_type }.
  • POST /gateway/smartbank dengan body { action, payload }.
  • POST /gateway/marketplace dengan body { action, payload }.
  • POST /gateway/logistics dengan body { order_id, address, distance, shipping_type }.
  • POST /gateway/supplier dengan body { supplier_id, material, qty, total_cost }.

Response sukses selalu dibungkus sebagai { "status": "success", "data": { ... } }. Payload tidak valid menghasilkan 400, token tidak ada menghasilkan 401, role tidak sesuai menghasilkan 403, dan kegagalan upstream menghasilkan 502.

Test dan build

Frontend:

Set-Location frontend
npm.cmd test
npm.cmd run lint
npm.cmd run build

Backend:

Set-Location backend
go test ./...
go test -race ./...
go vet ./...
go build ./cmd/server

Validasi Docker:

Copy-Item .env.example .env
docker compose config --quiet
docker compose build --pull
docker compose up --detach
docker compose ps

Struktur proyek

.
|-- backend/
|   |-- cmd/server/          # Entrypoint HTTP server
|   |-- config/              # Environment configuration
|   `-- internal/
|       |-- auth/            # Bcrypt, JWT, login service, dan seed
|       |-- gateway/         # Gateway routing, validation, forwarder, dan logging
|       |-- notification/    # Service notifikasi, alert generator, dan scheduler
|       |-- database/        # Koneksi dan migration Goose
|       |-- model/           # Model dan role user
|       |-- repository/      # Repository MySQL
|       `-- server/          # Fiber app factory, middleware, dan routes
|-- frontend/
|   `-- src/
|       |-- auth/            # Context sesi, route guard, dan token storage
|       |-- components/      # Komponen UI bersama dan landing page
|       |-- data/            # Konten statis landing page
|       |-- pages/           # Landing, login, dan placeholder dashboard
|       |-- services/        # Axios API client dan interceptor
|       `-- test/            # Setup pengujian frontend
|-- docs/
|   |-- architecture/       # Diagram dan dokumentasi arsitektur
|   |-- development/        # Panduan teknis pengembangan
|   |-- planning/           # Roadmap implementasi sprint
|   |-- project-management/ # Backlog dan administrasi proyek
|   |-- requirements/       # Kebutuhan dan kontrak produk
|   |-- report/             # Laporan pelaksanaan sprint
|   `-- misc/source-data/   # Data sumber tugas besar
|-- .github/workflows/       # Continuous integration
|-- AGENTS.md                 # Aturan TDD dan checklist Docker per sprint
`-- compose.yaml             # Frontend, backend, dan MySQL

Kontrak health check

GET /health menghasilkan HTTP 200:

{
  "status": "success",
  "data": {
    "service": "api-integrator-gateway",
    "environment": "development"
  }
}

Kontrak landing page

GET /landing bersifat publik dan menghasilkan HTTP 200 dengan struktur:

{
  "status": "success",
  "data": {
    "service_overview": {},
    "application_roles": [],
    "integration_flow": [],
    "contact_info": {
      "repository_url": "https://github.com/airdanapi/API_Integrator_gateway",
      "login_status": "available"
    }
  }
}

About

Fondasi API Gateway untuk ekosistem UMKM.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages