Skip to content

miracle709/d4l-backend

Repository files navigation

D4L Backend

Backend API for D4L, a fantasy meme-token betting platform where users create tokens, register fighters, run battles, and place bets.

Overview

This service is built with NestJS, Prisma, PostgreSQL, and EVM smart-contract integrations via ethers.

Core capabilities:

  • Wallet-based auth (challenge + signature verification, JWT sessions)
  • User management, profile updates, deposits, and withdrawals
  • Meme token creation and lifecycle updates
  • Fighting arena flow (register fighter, create battle, place bet, end battle, claim rewards)
  • History and analytics (PnL, betting history, leaderboards, dashboard)
  • Authenticated image upload with static file serving
  • Swagger docs at /api/docs

Tech Stack

  • NestJS (REST API)
  • Prisma + PostgreSQL
  • ethers + deployed contracts (supported networks: sepolia, amoy)
  • JWT authentication
  • Swagger API documentation
  • nestjs-pino logging

Getting Started

1) Install dependencies

yarn install

2) Configure environment variables

Copy .env.example to .env and fill all values:

PORT=<your-backend-port>
DATABASE_URL=<your-postgresql-database-url>
NETWORK=<sepolia-or-amoy>
PLATFORM_PRIVATE_KEY=<your-private-key>
RPC_URL=<your-rpc-url>
JWT_SECRET_KEY=<your-jwt-secret-key>
JWT_EXPIRES_IN=<your-jwt-expires-in>
APP_URL=<your-app-url>
FRONTEND_URL=<your-frontend-url>

3) Run database setup

yarn prisma generate
yarn prisma migrate dev

4) Start the API

# development (watch mode)
yarn start:dev

# production
yarn build
yarn start:prod

Server defaults to:

  • API base: http://localhost:<PORT>/api
  • Swagger docs: http://localhost:<PORT>/api/docs
  • Uploaded files: http://localhost:<PORT>/uploads/<filename>

Scripts

  • yarn build - Build NestJS app
  • yarn start - Start app
  • yarn start:dev - Start in watch mode
  • yarn start:prod - Run compiled app
  • yarn lint - Run ESLint (auto-fix enabled)
  • yarn test - Run unit tests
  • yarn test:e2e - Run e2e tests
  • yarn test:cov - Run test coverage

API Domains

All endpoints are prefixed with /api.

  • auth - wallet challenge and signature verification
  • users - account, profile, avatar, wallet operations
  • tokens - create/list/get/update token state and transactions
  • fighting - fighters, battles, bets, rewards
  • history - user activity, pnl, leaderboard, dashboard
  • file-upload - authenticated image upload

Data Model (Prisma)

Main entities:

  • User
  • Token
  • Fighter
  • Battle
  • Bet
  • UserHistory
  • UserPnL
  • BettingHistory
  • TokenFightingHistory
  • UserStatistics

See prisma/schema.prisma for full schema and enums.

Notes

  • CORS allows local frontend origins in development and FRONTEND_URL in production.
  • Contract addresses are resolved by NETWORK from src/contracts/addresses.
  • Uploaded assets are stored under uploads/ and served statically.

License

MIT

About

NestJS + Prisma backend for D4L: wallet-authenticated meme token creation, battle arena betting, and on-chain powered user analytics.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors