# DFD - Sistem Informasi Desa

---

## 1. CONTEXT DIAGRAM (DFD Level 0)

```
+----------------------------------------------------------+
|                  SISTEM INFORMASI DESA                    |
|                                                          |
|  +------------+   +-----------+   +------------------+   |
|  | Homepage   |   | Profil    |   | Portal Berita    |   |
|  | & Banner   |   | Desa      |   | & Kategori       |   |
|  +------------+   +-----------+   +------------------+   |
|                                                          |
|  +------------+   +-----------+   +------------------+   |
|  | Layanan    |   | Pengaduan|   | Kontak & Pesan   |   |
|  | Dokumen    |   | Masyarakat|  |                  |   |
|  +------------+   +-----------+   +------------------+   |
|                                                          |
|  +------------+   +-----------+                          |
|  | Auth Admin |   | Dashboard|                          |
|  | Reset Pass |   | Filament  |                          |
|  +------------+   +-----------+                          |
+----------------------------------------------------------+
       ^                         ^
       |                         |
       | Data & Informasi       | Data & Informasi
       |                         |
+------+------+           +-----+------+
| MASYARAKAT  |           |   ADMIN    |
| (Pengunjung)|           | (Perangkat |
|             |           |  Desa)     |
+-------------+           +------------+
```

---

## 2. DFD LEVEL 1

### 2.1 Proses Homepage

```
+------------+                              +--------------+
| MASYARAKAT | ---> Lihat Halaman Depan --> | Proses 1.0   |
|            | <--- Tampilan Banner     --- | Homepage      |
+------------+                              +------+-------+
                                                   |
                                                   v
                                          +--------+--------+
                                          | Data Store      |
                                          | homebanners     |
                                          +-----------------+
```

| Data Store | Tabel | Deskripsi |
|---|---|---|
| D1 | homebanners | Banner homepage aktif (title, image, order, is_active) |

**Alur Data:**
- `HomeController@index` → query `HomeBanner::where('is_active', true)->orderBy('order')` → return `view('pages.homepage', compact('banners'))`

---

### 2.2 Proses Profil Desa & Potensi Desa

```
+------------+                              +--------------+
| MASYARAKAT | ---> Lihat Profil Desa ----> | Proses 2.0   |
|            | <--- Tampilan Profil      ---| Profil Desa  |
+------------+      & Potensi               +------+-------+
                                                   |
                          +------------------------+------------------------+
                          |                        |                        |
                          v                        v                        v
                 +--------+--------+    +-----------+--------+    +--------+--------+
                 | D2              |    | D3                |    | D2 (lagi)       |
                 | village_profiles|    | village_potentials|    | village_profiles |
                 | (Visi, Misi,    |    | (title, image,    |    | (Perangkat Desa)|
                 |  Sejarah,       |    |  description)     |    |                  |
                 |  Wilayah, dll)  |    +-------------------+    +-----------------+
                 +-----------------+
```

**Alur Data:**
- `PotensiDesaController@index` → query `PotensiDesa::all()` + `VillageProfile::first()` → return `view('pages.profildesa', compact('potensiDesa', 'profil'))`

---

### 2.3 Proses Portal Berita

```
+------------+                              +------------------+
| MASYARAKAT | ---> Lihat Berita --------> | Proses 3.0       |
|            | ---> Filter by Kategori --> | Portal Berita     |
|            | ---> Cari Berita --------> | + Berita Detail   |
|            | <--- Daftar Berita       ---|                   |
|            | <--- Detail Berita       ---|                   |
+------------+                             +--------+---------+
                                                     |
                    +--------------------------------+-------------------------------+
                    |                                |                               |
                    v                                v                               v
           +--------+--------+            +-----------+--------+          +-----------+--------+
           | D4              |            | D5                 |          | D6                 |
           | news            |            | news_categories    |          | authors            |
           | (title, slug,   |            | (title, slug)      |          | (name, avatar,     |
           |  content,       |            +--------------------+          |  username, bio)    |
           |  thumbnail,     |                                            +--------------------+
           |  is_featured,   |
           |  views)         |
           +--------+--------+
                    |
                    v
           +--------+--------+
           | D7              |
           | banners         |
           | (news_id)       |
           +-----------------+
```

**Alur Data:**
- `NewsController@index` → query `News::with(['author','newsCategory'])` + filter by category/search → paginate(9)
- `NewsController@show($slug)` → query `News::where('slug', $slug)` + increment views → return detail

---

### 2.4 Proses Layanan Dokumen Desa

```
+------------+                              +--------------+
| MASYARAKAT | ---> Lihat Dokumen -------> | Proses 4.0   |
|            | <--- Daftar Dokumen      ---| Layanan Desa |
+------------+      (Download)             +------+-------+
                                                   |
                                                   v
                                          +--------+--------+
                                          | D8              |
                                          | dokumen_desas   |
                                          | (nama, file)    |
                                          +-----------------+
```

**Alur Data:**
- `DokumenDesaController@index` → query `DokumenDesa::all()` → return `view('pages.layanan.layanan', compact('dokumen'))`

---

### 2.5 Proses Pengaduan Masyarakat

```
+------------+                              +------------------+
| MASYARAKAT | ---> Isi Form Pengaduan --> | Proses 5.1       |
|            |      (Nama, NIK, Email,     | Buat Pengaduan   |
|            |       Telepon, Kategori,    +--------+---------+
|            |       Isi, Lampiran)                 |
|            | <--- Nomor Tiket            |         |
|            |      (TKT-XXXXXXXX)         |         v
|            |                              |  +------+-------+
|            | ---> Cek Status           -->|  | Proses 5.2   |
|            |      (Input Kode Tiket)     |  | Simpan Data  |
|            | <--- Detail Status       ---|  +------+-------+
|            |                              |         |
|            | ---> Download Lampiran   -->|  +------+-------+
|            | <--- File Lampiran       ---|  | Proses 5.3   |
+------------+                              |  | Upload &     |
                                            |  | Enkripsi File|
                                            |  +------+-------+
                                            |         |
                                            +----+----+
                                                 |
                                                 v
                                        +--------+--------+
                                        | D9              |
                                        | pengaduans      |
                                        | (nama_lengkap,  |
                                        |  nik, email,    |
                                        |  telepon,       |
                                        |  kategori,      |
                                        |  isi_pengaduan, |
                                        |  lampiran,      |
                                        |  nomor_tiket,   |
                                        |  status)        |
                                        +-----------------+

+------------+                              +------------------+
| ADMIN      | ---> Lihat Daftar --------> | Proses 5.4       |
|            | ---> Update Status ------> | Admin Pengaduan  |
|            | ---> Hapus (Soft Delete)-> | (Filament CRUD)  |
|            | <--- Data Pengaduan     ---|                  |
+------------+                             +------------------+
```

**Alur Data Detail:**
- **5.1 Buat Pengaduan:** `PengaduanController@create` → return form with categories
- **5.2 Simpan Data:** `PengaduanController@store` → validasi → generate tiket → upload & enkripsi lampiran → DB::transaction → `Pengaduan::create(...)` → return JSON
- **5.3 Upload & Enkripsi:** File → `Crypt::encrypt()` → Storage `local/lampiran_pengaduan/`
- **5.4 Admin:** Filament `PengaduanResource` → CRUD via `PengaduansTable`, `PengaduanForm` + SoftDeletes
- **Cek Status:** `PengaduanController@checkStatus` → query by `nomor_tiket` → return view
- **Download:** `downloadSecureLampiran` → `Crypt::decrypt()` → response file

---

### 2.6 Proses Kontak

```
+------------+                              +--------------+
| MASYARAKAT | ---> Isi Form Kontak ----> | Proses 6.0   |
|            |      (Nama, Email,         | Kontak Pesan  |
|            |       Subjek, Pesan)       +------+-------+
|            | <--- Notifikasi Sukses  ---|      |
+------------+                              |      v
                                            |  +---+---+
                                            |  | Email  |
                                            |  | Admin  |
                                            |  +---+---+
                                            +--+---+
                                                 |
                                                 v
                                        +--------+--------+
                                        | D10             |
                                        | contact_messages|
                                        | (nama, email,   |
                                        |  subjek, pesan) |
                                        +-----------------+
```

**Alur Data:**
- `ContactController@store` → validasi → `ContactMessage::create()` → `Mail::to(admin)` → redirect back

---

### 2.7 Proses Auth Admin (Password Reset)

```
+------------+                              +--------------------+
| ADMIN      | ---> Request Reset -------> | Proses 7.1         |
|            |      (Input Email)          | Kirim OTP via Email|
|            | <--- OTP dikirim ke Email   +--------+-----------+
|            |                              |        |
|            | ---> Input OTP + Password-> | Proses 7.2         |-------> D11
|            | <--- Password Diubah     ---| Verifikasi OTP     |         password_reset_tokens
+------------+                             | & Update Password  |         (email, otp)
                                            +--------------------+
                                                  |
                                                  v
                                         +-------+--------+
                                         | D12            |
                                         | users          |
                                         | (name, email,  |
                                         |  password)     |
                                         +----------------+
```

**Alur Data:**
- `PasswordResetController@sendOtp` → generate OTP → update `password_reset_tokens` → kirim email
- `PasswordResetController@resetPassword` → verifikasi OTP → update password users

---

### 2.8 Proses Admin Panel (Filament)

```
+------------+                              +--------------------+
| ADMIN      | ---> Login (email/pass) --> | Proses 8.0        |
|            |                              | Filament Admin     |
|            |                              | Panel              |
|            | <--- Dashboard Widgets   ---|                    |
|            |                              +-------+-----------+
|            |                                       |
|            |     +----------+----------+----------+-------+-------+
|            |     |          |          |          |       |       |
|            v     v          v          v          v       v       v
|         +--+--+ +--+--+ +--+--+ +---+--+ +---+--+ +--+--+ +--+--+
|         |New  | |Ktg  | |Auth | |Potensi| |Dok  | |Banner| |Profil|
|         |s    | |Berita| |or   | |Desa   | |Desa | |Home  | |Desa |
|         |CRUD | |CRUD  | |CRUD | |CRUD   | |CRUD | |CRUD  | |CRUD |
|         +--+--+ +--+--+ +--+--+ +---+--+ +---+--+ +--+--+ +--+--+
|            |       |       |        |        |       |       |
|            v       v       v        v        v       v       v
|         +--+--+ +--+--+ +--+--+ +---+--+ +---+--+ +--+--+ +--+--+
|         |D4   | |D5   | |D6   | |D3    | |D8    | |D1   | |D2   |
|         |news | |news | |auth | |village| |doku  | |home | |villa|
|         |     | |_cat | |ors  | |_poten | |men   | |bann | |ge_p |
|         +-----+ +-----+ +-----+ +------+ +------+ +-----+ +-----+
```

---

## 3. TABEL ENTITAS / DATA STORE

| Kode | Nama Tabel | Deskripsi |
|------|-----------|-----------|
| D1 | `homebanners` | Banner utama homepage |
| D2 | `village_profiles` | Profil desa (visi, misi, sejarah, perangkat, wilayah) |
| D3 | `village_potentials` | Potensi desa |
| D4 | `news` | Berita/artikel desa |
| D5 | `news_categories` | Kategori berita |
| D6 | `authors` | Penulis berita |
| D7 | `banners` | Banner berita (relasi ke news) |
| D8 | `dokumen_desas` | Dokumen layanan desa |
| D9 | `pengaduans` | Pengaduan masyarakat (+ soft deletes) |
| D10 | `contact_messages` | Pesan kontak masuk |
| D11 | `password_reset_tokens` | Token + OTP reset password |
| D12 | `users` | Akun admin |
| D13 | `agents` | (Cadangan/belum digunakan) |

---

## 4. ENTITAS EKSTERNAL

| Entitas | Deskripsi | Interaksi |
|---------|-----------|-----------|
| **Masyarakat/Pengunjung** | Warga desa / publik | Melihat informasi, mengisi pengaduan, kontak, download dokumen |
| **Admin (Perangkat Desa)** | Pengelola konten desa | Login Filament, CRUD semua data, kelola pengaduan, upload berita |
| **Email Server** | Mail server (SMTP) | Mengirim OTP reset password & notifikasi kontak ke admin |

---

## 5. SPESIFIKASI PROSES (Ringkasan)

| Proses | Input | Output | Method |
|--------|-------|--------|--------|
| 1.0 Homepage | GET / | View homepage + banners | `HomeController@index` |
| 2.0 Profil Desa | GET /profildesa | View profil + potensi desa | `PotensiDesaController@index` |
| 3.0 Portal Berita | GET /berita, /berita/{slug} | View daftar/detail berita | `NewsController@index`, `@show` |
| 4.0 Layanan | GET /layanan | View daftar dokumen | `DokumenDesaController@index` |
| 5.1 Buat Pengaduan | GET /pengaduan | Form pengaduan + kategori | `PengaduanController@create` |
| 5.2 Simpan Pengaduan | POST /pengaduan | JSON response + tiket | `PengaduanController@store` |
| 5.3 Cek Status | GET /check-status | View status pengaduan | `PengaduanController@checkStatus` |
| 5.4 Download Lampiran | GET /pengaduan/download/{id} | File (decrypted inline) | `PengaduanController@downloadSecureLampiran` |
| 6.0 Kontak | POST /contact | Redirect + flash message | `ContactController@store` |
| 7.1 Kirim OTP | POST /admin/lupa-password | Email OTP | `PasswordResetController@sendOtp` |
| 7.2 Reset Password | POST /admin/reset-password | Password updated | `PasswordResetController@resetPassword` |
| 8.0 Admin Panel | Login Filament | Full CRUD via UI | Filament Resources |
