Welcome to the backend repository for the NextNonce Crypto Portfolio Tracker application.
For more detailed documentation, including API specifications and architectural deep-dives, please visit official documentation site: NextNonce Docs
- Multi-Chain Support: Tracks assets across 15 of the most popular EVM blockchains:
- Arbitrum, Avalanche, Base, BNB, Ethereum, Fantom, Flare, Gnosis, Linea, Mantle, Metis, Optimism, Polygon, Scroll, and ZkSync.
- Comprehensive Wallet Support: Fetches balances for both Simple(EOA) and Smart wallets.
- Unified Token View: A standout feature that consolidates popular tokens (like ETH, USDC, USDT) from across all supported networks. It presents an aggregated total balance for each unified token, while also allowing users to see the specific balance on each individual chain.
- Robust Authentication: All API endpoints are secured. Requests must include a valid JWT issued for the NextNonce mobile application.
- Provider-Based Architecture: Core functionalities like authentication, database interaction, balance fetching, and caching are abstracted behind interfaces, making the system modular and easy to extend with new providers.
- Advanced Caching: Implements sophisticated caching strategies using Redis to ensure high performance and low latency for frequently accessed data.
- Rate Limiting: Protects the application and its underlying data providers from abuse and ensures service stability.
- Detailed Logging & Tracing: Integrated with New Relic for performance monitoring and structured logging for easier debugging.
The backend is built with a modern, robust, and scalable technology stack:
- Framework: NestJS (v11)
- Language: TypeScript (v5)
- Database: PostgreSQL managed via Supabase
- ORM: Prisma
- Authentication: Supabase Auth, with JWTs handled by
passport-jwt. - Caching: Redis via
ioredis. - API Specification: OpenAPI (Swagger)
- Testing: Jest for both unit and end-to-end (e2e) tests.
- Containerization: Docker & Docker Compose.
- Key Libraries:
axiosfor HTTP requests to external data providers (e.g., OKX DEX).class-validator&class-transformerfor robust DTO validation.rate-limiter-flexiblefor implementing rate-limiting strategies.newrelicfor application performance monitoring.
The backend is designed as a modular, service-oriented application following the principles of clean architecture.
- Modularity: The application is divided into feature-specific modules (e.g.,
User,Portfolio,Wallet,Balance,Token). Each module encapsulates its own logic, controllers, services, and DTOs. This separation of concerns makes the codebase easier to maintain, test, and scale. - Provider Abstraction: A core architectural pattern is the use of provider interfaces. For instance:
AuthProvider(/src/auth/interfaces/auth-provider.interface.ts) abstracts the authentication logic, withSupabaseAuthProviderbeing the concrete implementation.MetadataProvider(/src/metadata/interfaces/token-metadata-provider.interface.ts) defines the contract for fetching token's metadata, currently implemented byDuneTokenMetadataProvider.CacheProvider(/src/cache/interfaces/cache-provider.interface.ts) abstracts caching operations, withRedisCacheProviderproviding the implementation. This design allows for swapping out providers (e.g., moving from Supabase to another auth service, or adding a new balance data source) with minimal changes to the core application logic.
- Database & ORM: Prisma serves as the interface to the PostgreSQL database. The schema is defined in
prisma/schema.prisma, and migrations are managed by the Prisma CLI. - Configuration & Environment: The
@nestjs/configmodule is used for managing environment variables, allowing for different configurations across development, testing, and production environments. - Request Lifecycle:
- An incoming request first hits the global middleware and guards.
- The
JwtAuthGuardvalidates the JWT token. - A custom
UserInterceptorretrieves user details from the database based on the token and attaches it to the request object. - The request is routed to the appropriate controller and handler.
- Services are called to execute business logic, interacting with the database, cache, and external providers as needed.
- A global
AllExceptionsFiltercatches any unhandled errors and formats them into a standardized response.
Follow these instructions to get the backend running locally for development and testing.
- Node.js (v22 or higher recommended)
- Yarn
- Docker and Docker Compose
- Access to a Supabase project
- A Redis instance
-
Clone the repository:
git clone https://github.com/NextNonce/Backend.git cd backend -
Install dependencies:
yarn install
-
Set up environment variables: Create a
.envfile by copying the example file.cp .env.example .env
Populate the
.envfile with your credentials for Supabase, Redis, and any other required services. -
Set up the database: Apply the Prisma migrations to your database.
npx prisma migrate dev
-
Development mode with auto-reloading:
yarn start:dev
-
Production build & run:
yarn build yarn start:prod
-
Using Docker Compose: The
docker-compose.ymlis configured to run the application along with its dependencies like Redis.docker compose up --build -d
The application includes both unit tests and end-to-end (e2e) tests.
- Run all tests:
yarn test - Run unit tests with coverage report:
yarn test:cov
- Run e2e tests:
Ensure the testing database and other services are running before executing e2e tests.
yarn test:e2e
All API endpoints require authentication via a JWT Bearer token in the Authorization header.
The complete API contract is documented using the OpenAPI standard.
- Swagger UI: When the application is running in development mode, you can access the interactive Swagger UI at
http://localhost:3000/v1/docsor you can visit documentation NextNonce API. - Static Specification: A generated
openapi.jsonfile is available in the/staticdirectory for tooling and integration purposes.
A brief overview of the key directories in this project:
.
├── src/ # Main application source code
│ ├── auth/ # Authentication logic, guard, strategies
│ ├── balance/ # Balance fetching and aggregation logic
│ ├── cache/ # Caching service and provider
│ ├── chain/ # Chain-related service and mapper
│ ├── portfolio/ # Portfolio management
│ ├── portfolio-wallet/ # Logic for wallets within portfolios
│ ├── price/ # Price service
│ ├── token/ # Token and unified token
│ ├── user/ # User management
│ ├── wallet/ # Wallet management and utilities
│ ├── main.ts # Application entry point
│ └── app.module.ts # Root application module
├── prisma/ # Prisma schema and migration files
├── test/ # End-to-end (e2e) tests and mocks
├── Dockerfile # Docker build instructions
├── docker-compose.yml # Docker Compose setup
└── package.json # Project dependencies and scripts
This project is licensed under the MIT License. See the LICENSE file for more details.