diff --git a/apps/stock/data-ingestion/AWILIX-MIGRATION.md b/apps/stock/data-ingestion/AWILIX-MIGRATION.md deleted file mode 100644 index e23d3d1..0000000 --- a/apps/stock/data-ingestion/AWILIX-MIGRATION.md +++ /dev/null @@ -1,85 +0,0 @@ -# Awilix DI Container Migration Guide - -This guide explains how to use the new Awilix dependency injection container in the data-ingestion service. - -## Overview - -The Awilix container provides proper dependency injection for decoupled libraries, allowing them to be reused in other projects without stock-bot specific dependencies. - -## Current Implementation - -The data-ingestion service now uses a hybrid approach: -1. Awilix container for ProxyManager and other decoupled services -2. Legacy service factory for backward compatibility - -## Usage Example - -```typescript -// Create Awilix container -const awilixConfig = { - redis: { - host: config.database.dragonfly.host, - port: config.database.dragonfly.port, - db: config.database.dragonfly.db, - }, - mongodb: { - uri: config.database.mongodb.uri, - database: config.database.mongodb.database, - }, - postgres: { - host: config.database.postgres.host, - port: config.database.postgres.port, - database: config.database.postgres.database, - user: config.database.postgres.user, - password: config.database.postgres.password, - }, - proxy: { - cachePrefix: 'proxy:', - ttl: 3600, - }, -}; - -const container = createServiceContainer(awilixConfig); -await initializeServices(container); - -// Access services from container -const proxyManager = container.resolve('proxyManager'); -const cache = container.resolve('cache'); -``` - -## Handler Integration - -Handlers receive services through the enhanced service container: - -```typescript -// Create service adapter with proxy from Awilix -const serviceContainerWithProxy = createServiceAdapter(services); -Object.defineProperty(serviceContainerWithProxy, 'proxy', { - get: () => container.resolve('proxyManager'), - enumerable: true, - configurable: true -}); - -// Handlers can now access proxy service -class MyHandler extends BaseHandler { - async myOperation() { - const proxy = this.proxy.getRandomProxy(); - // Use proxy... - } -} -``` - -## Benefits - -1. **Decoupled Libraries**: Libraries no longer depend on @stock-bot/config -2. **Reusability**: Libraries can be used in other projects -3. **Testability**: Easy to mock dependencies for testing -4. **Type Safety**: Full TypeScript support with Awilix - -## Next Steps - -To fully migrate to Awilix: -1. Update HTTP library to accept dependencies via constructor -2. Update Queue library to accept Redis config via constructor -3. Create actual MongoDB, PostgreSQL, and QuestDB clients in the container -4. Remove legacy service factory once all services are migrated \ No newline at end of file diff --git a/apps/stock/ecosystem.config.js b/apps/stock/ecosystem.config.js deleted file mode 100644 index a94d2a4..0000000 --- a/apps/stock/ecosystem.config.js +++ /dev/null @@ -1,72 +0,0 @@ -module.exports = { - apps: [ - { - name: 'stock-ingestion', - script: './data-ingestion/dist/index.js', - instances: 1, - autorestart: true, - watch: false, - max_memory_restart: '1G', - env: { - NODE_ENV: 'production', - PORT: 2001 - }, - env_development: { - NODE_ENV: 'development', - PORT: 2001 - } - }, - { - name: 'stock-pipeline', - script: './data-pipeline/dist/index.js', - instances: 1, - autorestart: true, - watch: false, - max_memory_restart: '1G', - env: { - NODE_ENV: 'production', - PORT: 2002 - }, - env_development: { - NODE_ENV: 'development', - PORT: 2002 - } - }, - { - name: 'stock-api', - script: './web-api/dist/index.js', - instances: 2, - autorestart: true, - watch: false, - max_memory_restart: '1G', - exec_mode: 'cluster', - env: { - NODE_ENV: 'production', - PORT: 2003 - }, - env_development: { - NODE_ENV: 'development', - PORT: 2003 - } - } - ], - - deploy: { - production: { - user: 'deploy', - host: 'production-server', - ref: 'origin/master', - repo: 'git@github.com:username/stock-bot.git', - path: '/var/www/stock-bot', - 'post-deploy': 'cd apps/stock && npm install && npm run build && pm2 reload ecosystem.config.js --env production' - }, - staging: { - user: 'deploy', - host: 'staging-server', - ref: 'origin/develop', - repo: 'git@github.com:username/stock-bot.git', - path: '/var/www/stock-bot-staging', - 'post-deploy': 'cd apps/stock && npm install && npm run build && pm2 reload ecosystem.config.js --env development' - } - } -}; \ No newline at end of file diff --git a/apps/stock/package.json b/apps/stock/package.json index 91ceb42..be8e496 100644 --- a/apps/stock/package.json +++ b/apps/stock/package.json @@ -49,19 +49,11 @@ "docker:build": "docker-compose build", "docker:up": "docker-compose up", "docker:down": "docker-compose down", - "pm2:start": "pm2 start ecosystem.config.js", - "pm2:stop": "pm2 stop all", - "pm2:restart": "pm2 restart all", - "pm2:logs": "pm2 logs", - "pm2:status": "pm2 status", "db:migrate": "cd data-ingestion && bun run db:migrate", "db:seed": "cd data-ingestion && bun run db:seed", - "health:check": "bun scripts/health-check.js", - "monitor": "bun run pm2:logs", - "status": "bun run pm2:status" + "health:check": "bun scripts/health-check.js" }, "devDependencies": { - "pm2": "^5.3.0", "@types/node": "^20.11.0", "typescript": "^5.3.3", "turbo": "^2.5.4" diff --git a/apps/stock/tsconfig.json b/apps/stock/tsconfig.json index c8ae20d..fcce235 100644 --- a/apps/stock/tsconfig.json +++ b/apps/stock/tsconfig.json @@ -15,4 +15,4 @@ { "path": "./web-api" }, { "path": "./web-app" } ] -} +} \ No newline at end of file