How kiyoshi-work/app-server works
1. This is a NestJS backend composed as a modular monolith. src/main.ts boots a single application, while src/app.module.ts composes domain modules that expose multiple entrypoints: REST, GraphQL, JSON-RPC, WebSocket, and a Telegram bot listener.
2. The access layer lives mainly under src/modules/api, graphql, jrpc, websocket, and telegram-bot. These modules are responsible for request parsing, auth, validation, exception mapping, response shaping, and transport-specific concerns. The API layer includes JWT/RBAC guards, throttling, cache, and context/device interceptors; GraphQL and JSON-RPC have their own guards and resolvers/handlers; WebSocket uses Socket.IO gateways.
3. The business layer is split into feature-oriented modules: ai, blockchain, crawler, game, business, sync-contract, worker, listen-socket, and worker-thread. This is where the actual domain behavior sits: AI orchestration, blockchain interactions, contract synchronization, game lifecycle commands, notification/auth workflows, data scraping, scheduled jobs, and CPU-bound offloading.
4. The data layer is polyglot. database is the primary relational store with entities and repositories; timescale-db stores price/time-series data; redis-cache is used for caching and session/state; milvus-db and vectorstore-db provide vector search / document retrieval; elasticsearch supports full-text search; firebase and upload-file cover Firestore/Storage-backed persistence; onesignal is used for push notification delivery rather than primary storage.
5. There is a clear async boundary around messaging and background work. transporter abstracts RabbitMQ, Redis MQ, and Google Pub/Sub. queue and worker handle job consumption and scheduled execution. The worker side includes consumers for Telegram bot and user flows, plus a scheduler service for recurring tasks.
6. Real-time and streaming concerns are separated from request/response APIs. websocket/gateways exposes chat and price channels, with a Redis adapter for horizontal scaling. listen-socket appears to subscribe to external market feeds (for example BingX prices) and feed them into the real-time pipeline and/or time-series storage.
7. The Telegram bot is a stateful conversation subsystem, not just a thin adapter. It has command chains, handler pipelines, session storage, UI/page rendering, verification flows, and i18n content under src/i18n/telebot. It likely interacts with queues and workers for deferred processing and persistent user state.
8. Blockchain support is centered in blockchain and sync-contract. The module contains chain/token/contract configuration, Solana service integration, ERC20/USDC contract wrappers, and an orderbook SDK. The sync services suggest a pipeline that listens to on-chain events, normalizes them, and persists them into database entities such as smc-event and transaction logs.
9. AI and retrieval capabilities are isolated in ai, milvus-db, vectorstore-db, and crawler. Crawler services aggregate external market/social data from providers like CoinGecko, DexScreener, Birdeye, LunarCrush, and Twitter APIs. That data can be stored/indexed in vector stores and then used by the AI module and tools for retrieval-augmented workflows and function calling.
10. Cross-cutting infrastructure is centralized under shared, logger, sentry, and the custom JSON-RPC library in shared/libs/json-rpc. shared holds decorators, exceptions, pagination, validation, injection symbols, and common constants so feature modules stay thin. Logger and Sentry provide observability and error capture across all entrypoints.
11. The repo is built for multi-service deployment. The Docker files and compose stack include specialized containers for Nest, Postgres, TimescaleDB, Milvus, SearxNG, and CUDA-based AI runtimes, with Cloud Build configs for CI/CD. This indicates the application is expected to run as a coordinated stack rather than a single process with local-only dependencies.
12. In diagram terms, the main flow is: external clients and bots enter through transport adapters; those adapters call domain services; domain services read/write through repositories and integration clients; background workers and event handlers process deferred work; and shared infrastructure modules provide auth, logging, caching, and error handling across the whole system.
Main entry points: app.module.ts app module · database.module.ts Database · shared Shared · ai.module.ts AI
Components 31
Bootstrap
Application entry and module composition
- main · Starts the single Nest application
src/main.ts - app module · Assembles transport, domain, and infrastructure modules
src/app.module.ts
Access layer
Transport adapters and request-facing entrypoints
- API · REST controllers, guards, interceptors, filters, and DTO validation
src/modules/api/api.module.ts - GraphQL · GraphQL resolvers, models, and JWT guard
src/modules/graphql/graphql.module.ts - JSON-RPC · JSON-RPC handlers and auth boundary
src/modules/jrpc/jrpc.module.ts - WebSocket · Realtime chat and price gateways with Redis scaling
src/modules/websocket/websocket.module.ts - Telegram bot · Stateful bot commands, handlers, UI pages, sessions, and verification flows
src/modules/telegram-bot/telegram-bot.module.ts
Domain modules
Core business behavior and orchestration
- AI · AI service and tools for higher-level assistant workflows
src/modules/ai/ai.module.ts - Blockchain · Chain config, Solana service, contract wrappers, and orderbook SDK
src/modules/blockchain/blockchain.module.ts - Sync contract · Normalizes on-chain events and transaction data into persistence
src/modules/sync-contract/sync-contract.module.ts - Business · Application workflows for auth and notifications
src/modules/business/business.module.ts - Crawler · Aggregates market and social data from provider APIs
src/modules/crawler/crawler.module.ts - Game · Command-driven game lifecycle and room state management
src/modules/game/game.module.ts
Data layer
Persistent stores and repositories
- Database · Primary entities, repositories, and seed data
src/modules/database/database.module.ts - Timescale DB · Price history persistence and repository access
src/modules/timescale-db/timescale-db.module.ts - Redis cache · Caching and session/state support
src/modules/redis-cache/redis-cache.module.ts - Milvus · Vector search document repository
src/modules/milvus-db/milvus.module.ts - Vector store · LangChain-oriented document repository and mocks
src/modules/vectorstore-db/vector-store.module.ts - Search · Search service and DTO boundary
src/modules/elasticsearch/elasticsearch.module.ts - Firebase · Firestore repository and database interface
src/modules/firebase/module.ts - Upload file · Firebase and Google Cloud Storage backed file handling
src/modules/upload-file/upload-file.module.ts - OneSignal · Notification delivery client and API exceptions
src/modules/onesignal/onesignal.module.ts
Async & events
Messaging, queues, workers, and background processing
- Transporter · RabbitMQ, Redis MQ, and Google Pub/Sub abstraction
src/modules/transporter/transporter.module.ts - Queue · Queue configuration and service boundary
src/modules/queue/queue.module.ts - Worker · Consumers and scheduled task execution
src/modules/worker/worker.module.ts - Listen socket · Consumes external price feeds such as BingX
src/modules/listen-socket/listen-socket.module.ts - Worker thread · Threaded task execution for expensive computations
src/modules/worker-thread/worker-thread.module.ts
Shared infra
Cross-cutting utilities, error handling, and custom libraries
- Shared · Decorators, exceptions, constants, pagination, validation, and injection symbols
src/shared - JSON-RPC lib · Custom JSON-RPC server, context, routing, and error mapping
src/shared/libs/json-rpc/json-rpc.module.ts - Logger · Application logging services and helpers
src/modules/logger/logger.module.ts - Sentry · Exception filter and interceptor for telemetry
src/modules/sentry/sentry.module.ts
Connections 48
- main → app module: boots · Bootstrap creates the application module
- app module → API: imports · Composes REST access layer
- app module → GraphQL: imports · Composes GraphQL access layer
- app module → JSON-RPC: imports · Composes JSON-RPC access layer
- app module → WebSocket: imports · Composes realtime transport
- app module → Telegram bot: imports · Composes bot listener
- app module → AI: imports · Composes AI services
- app module → Blockchain: imports · Composes blockchain services
- app module → Sync contract: imports · Composes contract synchronization pipeline
- app module → Business: imports · Composes workflow services
- app module → Crawler: imports · Composes ingestion services
- app module → Game: imports · Composes game subsystem
- app module → Database: imports · Wires primary persistence
- app module → Timescale DB: imports · Wires time-series persistence
- app module → Redis cache: imports · Wires cache/session layer
- app module → Milvus: imports · Wires vector search store
- app module → Vector store: imports · Wires document retrieval store
- app module → Search: imports · Wires search service
- app module → Firebase: imports · Wires Firestore integration
- app module → Upload file: imports · Wires file storage services
- app module → OneSignal: imports · Wires push delivery client
- app module → Transporter: imports · Wires message transport abstraction
- app module → Queue: imports · Wires queue infrastructure
- app module → Worker: imports · Wires background workers
- app module → Listen socket: imports · Wires external feed listener
- app module → Worker thread: imports · Wires CPU-bound task offload
- API → Shared: uses · Relies on common decorators, exceptions, and validation
- GraphQL → Shared: uses · Shares common auth and response primitives
- JSON-RPC → JSON-RPC lib: uses · Built on custom JSON-RPC framework
- JSON-RPC → Shared: uses · Shares auth and exception contracts
- WebSocket → Redis cache: uses · Uses Redis adapter for horizontal scaling
- Telegram bot → Queue: uses · Defers work through queues
- Telegram bot → Worker: uses · Depends on worker consumers for background flows
- AI → Milvus: uses · Retrieval over vector index
- AI → Vector store: uses · Document retrieval and context storage
- AI → Crawler: uses · Consumes external knowledge sources
- Sync contract → Blockchain: uses · Reads on-chain contracts and events
- Sync contract → Database: writes · Persists normalized chain data
- Business → Database: uses · Reads and updates core business records
- Business → OneSignal: uses · Sends notifications
- Crawler → Shared: uses · Shares DTOs and utilities
- Game → WebSocket: publishes · Exposes game state through realtime channels
- Game → Database: uses · Persists game and battle records
- Database → Shared: uses · Entities and repositories rely on shared constants
- Timescale DB → Shared: uses · Shares common DTOs and config patterns
- Queue → Transporter: uses · Backed by transport layer for async messaging
- Worker → Queue: consumes · Worker processes queued jobs
- Worker → Database: uses · Reads and writes persisted state