Materi Go API Service
The core API service for Materiβs collaborative document platform, built with Go and Fiber for high-performance document management, AI integration, and hybrid real-time collaboration support.ποΈ Hybrid Collaboration Architecture
β οΈ Current Implementation Status: The API service provides collaboration endpoints with placeholder implementations. Full hybrid collaboration integration requires additional service layer development.Implemented Features
hello- Collaboration Controller: 6 REST endpoints for collaboration operations (placeholders)
- Document Management: Full CRUD operations with version control
- AI Integration: Content generation, summarization, and intelligent suggestions
- Event System Foundation: Redis-based event publishing framework (simplified)
- Models & Types: Complete collaboration data models and operation types
- Standardized Logging: Consistent structured logging across all services
π§ Architectural Work Remaining
- Service Layer Integration: Connect controllers to actual collaboration business logic
- Real-time WebSocket Sync: Implement operational transformation algorithms
- Permission Caching: High-performance authorization with Redis caching
- Cross-service Events: Full event-driven sync between API and Collaboration services
- Performance Optimization: Sub-50ms response times with intelligent caching
Current Service Responsibilities
β Implemented:- Document CRUD operations (basic implementation)
- AI-powered content generation and processing
- File upload and storage management (MinIO integration)
- Basic event publishing framework
- Collaboration REST endpoints (placeholder responses)
- Real-time sync to collaboration service
- Collaboration service integration for permission validation
- Bidirectional synchronization between HTTP and WebSocket operations
- Document permission caching and real-time cache invalidation
- Operational transformation algorithms
π Collaboration Service Integration Status
Current Implementation (Type-Safe Placeholders)
The collaboration service integration has been implemented with working placeholder endpoints that provide the correct API surface for front-end development while maintaining type safety: CollaborationController (/api/v1/collaboration/...):
- β Type-safe event structures and routing
- β Redis integration framework
- π§ Business logic requires implementation
- β Complete operation transformation types
- β Document presence and sync models
- β Vector clock and conflict resolution structures
π― Next Implementation Phase
-
Service Layer Development:
- Implement actual collaboration business logic
- Connect to operational transformation algorithms
- Add Redis-based state management
-
Real-time Integration:
- WebSocket connection management
- Bidirectional sync with Rust collaboration service
- Event-driven state synchronization
-
Performance Optimization:
- Permission caching layer
- Operational transform conflict resolution
- Sub-50ms response time optimization
π Event-Driven Architecture
β οΈ Current Status: Event system foundation is implemented with simplified placeholder logic. The API service participates in the event-driven ecosystem to ensure data consistency across services:Published Events
Consumed Events
Event Flow Example
π Getting Started
Prerequisites
- Go 1.21+
- Redis 7.0+
- PostgreSQL 15+
- Docker & Docker Compose
Development Setup
-
Clone and Install Dependencies
-
Configure Environment
-
Start Infrastructure
-
Run Database Migrations
-
Start API Service
π§ Collaboration Development Notes
The collaboration endpoints are currently functional placeholders:- All endpoints return valid responses for front-end integration
- Business logic returns mock data (documented in controller TODOs)
- Event publishing logs events but doesnβt implement full Redis streams
- Ready for service layer implementation without breaking changes
Event System Integration
The API service automatically publishes events when:- Documents are created, updated, or deleted
- User profiles are modified via API
- Document permissions change
- File uploads complete
- User synchronization from Shield service
- Collaboration state updates from Rust service
π Performance & Monitoring
Key Metrics
- Response Time: P95 < 100ms for document operations
- Throughput: 1000+ requests/second sustained
- Event Processing: Sub-50ms event publishing latency
- Cache Hit Rate: >90% for user context validation
Monitoring Endpoints
- Health Check:
GET /health - Metrics:
GET /metrics(Prometheus format) - Event Status:
GET /admin/events/status
Performance Optimizations
- Database Connection Pooling: Optimized for concurrent requests
- Redis Caching: User context and document metadata caching
- Event Batching: Batch processing for high-volume operations
- Background Processing: Async AI processing and file operations
π§ Configuration
Environment Variables
Event Configuration
π§ͺ Testing
Unit Tests
Integration Tests
Event System Tests
Load Testing
π³ Deployment
Docker Build
Docker Compose Deployment
Kubernetes Deployment
π Scaling & Operations
Horizontal Scaling
The API service supports horizontal scaling with:- Stateless Design: No local state, all data in databases/Redis
- Event Consumer Groups: Multiple instances process events in parallel
- Database Connection Pooling: Shared connection management
- Load Balancer Ready: Health checks and graceful shutdown
Event Processing at Scale
Operational Considerations
- Graceful Shutdown: 30-second grace period for event processing
- Circuit Breakers: Protection against downstream service failures
- Rate Limiting: Per-user and global rate limits
- Database Migrations: Zero-downtime schema changes
- Event Replay: Ability to replay events for data recovery
π Security
API Security
- JWT token validation with Redis caching
- Request rate limiting and DDoS protection
- Input validation and sanitization
- SQL injection prevention with parameterized queries
Event Security
- Redis AUTH for event stream access
- Event payload encryption for sensitive data
- Consumer group isolation
- Audit trail for all published events
π API Documentation
Core Endpoints
- Documents:
GET|POST|PUT|DELETE /api/v1/documents - AI Generation:
POST /api/v1/ai/generate - File Uploads:
POST /api/v1/files - User Context:
GET /api/v1/users/me
Event Management
- Event Status:
GET /api/v1/admin/events/status - Consumer Health:
GET /api/v1/admin/events/consumers - Event Replay:
POST /api/v1/admin/events/replay
π€ Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/event-driven-sync - Make changes and add tests
- Ensure all tests pass:
go test ./... - Test event integration:
docker-compose -f docker-compose.event-driven.yml up - Submit a pull request
π Troubleshooting
Common Issues
Event Publishing FailuresPerformance Debugging
Collaboration Service Development
Testing Placeholder Endpoints:- Phase 1: Service layer business logic (operational transformation)
- Phase 2: Redis state management and event streaming
- Phase 3: WebSocket integration with Rust collaboration service
- Phase 4: Performance optimization and caching
For more information about the overall Materi architecture and event-driven patterns, see the System Architecture Documentation.