A forex and crypto learning platform: a public learning site and an admin
portal in one Next.js app (apps/web), built as a pnpm + Turborepo
monorepo.
- Public site:
/(courses, quizzes, videos, glossary, news, tools) - Admin portal:
/admin(staff only)
This README gets you from zero to a running copy, on your own machine and on a live server, using git and SSH. Deeper references:
| Document | What it covers |
|---|---|
| docs/ops/deploy.md | Full server runbook: env vars, nginx, pm2/systemd, backups |
| docs/ops/cron.md | The five scheduled jobs and how to call them |
| CLAUDE.md | Architecture and the project's rules |
| docs/memory/stack.md | Exact tool and library versions |
- What you need
- Run it on your machine (local)
- Test accounts and credentials
- Working with git
- Set up SSH
- First install on the live server
- Deploying updates
- Command cheat sheet
- Troubleshooting
| Tool | Version | Notes |
|---|---|---|
| Node.js | 22.x LTS, 22.13.0 or newer | .nvmrc says 22 (ADR-145). nvm use picks it up |
| pnpm | the version in package.json → packageManager |
Install it with corepack enable, not npm i -g pnpm |
| Git | any recent | |
| MariaDB | 11.x | Locally this runs in Docker |
| Redis | 7.x | Required: sign-in sessions and rate limits use it |
| Docker Desktop | local only | Runs MariaDB, Redis and Mailpit for development |
The app itself never runs in Docker. Docker only holds the database, Redis and a mail catcher. The Next.js app runs directly on your machine or server.
git clone git@github.com:sufyan-mbxpro/MBFX-Learning-Center.git
cd MBFX-Learning-Center(Use the https://github.com/... URL instead if you have not set up an SSH
key yet — see §5.)
docker compose up -d
docker compose ps # wait until all three show "healthy"| Service | Address | Used for |
|---|---|---|
| MariaDB | localhost:3306 |
user user, password pass, db mbfx_learning_center |
| Redis | localhost:6379 |
sessions, rate limits |
| Mailpit | localhost:8025 |
web inbox that catches every email sent locally |
cp .env.example .envThe .env file lives at the repo root, never inside apps/web. It is
git-ignored. Never commit it.
Fill in these values. Generate each secret separately:
node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"DATABASE_URL="mysql://user:pass@localhost:3306/mbfx_learning_center"
REDIS_URL="redis://localhost:6379"
BETTER_AUTH_SECRET="<generated>"
BETTER_AUTH_URL="http://localhost:3000"
NEXT_PUBLIC_SITE_URL="http://localhost:3000"
NEXT_PUBLIC_ADMIN_URL="http://localhost:3000/admin"
EMAIL_SECRET_KEY="<generated>"
MARKET_SECRET_KEY="<generated>"
AI_SECRET_KEY="<generated>"
TRANSLATE_SECRET_KEY="<generated>"
EMAIL_LINK_SECRET="<generated>" # signs announcement unsubscribe links (ADR-171)
CRON_SECRET="<generated>"
# Creates the local admin account on the first seed (see §3)
SEED_ADMIN_EMAIL="admin@mbxpro.com"
SEED_ADMIN_PASSWORD="LocalAdmin#2026"corepack enable
pnpm install
pnpm db:generate # builds the Prisma client
pnpm db:deploy # creates the tables
pnpm db:seed # roles, permissions, settings, menus, the admin user
pnpm seed:live # optional: sample courses, quizzes, videos, images, themepnpm dev # or: pnpm --filter web devOpen:
- http://localhost:3000 for the public site
- http://localhost:3000/keystone for the admin portal
- http://localhost:8025 to read any email the app sent (Mailpit)
Windows: if
pnpm devfails withspawn UNKNOWN, Windows Smart App Control is blockingturbo.exe. Runpnpm --filter web devinstead, which skips turbo.
pnpm lint
pnpm typecheck
pnpm test
pnpm governance:checkCI runs the same checks on every push. See .github/workflows/ci.yml.
There are no built-in passwords in this repo. The admin account is
created by pnpm db:seed from two lines in .env:
| Variable | Default | Meaning |
|---|---|---|
SEED_ADMIN_EMAIL |
admin@mbxpro.com |
The super admin's email |
SEED_ADMIN_PASSWORD |
(none) | Its password. If empty, the seed skips the admin user |
With the .env from §2.3:
| Role | Sign-in URL | Password | |
|---|---|---|---|
| Super Admin (staff) | http://localhost:3000/keystone | admin@mbxpro.com |
LocalAdmin#2026 |
| Learner (public user) | http://localhost:3000/en/sign-up | any email you type | any 8–128 chars |
- Learners register themselves at
/en/sign-up. No email check is needed to sign in. The welcome/verification email appears in Mailpit. - Staff and learners use different sign-in pages: staff at
/keystone(ADR-146), learners at/en/sign-in. A learner account can never open/admin, even with a role. - More staff accounts: sign in as the admin → Users / Employees → create a user and give it a role (for example Content Manager).
LocalAdmin#2026is a local test value only. Never use it on the live server.
- Normal way: sign in and change it at
/admin/profile. - Forgot it (local): set a new
SEED_ADMIN_PASSWORDin.envand runpnpm db:seed. The seed resets the admin's password to that value. - Forgot it (live): use
/admin/forgot-password(needs working SMTP), or run the same one-off seed as in §6.6 and remove the line again afterwards.
- Choose a strong, one-off password. For example:
openssl rand -base64 18. - Put it in the server's
.envasSEED_ADMIN_PASSWORDfor the first seed only. - Sign in at
https://your-domain.com/keystone, then change the password at/admin/profile. - Delete the
SEED_ADMIN_PASSWORDline from the server's.env. Otherwise every laterdb:seedresets the password back.scripts/deploy.shrefuses to run while that line is still set.
Keep live credentials in a password manager. Never put them in git, in chat, or in this README.
The remote is origin → github.com/sufyan-mbxpro/MBFX-Learning-Center. The
live server deploys the main branch.
git checkout main
git pull # get the latest
git checkout -b feature/short-name # one branch per change
# ... edit, then check your work ...
pnpm lint && pnpm typecheck && pnpm test
git add -A
git commit -m "Explain what changed and why"
git push -u origin feature/short-nameThen open a Pull Request into main on GitHub. When CI is green, merge it
and deploy.
- Never commit
.env, uploaded files (storage/), or build output..gitignorealready excludes them. Checkgit statusbefore committing. - Database changes go through migrations. Create one locally with
pnpm db:migrate, then commit the new folder underpackages/db/prisma/migrations/. The server only ever runspnpm db:deploy, which applies committed migrations. - Never edit files directly on the server. Every change is a commit
pushed to GitHub and pulled on the server.
deploy.shstops if the server's checkout has local edits. - If you changed anything under
packages/, add an entry todocs/logs/DEVLOG.md.pnpm governance:checkand CI require it.
git status # what changed
git log --oneline -10 # recent commits
git diff # unstaged changes
git stash / git stash pop # park changes temporarily
git fetch && git status # is my branch behind origin?Two separate SSH connections are involved:
your laptop ──ssh──▶ live server (you log in to deploy)
live server ──ssh──▶ GitHub (the server pulls the code)
your laptop ──ssh──▶ GitHub (you push code)
ssh-keygen -t ed25519 -C "you@example.com" # press Enter for the default path
cat ~/.ssh/id_ed25519.pub # copy this lineAdd it on GitHub: Settings → SSH and GPG keys → New SSH key. Test it:
ssh -T git@github.com # "Hi <user>! You've successfully authenticated"Switch an existing HTTPS clone to SSH:
git remote set-url origin git@github.com:sufyan-mbxpro/MBFX-Learning-Center.gitssh-copy-id root@SERVER_IP # copies your public key to the server
ssh root@SERVER_IP # should log in without a passwordOptional shortcut. Add this to ~/.ssh/config on your laptop:
Host mbx-live
HostName SERVER_IP
User mbx
IdentityFile ~/.ssh/id_ed25519
After that, ssh mbx-live is enough.
The server needs read-only access to the repository. Use a deploy key, not your personal key.
On the server, as the app user mbx (created in §6.1):
sudo -iu mbx
ssh-keygen -t ed25519 -C "mbx-live-deploy" -f ~/.ssh/id_ed25519 -N ""
cat ~/.ssh/id_ed25519.pubOn GitHub: repo → Settings → Deploy keys → Add deploy key. Paste the key and leave Allow write access unticked. Then test it on the server:
ssh -T git@github.com # "Hi sufyan-mbxpro/MBFX-Learning-Center! ..."This is the short version for a fresh Ubuntu/Debian server. Every step is
explained in detail in docs/ops/deploy.md. Replace
example.com with your domain throughout.
As root:
apt update && apt install -y git nginx mariadb-server redis-server curl
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt install -y nodejs
node -v # v22.x
adduser --system --group --shell /bin/bash --home /home/mbx mbx
install -d -o mbx -g mbx /srv/mbx /srv/mbx/shared /srv/mbx/shared/uploadsmysql -u rootCREATE DATABASE mbfx_learning_center CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'mbx'@'localhost' IDENTIFIED BY 'STRONG_DB_PASSWORD';
GRANT ALL PRIVILEGES ON mbfx_learning_center.* TO 'mbx'@'localhost';
FLUSH PRIVILEGES;Set up the deploy key first (§5.3).
Then, as mbx:
sudo -iu mbx
git clone git@github.com:sufyan-mbxpro/MBFX-Learning-Center.git /srv/mbx/app
cd /srv/mbx/app
corepack enable --install-directory ~/.local/bin # or run `corepack enable` once as root
corepack install # installs the pinned pnpm
pnpm --versionKeep the real file outside the checkout and link it in:
cp /srv/mbx/app/.env.example /srv/mbx/shared/.env
chmod 600 /srv/mbx/shared/.env
ln -sfn /srv/mbx/shared/.env /srv/mbx/app/.env
nano /srv/mbx/shared/.envMinimum values for production:
NODE_ENV="production"
DATABASE_URL="mysql://mbx:STRONG_DB_PASSWORD@localhost:3306/mbfx_learning_center"
REDIS_URL="redis://127.0.0.1:6379"
BETTER_AUTH_SECRET="<generated>"
BETTER_AUTH_URL="https://example.com"
NEXT_PUBLIC_SITE_URL="https://example.com"
NEXT_PUBLIC_ADMIN_URL="https://example.com/admin"
UPLOADS_DIR="/srv/mbx/shared/uploads"
EMAIL_SECRET_KEY="<generated>"
MARKET_SECRET_KEY="<generated>"
AI_SECRET_KEY="<generated>"
TRANSLATE_SECRET_KEY="<generated>"
EMAIL_LINK_SECRET="<generated>" # signs announcement unsubscribe links (ADR-171)
CRON_SECRET="<generated>"
HOME_CONTENT_MODE="real" # hide the homepage's placeholder figures
# FIRST SEED ONLY: delete both lines after §6.6
SEED_ADMIN_EMAIL="admin@your-domain.com"
SEED_ADMIN_PASSWORD="<strong one-off password>"Back up this file somewhere safe. If you lose
EMAIL_SECRET_KEY,MARKET_SECRET_KEY,AI_SECRET_KEYorTRANSLATE_SECRET_KEY, the SMTP password and API keys stored in the database can no longer be read. They would have to be typed in again.
cd /srv/mbx/app
pnpm install --frozen-lockfile
pnpm db:generate
pnpm db:deploy # NEVER db:migrate or db:reset on a live database
pnpm db:seed
pnpm seed:live # sample corpus + theme + optional provider keys
pnpm --filter web build- Start the app (next step), then sign in at
https://example.com/keystone. - Change the password at
/admin/profile. - Delete the
SEED_ADMIN_PASSWORDline (and any otherSEED_*lines) from/srv/mbx/shared/.env.
npm install -g pm2 # as rootAs mbx, create /srv/mbx/ecosystem.config.cjs:
module.exports = {
apps: [
{
name: "mbx",
cwd: "/srv/mbx/app/apps/web",
script: "node_modules/next/dist/bin/next",
// `-H localhost`, never `-H 127.0.0.1`: the proxy's next-intl rewrite
// treats a 127.0.0.1 origin as external and every public page then
// answers `307 -> itself`. Port 3003 — :3000 is a different app on this
// host, and Next's own default is 3000, so it is always passed.
args: "start -H localhost -p 3003",
exec_mode: "fork", // pm2 defaults to cluster when `instances` is set
env: { NODE_ENV: "production" },
instances: 1,
max_memory_restart: "1500M",
},
],
};pm2 start /srv/mbx/ecosystem.config.cjs
pm2 save
pm2 startup # run the command it prints (as root) so it starts on bootA systemd unit works too. See deploy.md §5.
Put the server block from deploy.md §6 in
/etc/nginx/sites-available/mbx, enable it, then add a certificate:
ln -s /etc/nginx/sites-available/mbx /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx
apt install -y certbot python3-certbot-nginx
certbot --nginx -d example.comKeep client_max_body_size 110m;. Without it, nginx rejects video uploads
before they reach the app.
Create /srv/mbx/cron.sh. It reads only the token from .env, without
running the whole file as a shell script:
#!/usr/bin/env bash
# Usage: cron.sh market-sync | publish-due | translate | announcements | housekeeping
S=$(grep -E '^CRON_SECRET=' /srv/mbx/shared/.env | cut -d= -f2- | tr -d '"\r')
curl -fsS -X POST "https://example.com/api/cron/$1" -H "Authorization: Bearer $S" >/dev/nullchmod 700 /srv/mbx/cron.sh
crontab -e # as mbx*/15 * * * * /srv/mbx/cron.sh market-sync
*/15 * * * * /srv/mbx/cron.sh publish-due
*/5 * * * * /srv/mbx/cron.sh translate
* * * * * /srv/mbx/cron.sh announcements
30 3 * * * /srv/mbx/cron.sh housekeepingDetails and the expected responses are in docs/ops/cron.md.
https://example.comloads the homepage.https://example.com/keystoneaccepts the admin account.pm2 logs mbxshows no errors.- Admin → Settings → Email: set SMTP and send a test mail. Password reset and newsletter emails need it.
After a change is merged into main on GitHub, deploy it with one
command from your laptop:
ssh mbx@SERVER_IP 'bash /srv/mbx/app/scripts/deploy.sh'
# or, with the ~/.ssh/config shortcut:
ssh mbx-live 'bash /srv/mbx/app/scripts/deploy.sh'scripts/deploy.sh runs these steps on the server, in this order. It stops at the first one that fails:
- Refuses to run if
SEED_ADMIN_PASSWORDis still in.env, or if someone edited files on the server. git pull --ff-only origin mainpnpm install --frozen-lockfilepnpm db:generate, thenpnpm db:deploy(applies new migrations)pnpm db:seed(safe to repeat; it only adds or repairs rows)pnpm --filter web build- Restarts the app (
pm2 reload mbx, orsystemctl restart mbx)
Options:
BRANCH=hotfix bash scripts/deploy.sh # deploy another branch
SERVICE=mbx-staging bash scripts/deploy.sh # another pm2/systemd name
RESTART_CMD="pm2 reload all" bash scripts/deploy.sh # custom restartssh mbx-live
cd /srv/mbx/app
git log --oneline -10 # find the last good commit
git checkout <good-sha>
pnpm install --frozen-lockfile && pnpm db:generate && pnpm --filter web build
pm2 reload mbxThen fix the problem on a branch, merge, and run deploy.sh again. It
switches back to main. A migration that already ran is not undone by a
rollback, so write migrations that the previous release can still work with.
| Command | Where | What it does |
|---|---|---|
docker compose up -d |
local | Start MariaDB, Redis, Mailpit |
pnpm dev |
local | Dev server on :3000 |
pnpm lint / typecheck / test |
local | The CI checks |
pnpm db:migrate |
local only | Create a new migration from a schema change |
pnpm db:reset |
local only | Wipe and rebuild the local database |
pnpm db:studio |
local | Browse the database in a web UI |
pnpm db:deploy |
both | Apply committed migrations |
pnpm db:seed |
both | Roles, permissions, settings, menus, admin user |
pnpm seed:live |
both | Sample content, images, theme, provider keys |
pnpm --filter web build |
server | Production build |
bash scripts/deploy.sh |
server | Pull and redeploy main |
pm2 logs mbx / pm2 status |
server | App logs / process state |
| Symptom | Cause and fix |
|---|---|
SKIPPED admin user during seed |
SEED_ADMIN_PASSWORD was empty. Set it and run pnpm db:seed again |
| Admin sign-in says the credentials are wrong | You may be on the learner page. Staff use /keystone |
Every page fails with a Redis or ECONNREFUSED error |
Redis is not running: docker compose up -d (local) or systemctl status redis-server (server) |
Can't reach database server |
Check DATABASE_URL and that MariaDB is up |
Changed .env but nothing happened |
.env is read at startup. Restart the app. NEXT_PUBLIC_* values also need a rebuild |
| Upload fails with 413 | Raise client_max_body_size in nginx |
| Uploaded images vanish after a redeploy | UPLOADS_DIR is blank or inside the checkout. Set it to /srv/mbx/shared/uploads |
deploy.sh: "local modifications" |
Someone edited files on the server. Look with git diff, move the change into a commit locally, then git checkout -- . on the server |
pnpm install --frozen-lockfile fails |
pnpm-lock.yaml is out of date. Run pnpm install locally, commit the lockfile, push |
Permission denied (publickey) on git pull |
The server's deploy key is missing on GitHub. See §5.3 |
Every local route answers 500 with a JSON SyntaxError |
Stop the dev server, delete apps/web/.next, start it again |