PVPipe Architecture
System Architecture Overview
PVPipe is built using a microservices architecture that ensures scalability, maintainability, and resilience.
Architecture Diagram
graph TB
subgraph "Client Layer"
WEB[Web App - Next.js]
MOBILE[Mobile App - React Native]
end
subgraph "API Gateway"
NGINX[Nginx Ingress]
end
subgraph "Application Layer"
API[Main API - NestJS]
AUTH[Auth Service - Go]
FILES[Files Service - Go]
EMAIL[Email Service]
PDF[PDF Service]
end
subgraph "Data Layer"
PG[(PostgreSQL)]
REDIS[(Redis)]
S3[AWS S3]
end
subgraph "External Services"
VNPT[VNPT SmartCA]
SMTP[Email Provider]
end
WEB --> NGINX
MOBILE --> NGINX
NGINX --> API
NGINX --> AUTH
NGINX --> FILES
API --> PG
API --> REDIS
API --> EMAIL
API --> PDF
AUTH --> PG
AUTH --> REDIS
FILES --> S3
FILES --> PG
PDF --> VNPT
EMAIL --> SMTP
Core Components
1. Frontend Applications
Web Application (Next.js)
- Purpose: Main user interface for document management
- Technologies: Next.js 14, TypeScript, Tailwind CSS
- Key Features:
- Server-side rendering for performance
- Real-time updates via WebSocket
- Progressive Web App capabilities
Mobile Application (React Native)
- Purpose: Mobile access to core features
- Technologies: React Native, TypeScript
- Platforms: iOS and Android
2. Backend Services
Main API (NestJS)
- Purpose: Core business logic and orchestration
- Responsibilities:
- Document workflow management
- User management
- Project and task management
- Integration coordination
Authentication Service (Go)
- Purpose: Handle authentication and authorization
- Features:
- JWT token management
- OTP generation and verification
- Session management
- Role-based access control
Files Service (Go)
- Purpose: File upload and management
- Features:
- Multipart upload support
- File versioning
- Virus scanning integration
- Thumbnail generation
Email Service
- Purpose: Email integration and management
- Features:
- IMAP/SMTP integration
- Email parsing and threading
- Attachment handling
PDF Service
- Purpose: PDF processing and manipulation
- Features:
- PDF generation
- Digital signature placement
- PDF merging and splitting
- OCR capabilities
3. Data Storage
PostgreSQL
- Purpose: Primary data store
- Usage:
- User data
- Document metadata
- Workflow states
- Audit logs
Redis
- Purpose: Caching and session storage
- Usage:
- Session management
- API response caching
- Rate limiting
- Real-time features
AWS S3
- Purpose: Object storage
- Usage:
- Document storage
- File attachments
- Backup storage
Communication Patterns
Synchronous Communication
- REST APIs for client-server communication
- gRPC for inter-service communication (where applicable)
Asynchronous Communication
- Redis Pub/Sub for real-time updates
- Bull queues for background jobs
- WebSocket for real-time client updates
Security Architecture
Authentication Flow
- User login with credentials
- OTP verification (if enabled)
- JWT token generation
- Token refresh mechanism
Authorization
- Role-Based Access Control (RBAC)
- Resource-level permissions
- API key authentication for external integrations
Data Security
- Encryption at rest (database)
- Encryption in transit (HTTPS)
- Document encryption for sensitive files
Deployment Architecture
Kubernetes Deployment
- Namespaces: Separate environments (dev, staging, production)
- Services: LoadBalancer for external access
- Ingress: Nginx ingress controller
- Secrets: Kubernetes secrets for sensitive data
Scaling Strategy
- Horizontal Pod Autoscaling for services
- Database read replicas for read-heavy operations
- CDN for static assets
Monitoring and Observability
Metrics
- Prometheus for metrics collection
- Grafana for visualization
Logging
- Centralized logging with ELK stack
- Structured logging format
Tracing
- OpenTelemetry for distributed tracing
- Jaeger for trace visualization
Disaster Recovery
Backup Strategy
- Daily database backups
- S3 cross-region replication
- Configuration backups in Git
High Availability
- Multi-zone deployment
- Database replication
- Service redundancy
Future Considerations
Planned Improvements
- Event-driven architecture with Kafka
- GraphQL API gateway
- Machine learning for document classification
- Blockchain integration for document verification