# HARTI Advanced Programme Management System

The application backend is PHP and the database is MySQL, accessed through PHP PDO. It has no Node.js server, npm runtime, or Node package dependencies. It is intended to run locally on this computer; it does not require an online server. Small inline browser scripts are used only for interface interactions; they do not run on Node.js.

## Technology stack

- PHP 8.1+ handles pages, authentication, permissions, workflow, PDF generation, and email.
- MySQL stores users, programmes, reviews, notifications, and login throttling records.
- `assets/app.css` is the application's custom CSS. The current interface does not use Bootstrap.
- Small inline JavaScript snippets support form and navigation interactions; there is no separate JavaScript build system.
- Composer installs the PHP libraries listed in `php-dependencies.json` and locked in `php-dependencies.lock`.
- The project also includes SQL schema, Apache rewrite/configuration files, PowerShell and batch setup tools, SVG diagrams, and a PNG logo. These are not web application runtimes.

## Project structure

- `admin/front-controller.php` is the application entry point and loads the request controller in `admin/index.php`.
- `admin/` contains the request controller, workflow/PDF/email modules, and separate PHP page entry points for login, registration, sign-out, password reset, and notifications. Internal handlers remain private.
- Open the dedicated pages at `/admin/login.php`, `/admin/register.php`, `/admin/forgot-password.php`, `/admin/reset-password.php`, and `/admin/notifications.php`. Sign-out is a POST-only `/admin/logout.php` action.
- `assets/` contains UI CSS, images, and the PHP page layout.
- `config/` contains authentication/session/application helpers in `auth.php` and database connection and schema compatibility code in `db.php`. Local defaults are defined in those files and can be overridden with environment variables.
- `database/` contains the MySQL schema.
- `documentation/` contains application and setup notes.
- [Entity relationship diagram](documentation/ER-Diagram.svg) visualizes the MySQL tables, keys, and declared relationships.
- [Use case diagram](documentation/Use-Case-Diagram.svg) visualizes the system actors, permissions, and programme workflow.
- `includes/` contains the shared PHP header, sidebar, and footer templates.
- `scripts/` contains administrator setup and queued-email commands.
- `storage/logs/` contains local server logs.
- `uploads/` contains private uploaded documents and generated PDFs.
- `php-dependencies/` contains Composer-managed PHP libraries.
- `php-dependencies.json` and `php-dependencies.lock` define and lock the PHP Composer dependencies.

Configuration, backend source, uploaded files, logs, database files, and dependencies are not public URLs.

## Run locally

1. Start MySQL. Use PHP 8.1 or later with `pdo_mysql`, `fileinfo`, and `mbstring`.
2. Create a local MySQL database named `advanced_programme_php` and import `database/schema.sql`.
3. Copy `config/db.local.php.example` to `config/db.local.php`, then enter the MySQL username and password used on this computer. This file is excluded from source control. Alternatively set `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER`, and `DB_PASSWORD` environment variables.
4. If `php-dependencies/` is missing, install Composer for PHP, open PowerShell in the project root, and run:

   ```powershell
   $env:COMPOSER = 'php-dependencies.json'
   try {
       composer install
   } finally {
       Remove-Item Env:COMPOSER -ErrorAction SilentlyContinue
   }
   ```

   Composer reads `php-dependencies.json`, uses its matching `php-dependencies.lock`, and places PHP libraries in `php-dependencies/`. No Node.js or npm installation is required.
5. To create the first System Administrator, run `.\scripts\create-admin.ps1` in PowerShell and enter the requested details at the prompts.

For local development, run this command from the project root:

```powershell
php -d upload_max_filesize=10M -d post_max_size=12M -S 127.0.0.1:8000 -t . scripts/local-router.php
```

Then open `http://localhost:8000/`. The server binds to `127.0.0.1`, so it is for use on this computer and is not an online host. Server logs are saved in `storage/logs/`.

## Deploy online

Upload the contents of this project directory to an Apache or LiteSpeed web root (or a subdirectory within it). Keep the root `.htaccess` file enabled; it routes the application entry point and blocks direct access to private folders and PHP modules. Set the site's document root to this project directory when possible. The public entry point is `admin/front-controller.php`, and the CSS and images are in the sibling `assets/` directory, so the `admin/` directory alone is not a complete deployment.

For `https://advanced-programme-management-system.harti.lk`, create that subdomain in the hosting control panel, point its DNS A/AAAA or CNAME record to the host, and set its document root to the extracted project root. Enable an SSL certificate for the subdomain before sharing the HTTPS URL. The application canonical URL defaults to this hostname and can be overridden with the `APP_URL` environment variable.

Use PHP 8.1 or later with `pdo_mysql`, `fileinfo`, and `mbstring`, configure the database and SMTP settings through environment variables, and import `database/schema.sql`. Use a dedicated MySQL account with access only to this application's database; do not use the MySQL root account for a production deployment. Set `APP_ENV=production`, keep PHP `display_errors=Off` and `log_errors=On`, and serve the site only over HTTPS. If TLS terminates at a reverse proxy, configure the web server/PHP-FPM so PHP receives the correct HTTPS state; do not trust arbitrary client-supplied forwarding headers.

If the host uses Nginx or does not allow `.htaccess`, configure equivalent routing and deny rules in the web-server configuration before uploading; do not make `config/`, `includes/`, `storage/`, `uploads/`, `php-dependencies/`, `scripts/`, or `database/` publicly accessible. Store database and SMTP passwords in the hosting environment/secret manager, not in a public web folder. `scripts/package-server.ps1` excludes the local database configuration and local-only MySQL reset script from deployment archives.
Application and asset responses disable browser and intermediary HTTP caching.

## Workflow

Investigators create drafts and forward programmes to their assigned SA/SO. Supervisors review and forward programmes to HOD; HODs approve or reject them. Approval generates the final report. Users can manage their profile and notifications, and password recovery requires working SMTP settings.
System Administrators can create Investigator, SA, SO, HOD, and additional System Administrator accounts from the Accounts page. Public self-registration is limited to Investigator accounts; privileged accounts must be created or promoted by an administrator. Only a System Administrator can grant or remove System Administrator access. Share initial passwords securely. Sign-in attempts are limited per email and client IP; password reset codes are time-limited and attempt-limited.

Investigators may save up to five programmes for each reporting month. They must forward each programme by 11:59 PM Sri Lanka time on the 20th of the preceding month; drafts may still be saved after that deadline, but cannot be forwarded.

After saving a programme draft, Investigators can optionally attach a supporting PDF of up to 10 MB in the compact attachment section. The assigned SA/SO can download it during review and add or replace the attachment if needed.

Uploaded documents are stored under `uploads/` and are served through authenticated application routes. Do not expose `config/`, `includes/`, `storage/`, `uploads/`, `php-dependencies/`, or database files through another web-server configuration.
