How sg-milad/ton-payment-system works
Main Components
• API / Entry Point: The NestJS application is the central hub, starting at src/main.ts, which loads the application modules.
• Payment Module: Contains payment.controller.ts and payment.service.ts. It is responsible for handling incoming payment requests.
• TON Module: Includes ton.module.ts, ton.service.ts, and support components (DTOs, enums, constants, queues, and types). It encapsulates all TON-related logic including managing payment data and using queues for background processing.
• Wallet Module: Contains wallet.module.ts and wallet.service.ts. This module handles wallet generation and possibly consolidation of funds.
• Config Modules: Under src/configs, these files (app.config.ts, bullmq.config.ts, redis.config.ts, wallet.config.ts) provide configuration details for application settings, BullMQ (for queues), Redis, and wallet-specific parameters.
• Shared Services: The shared folder features helper functions and a Prisma module, which is used for data persistence (via src/shared/prisma). Prisma is critical as an ORM here.
• Infrastructure: Dockerfile, docker-compose.yml, and other environment & CI/CD files (.env.dev, GitHub workflows) define how the application is built and deployed.
Out Relationships and Interactions
• The API layer (bootstrapped via main.ts and the app.module.ts) mediates HTTP requests and directs them to respective modules (Payment, Ton, Wallet).
• The Payment Module likely invokes functions from both the Ton and Wallet Modules to handle the process of receiving payment requests, generating a new wallet address, and initiating fund consolidation.
• The TON Module processes blockchain-specific logic. It also handles messages/events using queues (supported by BullMQ configurations and files under src/ton/queues) to asynchronously process transactions.
• The Wallet Module manages wallet creation and may interact with external TON wallet services.
• The Shared Prisma Service ensures that all these modules persist or retrieve data from the database.
• Configuration files ensure that the necessary system parameters are centralized and modifiable (app config, Redis for caching/queueing, etc.).
Architectural Patterns/Design Principles
• Modular Architecture: The system is split into discrete modules (Payment, TON, Wallet) which promote separation of concerns.
• Dependency Injection: Standard in NestJS, ensuring that services (like Prisma, BullMQ) are injected where needed.
• Asynchronous Processing: Use of queues (BullMQ) to handle background tasks such as payment transaction processing.
• Containerization: Docker and docker-compose configurations indicate that the service is containerized and can run within a Docker ecosystem.
• API Documentation: Swagger integration (via src/shared/swagger.ts) is included to automatically document API endpoints.
Detailed Data Flow
• Start from when a user initiates a payment request which is handled by the Payment Controller.
• How the Payment Service coordinates this by calling:
• The TON Module to handle TON-specific computations/queues.
• The Wallet Module to generate or access wallet data.
• Finally, interactions with the database via the Prisma Service are depicted.
• How responses and asynchronous events (through BullMQ queues) are managed.