mohmdsdgandCursor 811f671e78 Restore git-pull-only deploy: single compose path with schema from git
Deploy is back to the flow that worked: build dist locally, push, then on the
server only `git pull` + `docker compose up -d --build`. The Dockerfile now
also takes prisma/ and package.json from git and runs `prisma generate`, so
schema and migration changes ship without rebuilding the 120MB node_modules
bundle. Removes the prebuilt compose path, which could never work on a server
without npm.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-08 16:14:53 +03:30

Fabric Trade Server

بک‌اند NestJS + Prisma + PostgreSQL برای اپ کاربر و پنل ادمین تجارت پارچه.

پیش‌نیاز

  • Node.js 20+
  • Docker (برای PostgreSQL)

اگر به Docker دسترسی ندارید:

sudo usermod -aG docker "$USER"
# سپس یک‌بار logout/login کنید

راه‌اندازی سریع (لوکال بدون Docker برای API)

cd fabric_trade_server
docker compose up -d postgres
npm install
npx prisma migrate deploy
npm run prisma:seed
npm run start:dev

دیپلوی: بیلد روی سیستم خودت، اجرا روی سرور

روی سرور هیچ npm یا دانلودی لازم نیست. node_modules از قبل داخل deploy-bundle.tar.gz (روی گیت) است و dist هم روی گیت commit می‌شود.

۱) روی سیستم خودت:

cd fabric_trade_server
npm run build
git add dist && git commit -m "..." && git push

۲) روی سرور:

cd /opt/parche/server
git pull
docker compose up -d --build
docker compose logs -f api

Dockerfile باندل را باز می‌کند، بعد dist و prisma و package.json را از گیت روی آن می‌نویسد و prisma generate می‌زند؛ پس تغییر schema و مایگریشن جدید هم فقط با git pull می‌رسد.

فقط اگر پکیج npm جدید اضافه شد باندل را دوباره بساز و push کن:

bash scripts/pack-bundle.sh
git add deploy-bundle.tar.gz && git commit -m "refresh deploy bundle" && git push
  • env سرور از .env همان پوشه خوانده می‌شود (env_file در compose)
  • API روی 127.0.0.1:${API_PORT} بالا می‌آید (سرور: 8585)
  • مایگریشن موقع استارت کانتینر اجرا می‌شود
  • LiteSpeed را Reverse Proxy کنید به http://127.0.0.1:8585

مثال مسیر LiteSpeed: https://domain.com/api/ → http://127.0.0.1:3000/api/

حساب‌های تست (پس از seed)

نقش ورود رمز / OTP
ادمین 09121112222 admin123
مشتری 09121234567 OTP پیامکی (۴ رقم) — با SMS_ENABLED=false کد ثابت: 1234

متغیرهای محیطی

فایل .env:

DATABASE_URL=postgresql://fabric:fabric123@localhost:5432/fabric_trade?schema=public
JWT_SECRET=fabric-trade-dev-secret-change-me
JWT_EXPIRES_IN=7d
PORT=3000
MOCK_OTP_CODE=1234
OTP_TTL_MINUTES=5
SMS_ENABLED=true
SMS_API_URL=http://185.231.112.101/api/createsms
SMS_SECRET_KEY=...
SMS_PLATFORM=rayegansms
SMS_HOST=پارچه
SMS_APP_NAME=پارچه

اسکریپت‌ها

دستور کار
npm run db:up بالا آوردن Postgres
npm run prisma:migrate مایگریشن توسعه
npm run prisma:seed دیتای فیک
npm run start:dev سرور با watch
npm run db:reset ریست کامل دیتابیس

ساختار API (خلاصه)

کاربر (Bearer JWT مشتری)

  • POST /api/auth/otp/request / verify
  • GET /api/auth/me · PATCH /api/auth/profile
  • GET /api/companies · catalogs · products · bank-accounts
  • GET/POST /api/carts …
  • GET/POST /api/orders · POST /api/orders/:id/cash-receipt

ادمین (Bearer JWT ادمین)

  • POST /api/admin/auth/login
  • GET /api/admin/dashboard · /admin/reports · /admin/settings
  • CRUD: companies, catalogs, products, customers, users, orders, checks, cash-payments, shipments
S
Description
No description provided
Readme
269 MiB
Languages
TypeScript 84.9%
JavaScript 10.8%
Shell 3.8%
Dockerfile 0.5%