¥79.90

One-time template price with installation and customization

One-click private deployment after purchase, details

Choose a payment method

Live preview
Version 1.0.0 Updated 11/26/2026 0 downloads · 0 deployments Education

Deployment Guide

This document explains how to deploy AIQuiz onto a server of your own. Finish section 1 and you can reach the site; everything after that is reference material for configuration, backup, and troubleshooting.

The delivery package already contains the built artifacts (apps/web/dist, apps/api/out, apps/api/drizzle), so deployment needs no Node installation, no dependency installation, and no build commands.


1. Five-Minute Deployment

1. Environment requirements

Item Requirement
How it runs Docker (24 or newer recommended), or any machine that can run Bun 1.4
Resources Minimum 1 vCPU / 1 GB RAM / 20 GB disk; for classes in the hundreds, 2 vCPU / 2 GB recommended
Operating system Linux (amd64 or arm64 both fine)
Port Fixed at 8080 inside the container; the host port can be changed
Replicas Exactly 1 (the database is a single-file SQLite database; multiple replicas will corrupt the data)

2. Start it

Run this in the root of the delivery package:

# 1) Set the two values you must change first (otherwise you fall back to default passwords, see section 5)
export JWT_SECRET=$(openssl rand -hex 32)
export SUPER_ADMIN_PASSWORD='use-your-own-strong-password-here'

# 2) Build and start
docker compose up -d --build

# 3) Check the status (it is only really up once the health check passes)
docker compose ps
docker compose logs -f app

Then open http://SERVER_IP:8080 in a browser:

  • Health check: http://SERVER_IP:8080/api/health (returns ok plus a features capability list, see section 10)
  • Log in with admin@example.com + the SUPER_ADMIN_PASSWORD you set. The first login is stopped at the change-password page (a seed password written in the docs is a public password); only then can you enter the school admin console.

3. What the first start does automatically

On the first start (/app/data empty), the service completes these in order:

  1. Run database migrations: it reads the migration files under /app/drizzle and creates all tables. The log prints migrations applied (sqlite).
  2. Write demo data: school / subjects / textbook editions / four-level topic tree / classes and students / question bank / papers / practices / submissions / wrong questions, for acceptance testing and training; the demo data is written idempotently, so a restart will not insert it twice.
  3. Create the super admin: the account comes from SUPER_ADMIN_EMAIL, the password from SUPER_ADMIN_PASSWORD, and "must change password on first login" is set.

Once startup finishes, call the health check endpoint again; an ok response means you are done.

The demo data and demo accounts are for acceptance testing and training. Before going live, deal with the demo content you do not need.

Note the idempotency rule of the seed: existing records are not overwritten, but if a table is emptied, a restart will seed the demo data back into it. So the recommended approach is "turn the demo data into your real data" (change the school name, the classes, the students, the questions) rather than bulk-emptying tables. Demo accounts are in the Product Spec.


2. Plain Docker Without Compose

If compose is inconvenient on your server, the equivalent commands are:

docker build -t aiquiz:1.0 .

docker run -d --name aiquiz \
  -p 8080:8080 \
  -v aiquiz-data:/app/data \
  -e JWT_SECRET="$(openssl rand -hex 32)" \
  -e SUPER_ADMIN_PASSWORD='use-your-own-strong-password-here' \
  --restart unless-stopped \
  aiquiz:1.0

-v aiquiz-data:/app/data is not optional; it is the only directory that needs persistence (see section 6).

intematrix.deploy.json in the package root is the manifest read by the platform's "one-click deploy" (single container, port 8080, health check /api/health, 0.5 vCPU / 1 GB). When you deploy through the platform you do not need to type the commands above; docker-compose.yml suits your own server or local debugging better.


3. What Runs Inside the Container

The delivery package is a single container: one Bun process is both the backend API and the host for the frontend static files.

Content Path in the container Description
Backend artifact /app/server/index.js Start command bun server/index.js
Frontend artifact /app/public Served by the API; / returns index.html
Migration files /app/drizzle Run automatically at startup
Data directory /app/data SQLite database + uploaded files, must be a mounted volume
Entry point Address Description
Frontend http://host:8080/ Teacher side and student H5 on the same site
API http://host:8080/api/** Business endpoints
Runtime configuration GET /config.js The frontend loads it from index.html first, and it decides "real API or demo data" (see section 4)
Health check GET /api/health Returns ok
API docs http://host:8080/docs Swagger (open by default, see section 8)

The frontend uses HashRouter and all routes live after #/, so you do not need a "fall back to index.html when the file is missing" rewrite rule for the frontend.


4. How Frontend and Backend Connect (runtime configuration, not build time)

The frontend in the upload package is a production build (apiMode is http in apps/web/dist/.build-meta.json). Which mode it runs in is decided by the runtime configuration at deploy time, not by how it was packaged:

Browser → index.html → <script src="./config.js"> → window.__IMX_CONFIG__ = { apiMode, apiBase }
                              ↓
         apiMode = http  → always use the real API (the normal deployed state)
         apiMode = mock  → use demo data held in browser memory (marketplace online preview / local demo)

/config.js is emitted by the backend (an early onRequest interception, ahead of static files), and its content comes from environment variables:

Variable Default Effect
PUBLIC_API_MODE http The apiMode emitted to the frontend. Keep http in deployment; only switch to mock if you want a local demo
PUBLIC_API_BASE /api The API prefix emitted to the frontend; no change needed when frontend and backend share a domain

Three conclusions follow:

  1. The same artifact works both as a real deployment and as an online preview — deployment has PUBLIC_API_MODE=http (hard-coded to http in the image), and the marketplace preview has mock injected by the preview service.
  2. There is no "probe the backend" step any more. The old version guessed from the frontend whether a backend existed (GET /api/health, 1.5-second timeout, failure latched), with the result that "if the container was not reachable in those first few seconds, the whole site stayed on demo data". That logic has been deleted.
  3. The frontend does not log in automatically. Even in demo mode (apiMode=mock) it stops at the login page and only enters the workspace when you click a demo identity — avoiding "leftover demo mode in the browser after deployment".

One command to check for yourself:

curl -s http://SERVER_IP:8080/config.js
# Expected: window.__IMX_CONFIG__ = {"apiMode":"http","apiBase":"/api"};

5. Environment Variables

All the variables below have defaults, so "it starts even if you configure nothing"; but the two in bold must be changed before going live.

Variable Default Description
PORT 8080 (in the container) Port to listen on inside the container; usually no need to change. To change the host port, change the port mapping in compose. If unset it falls back to 3000, which does not match the 8080 the image exposes
BIND_HOST 0.0.0.0 Bind address. Injected during platform deployment; usually not set when you run docker yourself. Setting it to 127.0.0.1 makes the container fail its health probe
NODE_ENV production (already set in the image) Must be production. The image only serves the frontend static files under production; otherwise visiting the page returns 404 directly
JWT_SECRET dev-secret-change-me Signing key for login tokens. Must be replaced with a random string of at least 32 characters, otherwise anyone can forge a login session
PUBLIC_API_MODE http (already set in the image) The runtime mode that /config.js emits to the frontend. Always http in deployment; mock is only for local demos
PUBLIC_API_BASE /api The API prefix that /config.js emits to the frontend
DB_DRIVER sqlite Database type. The business tables in this package implement the SQLite dialect; any other value fails at startup
DATABASE_URL /app/data/sqlite.db Database file path, which must be inside the persistent volume
PUBLIC_DIR /app/public Frontend artifact directory
UPLOAD_DIR /app/data/uploads Upload directory, which must be inside the persistent volume
MIGRATIONS_DIR /app/drizzle Migration file directory, executed at startup. This value is built into the image; do not omit it or point it somewhere else, or startup will not find the migration files
LOG_LEVEL info debug / info / warn / error
STORAGE_DRIVER local File storage driver; local means the local disk (s3 / oss are reserved and not currently implemented)
MAIL_PROVIDER console Email sending; console means it only prints to the log
SMS_PROVIDER console SMS sending; console means it only prints to the log
CORS_ORIGIN * Allowed cross-origin sources. The default is fine when frontend and backend share a domain
SUPER_ADMIN_PASSWORD Admin@123456 Initial super admin password; must be changed before the first start
SUPER_ADMIN_EMAIL admin@example.com Super admin account
SUPER_ADMIN_NAME Super Admin Super admin display name
RATE_LIMIT_LOGIN_PER_MINUTE 30 Login requests per IP per minute; <=0 disables it. It only applies to the base-platform account endpoints — AIQuiz's own login endpoint is not rate-limited, so do not count on it to stop credential stuffing
WS_TICKET_TTL_SEC 60 Lifetime of one-time tickets for the realtime channel (seconds)

AI generation related (optional, see section 7):

Variable Default Description
AI_PROVIDER empty Provider identifier (OpenAI-compatible protocol)
AI_API_KEY empty Provider key
AI_MODEL empty Model name
AI_BASE_URL empty API address when you use your own gateway/proxy
AI_CONFIG_SECRET empty Passphrase used to encrypt keys saved under the console "AI settings"; generate with openssl rand -hex 32

⚠️ The super admin password is only written when this account does not exist in the database yet. If /app/data already has data, changing SUPER_ADMIN_PASSWORD will not change the password — to change it, use the console's user management or reinitialize from an empty data directory.

⚠️ Login tokens never expire. Changing JWT_SECRET logs everyone (including you) out and forces a fresh login, so once the key is set, keep it fixed.


6. Data and Persistence

Only /app/data needs persistence. It holds two kinds of things:

Path Content
/app/data/sqlite.db All business data (accounts, question bank, papers, submissions, results, review records, system settings)
/app/data/sqlite.db-wal, -shm SQLite write-ahead logs (the database runs in WAL mode; these two files cannot be copied away on their own)
/app/data/uploads/ Uploaded material files and attachments (public address /upload/year/month/day/xxx)
/app/data/ai-config-secret The passphrase file used to encrypt keys saved under the console "AI settings" (generated automatically when AI_CONFIG_SECRET is not set)

Three constraints:

  1. A volume is mandatory, otherwise data is lost the moment the container is recreated.
  2. Exactly 1 replica. SQLite is a single-file database, and the cache/queue/rate limiting are all in-process; two processes writing at the same time will corrupt the database. To scale, add resources vertically, not replicas horizontally.
  3. Backups must be taken at the volume level (see below). The data backup button under the console "System tools" currently only records a backup metadata entry and does not actually produce a backup file, so do not rely on it.

Backup and restore

# Backup (copying with the service stopped is the safest; under WAL mode a live single-file copy may be inconsistent)
docker compose stop app
docker run --rm -v aiquiz-data:/data -v "$PWD":/backup alpine \
  tar czf /backup/aiquiz-$(date +%F).tar.gz -C /data .
docker compose start app

# Restore (unpack the backup contents back into the data volume)
docker compose stop app
docker run --rm -v aiquiz-data:/data -v "$PWD":/backup alpine \
  sh -c "rm -rf /data/* && tar xzf /backup/aiquiz-YYYY-MM-DD.tar.gz -C /data"
docker compose start app

The data volume name defaults to "project directory name_app-data"; use docker volume ls to confirm the real name.

When restoring, be sure to bring ai-config-secret back too, otherwise the AI keys you previously saved in the console cannot be decrypted and must be re-entered.


7. AI Generation (Optional)

The generation flow works end to end without any AI configuration: the generated results then come from "isomorphic rewriting", suitable for demos and for walking through the flow, with question quality not meant as formal teaching content.

To enable real generation, pick one of two ways:

Option 1: environment variables

AI_PROVIDER=openai
AI_API_KEY=sk-...
AI_MODEL=gpt-4o-mini
# Only for a self-hosted gateway or proxy: AI_BASE_URL=https://your-gateway/v1

Then restart with docker compose up -d for it to take effect.

Option 2: the console UI

Log in to the console → fill in the provider and key under "AI settings". The key is encrypted with AI_CONFIG_SECRET before being stored in the database, and the UI only shows a mask. This suits scenarios where you do not want the key in environment variables or the compose file.

Supported providers use the OpenAI-compatible protocol; AI_PROVIDER can be openai / anthropic / google / deepseek / xai / mistral / groq / openrouter / azure / compatible and so on; compatible requires both AI_BASE_URL and AI_MODEL.


8. Reverse Proxy and HTTPS

In production, put nginx in front. Key points:

server {
    listen 80;
    server_name aiquiz.example.com;

    # Material uploads: without this, nginx's default 1MB limit blocks them (the application has its own cap, see below)
    client_max_body_size 64m;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 300s;
    }

    # The realtime channel needs the WebSocket upgrade
    location /api/ws {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 3600s;
    }
}

Set client_max_body_size according to the material size you allow; X-Forwarded-For must be passed, otherwise login rate limiting treats every request as coming from the same IP.

Two upload limits

Material uploads pass two gates, so do not adjust only one of them:

Location Default How to adjust
Application (KV settings) 10 MB per file, at most 20 files per request, only 18 extensions such as images/documents/archives Change keys like upload.maxSizeMb under the console "Settings"; saving takes effect immediately
Reverse proxy nginx default 1 MB client_max_body_size in the config above

What going over the limit looks like: the application returns 413 (size exceeded) or 415 (extension not allowed).

About Swagger

/docs is open by default (an interactive API reference). If you do not want it exposed, block it in nginx:

location /docs { return 404; }

9. Upgrading

  1. Back up /app/data (see section 6).
  2. Replace the files with the new delivery package (leave /app/data untouched).
  3. docker compose up -d --build.

New database migrations run automatically at startup, and demo data seeding is idempotent (skipped when it already exists), so it will not overwrite your business data.

Rolling back: just swap the delivery package back to the older image, but a database that the newer version has migrated may not be readable by the older version, which is why the backup before upgrading is mandatory.


10. Troubleshooting

Symptom Cause and fix
Port 8080 will not open Check with docker compose ps whether the container is healthy; check the startup log with docker compose logs -f app
The log shows migrations applied and then exits immediately Most likely a /app/data permission problem or a full disk; check the owner of the mounted directory and the free space
The health check keeps failing The first start has to run migrations + seeding, so this is normal within start_period; if it is still failing after 1 minute, read the log
Logged out immediately after login / repeated logins required JWT_SECRET changes on every restart (no fixed value set); pin it as an environment variable
Uploading materials returns 413 nginx's client_max_body_size is too small
The page works but keeps showing demo data First check curl /config.js: if apiMode is mock, that is the reason. In a deployment set PUBLIC_API_MODE=http (the image default is already http; this happens when compose or the platform environment variables set it to mock)
/config.js returns 404 or stale static content This file must be emitted by the backend. Confirm you are hitting the deployment address (not pure static hosting) and that PUBLIC_DIR points to the directory containing index.html
No demo identity buttons on the login page Normal. Demo identities only appear when apiMode=mock (marketplace online preview); the login page of a real deployment does not render demo accounts
The console keeps asking for a password change mustChangePassword has not been cleared yet: the change-password endpoint /api/auth/change-password clears the flag, and an admin reset sets it again
Data corruption or intermittent write failures Most likely more than one replica is running; set the replica count back to 1

Prove the environment first (do not suspect the code first)

# 1) Which mode is the frontend running in
curl -s http://SERVER_IP:8080/config.js

# 2) Is the backend this version (does features contain the capability name you need)
curl -s http://SERVER_IP:8080/api/health | head -c 600

# 3) Type of error on the page (browser console)
#    "mock mode is missing mockData" → the frontend is in mock mode but the API carries no demo data
#    "request failed (HTTP 404)"     → a real request was sent; check step 2's features for that capability

The features in /api/health is a hand-written capability list (apps/api/src/routes/health.ts); when you add an endpoint you must add it there too, otherwise this self-diagnosis trick stops working.


11. Custom Development (Redeploy After Changing the Source)

The delivery package also contains the full source, so when you need to change functionality, build locally:

bun install

# Production build: frontend apps/web/dist + backend apps/api/out
bun run build
bun run check:dist        # should print: dist mode: http (per .build-meta.json)

# Then rebuild the image
docker compose up -d --build

Two notes:

  • Build the frontend with bun run build (production build), not build:mock: build:mock is only for local demos, and the upload gate (bun run verify:upload) rejects mock artifacts. check:dist exists to regress exactly this point.
  • The image only COPYs the artifacts; it does not build inside the image: after changing code, run the build commands above on your own machine first, otherwise docker build has no new artifacts to copy.

Building your own upload package

bun run pack:upload
# = check (design/i18n/permission gates + type checking) → test → build → check:dist → pack → verify:upload

verify:upload is this project's packaging gate (five layers agreeing on port 8080, apiMode in dist/.build-meta.json must be http, dist/config.js present in the package, all four user documents + docs.json + docs/rag.json complete in both Chinese and English, conversation.seed.json matching the package.json version, and no node_modules / data / keys in the package). Only upload once all 32 of its checks are green.

After packaging you must restart the service before accepting the build: staticPlugin preloads the static file table at startup, so newly built JS with new hashes is not in that table and the old process returns 404 (the symptom is "a blank page with no error at all in the console").

For directory conventions and development details see README.md and AGENT.MD in the package root.

Frequently asked questions

What do I get after purchase?
The full source code (web frontend + API backend), deployment documentation and an online preview. After purchase you can download it from "My Projects" and use it for your own product.
Can it be deployed to my own server?
The Web + API edition supports one-click private deployment, so data stays on your own infrastructure. Mini-program and App add-on packages are not one-click deployable.
Can I get a refund?
Orders whose code package has not been downloaded can request a refund through a support ticket. Once the code package has been downloaded, refunds are not supported.
How do I reach support?
Open "My Projects" and click "Support" to submit a ticket. Staff reply inside the ticket, and status changes are pushed as WeChat notifications.

部署 API Key

用于「一键部署」与部署 Skill/脚本;明文经服务端 RSA 加密后由本页解密,不会明文出网。

你的 API Key(前缀 )
配置环境变量 INTEMATRIX_DEPLOY_APIKEY
export INTEMATRIX_DEPLOY_APIKEY=imd_xxx

macOS/Linux 追加到 ~/.zshrc 或 ~/.bashrc 可持久化;Windows 的 setx 需重开终端生效。

重置后旧 Key 立即失效;请勿把 Key 写进前端代码或提交到仓库。