|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | + |
| 6 | +## Repository Overview |
| 7 | + |
| 8 | +This is an event-driven notification system for DAO governance built with microservices architecture. The system monitors blockchain proposals and delivers notifications via Telegram (with extensibility for other channels). |
| 9 | + |
| 10 | +## Architecture |
| 11 | + |
| 12 | +The system consists of 4 microservices connected via RabbitMQ: |
| 13 | + |
| 14 | +1. **Logic System** - Monitors AntiCapture API for proposal events and triggers notifications |
| 15 | +2. **Dispatcher** - Processes events, fetches subscribers, and creates notification messages |
| 16 | +3. **Subscription Server** - REST API for managing user preferences and tracking notifications |
| 17 | +4. **Consumer** - Telegram bot that delivers notifications and handles user interactions |
| 18 | + |
| 19 | +## Key Commands |
| 20 | + |
| 21 | +### Development |
| 22 | +```bash |
| 23 | +# Install dependencies (requires pnpm) |
| 24 | +pnpm install |
| 25 | + |
| 26 | +# Start all services with Docker Compose |
| 27 | +pnpm dev |
| 28 | + |
| 29 | +# Build all services |
| 30 | +pnpm build |
| 31 | + |
| 32 | +# Run tests across all services |
| 33 | +pnpm test |
| 34 | + |
| 35 | +# Format code |
| 36 | +pnpm format |
| 37 | +``` |
| 38 | + |
| 39 | +### Service-Specific Commands |
| 40 | +```bash |
| 41 | +# Run commands for specific services |
| 42 | +pnpm logic-system <command> |
| 43 | +pnpm dispatcher <command> |
| 44 | +pnpm subscription-server <command> |
| 45 | +pnpm consumer <command> |
| 46 | + |
| 47 | +# Example: Run tests for logic-system |
| 48 | +pnpm logic-system test |
| 49 | + |
| 50 | +# Example: Start a single service in dev mode |
| 51 | +pnpm logic-system dev |
| 52 | +``` |
| 53 | + |
| 54 | +### Testing |
| 55 | +```bash |
| 56 | +# Run all tests |
| 57 | +pnpm test |
| 58 | + |
| 59 | +# Run tests for a specific service |
| 60 | +pnpm --filter @notification-system/logic-system test |
| 61 | + |
| 62 | +# Run a single test file |
| 63 | +pnpm --filter @notification-system/logic-system test -- path/to/test.spec.ts |
| 64 | +``` |
| 65 | + |
| 66 | +## Project Structure |
| 67 | + |
| 68 | +``` |
| 69 | +apps/ |
| 70 | +├── logic-system/ # Event monitoring and triggering |
| 71 | +├── dispatcher/ # Message processing and routing |
| 72 | +├── subscription-server/ # User preference API |
| 73 | +├── consumers/ # Telegram bot delivery |
| 74 | +└── integrated-tests/ # End-to-end testing |
| 75 | +
|
| 76 | +packages/ |
| 77 | +├── anticapture-client/ # GraphQL client for DAO data |
| 78 | +└── rabbitmq-client/ # Shared RabbitMQ utilities |
| 79 | +``` |
| 80 | + |
| 81 | +## Key Technologies |
| 82 | + |
| 83 | +- **Runtime**: Node.js 18+, TypeScript 5.8.2 |
| 84 | +- **Frameworks**: Fastify (APIs), Express (legacy) |
| 85 | +- **Database**: PostgreSQL with Knex.js migrations |
| 86 | +- **Message Queue**: RabbitMQ for service communication |
| 87 | +- **Testing**: Jest with ts-jest |
| 88 | +- **Build**: Turbo monorepo with pnpm workspaces |
| 89 | + |
| 90 | +## Message Flow |
| 91 | + |
| 92 | +1. Logic System polls AntiCapture API every 30 seconds |
| 93 | +2. On new proposals, sends `TriggerEvent` to dispatcher queue |
| 94 | +3. Dispatcher fetches relevant subscribers and creates notifications |
| 95 | +4. Consumer receives notifications and delivers via Telegram |
| 96 | +5. Delivery status tracked in Subscription Server |
| 97 | + |
| 98 | +## Database Schema |
| 99 | + |
| 100 | +The Subscription Server manages: |
| 101 | +- `users`: User profiles with Telegram/Discord IDs |
| 102 | +- `daos`: DAO registry from AntiCapture |
| 103 | +- `user_dao_subscriptions`: Many-to-many subscription relationships |
| 104 | +- `user_notifications`: Notification delivery tracking for deduplication |
| 105 | + |
| 106 | +## Environment Configuration |
| 107 | + |
| 108 | +Each service requires specific environment variables: |
| 109 | +- Copy `env.example` to `.env` at project root |
| 110 | +- Key variables: `DATABASE_URL`, `RABBITMQ_URL`, `TELEGRAM_BOT_TOKEN` |
| 111 | +- AntiCapture API endpoint configuration |
| 112 | + |
| 113 | +## Testing Strategy |
| 114 | + |
| 115 | +- Unit tests for business logic in each service |
| 116 | +- Integration tests for API endpoints |
| 117 | +- End-to-end tests in `integrated-tests` app |
| 118 | +- Jest configuration in each service's `jest.config.js` |
| 119 | + |
| 120 | +## Deployment |
| 121 | + |
| 122 | +- GitHub Actions workflow in `.github/workflows/` |
| 123 | +- Deploys to Railway on push to `dev` or `main` |
| 124 | +- Path-based deployment triggers for specific services |
| 125 | +- Docker Compose for local development mimics production |
| 126 | +======= |
| 127 | +## Project Overview |
| 128 | + |
| 129 | +This is an event-driven notification system for DAO governance built with microservices architecture. The system monitors blockchain data for DAO proposals and delivers real-time notifications to users via Telegram. It uses RabbitMQ for message queuing and PostgreSQL for persistence. |
| 130 | + |
| 131 | +## Architecture |
| 132 | + |
| 133 | +The system consists of 4 main microservices: |
| 134 | + |
| 135 | +1. **Logic System** (`apps/logic-system/`) - Monitors AntiCapture GraphQL API and triggers events |
| 136 | +2. **Dispatcher** (`apps/dispatcher/`) - Processes trigger events and coordinates notification delivery |
| 137 | +3. **Subscription Server** (`apps/subscription-server/`) - REST API for user preferences and subscription management |
| 138 | +4. **Consumer** (`apps/consumers/`) - Telegram bot and notification delivery service |
| 139 | + |
| 140 | +## Development Commands |
| 141 | + |
| 142 | +### Root Level Commands |
| 143 | +- `pnpm dev` - Start all services with Docker Compose |
| 144 | +- `pnpm build` - Build all apps using Turbo |
| 145 | +- `pnpm test` - Run tests across all apps |
| 146 | +- `pnpm format` - Format code with Prettier |
| 147 | + |
| 148 | +### Per-Service Commands |
| 149 | +Use the filter pattern to run commands in specific services: |
| 150 | +- `pnpm --filter @notification-system/logic-system <command>` |
| 151 | +- `pnpm --filter @notification-system/dispatcher <command>` |
| 152 | +- `pnpm --filter @notification-system/subscription-server <command>` |
| 153 | +- `pnpm --filter @notification-system/consumer <command>` |
| 154 | + |
| 155 | +### Testing and Quality |
| 156 | +- **Tests**: Each service uses Jest with TypeScript (`jest.config.js` or `jest.config.ts`) |
| 157 | +- **Linting**: Logic system has ESLint configured (`pnpm logic-system lint`) |
| 158 | +- **Type Checking**: Consumers service has type checking (`pnpm consumer check-types`) |
| 159 | + |
| 160 | +## Message Flow Architecture |
| 161 | + |
| 162 | +1. **Logic System** polls AntiCapture API → sends trigger events to RabbitMQ |
| 163 | +2. **Dispatcher** consumes trigger events → fetches subscribers → creates notifications → publishes to Consumer queue |
| 164 | +3. **Consumer** delivers notifications via Telegram → tracks delivery status in Subscription Server |
| 165 | + |
| 166 | +## Key Implementation Patterns |
| 167 | + |
| 168 | +### Trigger System |
| 169 | +New trigger types follow this pattern: |
| 170 | +- Extend base `Trigger` class in Logic System |
| 171 | +- Implement `fetchData()` and `process()` methods |
| 172 | +- Register in Logic System's `App` class |
| 173 | +- Create corresponding handler in Dispatcher's trigger handlers |
| 174 | +- Register handler in `TriggerProcessorService` |
| 175 | + |
| 176 | +### RabbitMQ Integration |
| 177 | +- Logic System publishes trigger events |
| 178 | +- Dispatcher consumes trigger events and publishes notification events |
| 179 | +- Consumer consumes notification events for delivery |
| 180 | + |
| 181 | +### Database Migrations |
| 182 | +Subscription Server uses Knex.js for database operations with migrations in `db/migrations/` |
| 183 | + |
| 184 | +## Technology Stack |
| 185 | + |
| 186 | +- **Runtime**: Node.js 18+ with pnpm workspaces |
| 187 | +- **Build Tool**: Turbo for monorepo builds |
| 188 | +- **Messaging**: RabbitMQ with custom client abstractions |
| 189 | +- **Database**: PostgreSQL with Knex.js migrations |
| 190 | +- **API**: Fastify for REST endpoints |
| 191 | +- **GraphQL**: Custom AntiCapture client in packages/ |
| 192 | +- **Testing**: Jest with ts-jest preset |
| 193 | +- **Containerization**: Docker with multi-service compose |
| 194 | + |
| 195 | +## Environment Requirements |
| 196 | + |
| 197 | +Essential environment variables: |
| 198 | +- `TELEGRAM_BOT_TOKEN` - Telegram bot authentication |
| 199 | +- `ANTICAPTURE_GRAPHQL_ENDPOINT` - DAO data source |
| 200 | +- `DATABASE_URL` - PostgreSQL connection |
| 201 | +- `RABBITMQ_URL` - Message broker connection |
| 202 | + |
| 203 | +## Extension Points |
| 204 | + |
| 205 | +- **New Trigger Types**: Follow the pattern documented in `apps/logic-system/add-trigger-logic.md` |
| 206 | +- **Notification Channels**: Add new delivery mechanisms in Consumer service |
| 207 | +- **DAO Data Sources**: Extend AntiCapture client or add new data providers |
0 commit comments