A robust backend service built with NestJS, supporting the SafeSwap marketplace's API, business logic, and blockchain integration.
- NestJS - Progressive Node.js framework
- TypeScript - Type safety
- GraphQL - API query language
- Apollo GraphQL - GraphQL server implementation
- Prisma - ORM for database management
- PostgreSQL - Relational database
- Docker - Containerization for database and services
- ESLint - Linting tool
- Prettier - Code formatter
- Jest - Testing framework
Before starting, ensure you have the following installed:
✅ Docker Desktop (Required)
☑️ NestJS CLI (Optional, for easier development)
To install NestJS CLI, run:
npm install -g @nestjs/cli
backend/
├── prisma/ # Prisma schema and migrations
│ ├── schema.prisma # Database schema
├── src/
│ ├── core/ # Global configuration (Prisma, GraphQL, security)
│ ├── modules/ # Feature-based modules
│ │ ├── categories/ # Categories module
│ ├── shared/ # Utilities, decorators, pipes, filters
│ ├── main.ts # Application entry point
├── test/ # Unit and integration tests
├── dist/ # Compiled output (build)
├── package.json # Project configuration
├── tsconfig.json # TypeScript configuration
└── .env.example # Environment variables template
-
Install dependencies:
npm install
-
Start the Database with Docker:
Ensure Docker Desktop is running, then execute:
docker-compose up -d
This will start a PostgreSQL database container in the background.
You can check running containers with:
docker ps
For detailed database setup, visit: 📖 PostgreSQL Database Setup
-
Configure Environment Variables:
Create a
.env
file based on.env.example
:cp .env.example .env
You can configure the variables as you prefer or leave the default values.
-
Set Up Database (Prisma & PostgreSQL):
Run database migrations:
npm run db:migrate
Check database records using Prisma Studio:
npm run db:studio
-
Run development server:
npm run dev
-
Access the API:
Open http://localhost:4000/graphql in your browser or API client.
npm run build
- Compile the applicationnpm run dev
- Start the development servernpm run start
- Start the application in productionnpm run start:debug
- Start the application with debuggingnpm run test
- Run unit testsnpm run test:watch
- Run tests in watch modenpm run lint
- Run ESLint with autofixnpm run format
- Format the codebase with Prettiernpm run db:migrate
- Apply database migrationsnpm run db:push
- Update the database schema without migrationsnpm run db:studio
- Open Prisma Studio for database inspection
- Code Formatting:
- Use Prettier to ensure consistent code formatting.
- Run
npm run format
before committing changes.
- Linting:
- Follow ESLint rules to maintain code quality.
- Run
npm run lint
to check for and fix linting issues.
- Testing:
- Write unit tests for all modules and services.
- Run tests using
npm run test
.
- TypeScript:
- Use TypeScript features for strong typing and code clarity.
- Type safety is mandatory across all modules.
- 📖 NestJS Documentation
- 📖 Prisma Documentation
- 📖 GraphQL Documentation
- 📖 Apollo GraphQL Documentation
- 📖 PostgreSQL Documentation
- 📖 Docker Documentation
- 📖 ESLint Documentation
- 📖 Jest Documentation
MIT License