◉ Pulse
Evanli21 avatar
#3 today

Evanli21/token-factory

TypeScript App

https://szrouter.shop/

Created Jul 22, 2026
Stars
69
Today
+69
Forks
0
Quality
85/100
Momentum
24

README

Fetched from GitHub on Oct 30, 2026, 9:23 PM UTC · README.md

View original on GitHub

Third-party content — Open Source Pulse is not the owner of this repository.

This README belongs to Evanli21/token-factory and its contributors. We fetch it directly from the project’s public GitHub repository and display it for reference only. All text, code, images and trademarks remain the property of their respective authors. See the repository for its license terms. Copyright / takedown policy.

SZRouter

SZRouter 是一个可自托管的多租户 AI Token 平台:前台、运营后台、OpenAI Compatible API Gateway、异步 Worker、PostgreSQL/pgvector、Redis/BullMQ 与 Nginx/Let's Encrypt 都包含在同一个 TypeScript monorepo 中。

能力概览

  • Web 前台:注册登录、API Key、充值订单/卡密、模型广场、价格中心、流式 Playground、知识库与引用问答、Agent 市场、Workflow、组织租户、数据导出。
  • Admin 后台:管理员登录、用户/模型/渠道/订单/卡密管理、调用日志、内容审核、代理与提现、组织财务、月结/PDF 账单、告警、后台任务、审计日志与平台总览。
  • Gateway:API Key 鉴权、用户/组织余额预扣和结算、Token/工具/Agent 计费、Redis 限流、月度额度、加权渠道选择、熔断与失败回退、SSE、内容审核。
  • RAG:PDF/DOCX/TXT/MD 解析、1536 维 Embedding、pgvector HNSW、向量+全文混合检索、本地 Rerank 和来源引用。
  • Worker:邮件、Webhook 重试、导出、文档解析与 Embedding、知识库/Agent 评估、月报/PDF 账单、对账、告警与日志清理。

目录

token-factory/
├── web/                 Next.js 用户前台(3000)
├── admin/               Next.js 管理后台(3001)
├── gateway/             Express API Gateway(8000)
├── worker/              BullMQ Worker / Scheduler
├── packages/database/   Prisma Client、Schema、pgvector SQL
├── nginx/               三域名反向代理与 TLS 配置
├── docs/                API、架构和部署文档
├── docker-compose.yml
└── docker-compose.prod.yml

一键本地启动

前置条件:Docker 24+ 与 Docker Compose v2。

cp .env.example .env
# 至少修改 ADMIN_PASSWORD、JWT_SECRET、API_KEY_PEPPER 和数据库密码
docker compose up -d --build

服务地址:

首次启动会自动创建数据库表、pgvector 索引与演示数据。演示用户为 demo@szrouter.local / demo123456。未配置 OPENAI_API_KEY 时使用内置 Mock 渠道,便于完整验证登录、API Key、余额计费和 SSE;配置真实 Key 后执行 docker compose restart gateway worker 并重新运行 docker compose exec gateway npm run db:seed。

查看状态与日志:

docker compose ps
docker compose logs -f gateway worker
curl http://localhost:8000/health

停止服务(保留数据):

docker compose down

非 Docker 开发

本机需要 Node.js 20+、PostgreSQL 16 + pgvector、Redis 7。

cp .env.example .env
# 把 DATABASE_URL / REDIS_URL 的主机名改为 localhost
npm install
npm run prisma:generate
npm run db:push
npm run db:seed
npm run dev

质量检查:

npm test
npm run typecheck
npm run build

OpenAI Compatible API

创建 API Key 后:

curl http://localhost:8000/v1/chat/completions \
  -H "Authorization: Bearer sz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model":"gpt-4o-mini",
    "stream":true,
    "messages":[{"role":"user","content":"Hello SZRouter"}]
  }'

接口:

  • GET /v1/models
  • POST /v1/chat/completions
  • POST /v1/embeddings
  • POST /v1/agent/chat
  • POST /v1/knowledge/:id/ask
  • POST /v1/workflows/:id/run

请求鉴权支持 Authorization: Bearer sz_... 或 X-API-Key;历史 tf_... Key 仍可继续使用。更多示例见 docs/API.md。

生产部署与域名

  1. 将代码放到安装了 Docker 的 Linux 服务器,确保 80/443 端口开放。
  2. 复制并填写生产配置:
cp .env.example .env.production

必须替换所有 change-* 值,并设置:

DOMAIN=yourdomain.com
LETSENCRYPT_EMAIL=admin@yourdomain.com
NEXT_PUBLIC_BASE_URL=https://yourdomain.com
NEXT_PUBLIC_API_BASE_URL=https://api.yourdomain.com
ADMIN_BASE_URL=https://admin.yourdomain.com
GATEWAY_PUBLIC_URL=https://api.yourdomain.com
CORS_ORIGINS=https://yourdomain.com,https://admin.yourdomain.com

DNS 需要配置三个 A/AAAA 记录指向服务器:yourdomain.com、admin.yourdomain.com、api.yourdomain.com。

首次签发证书并启动:

set -a; source .env.production; set +a
bash scripts/init-letsencrypt.sh
docker compose -f docker-compose.prod.yml ps

后续部署:

docker compose --env-file .env.production -f docker-compose.prod.yml up -d --build

续签证书(可放入 cron):

docker compose --env-file .env.production -f docker-compose.prod.yml run --rm certbot renew
docker compose --env-file .env.production -f docker-compose.prod.yml exec nginx nginx -s reload

详见 docs/DEPLOYMENT.md 与 docs/ARCHITECTURE.md。

打包

在项目根目录运行:

npm run pack

压缩包会生成在项目上一级目录:token-factory.zip。脚本排除 .git、node_modules、.next、dist、.env*(保留 .env.example)、日志、上传和导出目录。

管理员登录

Admin 没有写死的用户名。打开 http://localhost:3001/login,输入 .env 中配置的 ADMIN_PASSWORD。生产环境建议再使用 Cloudflare Access、VPN 或企业 SSO 保护 Admin 域名。

上传到 GitHub

第一次上传:

git init
git add .
git commit -m "complete SZRouter platform"
git branch -M main
git remote add origin https://github.com/Evanli21/token-factory.git
git push -u origin main

后续更新:

git add .
git commit -m "update SZRouter"
git push origin main

.gitignore 已排除 .env、.env.production、node_modules、.next、dist、日志、上传和导出文件。提交前仍应执行 git status,确认没有密钥。

常见问题

  • 页面 404:拉取最新代码并重新构建;Web 与 Admin 清单中的 URL 现在都有真实 App Router 页面。
  • 前端显示网络错误:确认 NEXT_PUBLIC_API_BASE_URL 是浏览器可以访问的 Gateway 地址,修改后必须重新构建 Next.js。
  • Gateway 无法启动:先运行 docker compose ps,确认 PostgreSQL 和 Redis 健康;再看 docker compose logs gateway。
  • 文档一直 PENDING:检查 Worker 日志、Redis 连接、上传卷以及 Embedding 上游配置。
  • 向量表不存在:运行 npm run db:sql;全新数据库也可运行 npm run db:migrate。
  • 真实模型不可调用:在 .env 中设置上游 API Key,或在 Admin 的渠道管理中增加 OpenAI-compatible 渠道和模型映射。
  • 端口被占用:关闭占用 3000、3001、8000、5432 或 6379 的本地程序,或修改 Compose 端口映射。

完整生产部署、备份和回滚步骤见 DEPLOY.md。完整修复审计见 docs/AUDIT.md。

上线前安全清单

  • 替换数据库、Redis、管理员、JWT、内部 API 和 API Key pepper 的所有默认密钥。
  • 禁用演示用户,配置真实支付 Webhook 后再开放充值;当前订单接口不会伪造支付成功。
  • 上游渠道密钥当前保存于数据库字段。正式环境建议接入 KMS/Vault,并在渠道创建接口前置企业 SSO。
  • 将 Admin 域名放在 VPN、Cloudflare Access 或其他 Zero Trust 身份层之后。
  • 配置对象存储、备份、集中日志与告警接收人;验证恢复流程。
  • 按地区法规补齐隐私政策、退款规则、内容政策和数据保留策略。

License

Proprietary. Add your organization license before public distribution.

Rendered by GitHub from the repository’s README. Scroll to read the full file.
First trending

Jul 22, 2026

first spotted on the list

Best rank

#3

top 3 on trending

Appearances

2

times on the trending list

Quality score

85

out of 100

Momentum

24

trend strength indicator

Star velocity

0.69

stars per day since creation

Activity — last 60 days

daily counts, collected every 6 hours
  • Stars
  • Forks
  • Merged PRs
  • Issues
  • Closed issues

Collecting activity data since launch — check back in a few days.

Star history

total stars per snapshot
1020304050607080Evanli21/token-factory · Jul 22, 7 PM UTC: 24 starsEvanli21/token-factory · Jul 23, 8 AM UTC: 69 stars7 PM2 AM8 AM

Rank history

position on trending · lower is better
#1#3#4#5#6#7#8#9#10Jul 22, 7 PM UTC: rank #10Jul 23, 8 AM UTC: rank #37 PM2 AM8 AM

3D card for your website

Live HTML card with a glass surface and pointer tilt. Paste the iframe on any website.

<iframe src="https://www.notionpulse.cc/embed/Evanli21/token-factory" width="420" height="240" style="border:0;max-width:100%;background:transparent" loading="lazy" title="Evanli21/token-factory — trending on Open Source Pulse"></iframe>

Stars badge

Show current stars in your README or profile. Auto-updates every 6 hours.

Evanli21/token-factory stars badge
Markdown
[![Evanli21/token-factory](https://www.notionpulse.cc/api/badge/Evanli21/token-factory.svg)](https://www.notionpulse.cc/repo/Evanli21/token-factory)
HTML
<a href="https://www.notionpulse.cc/repo/Evanli21/token-factory"><img src="https://www.notionpulse.cc/api/badge/Evanli21/token-factory.svg" alt="Evanli21/token-factory stars badge" /></a>

Repository of the Day

#3 Repository of the Day

Repository of the Week

#3 Repository of the Week

Repository of the Month

#3 Repository of the Month