docs: update backend readme

This commit is contained in:
mwpn
2026-03-05 14:45:01 +07:00
parent b4fda6b9c9
commit cea6b06638

143
README.md
View File

@@ -1,69 +1,120 @@
# CodeIgniter 4 Application Starter
# SMAN 1 Garut Backend Presensi Siswa
## What is CodeIgniter?
Backend presensi siswa berbasis **CodeIgniter 4** untuk:
CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure.
More information can be found at the [official site](https://codeigniter.com).
- 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).
This repository holds a composer-installable app starter.
It has been built from the
[development repository](https://github.com/codeigniter4/CodeIgniter4).
Backend ini biasanya dipakai bersama:
- Frontend mobile: folder `../mobile` (repo terpisah).
- Face embedding service: folder `../face-service` (FastAPI + InsightFace).
More information about the plans for version 4 can be found in [CodeIgniter 4](https://forum.codeigniter.com/forumdisplay.php?fid=28) on the forums.
## 1. Kebutuhan Server
You can read the [user guide](https://codeigniter.com/user_guide/)
corresponding to the latest version of the framework.
- PHP **8.2+** dengan ekstensi:
- `intl`, `mbstring`, `json`, `curl`, `gd`, `mysqli`/`mysqlnd`.
- MySQL/MariaDB.
- Composer.
## Installation & updates
## 2. Setup Cepat (Development)
`composer create-project codeigniter4/appstarter` then `composer update` whenever
there is a new release of the framework.
Di folder `backend`:
When updating, check the release notes to see if there are any changes you might need to apply
to your `app` folder. The affected files can be copied or merged from
`vendor/codeigniter4/framework/app`.
```bash
composer install
cp env .env # atau copy manual
```
## Setup
Edit `.env`:
Copy `env` to `.env` and tailor for your app, specifically the baseURL
and any database settings.
```ini
app.baseURL = 'http://localhost/sman1/backend/public/'
## Important Change with index.php
database.default.hostname = localhost
database.default.database = absen_sman1
database.default.username = root
database.default.password = your_password
`index.php` is no longer in the root of the project! It has been moved inside the *public* folder,
for better security and separation of components.
telegram.bot_token = your_telegram_bot_token
telegram_bot_token = your_telegram_bot_token
This means that you should configure your web server to "point" to your project's *public* folder, and
not to the project root. A better practice would be to configure a virtual host to point there. A poor practice would be to point your web server to the project root and expect to enter *public/...*, as the rest of your logic and the
framework are exposed.
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
```
**Please** read the user guide for a better explanation of how CI4 works!
Jalankan migration & seeder yang diperlukan:
## Repository Management
```bash
php spark migrate --all
php spark db:seed DeviceSeeder
php spark db:seed StudentMobileAccountsSeeder # opsional untuk dummy data
```
We use GitHub issues, in our main repository, to track **BUGS** and to track approved **DEVELOPMENT** work packages.
We use our [forum](http://forum.codeigniter.com) to provide SUPPORT and to discuss
FEATURE REQUESTS.
Jalankan server dev:
This repository is a "distribution" one, built by our release preparation script.
Problems with it can be raised on our forum, or as issues in the main repository.
```bash
php spark serve
```
## Server Requirements
Lalu akses:
PHP version 8.2 or higher is required, with the following extensions installed:
- Dashboard: `http://localhost:8080` atau `http://localhost/sman1/backend/public` (sesuai web server).
- API mobile: `http://localhost/sman1/backend/public/api/mobile/...`.
- [intl](http://php.net/manual/en/intl.requirements.php)
- [mbstring](http://php.net/manual/en/mbstring.installation.php)
## 3. Modul Utama
> [!WARNING]
> - The end of life date for PHP 7.4 was November 28, 2022.
> - The end of life date for PHP 8.0 was November 26, 2023.
> - The end of life date for PHP 8.1 was December 31, 2025.
> - If you are still using below PHP 8.2, you should upgrade immediately.
> - The end of life date for PHP 8.2 will be December 31, 2026.
- `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.
Additionally, make sure that the following extensions are enabled in your PHP:
Struktur detail endpoint dan flow presensi dijelaskan di:
- json (enabled by default - don't turn it off)
- [mysqlnd](http://php.net/manual/en/mysqlnd.install.php) if you plan to use MySQL
- [libcurl](http://php.net/manual/en/curl.requirements.php) if you plan to use the HTTP\CURLRequest library
- `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.