¥59.90
One-time template price with installation and customization
One-click private deployment after purchase, details Live previewDeployment Guide
MedStock runs as one public container api (8080) plus one internal container worker (3001), with all mutable data in a single volume (SQLite plus uploads). The package already contains the built artifacts, so the image only runs — it never installs or compiles.
Use this package for the marketplace upload. For local development see §5.
1. Five-minute deployment
1.1 Requirements
| Item | Requirement |
|---|---|
| Docker | 20.10+ with the docker compose subcommand |
| Resources | 0.5 CPU / 1 GB RAM / 20 GB disk (SQLite single file; add disk as data grows) |
| Port | 8080 available on the host (or change the mapping) |
| Replicas | Exactly one — SQLite cannot scale horizontally |
1.2 Start
# Option A: docker compose (volume and healthcheck included)
docker compose up -d --build
# Option B: plain docker
docker build -t medstock .
docker run -d --name medstock \
-p 8080:8080 \
-v medstock-data:/app/data \
-e JWT_SECRET="$(openssl rand -hex 32)" \
medstock
Open http://<host>:8080 and sign in as admin / admin123 (change it before going live).
1.3 What happens on first start
- Tables are created and migrations run (
apps/api/drizzle/sqlite/*.sql, idempotent) - The default organisation row is created (
ms_org) - Demo data is seeded: 7 staff accounts, 20+ drugs (near-expiry, expired, low-stock samples), purchase orders, prescriptions, dispensing records, stocktaking, temperature logs and quality events
- Default business parameters (78 keys) and the app identity (branding) are written
- The parameter cache is warmed
Demo data is only seeded into an empty database. To start over: remove the volume (
docker volume rm medstock-data) and start again.
2. What runs in the containers
| Container | Image | Listens | Public | Purpose |
|---|---|---|---|---|
api |
Dockerfile |
8080 |
yes (domain/proxy points here) | Business API plus static hosting of the frontend dist |
worker |
Dockerfile.worker |
3001 |
no (internal network only) | Placeholder background worker from the base template: serves /api/health and /api/worker/info, no business logic |
The image contains only three things:
/app/server ← apps/api/out/index.js (+ worker.js)
/app/public ← apps/web/dist (production build, includes config.js)
/app/drizzle ← migration SQL
/app/data ← volume: sqlite.db + uploads/
Dockerfile deliberately does not run bun install or vite build: the build happens on the packaging machine, so the deployment host does not need network access.
3. How the frontend talks to the backend
- The frontend uses HashRouter (all pages live under
#/...), so no server-side deep-link fallback is needed; everything outside/api/*is served statically by theapicontainer. - Runtime configuration comes from
GET /config.js, not from build-time constants:
// deployed
window.__IMX_CONFIG__ = { "apiMode": "http", "apiBase": "/api" };
// marketplace preview (injected by the preview service)
window.__IMX_CONFIG__ = { "apiMode": "mock", "apiBase": "/api" };
- To switch a deployment into demo mode temporarily: set
PUBLIC_API_MODE=mockand restart the container. index.htmlis served withno-store, so a redeploy never keeps an old HTML that points at removed chunks.
4. Environment variables
| Variable | Default | Notes |
|---|---|---|
PORT |
8080 |
Port of the api container (injected by the platform; worker is fixed at 3001) |
BIND_HOST |
0.0.0.0 |
Bind address (platform injects it from the manifest host; never use HOST for binding) |
JWT_SECRET |
dev-secret-change-me |
Must change in production: 32+ random characters |
DB_DRIVER |
sqlite |
sqlite / mysql / pg |
DATABASE_URL |
/app/data/sqlite.db |
SQLite path or database URL |
PUBLIC_DIR |
/app/public |
Frontend artifact directory |
UPLOAD_DIR |
/app/data/uploads |
Upload directory (must be on the volume) |
MIGRATIONS_DIR |
/app/drizzle |
Migration SQL directory |
PUBLIC_API_MODE |
http |
http (deployed) or mock (demo); served by /config.js |
PUBLIC_API_BASE |
/api |
Frontend request prefix |
LOG_LEVEL |
info |
debug / info / warn / error |
STORAGE_DRIVER |
local |
local (s3/oss are unimplemented stubs) |
MAIL_PROVIDER / SMS_PROVIDER |
console |
Print to logs until a real provider is configured |
CORS_ORIGIN |
* |
Same-origin deployments do not need to change it |
AI_CONFIG_SECRET |
empty | Only needed for the optional AI assistant (encrypts model keys entered in the UI) |
SUPER_ADMIN_* |
admin@example.com etc. |
Used only for the initial super-admin seed; MedStock signs in with staff usernames |
Never bake production secrets into the package; the platform injects them.
5. Local development (not deployment)
bun install
bun run dev # web on 5173 + api on 3000
bun run medstock:db # initialise or reset MedStock tables and demo data
- Locally the app runs in
httpmode (.env.localwithVITE_API_MODE=http), so sign in with a seed account. - To browse mock data locally, run
bun run dev:weband use?lang=zh; without runtime config the app falls back to mock and the login page offers demo identities. - Ports 3000 / 5173 are development ports only and unrelated to the deployed 8080 — do not mix them up in documentation.
6. Data and persistence
- Everything mutable lives under
/app/data:sqlite.dbanduploads/. docker-compose.ymldeclares the named volumeapp-data; with plaindocker runremember-v.- Container recreation does not lose data, as long as the volume survives.
Backup and restore
UI: Settings → Backup and export → one-click backup (backup-YYYYmmdd-HHMMSS.db, downloadable), cleaned up according to the retention parameter.
Command line (safest while stopped):
# backup
docker exec medstock sh -c 'cp /app/data/sqlite.db /app/data/backup-$(date +%Y%m%d).db'
docker cp medstock:/app/data/backup-20260101.db ./backup-20260101.db
# restore (stop the container first)
docker compose down
docker run --rm -v medstock-data:/data -v "$PWD":/backup alpine \
cp /backup/backup-20260101.db /data/sqlite.db
docker compose up -d
The SQLite -wal and -shm files do not need separate backups (they are rebuilt on restore), but let the container idle for a few seconds before copying so you do not copy mid-transaction.
7. Reverse proxy and HTTPS
The api container exposes a single port (8080) and serves both UI and API, so the proxy is simple:
server {
listen 443 ssl;
server_name med.example.com;
client_max_body_size 100m; # match the upload limit (default 100 MB)
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 300s; # report exports can be slow
}
}
- There are two upload limits: nginx
client_max_body_sizeand the "upload size limit (MB)" parameter (default 100). Both must be large enough. - With a same-domain proxy, leave
VITE_WS_URLempty (the frontend derives it); set it explicitly only for split domains. - Hashed assets can be cached for a long time;
index.htmland/config.jsareno-storeand must not be cached.
8. Upgrading
# 1. get the new package
unzip medstock-drug-inventory-system-upload.zip -d medstock-new
# 2. back up (important)
docker compose stop app
docker run --rm -v medstock-data:/data -v "$PWD":/backup alpine cp /data/sqlite.db /backup/pre-upgrade.db
docker compose start app
# 3. rebuild and restart with the new package
docker compose up -d --build
# 4. verify health and version
curl -s http://127.0.0.1:8080/api/health | head -c 300
- Migrations run automatically at startup and are idempotent; always back up before a major version jump.
/api/healthreturns thefeatureslist andstartedAt: check the list for new capabilities to confirm the new image is running.
9. Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Blank page or endless spinner | Frontend artifacts missing from the image (/app/public/index.html) |
Confirm the package contains apps/web/dist/index.html, rebuild the image |
| UI loads but API returns 404 | The proxy forwards / but not /api, or PUBLIC_API_BASE was changed |
Check the proxy and the content of GET /config.js |
| Deployed site shows demo data | PUBLIC_API_MODE=mock is set |
Remove the variable and restart |
| Signed out right after signing in | JWT_SECRET changes on every restart |
Pin JWT_SECRET in the platform environment |
| Upload returns 413 | nginx or the parameter limit is too small | Raise both client_max_body_size and the upload-size parameter |
| Container exits immediately | Migration failure or unwritable volume | docker logs medstock; confirm /app/data is writable |
| Data disappears after restart | /app/data is not mounted |
Add -v medstock-data:/app/data |
| Times are off by 8 hours | Container runs in UTC | -e TZ=Asia/Shanghai |
10. Packaging and upload (for the template vendor)
bun run check # design gate + i18n + permissions + business dictionary + typecheck
bun run test # 1012 tests
bun run pack:upload # build → check:dist(http) → pack → verify (33 checks)
The package must contain: apps/web/dist (production build, dist/.build-meta.json with apiMode: "http"), apps/web/dist/config.js, apps/api/out/index.js, apps/api/out/worker.js, Dockerfile, Dockerfile.worker, intematrix.deploy.json, docs/ (four user documents plus docs.json and rag.json, Chinese and English), and conversation.seed.json at the package root.
The package must not contain: node_modules, data/, real .env files, logs or .db files. Internal material that should never reach buyers (docs-internal/, AGENT.MD, skills/) is hidden by .intematrixignore at client download time.
Marketplace form values: port 8080, Dockerfile Dockerfile, build context ., max replicas 1, two apps (apps/api → api, apps/web → web, both pointing at Dockerfile, port 8080).
11. Redeploying after custom development
bun install # only when dependencies changed
bun run build # regenerate apps/web/dist and apps/api/out
bun run check && bun run test
bun run pack:upload # repackage and self-check
# then follow §8 "Upgrading" with the new zip
When the schema changes: bun run --filter api db:generate produces a new migration, which ships inside /app/drizzle and runs automatically at startup.
12. Domains and the HOST variable
- the same template is deployed many times, so never hardcode domains or callback URLs;
- the platform injects
HOST(current container domain),PUBLIC_HOST/PUBLIC_URL(public container),DEPLOYMENT_IDandBIND_HOST; - build links from
process.env.PUBLIC_URL ?? process.env.HOSTat runtime; - internal networking: the container name is the DNS name (
http://worker:3001); the platform also injectsAPI_HOST/PORT/IPandWORKER_HOST/PORT/IP; - the internal network is closed (
docker --internal): containers cannot reach the internet, so dependencies must be baked into the image.
13. Health check and self-verification
GET /api/health→200 {"status":"ok","service":"api","features":[...34 flags...],"startedAt":"..."}- The platform probes
healthcheck.path(/api/health) with a 60 s timeout. - To debug "my change is not live": check whether
startedAtis the new start time, then whetherfeaturescontains the capability you added.
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.
