Files
presensi/README.md

121 lines
4.2 KiB
Markdown
Raw Permalink Normal View History

2026-03-05 14:45:01 +07:00
# SMAN 1 Garut Backend Presensi Siswa
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
Backend presensi siswa berbasis **CodeIgniter 4** untuk:
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
- Presensi masuk/pulang & permapel (QR).
- Zona lokasi (geofence) & pengaturan jam masuk/pulang.
- Akun mobile siswa (NISN + PIN).
- Portal orang tua & poin pelanggaran.
- Integrasi foto formal + verifikasi wajah (via service AI eksternal).
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
Backend ini biasanya dipakai bersama:
- Frontend mobile: folder `../mobile` (repo terpisah).
- Face embedding service: folder `../face-service` (FastAPI + InsightFace).
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
## 1. Kebutuhan Server
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
- PHP **8.2+** dengan ekstensi:
- `intl`, `mbstring`, `json`, `curl`, `gd`, `mysqli`/`mysqlnd`.
- MySQL/MariaDB.
- Composer.
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
## 2. Setup Cepat (Development)
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
Di folder `backend`:
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
```bash
composer install
cp env .env # atau copy manual
```
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
Edit `.env`:
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
```ini
app.baseURL = 'http://localhost/sman1/backend/public/'
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
database.default.hostname = localhost
database.default.database = absen_sman1
database.default.username = root
database.default.password = your_password
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
telegram.bot_token = your_telegram_bot_token
telegram_bot_token = your_telegram_bot_token
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
FACE_SERVICE_URL = 'http://localhost:5000'
FACE_EMBEDDING_DIM = 512
FACE_SIM_THRESHOLD = 0.85
FACE_MIN_SIZE = 80
FACE_MIN_BLUR = 30
FACE_MIN_BRIGHTNESS = 0.2
```
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
Jalankan migration & seeder yang diperlukan:
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
```bash
php spark migrate --all
php spark db:seed DeviceSeeder
php spark db:seed StudentMobileAccountsSeeder # opsional untuk dummy data
```
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
Jalankan server dev:
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
```bash
php spark serve
```
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
Lalu akses:
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
- Dashboard: `http://localhost:8080` atau `http://localhost/sman1/backend/public` (sesuai web server).
- API mobile: `http://localhost/sman1/backend/public/api/mobile/...`.
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
## 3. Modul Utama
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
- `Modules/Academic` kelas, mapel, guru, jadwal, siswa, Dapodik.
- `Modules/Attendance` checkin device, checkin QR mapel, laporan, `student_faces` + verifikasi wajah.
- `Modules/Mobile` API mobile (login NISN+PIN, registrasi PIN, checkinqr, checkinmasukpulang, status hari ini).
- `Modules/Devices` device absen, autentikasi device (code + api_key).
- `Modules/Dashboard` halaman dashboard + pengaturan presensi (zona + jam masuk/pulang).
- `Modules/Parent` portal orang tua (riwayat presensi & pelanggaran).
- `Modules/Discipline` kategori pelanggaran, poin, rekap siswa.
- `Modules/Notification` integrasi Telegram.
- `Modules/Face` penyimpanan embedding wajah (`student_faces`) + endpoint import/enroll.
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
Struktur detail endpoint dan flow presensi dijelaskan di:
2026-03-05 14:37:36 +07:00
2026-03-05 14:45:01 +07:00
- `docs/SETUP_PRESENSI.md` (jika ada).
- `docs/SYNC_FOTO_WAJAH.md` cara sync foto formal dari Google Drive + face hash.
## 4. Integrasi Face Embedding Service
Backend **tidak menghitung embedding wajah sendiri**, tapi memanggil service eksternal (lihat folder `../face-service`):
- Service Python (`FACE_SERVICE_URL`) menyediakan endpoint:
- `POST /embed` → menerima file gambar, mengembalikan:
- `embedding` float[],
- `faces_count`, `face_size`, `blur`, `brightness`, `quality_score`.
- `App\Modules\Face\Services\FaceService`:
- `extractEmbeddingWithQuality()` → kirim gambar ke `/embed`, terapkan quality gate.
- `cosineSimilarity()` → untuk matching saat verifyface.
### Alur singkat
1. **Import foto formal** (admin):
`POST /api/face/import-formal` → ambil foto dari URL (Google Drive/hasil sync) → simpan embedding `source='formal'` ke `student_faces`.
2. **Enroll live** (siswa, 35 frame):
`POST /api/face/enroll-live` → simpan beberapa embedding `source='live'` + satu `live_avg`.
3. **Verifikasi saat presensi**:
`POST /api/attendance/verify-face` → bandingkan embedding probe dengan semua embedding siswa → kembalikan `similarity`, `matched_source`, `status (match/no_match)`.
## 5. Catatan Git & Deployment
- File yang **tidak** ikut repo (lihat `.gitignore`):
- `.env`, `writable/*`, `vendor/`, direktori IDE, dll.
- Untuk produksi:
- Pastikan PHP 8.2+, ekstensi lengkap, dan baseURL `.env` sudah sesuai domain sekolah.
- Jalankan `php spark migrate --all` di server.
- Jalankan faceservice Python di host/port yang sama dengan `FACE_SERVICE_URL` di `.env`.
---
Kalau develop bareng frontend mobile, lihat juga `../mobile/README.md` untuk cara run klien presensi di HP/device.