# Putting RUA Mall online

This folder is the whole RUA Mall website: the shop, the server that keeps everyone's accounts, listings and orders in one shared database, the emails from **RUA Mall Admin**, and the **admin dashboard** at `/admin`.

You do not need to write code. You need a web host, about an hour, and these steps.

---

## What is in the folder

| Part | What it is |
|---|---|
| `public/index.html` | The shop (version 5: the v4 pilot, now connected to the server) |
| `public/admin/index.html` | The admin dashboard (dark and light mode) |
| `server.js` and `lib/` | The server: accounts, approvals, emails, settings |
| `data/` | Created on first start. Holds the database file (`rua-mall.db`), pictures and private documents. **Back this up.** |
| `.env.example` | The settings file to copy and fill in |

The database is a single file (SQLite). There is no separate database server to buy or set up.

---

## Step 1. Choose hosting

**Recommended for the pilot: a Ugandan cPanel hosting plan that supports Node.js apps.**
Ugandan shared hosting plans cost roughly UGX 70,000 to 250,000 a year. Before you pay, ask the host one question:

> "Does this plan have **Setup Node.js App** in cPanel, with Node.js version 22 or newer?"

If they say yes, that plan works. If they only offer PHP, it will not run RUA Mall; ask for a plan that has Node.js or choose option B.

**Option B: a small virtual server (VPS).** More power and control, from about UGX 45,000 a month in Uganda, or about USD 5 a month abroad. It needs someone comfortable with a command line for the first setup (see "Option B" at the end).

You also need a **web address** (domain), for example `ruamall.co.ug` or `mall.riseupacholi.org`. Most hosts sell or connect one.

---

## Step 2. Upload the files (cPanel)

1. Sign in to cPanel and open **File Manager**.
2. Create a folder in your home folder called `ruamall` (not inside `public_html`).
3. Open it, click **Upload**, and upload `rua-mall-backend-v1.zip`.
4. Right-click the zip and choose **Extract**. You should now see `server.js`, `package.json`, `public`, `lib` and the other files inside `ruamall`.

## Step 3. Start the app (cPanel "Setup Node.js App")

1. In cPanel, open **Setup Node.js App** and click **Create Application**.
2. Fill in:
   - **Node.js version:** 22 (or the newest offered)
   - **Application mode:** Production
   - **Application root:** `ruamall`
   - **Application URL:** your web address
   - **Application startup file:** `server.js`
3. Click **Create**.
4. Scroll down and click **Run NPM Install**. Wait until it finishes.
5. Under **Environment variables**, add these (click "Add variable" for each):

   | Name | Value |
   |---|---|
   | `SITE_URL` | your full address, for example `https://ruamall.co.ug` |
   | `COOKIE_SECURE` | `1` |

   Email settings come in step 5.
6. Click **Save**, then **Restart**.
7. Turn on the padlock (https): in cPanel open **SSL/TLS Status** and run **AutoSSL** for your address (most hosts do this on their own).

Open your web address. You should see the RUA Mall shop.

## Step 4. Create the first admin

1. Go to `https://your-address/admin`.
2. It asks for a **set-up code**. In File Manager, open the file `ruamall/data/setup-code.txt` and copy the code inside.
3. Enter the code, your name, email and a password. You are now signed in to the dashboard.
4. The set-up code works once. Add more admins later in **Site settings > Admins**: they get an email with a link to choose a password.

Forgot your admin password? Use **Forgot password?** on the sign-in page (needs email, step 5).

## Step 5. Turn on email (so people receive what "RUA Mall Admin" sends)

Until this is done, every email is still saved and visible in the dashboard (**Emails**), marked "Not sent", but nobody receives it.

You need an email-sending service. Two simple, free choices for a pilot:

- **Brevo** (free plan, 300 emails a day). Sign up, add and verify your sender address, then open *SMTP & API* to see your SMTP login and key.
  `SMTP_HOST` = `smtp-relay.brevo.com`, `SMTP_PORT` = `587`, `SMTP_USER` = your Brevo SMTP login, `SMTP_PASS` = your SMTP key, `MAIL_FROM` = the verified sender address.
- **Gmail** (for example riseupacholi@gmail.com, about 500 emails a day). Turn on 2-step verification on the Google account, then create an **App password** (Google Account > Security > App passwords).
  `SMTP_HOST` = `smtp.gmail.com`, `SMTP_PORT` = `465`, `SMTP_USER` = the Gmail address, `SMTP_PASS` = the 16-letter app password, `MAIL_FROM` = the same Gmail address.

Add these five as environment variables in **Setup Node.js App** (same place as step 3), then **Restart**.
Check it worked: the dashboard Overview no longer shows "Emails are not being sent yet". In **Emails > Sent emails** you can open any "Not sent" email and click **Send again**.

Every email is sent with the name **RUA Mall Admin**. Replies go to the support email set in **Site settings**.

## Step 6. Before you invite testers

In the dashboard:
1. **Site settings > Site and contact:** check the name, support phone and email, WhatsApp number, and upload the logo.
2. **About page:** add the real history, impact figures and stories.
3. **Home page and sliders:** pick the Recommended products, the Fast-selling photos, the headline and the announcement bar. Decide whether sample listings stay on.
4. **Emails > Email wording:** read the emails and change any wording you like.
5. Try the full flow yourself: apply as a seller in the shop, approve yourself in the dashboard, add a listing, approve it, then order it from a buyer account.

## Step 7. Backups

In the dashboard, **Site settings > Backup > Download a backup** saves the whole database to your computer. Do it once a week and before any big change. Your host's own backup also copies the `data` folder (pictures and documents).

To restore a backup: stop the app, replace `data/rua-mall.db` with the backup file (renamed to `rua-mall.db`), and start the app again.

## Updating to a newer version later

1. Download a backup first (step 7).
2. Upload the new zip and extract it **over** the old files. Never delete the `data` folder: it holds everything people have entered.
3. In **Setup Node.js App**, click **Run NPM Install**, then **Restart**.

---

## Trying it on your own computer first (optional)

1. Install Node.js 22 from nodejs.org.
2. Open a terminal in this folder and run `npm install`, then `npm start`.
3. Open http://localhost:3000 for the shop and http://localhost:3000/admin for the dashboard (the set-up code is in `data/setup-code.txt`).

## Option B: a VPS (for a technical helper)

On Ubuntu: install Node.js 22, copy this folder to the server, run `npm install --omit=dev`, copy `.env.example` to `.env` and fill it in, then keep it running with a process manager (for example `pm2 start server.js --name ruamall`) behind a web server with https (for example Caddy, which sets up https on its own: `reverse_proxy localhost:3000`).

---

## How it keeps people safe

- Passwords are stored scrambled (scrypt), never as plain text. Sign-in uses a secure cookie that lasts 30 days.
- Only admin accounts can open the dashboard or anything under `/api/admin`. Sellers and buyers are refused.
- Repeated wrong passwords are slowed down (10 tries per 15 minutes per email).
- Verification documents (ID, business registration) are private: only that seller and admins can open them.
- Update links and password links work once and expire.
- RUA Mall never takes payment for products. The server has no payment feature at all.
