System Overview
Components
1. vij-sdk (Client Library)
The SDK is a lightweight JavaScript/TypeScript library that integrates into your applications. Responsibilities:- Capture uncaught errors and unhandled promise rejections
- Collect rich contextual metadata
- Queue and batch error payloads
- Send data to VIJ Admin API
- Provide manual error logging APIs
- Environment Detection: Automatically detects browser vs Node.js
- Batching: Groups multiple errors into single requests
- Queue Management: Bounded queue with FIFO dropping
- Reliable Transport: Uses sendBeacon (browser) or fetch (Node.js)
- Zero Dependencies: Minimal footprint (only tslib)
- Built with TypeScript for type safety
- Rollup bundler produces ESM and CommonJS outputs
- Platform-specific hooks for error capture
- Separate context collectors for browser and Node.js
2. VIJ Admin (Dashboard & API)
The admin dashboard is a Next.js application that serves dual purposes: API server and visualization interface. Responsibilities:- Receive and validate error payloads
- Store errors in MongoDB
- Generate error fingerprints for grouping
- Analyze errors with AI
- Serve dashboard UI for visualization
- Provide analytics and search APIs
- Next.js 16 with App Router for server and client rendering
- MongoDB with Mongoose ODM for data persistence
- Google Gemini AI for intelligent error analysis
- Recharts for data visualization
- SWR for client-side data fetching and caching
- Tailwind CSS 4 for styling
POST /api/logs- Ingest errors from SDKGET /api/logs- Query logs with filteringGET /api/stats- Get aggregated analyticsGET /api/groups- Get error groups
3. MongoDB (Data Layer)
MongoDB stores all error data, grouped errors, and AI analysis cache. Collections:logs
Primary collection for error events with full metadata. Indexes:appId,message,timestamp,severity,environment,fingerprint,groupId,tags{ appId: 1, timestamp: -1 }(compound)- Full-text search on
message
error_groups
Aggregated error groups by fingerprint. Indexes:appId,fingerprint,tags{ appId: 1, fingerprint: 1 }(compound)
ai_cache
Cached AI analysis results. Indexes:{ appId: 1, fingerprint: 1 }(compound, unique)
Data Flow
1. Error Capture Flow
2. Ingestion & Processing Flow
3. Dashboard Query Flow
Key Design Patterns
Singleton Pattern (MongoDB Connection)
MongoDB connection is cached globally to prevent connection leaks in Next.js development mode:Fingerprinting for Error Grouping
Errors are grouped using MD5 hashing:AI Response Caching
AI analysis is expensive and slow. VIJ caches results by fingerprint:Batching for Performance
SDK batches multiple errors into single requests:SWR for Real-time Updates
Dashboard uses SWR with automatic revalidation:Security Considerations
CORS Configuration
VIJ Admin allows all origins by default for ease of integration:Input Validation
All API endpoints use Zod for strict input validation:Body Size Limits
API routes enforce a 10KB body size limit to prevent DoS attacks:No Authentication (Self-Hosted)
VIJ Admin does not include built-in authentication, assuming:- You deploy it privately (not publicly accessible)
- You add authentication middleware if needed
- Your firewall/VPC provides network-level security
Scalability
Horizontal Scaling
VIJ Admin can scale horizontally:- Deploy multiple Next.js instances behind a load balancer
- MongoDB handles concurrent connections from all instances
- No shared state between instances (stateless API)
Database Optimization
MongoDB indexes ensure fast queries even with millions of logs:- Compound indexes for common filter combinations
- Full-text search index for message queries
- Covered queries when possible
AI Cost Optimization
AI caching reduces Gemini API costs:- Only analyze each unique error once
- Subsequent occurrences use cached analysis
- No TTL on cache (errors rarely change)
Monitoring & Observability
VIJ provides observability through:- Dashboard Analytics - Error trends, severity distribution, top messages
- Real-time Updates - SWR polling keeps data fresh
- Detailed Logs - Full stack traces and metadata for debugging
- Error Grouping - See patterns and occurrence counts
- Next.js logs for API errors
- MongoDB slow query logs
- Gemini API usage metrics
Next Steps
SDK Configuration
Learn how to configure the SDK for your needs
Dashboard Features
Explore all dashboard features and capabilities
Error Grouping
Understand how VIJ groups and deduplicates errors
AI Integration
Set up AI-powered error analysis