ShipAny Image Lite

新官方
Iidoubi·发布于 3个月前
$199$49会员价

专注的 AI 图片生成器:文本与参考图生成,配齐账户、积分、订阅和管理后台。

ai-image-generator
成为 ShipAny Premium 会员,即可用会员价购买模板

技术栈

Next.jsTanStackReactTailwindCSSShadcn/UIAI SDKNode.js

ShipAny Image Lite 是什么?

ShipAny Image Lite 是基于 TanStack Start 和 ShipAny SaaS 引擎的专注型 AI 图片生成器。它把一个公开生成器(提示词加可选参考图)与账户、积分、订阅、「我的作品」、权限和管理后台组合在一起。

它刻意保持产品面精简:把一个生成页面做好,方便你围绕单个模型或细分方向快速上线,之后再逐步加功能。

适合谁

  • 想上线单一功能图片站的开发者
  • 想先验证细分方向的创业者
  • 希望代码量小、易于定制的工程师
  • 围绕某个新图片模型建站的团队

核心功能

文本与参考图生成

用户输入提示词,并可上传参考图引导生成结果。

我的作品

每位用户私有的生成作品库。

积分与订阅

按张扣积分,通过内置收银台售卖套餐和积分包。

管理后台

管理用户、角色、订单和设置,配置 AI、存储、支付、邮件、OAuth 和统计。

适配 Cloudflare

通过内置 /deploy-cloudflare 技能部署到 Workers + D1 + R2。

包含内容

框架
TanStack Start、Vite 8、Nitro、React 19、TypeScript
UI
Tailwind CSS 4、shadcn/ui v4
登录与多语言
better-auth、Paraglide JS
数据库
Drizzle ORM:本地 SQLite;生产可用 PostgreSQL、MySQL、Turso 或 D1
存储
Cloudflare R2 或 S3 兼容存储(生产环境上传必需)
部署
Cloudflare Workers(D1、R2、Hyperdrive)或 Node

如何开始

  1. 1

    安装与配置

    执行 pnpm install,复制 .env.example,设置 AUTH_SECRET 和 CONFIG_ENCRYPTION_KEY。

  2. 2

    准备数据库

    依次运行 db:setup、db:push 和带管理员邮箱的 rbac:init,然后 pnpm dev。

  3. 3

    配置并部署

    在后台「设置」中填写 AI、存储和支付密钥,然后运行 /deploy-cloudflare。

可以用 ShipAny Image Lite 做什么

单模型图片站

专门围绕一个热门图片模型的网站。

细分生成器

面向特定人群的头像、壁纸、Logo 或商品图生成。

MVP 验证

先用付费图片工具验证需求,再投入更多功能。

常见问题

选 Image Lite 还是 Image Generator?

只要一个专注的生成器、代码更少,选 Image Lite;还需要抠图、放大、扩图和风格迁移工具,选 Image Generator。

需要对象存储吗?

生产环境需要。参考图上传和生成结果要存到 R2 或 S3 兼容存储,因为 Workers 没有可写磁盘。

服务商密钥在哪里设置?

在后台「设置」中,环境变量只作为备用值。

技术说明(README)

Image Lite

Image Lite is a focused AI image generator built with TanStack Start and the ShipAny SaaS engine. It combines a public text/reference-image generator with accounts, credits, subscriptions, My Creations, RBAC, and an admin console.

Stack

  • TanStack Start, Vite 8, Nitro, React 19, and TypeScript
  • Tailwind CSS 4 and shadcn/ui v4
  • TanStack Query, Router, Form, and Table
  • better-auth, Drizzle ORM, and Paraglide JS
  • SQLite for local development; PostgreSQL, MySQL, Turso, or Cloudflare D1 in production
  • Cloudflare Workers, D1, R2, and Hyperdrive support

Local development

Requirements

  • Node.js 22+
  • pnpm 10+
  • OpenSSL

Enable pnpm through Corepack if necessary:

corepack enable

1. Install and configure

pnpm install
cp .env.example .env.development

Generate two independent secrets:

openssl rand -base64 32
openssl rand -base64 32

Put the first value in AUTH_SECRET and the second in CONFIG_ENCRYPTION_KEY inside .env.development. Never commit that file.

2. Prepare the local database

pnpm db:setup
pnpm db:push
pnpm rbac:init \
  --admin-email=admin@example.com \
  --admin-password=choose-a-local-password

db:push directly synchronizes the development database and may be destructive. Do not use it against a production database.

3. Start the app

pnpm dev

Open:

After signing in as the administrator, configure AI, storage, payments, email, OAuth, and analytics under Admin → Settings. Provider credentials belong in the admin settings; environment variables are only fallback values.

Debugging and verification

Command Purpose
pnpm dev Start Vite on port 3000 with hot reload
pnpm build Build the production client and Nitro server
pnpm start Run the generated Node server from .output/
pnpm format:check Check formatting without changing files
pnpm db:studio Inspect the current database in Drizzle Studio
pnpm db:push Sync schema changes to a development database
pnpm db:generate Generate reviewable production migration SQL
pnpm db:migrate Apply migrations to a direct database connection

Use .env.development as the single local environment file. Conflicting values in .env.local can override it and commonly cause database or auth origin problems.

Before pushing code, run:

pnpm format:check
pnpm build

To test the generated Node bundle locally:

pnpm build
pnpm start

Common local problems

Symptom Fix
Database tables are missing Run pnpm db:setup and pnpm db:push
Sign-in reports an invalid origin Keep VITE_APP_URL=http://localhost:3000
Image generation is unavailable Configure an AI provider in Admin → Settings
Reference-image upload fails Configure public R2/S3 storage in Admin → Settings
Admin returns 403 after assigning a role Sign out and sign in again

Environment variables

The committed .env.example intentionally contains only the local essentials.

Variable Required Notes
VITE_APP_URL Yes Public URL used by auth, callbacks, and SEO
VITE_APP_NAME Yes Product name shown in the UI
DATABASE_PROVIDER Yes sqlite, postgresql, mysql, turso, or d1
DATABASE_URL Local/Node Direct database connection string
AUTH_SECRET Yes Generate with openssl rand -base64 32
CONFIG_ENCRYPTION_KEY Recommended Encrypts secrets saved from Admin → Settings

Only public browser-visible values may use the VITE_ prefix. Never expose database credentials, API keys, or auth secrets through VITE_* variables.

Database changes

For development:

pnpm db:push

For production, generate and review a migration before applying it:

pnpm db:generate
# Review the SQL under drizzle/.
pnpm db:migrate

src/config/db/schema.ts and drizzle/ are working files and are ignored by Git. The committed dialect templates live under src/config/db/.

Deploy to Cloudflare Workers

Cloudflare Workers with D1 is the default deployment target. Production image upload also requires R2 or another public S3-compatible storage provider; a Worker has no persistent writable filesystem.

In a compatible coding-agent environment, run:

/deploy-cloudflare

The project deployment skill performs the build, creates or reuses D1 or Hyperdrive, applies migrations, seeds RBAC, uploads secrets, configures the production URL, deploys, and smoke-tests the result. It always asks before the final production deployment. Run it again for subsequent releases.

Manual D1 deployment

1. Authenticate and create the working config

npx wrangler login
cp wrangler.example.jsonc wrangler.jsonc
npx wrangler d1 create image-lite-db

In the ignored wrangler.jsonc, replace the D1 placeholder with the returned database ID. Keep the binding name DB, DATABASE_PROVIDER set to d1, and migrations_dir set to drizzle.

2. Set the production URL

Create the ignored .env.production:

VITE_APP_URL=https://image-lite.<your-subdomain>.workers.dev
VITE_APP_NAME=Image Lite
DATABASE_PROVIDER=d1

Set the same VITE_APP_URL and VITE_APP_NAME in wrangler.jsonc vars. They must match because the URL is used during both build and runtime.

For a custom domain, add this to wrangler.jsonc and use the same domain for VITE_APP_URL:

"routes": [{ "pattern": "images.example.com", "custom_domain": true }]

The domain or its parent zone must already exist in the Cloudflare account.

3. Generate and apply migrations

DATABASE_PROVIDER=d1 pnpm db:setup
DATABASE_PROVIDER=d1 pnpm db:generate
npx wrangler d1 migrations apply image-lite-db --remote

Review the generated SQL under drizzle/ before applying it.

4. Seed RBAC

Remote D1 is accessed through a Worker binding, so seed a local Wrangler D1 and import only the RBAC rows:

npx wrangler d1 migrations apply image-lite-db --local

LOCAL_D1=$(find .wrangler/state -name "*.sqlite" -path "*d1*" | head -1)
DATABASE_PROVIDER=sqlite DATABASE_URL="file:$LOCAL_D1" pnpm rbac:init

sqlite3 "$LOCAL_D1" ".dump role permission role_permission" \
  | grep "^INSERT INTO" \
  | sed 's/^INSERT INTO/INSERT OR IGNORE INTO/' \
  > /tmp/image-lite-rbac.sql

npx wrangler d1 execute image-lite-db \
  --remote \
  --file=/tmp/image-lite-rbac.sql

Manual RBAC seeding requires the sqlite3 CLI.

5. Add Worker secrets and deploy

openssl rand -base64 32 | npx wrangler secret put AUTH_SECRET
openssl rand -base64 32 | npx wrangler secret put CONFIG_ENCRYPTION_KEY
pnpm cf:deploy

Never put secrets in wrangler.jsonc vars. After the first deployment, synchronize the exact deployed URL in .env.production and wrangler.jsonc, then run pnpm cf:deploy again if the URL changed.

6. Finish production setup

  1. Sign up through /sign-up.

  2. Promote the first administrator with /deploy-cloudflare --admin=<email>. For a fully manual deployment, run:

    npx wrangler d1 execute image-lite-db --remote --command="
    INSERT OR IGNORE INTO user_role (id, user_id, role_id)
    SELECT lower(hex(randomblob(16))), u.id, r.id
    FROM user u, role r
    WHERE u.email = 'admin@example.com' AND r.name = 'super_admin'
    "
    
  3. Sign out and sign back in.

  4. Configure AI and R2 under Admin → Settings.

  5. Verify / and /api/config/public return HTTP 200.

For live Worker errors:

npx wrangler tail

PostgreSQL with Hyperdrive

When using an existing PostgreSQL database:

  1. Create Hyperdrive with npx wrangler hyperdrive create image-lite --connection-string="$DATABASE_URL".

  2. Set DATABASE_PROVIDER to postgresql in wrangler.jsonc, remove d1_databases, and add a Hyperdrive binding named exactly HYPERDRIVE.

  3. Load a local .env.production containing the direct PostgreSQL URL, then prepare and migrate the schema:

    set -a
    . ./.env.production
    set +a
    
    DATABASE_PROVIDER=postgresql pnpm db:setup
    DATABASE_PROVIDER=postgresql pnpm db:generate
    DATABASE_PROVIDER=postgresql pnpm db:migrate
    

    Review the generated SQL before running db:migrate.

  4. Run pnpm rbac:init against the direct PostgreSQL connection.

  5. Add Worker secrets and deploy with pnpm cf:deploy.

The PostgreSQL connection string is a secret. Do not place it in wrangler.jsonc vars; Hyperdrive supplies it at runtime.

Deploy to a Node server

Use PostgreSQL, MySQL, or Turso for multi-instance production. SQLite is only suitable for one instance with persistent storage.

  1. Create .env.production with the production URL, database provider and connection, AUTH_SECRET, and CONFIG_ENCRYPTION_KEY.
  2. Run NODE_ENV=production pnpm db:setup.
  3. Generate and review migrations with NODE_ENV=production pnpm db:generate.
  4. Apply them with NODE_ENV=production pnpm db:migrate.
  5. Seed roles with NODE_ENV=production pnpm rbac:init.
  6. Build with NODE_ENV=production pnpm build.
  7. Start with NODE_ENV=production PORT=3000 pnpm start.

Run the server behind TLS and pass production secrets through the hosting platform rather than committing .env.production.

Project layout

src/blocks/          Landing-page sections
src/components/      Reusable UI and shadcn primitives
src/core/            Auth, database, AI, payments, email, and storage
src/modules/         Business services
src/routes/          Pages and API routes
messages/            English and Chinese translations
wrangler.example.jsonc  Cloudflare configuration template

License

Proprietary software. See LICENSE.

Built with ShipAny.

开始构建你的 AI 产品

成为 ShipAny Premium 会员,获取 ShipAny 模板代码,一小时极速上线