# NFT Event Oracle - CursorRules
## Project Structure
- src/
- config/
- chainConfig.ts
- services/
- apiService.ts
- blockchainService.ts
- eventProcessorService.ts
- metadataService.ts
- models/
- Contract.ts
- Event.ts
- utils/
- logger.ts
- index.ts
- docker/
- Dockerfile
- docker-compose.yml
- .env.example
- package.json
- tsconfig.json
## Technology Stack
- Language: TypeScript
- Runtime: Node.js
- Framework: Nest.js (for scalability and modularity)
- Blockchain Interaction: ethers.js (for EVM chains)
- Database: PostgreSQL (for storing processed events and metadata)
- Message Queue: RabbitMQ (for handling high throughput of events)
- Containerization: Docker and Docker Compose
## Core Components
## Implementation Guidelines
11. Use Docker for containerization and easy deployment
12. Create a docker-compose.yml file for orchestrating all services
## Docker Setup
### Dockerfile (docker/Dockerfile)
- Use a multi-stage build for smaller image size
- Install dependencies and build the application
- Use a lightweight Node.js image for the final stage
### Docker Compose (docker/docker-compose.yml)
- Define services for the main application, PostgreSQL, and RabbitMQ
- Use environment variables for configuration
- Set up volume mounts for persistent data
- Configure health checks for each service
## Environment Variables
- Create a .env.example file with all required environment variables
- Include variables for:
- Database connection
- RabbitMQ connection
- API endpoints
- Blockchain RPC URLs
- Log levels
## Single VM Deployment
- Ensure the VM has Docker and Docker Compose installed
- Clone the repository to the VM
- Copy .env.example to .env and fill in the required values
- Run `docker-compose up -d` to start all services
- Implement a simple monitoring solution (e.g., Prometheus + Grafana) for VM resource usage
## Performance Tuning for Single VM
- Adjust container resource limits in docker-compose.yml
- Optimize PostgreSQL configuration for the VM's resources
- Configure RabbitMQ for optimal performance on a single node
- Implement caching mechanisms to reduce database load
## Backup and Recovery
- Set up regular backups of the PostgreSQL database
- Create a backup script and schedule it with cron
- Document the restore process for quick recovery
## Logging and Monitoring
- Use Docker's logging driver to centralize logs
- Implement a log rotation strategy to manage disk space
- Set up Prometheus and Grafana for monitoring (optional)
## Development Workflow
- Use Docker Compose for local development
- Create separate docker-compose.override.yml for development-specific settings
- Implement hot-reloading for faster development cycles
## Deployment Workflow
1. Build and test the application locally
2. Push changes to the repository
3. SSH into the VM
4. Pull the latest changes
5. Rebuild and restart the containers with `docker-compose up -d --build`
## Scaling Considerations
- While designed for a single VM, prepare for future scaling:
- Use environment variables for easy configuration changes
- Design services to be stateless where possible
- Implement health checks for potential load balancing in the future
docker
dockerfile
less
nestjs
postgresql
rest-api
shell
solidity
+1 more
First Time Repository
TypeScript
Languages:
Dockerfile: 1.2KB
Shell: 4.3KB
Solidity: 2.0KB
TypeScript: 68.4KB
Created: 10/29/2024
Updated: 1/23/2025