# FreeFlow Backend

## Tech Stack
- NestJS + Prisma ORM + TypeScript
- MySQL (officialsite.kr:23306 / freeflow)
- JWT Authentication (access + refresh tokens)
- TossPayments for billing (test keys)

## 포트 구성
- **Backend API**: port 3006 (`api-freeflow.officialsite.kr`)
- **Frontend**: port 3005 (`freeflow.officialsite.kr`)

## Database
- Host: officialsite.kr:23306
- Schema: freeflow
- Credentials: .env 파일 참조
- **DB 작업은 반드시 Python 스크립트로 처리 (scripts/ 디렉토리)**
  - `scripts/create_schema.py` - 스키마 생성
  - `scripts/check_db.py` - DB 상태 확인
  - `scripts/seed_plans.py` - 플랜/부가서비스 시드
  - `scripts/seed_categories.py` - 경비 카테고리 시드
  - `scripts/reset_db.py` - DB 리셋 (개발용)

## Development
- Port: 3006
- API prefix: /api
- Build: `npm run build` → dist/main.js
- Dev: `npm run start:dev`
- Prisma: `npx prisma generate` / `npx prisma db push`

## Project Structure
- `src/modules/` - 기능별 모듈 (auth, users, businesses, clients, projects, estimates, contracts, tax-invoices, cash-receipts, settlements, purchase-sales, expenses, reports, dashboard, templates, ai-chat, subscriptions, credits, payments, integrations, notifications)
- `src/common/` - 공통 가드, 데코레이터, 필터, DTO
- `src/prisma/` - Prisma 서비스
- `prisma/schema.prisma` - DB 스키마 정의
- `scripts/` - Python DB 스크립트

## Deployment
- PM2: `freeflow-back` (port 3006)
- Server path: /var/www/back/freeflow
- GitHub Actions: appleboy/ssh-action

## 작업 규칙
- **작업 완료 후 항상 커밋 + 푸시 함께 처리**
- DB 관련 작업은 Python 스크립트로 처리
- 환경변수는 .env 파일로 관리 (커밋 금지)
