NestJS 기반의 암호화폐 포트폴리오 관리 백엔드 API
- Framework: NestJS
- Database: SQLite (Prisma ORM)
- Authentication: JWT (JSON Web Token)
- Real-time: Socket.IO (WebSocket)
- Language: TypeScript
- 회원가입 (
POST /auth/register) - 로그인 (
POST /auth/login) - JWT 기반 인증
- 잔액 조회 (
GET /wallet/balance) - 코인 구매 (
POST /wallet/buy) - 트랜잭션 기록
- 지갑 잔액 변경 시 실시간 알림
- Socket.IO 기반
npm install.env 파일을 생성하고 다음 내용을 추가:
DATABASE_URL="file:./dev.db"
JWT_SECRET="your-secret-key"
PORT=3001npx prisma migrate dev --name init
npx prisma generate# 개발 모드
npm run start:dev
# 프로덕션 모드
npm run build
npm run start:prod서버는 http://localhost:3001에서 실행됩니다.
# 회원가입
POST /auth/register
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123",
"name": "User Name"
}
# 로그인
POST /auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123"
}# 잔액 조회
GET /wallet/balance
Authorization: Bearer {accessToken}
# 코인 구매
POST /wallet/buy
Authorization: Bearer {accessToken}
Content-Type: application/json
{
"coinId": "bitcoin",
"amount": 0.1,
"price": 50000
}id: 사용자 IDemail: 이메일 (unique)password: 암호화된 비밀번호name: 사용자 이름createdAt: 생성일
id: 지갑 IDbalance: 잔액userId: 사용자 ID (1:1)
id: 트랜잭션 IDwalletId: 지갑 IDcoinId: 코인 IDamount: 수량price: 가격type: 거래 타입 (BUY/SELL)createdAt: 생성일
backend/
├── prisma/
│ ├── schema.prisma # 데이터베이스 스키마
│ └── migrations/ # 마이그레이션 파일
├── src/
│ ├── auth/ # 인증 모듈
│ │ ├── auth.controller.ts
│ │ ├── auth.service.ts
│ │ ├── auth.module.ts
│ │ └── jwt.strategy.ts
│ ├── wallet/ # 지갑 모듈
│ │ ├── wallet.controller.ts
│ │ ├── wallet.service.ts
│ │ └── wallet.module.ts
│ ├── events/ # WebSocket 모듈
│ │ ├── events.gateway.ts
│ │ └── events.module.ts
│ ├── prisma/ # Prisma 서비스
│ │ ├── prisma.service.ts
│ │ └── prisma.module.ts
│ └── main.ts # 애플리케이션 엔트리
└── package.json
# 유닛 테스트
npm run test
# E2E 테스트
npm run test:e2e
# 테스트 커버리지
npm run test:cov- Prisma Studio: 데이터베이스 GUI
npx prisma studio
프론트엔드(http://localhost:3000)에서의 요청을 허용하도록 CORS가 설정되어 있습니다.
MIT