<p align="center"><img src="public/assets/img/geoforestLogo.png" height="100" alt="eGP Logo"></p>

<h1 align="center">Sistem e-Geospatial Perhutanan (e-GP)</h1>

## Overview

Sistem e-Geospatial Perhutanan (e-GP) adalah sebuah sistem maklumat perhutanan yang dibangunkan oleh Jabatan Perhutanan Semenanjung Malaysia. Sistem ini menyediakan pelbagai maklumat perhutanan yang berkaitan dengan pengurusan data spatial dan bukan spatial, peta interaktif, serta pengurusan kandungan web bagi Semenanjung Malaysia.


## Tech Stack

| Layer         | Technology                                                                 |
|---------------|----------------------------------------------------------------------------|
| **Backend**   | PHP 8.1+, Laravel 10                                                       |
| **Frontend**  | Blade Templates, Bootstrap 5, Vite, NiceAdmin Template                     |
| **Database**  | SQL Server                                                                      |
| **Styling**   | Sass, Vanilla CSS                                                          |
| **API**       | Laravel Sanctum (token-based auth), ArcGIS MapServer REST API              |

### Packages & Plugins

| Package / Plugin                 | Purpose                                      |
|----------------------------------|----------------------------------------------|
| `yajra/laravel-datatables`       | Server-side DataTables configuration         |
| `DataTables (jQuery)`            | Unified client-side table rendering          |
| `SweetAlert2`                    | User notifications & confirmation dialogs    |
| `owen-it/laravel-auditing`       | Audit trail / activity logging               |
| `intervention/image`             | Image processing, compression & resizing     |
| `barryvdh/laravel-dompdf`        | PDF report generation                        |
| `laravel/sanctum`                | API token authentication                     |
| `laravel/ui`                     | Authentication scaffolding                   |
| `guzzlehttp/guzzle`              | HTTP client for external API calls           |


## Prerequisites

Before you begin, ensure you have the following installed:

- **PHP** >= 8.1 with extensions: `mbstring`, `xml`, `bcmath`, `gd` or `imagick`, `pdo_mysql`
- **Composer** >= 2.x
- **Node.js** >= 16.x & **npm**
- **SQL Server** >= 2016
- **Git**

## Setup


### Initial Setup Commands:
#### 1. Install dependencies

```bash
# PHP dependencies
composer install

# Node dependencies
npm ci
```

#### 2. Environment configuration

```bash
# Copy environment file
cp .env.example .env

# Generate application key
php artisan key:generate
```

#### 3. Database setup

```bash
# Run migrations
php artisan migrate

# Seed the database
php artisan db:seed
```

#### 4. Storage & assets

```bash
# Create storage symlink
php artisan storage:link

# Build assets for development / production
npm run dev / npm run build
```

#### 5. Set permissions (Linux / macOS)

```bash
chmod -R 755 storage
chmod -R 755 bootstrap/cache
```

#### 6. Make this change in php.ini

```bash
# This change is to allow file upload up to 200MB/file

upload_max_filesize = 200M
post_max_size = 220M
memory_limit = 256M
```
#### 7. Run the application

```bash
php artisan serve
```

Edit `.env` and configure the following:

```env
APP_NAME=eGP
APP_URL=http://your-domain.com

DB_DATABASE=egp
DB_USERNAME=your_username
DB_PASSWORD=your_password

MAIL_MAILER=smtp
MAIL_HOST=your-smtp-host
MAIL_PORT=587
MAIL_USERNAME=your-email
MAIL_PASSWORD=your-password
MAIL_FROM_ADDRESS=noreply@your-domain.com
MAIL_FROM_NAME="${APP_NAME}"
```

## Production Deployment

```bash
# Install dependencies (optimized)
composer install --optimize-autoloader --no-dev

# Build production assets
npm run build

# Cache configuration
php artisan config:cache
php artisan route:cache
php artisan view:cache

# Optimize (To clear all caches)
php artisan optimize
```

## Project Structure

```
egp-new/
├── app/
│   ├── Helper/            # Global helper functions
│   ├── Http/
│   │   ├── Controllers/   # 31 controllers (Auth, CMS, Map, Data, Reports, etc.)
│   │   └── Middleware/     # Custom middleware (session timeout, visitor tracking)
│   ├── Mail/              # Mailable classes (registration, password reset)
│   ├── Models/            # 39 Eloquent models
│   └── Notifications/     # Notification classes
├── config/                # Application configuration
├── database/
│   ├── migrations/        # Database migrations
│   └── seeders/           # Database seeders
├── public/                # Public assets (images, CSS, JS)
├── resources/
│   └── views/             # Blade templates
│       ├── layouts/       # Layout files & partials
│       ├── email/         # Email templates
│       └── ...            # Feature-specific views
├── routes/
│   └── web.php            # Web routes
├── storage/               # Uploaded files, logs, cache
└── vite.config.js         # Vite configuration
```

## Security Features

- **Authentication**: Laravel UI with custom login/register flow and admin approval
- **Authorization**: Role-based permissions (Pentadbir Utama, Pentadbir, Pentadbir Negeri, Pengguna)
- **API Authentication**: Laravel Sanctum token-based authentication
- **Audit Logging**: Full audit trail via `owen-it/laravel-auditing`
- **Session Management**: Heartbeat mechanism with automatic session timeout
- **CSRF Protection**: Laravel built-in CSRF token verification
- **Password Reset**: Secure token-based password reset via email


## Map Service

Dashboard map data is served from:

```
https://egpserver.forestry.gov.my/server/rest/services/SEMENANJUNG_EGP/SEMENANJUNG_EGP/MapServer
```


## User Roles

| Role               | Description                                    |
|--------------------|------------------------------------------------|
| Pentadbir Utama    | Super administrator with full system access    |
| Pentadbir          | Administrator (Pentadbir JPSM)                 |
| Pentadbir Negeri   | State-level administrator                      |
| Pengguna           | Regular user                                   |
