# GSCXNodeJS

Converted from the React `GSCXProduction` app into:
- Node.js + Express backend
- MariaDB database
- Vanilla HTML/CSS/JavaScript frontend

## 1. Setup

1. Install MariaDB and create a database:
```sql
CREATE DATABASE gscx_db;
```

2. Copy env file:
```bash
cp .env.example .env
```

3. Update `.env` with your MariaDB credentials.

4. Install dependencies:
```bash
npm install
```

## 2. Run

```bash
npm run dev
```

The app starts on `http://localhost:3000`.

On first load, frontend calls `POST /api/init` to create tables and seed admin.

## 3. Optional SSL with Let's Encrypt

The server can run over HTTPS directly using existing Let's Encrypt certificate files.

1. Issue a certificate for your domain with Certbot.

2. Set these values in `.env`:
```bash
SSL_ENABLED=true
SSL_PORT=443
LETSENCRYPT_PRIVKEY_PATH=/etc/letsencrypt/live/your-domain/privkey.pem
LETSENCRYPT_FULLCHAIN_PATH=/etc/letsencrypt/live/your-domain/fullchain.pem
```

3. Start the app normally:
```bash
npm run dev
```

With SSL enabled, the app serves HTTPS on `SSL_PORT`.

## 4. Optional DB seeding command

```bash
npm run db:init
```

## 5. Main API endpoints

- `GET /api/health`
- `POST /api/auth/register`
- `POST /api/auth/login`
- `POST /api/auth/logout`
- `POST /api/auth/settings`
- `GET /api/dashboard`
- `GET/POST/PATCH /api/members`
- `GET/POST/PATCH /api/products`
- `GET/POST /api/bonds`
- `GET/POST/PATCH /api/transactions`
- `POST /api/matching/execute`

## 6. Member services added

- Entity self-registration for `REMITTER/IMPORTER/EXPORTER/TRANSPORT/INSURANCE/BANK/INSPECTOR`
- Sign-in with password and optional OTP verification
- Settings page for members to:
	- set/update their own OTP code
	- require OTP for future sign-ins
	- change password (with current-password verification)

## 7. Notes on conversion scope

This conversion keeps the same major modules and workflows:
- Dashboard
- Member Onboarding
- Clearinghouse
- Marketplace
- Transaction Center
- Matching Engine

The UI is now plain HTML/CSS/JS and no React/Vite/IndexedDB is used.
