# Nzeru Lab: installation guide (Parts 1-10)

Nzeru Lab is a Laravel 11/12 application. The 10 zip parts are an **overlay**: they contain only Nzeru Lab's own files
(app/, routes/, resources/, database/, config/). You lay them on top of a fresh Laravel install, which supplies
the framework skeleton and `vendor/`.

## Requirements (Truehost / cPanel)
- PHP 8.2 or newer (cPanel > MultiPHP Manager). Extensions: mbstring, xml, zip, gd, curl, pdo_mysql, fileinfo, bcmath.
- Composer (cPanel > Terminal, or SSH). No Terminal? See "No SSH" at the bottom.
- MySQL database `kimlrgeb_nzerulab` (already created) and a MySQL user attached to it with ALL PRIVILEGES.

## Steps
1. Create the Laravel skeleton in your account home (not inside public_html):
       cd ~ && composer create-project laravel/laravel nzerulab
2. Upload **all 10 zips** into `~/nzerulab`, extract each, choosing "overwrite" when asked
   (Part 1 replaces bootstrap/app.php, routes/*.php and the default users migration, which is intended).
3. Install the extra packages:
       cd ~/nzerulab
       composer require laravel/sanctum laravel/socialite barryvdh/laravel-dompdf phpoffice/phpword smalot/pdfparser
4. Configure:
       cp .env.example .env
       php artisan key:generate
   Then edit `.env`: set DB_USERNAME / DB_PASSWORD (cPanel prefixes names, e.g. `kimlrgeb_nzeru`),
   APP_URL, mail settings, payment keys, AI key.
5. Create the tables, choose ONE:
   a) `php artisan migrate --seed`   (creates every table and the admin user; the seeder prints the admin password), or
   b) phpMyAdmin > database `kimlrgeb_nzerulab` > Import > `database/schema.sql`. Do NOT run `migrate` afterwards.
      Then set INSTALL_TOKEN in `.env` and open `/install/admin` once to create the admin account.
6. `php artisan storage:link && php artisan config:cache && php artisan route:cache`
7. Point the domain/subdomain document root to `~/nzerulab/public` (cPanel > Domains). If you cannot change it,
   the bundled root `.htaccess` forwards requests to `public/`.
8. Cron (cPanel > Cron Jobs, every minute):
       * * * * * /usr/local/bin/php /home/YOURUSER/nzerulab/artisan schedule:run >> /dev/null 2>&1
   This runs the daily subscription renewal and auto-downgrade job.
9. Payment webhooks (set in each provider dashboard):
       PayChangu    https://YOURDOMAIN/webhooks/paychangu
       Flutterwave  https://YOURDOMAIN/webhooks/flutterwave
       Stripe       https://YOURDOMAIN/webhooks/stripe   (events: checkout.session.completed, invoice.paid, customer.subscription.deleted)
       PayPal       return flow only, no webhook needed

## No SSH
Run steps 1-3 on your own PC (needs PHP 8.2 + Composer), then zip the whole `nzerulab` folder, upload and extract it
on the server, import `database/schema.sql` with phpMyAdmin, and edit `.env` with the File Manager.

## Part map
 1 Foundation: config, database schema, models, layout, landing page
 2 Accounts: register/login, Google/LinkedIn OAuth, onboarding wizard, MFA, settings, API tokens, dashboard
 3 Payments: PayChangu, Flutterwave, Stripe, PayPal, wallet engine, pricing, billing, renewals job
 4 Surveys: builder, public response pages, free-tier response cap
 5 Analytics: charts, statistics, regression, CSV/Word/LaTeX/image exports
 6 AI assistant: chat, drafting modes, quotas, token and cost tracking, throttling
 7 Marketplace: Buy Responses, respondent wallet and withdrawals, Plagiarism & AI-Sincerity check
 8 Career suite: CV builder, AI polish, watermarked preview, paywall, PDF/Word download
 9 Institutional: institutions, seat licences, lecturer monitoring, branding, templates
10 Admin panel: MRR, revenue by region, LTV, AI cost tracking, feature flags, global config, system stats

## Security notes
- Keep `.env` out of the web root. Payment confirmation always re-verifies with the provider API, so a forged webhook cannot grant access.
- Remove INSTALL_TOKEN from `.env` after the admin account exists.
- Gateway/AI keys can also be changed from Admin > Config; they are stored encrypted in the settings table.
