OS Trading Engine
Technical Documentation
Architecture
Technology Stack

Technology Stack

Nexgent is built with a modern TypeScript stack optimized for real-time trading operations.

Core Technologies

CategoryTechnologyVersionPurpose
RuntimeNode.js18+Server runtime
LanguageTypeScript5.7Type-safe development
Package Managerpnpm8+Workspace management

Backend Stack

Web Framework

TechnologyPurpose
ExpressHTTP server and REST API routing
wsWebSocket server for real-time updates
corsCross-origin resource sharing

Database & ORM

TechnologyPurpose
PostgreSQLPrimary database for persistent storage
PrismaType-safe ORM with migrations

Prisma generates TypeScript types from the database schema, ensuring type safety from database to API responses.

Caching

TechnologyPurpose
RedisIn-memory caching and pub/sub
ioredisRedis client with cluster support

Redis is used for:

  • Balance caching (write-through)
  • Position caching (write-through)
  • Price caching (TTL-based)
  • Agent configuration caching
  • Idempotency keys (preventing duplicate trades)
  • Rate limiting state

Job Queue

TechnologyPurpose
BullMQBackground job processing

BullMQ handles:

  • Async database writes (historical swaps)
  • Scheduled balance snapshots
  • Retry logic for failed operations

Authentication

TechnologyPurpose
jsonwebtokenJWT token generation and verification
bcryptPassword hashing

Validation

TechnologyPurpose
ZodRuntime schema validation

Logging & Monitoring

TechnologyPurpose
PinoStructured JSON logging
prom-clientPrometheus metrics

Development

TechnologyPurpose
tsxTypeScript execution with watch mode
JestUnit and integration testing
SupertestHTTP assertion testing

Frontend Stack

Framework

TechnologyVersionPurpose
Next.js15React framework with App Router
React18UI library

State Management

TechnologyPurpose
TanStack React QueryServer state management, caching, and synchronization
React ContextClient state (user, agent selection, currency)
WebSocketReal-time position and price updates
💡

React Query handles all API data fetching with automatic caching, background refetching, and optimistic updates. WebSocket updates are merged into React Query cache for consistency.

UI Components

TechnologyPurpose
shadcn/uiComponent library (Radix UI primitives)
Tailwind CSSUtility-first styling
Lucide ReactIcon library
RechartsCharting library

Forms

TechnologyPurpose
React Hook FormForm state management
@hookform/resolversZod integration for validation

Authentication

TechnologyPurpose
NextAuth.jsAuthentication framework
jwt-decodeClient-side token decoding

Blockchain Integrations

Solana

TechnologyPurpose
@solana/web3.jsSolana blockchain interaction
bs58Base58 encoding for keys

Trading

IntegrationPurpose
Jupiter AggregatorDEX aggregation for optimal swap routing
Pyth NetworkSOL/USD price oracle
DexScreenerToken price feeds and liquidity data
⚠️

Jupiter API requires an API key for production use. Rate limits apply to all external APIs.


Infrastructure

Containerization

TechnologyPurpose
DockerContainer runtime
Docker ComposeMulti-container orchestration

Deployment

PlatformPurpose
RailwayRecommended hosting platform

The railway.json configures:

  • Backend service
  • Frontend service
  • PostgreSQL database
  • Redis instance

Development Tools

Code Quality

ToolPurpose
ESLintCode linting
TypeScriptStatic type checking
PrettierCode formatting

Testing

ToolPurpose
JestTest runner
ts-jestTypeScript support for Jest
SupertestHTTP integration testing

Version Requirements

{
  "engines": {
    "node": ">=18.0.0",
    "pnpm": ">=8.0.0"
  }
}

Key Dependencies by Package

nexgent-open-source-trading-engine/backend

@prisma/client    ^5.22.0   Database ORM
@solana/web3.js   ^1.87.0   Blockchain interaction
bullmq            ^5.65.0   Job queue
express           ^4.18.2   Web framework
ioredis           ^5.3.2    Redis client
jsonwebtoken      ^9.0.2    JWT handling
pino              ^8.17.2   Logging
ws                ^8.16.0   WebSocket server
zod               ^3.25.76  Validation

nexgent-open-source-trading-engine/frontend

next              ^15.5.9   React framework
react             ^18.2.0   UI library
@tanstack/react-query ^5.90.7  Server state
next-auth         ^4.24.7   Authentication
recharts          ^3.4.1    Charts
tailwindcss       ^3.4.1    Styling
zod               ^3.25.76  Validation

nexgent-open-source-trading-engine/shared

zod               ^3.25.76  Schema validation