NestJS Application Core
Relevant source files
The following files were used as context for generating this wiki page:
The NestJS Application Core serves as the server-side engine for the Technical Analysis project. It is built using the NestJS framework, a progressive Node.js framework designed for creating efficient, scalable, and testable server-side applications using TypeScript. The core is responsible for orchestrating various modules that handle financial data integration, technical indicators, and algorithmic testing.
Sources: backend/README.md:21-23, backend/src/main.ts:1-7
Architecture Overview
The application follows a modular architecture where the AppModule acts as the root container. This module imports and configures global services such as GraphQL for API communication and TypeORM for database management.
System Flow
The following diagram illustrates how the application initializes and manages its internal modules.
Core Components
1. Application Entry Point
The execution begins in main.ts, which uses the NestFactory to instantiate the application using the AppModule. By default, the server listens on port 3000.
Sources: backend/src/main.ts:4-7
2. Root Module (AppModule)
The AppModule is the central hub for dependency injection. It configures the three primary infrastructure components:
- GraphQLModule: Configured for code-first schema generation (
schema.gql) and enables subscription handlers for real-time data updates. - TypeORMModule: Specifically configured to use a SQLite database named
database.sqlite. It is set to automatically synchronize entities found in the distribution directory. - ConfigModule: Set as a global module to provide configuration variables across the entire application.
Sources: backend/src/app.module.ts:14-29
3. Module Registry
The application core integrates several domain-specific modules that provide the actual business logic for technical analysis:
| Module | Purpose |
|---|---|
TinkoffModule | Integration with Tinkoff Invest API. |
WatchListModule | Management of user-tracked financial instruments. |
TradingViewModule | Scraping or integrating TradingView ideas. |
TipRanksModule | Analysts' price predictions and sentiment data. |
IndicatorModule | Calculation of technical indicators (e.g., SMA, RSI). |
AlgorithmTestingModule | Backtesting and live testing of trading strategies. |
Sources: backend/src/app.module.ts:31-37
Data Infrastructure
The core uses TypeORM with SQLite to persist data. The synchronization setting is enabled, allowing the database schema to stay in sync with the TypeScript entities automatically during development.
Development and Build Configuration
The project utilizes the Nest CLI for building and managing the lifecycle of the application. The nest-cli.json specifies the source root as the src directory.
Build Scripts
Key scripts defined in package.json manage the application lifecycle:
npm run start:dev: Launches the application in watch mode, rebuilding on file changes.npm run build: Compiles the TypeScript code into thedistfolder.npm run test: Executes unit tests using the Jest framework.
Sources: backend/package.json:8-23, backend/nest-cli.json:1-4
Real-time Capabilities
The inclusion of installSubscriptionHandlers: true in the GraphQLModule configuration indicates that the core supports WebSocket-based subscriptions. This is critical for the application's purpose of technical analysis, where live price updates (candles) are required.
Sources: backend/src/app.module.ts:16, backend/package.json:44
Summary
The NestJS Application Core provides a robust foundation for financial data analysis. By leveraging a modular architecture, it separates concerns between data acquisition (Tinkoff, TipRanks), analysis (Indicators, Algorithm Testing), and presentation (GraphQL). The use of SQLite and TypeORM ensures easy-to-manage persistence for instrument watchlists and algorithm results.