Skip to content

janbu12/laravel-multiplatform-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

laravel-multi-platform-starter

Starter monorepo untuk aplikasi multi-platform dengan arsitektur:

  • backend-web -> Laravel Web + REST API (MySQL)
  • mobile-app -> NativePHP Mobile client (tanpa koneksi DB langsung)
  • desktop-app -> NativePHP Desktop client (tanpa koneksi DB langsung)

Arsitektur

Semua akses data dari mobile/desktop wajib melalui API backend:

mobile-app / desktop-app -> HTTPS -> backend-web -> MySQL image

Modul Yang Sudah Ada

1) backend-web

  • Laravel 12 + Livewire 4 (livewire/livewire) + Flux (livewire/flux)
  • Fortify untuk auth berbasis session (web login/register/reset/2FA views)
  • Sanctum token auth untuk client mobile/desktop
  • Model User sudah memakai HasApiTokens
  • Endpoint API auth:
    • POST /api/auth/register
    • POST /api/auth/login
    • GET /api/me (auth:sanctum)
    • POST /api/auth/logout (auth:sanctum)

File penting:

  • backend-web/routes/api.php
  • backend-web/app/Http/Controllers/Api/AuthController.php
  • backend-web/app/Models/User.php
  • backend-web/app/Providers/FortifyServiceProvider.php

2) mobile-app

  • Laravel 12 + NativePHP Mobile 3 (nativephp/mobile)
  • UI Tailwind untuk testing auth:
    • Login
    • Register
    • Me
    • Logout
  • API client service ke backend (BackendApi)
  • Token disimpan terenkripsi lokal (fallback aman) via Crypt:
    • storage/app/private/auth_token.enc
  • Fallback parser request body untuk kompatibilitas WebView form submit

File penting:

  • mobile-app/routes/web.php
  • mobile-app/app/Http/Controllers/MobileAuthController.php
  • mobile-app/app/Services/BackendApi.php
  • mobile-app/app/Support/AuthTokenStore.php
  • mobile-app/resources/views/mobile/*

3) desktop-app

  • Laravel 12 + NativePHP Desktop 2 (nativephp/desktop)
  • UI Tailwind untuk testing auth:
    • Login
    • Register
    • Me
    • Logout
  • API client service ke backend (BackendApi)
  • Token disimpan terenkripsi via NativePHP Settings + Crypt
  • Window bootstrap sudah diset:
    • ukuran awal 1280x800
    • min size 980x640
    • remember state
    • DevTools bisa ditoggle via env NATIVEPHP_OPEN_DEVTOOLS

File penting:

  • desktop-app/routes/web.php
  • desktop-app/app/Http/Controllers/DesktopAuthController.php
  • desktop-app/app/Services/BackendApi.php
  • desktop-app/app/Support/AuthTokenStore.php
  • desktop-app/app/Providers/NativeAppServiceProvider.php
  • desktop-app/resources/views/desktop/*

Prasyarat

  • PHP 8.3+ (direkomendasikan 8.4 di Windows/Herd)
  • Composer 2.x
  • Node.js + npm
  • MySQL server (contoh: Hostinger)
  • Untuk mobile: Android SDK/Emulator (NativePHP Mobile)
  • Untuk desktop: Electron dependencies (NativePHP Desktop)

Instalasi

1) Clone repo

git clone <repo-url> laravel-multi-platform-starter
cd laravel-multi-platform-starter

2) Setup backend-web

cd .\backend-web
composer install
npm install
copy .env.example .env
php artisan key:generate
php artisan migrate

Atur .env backend:

  • APP_URL=...
  • DB_HOST=...
  • DB_PORT=...
  • DB_DATABASE=...
  • DB_USERNAME=...
  • DB_PASSWORD=...

3) Setup mobile-app

cd ..\mobile-app
composer install
npm install
copy .env.example .env
php artisan key:generate
php artisan native:install

Atur .env mobile:

  • API_BASE_URL=http://IP_BACKEND:8000 (atau HTTPS domain backend)

Catatan: jangan isi credential DB backend di mobile app.

4) Setup desktop-app

cd ..\desktop-app
composer install
npm install
copy .env.example .env
php artisan key:generate
php artisan native:install

Atur .env desktop:

  • API_BASE_URL=http://IP_BACKEND:8000 (atau HTTPS domain backend)
  • NATIVEPHP_OPEN_DEVTOOLS=false

Catatan: jangan isi credential DB backend di desktop app.

Menjalankan Project

Backend

cd .\backend-web
php artisan serve

Mobile

cd .\mobile-app
php artisan native:run

Desktop

cd .\desktop-app
php artisan native:run

Test API Cepat (Backend)

Register:

curl.exe -X POST http://127.0.0.1:8000/api/auth/register `
  -H "Accept: application/json" `
  -H "Content-Type: application/json" `
  -d "{\"name\":\"Test\",\"email\":\"test@example.com\",\"password\":\"password123\",\"password_confirmation\":\"password123\",\"device_name\":\"postman\"}"

Login:

curl.exe -X POST http://127.0.0.1:8000/api/auth/login `
  -H "Accept: application/json" `
  -H "Content-Type: application/json" `
  -d "{\"email\":\"test@example.com\",\"password\":\"password123\",\"device_name\":\"postman\"}"

Me (gunakan token dari login):

curl.exe http://127.0.0.1:8000/api/me `
  -H "Accept: application/json" `
  -H "Authorization: Bearer TOKEN_ANDA"

Catatan Penting

  • Mobile/Desktop tidak boleh connect langsung ke MySQL.
  • Semua CRUD lewat backend-web API.
  • Auth web (session/Fortify) dan auth API (Sanctum token) dipisah dan bisa berjalan bersamaan.

About

Laravel multi-platform starter: one backend (Livewire + REST API + Sanctum) powering NativePHP Mobile and NativePHP Desktop clients.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors