+276
-24
docs/COMMENT_SYSTEM_IMPLEMENTATION.md
···This document details the complete implementation of the comment system for Coves, a forum-like atProto social media platform. The comment system follows the established vote system pattern, with comments living in user repositories and being indexed by the AppView via Jetstream firehose.-**Last Updated:** November 6, 2025 (Final PR review fixes complete - lexicon compliance, data integrity, SQL correctness)+**Status:** โ Phase 1, 2A & 2B Complete - Production-Ready with Vote Integration + PR Hardening···+2. `internal/atproto/jetstream/vote_consumer.go` - Refactored for comment support with URI parsing+3. `internal/atproto/jetstream/comment_consumer.go` - Applied URI parsing pattern for consistency+- Viewer state population (authenticated with vote, authenticated without vote, unauthenticated)+After Phase 2B implementation, a thorough PR review identified several critical issues and improvements that were addressed before production deployment:+- **Problem:** When a comment arrives before its parent post (common with Jetstream's cross-repository event ordering), the post update returns 0 rows affected. Later when the post is indexed, there was NO reconciliation logic to count pre-existing comments, causing posts to have permanently stale `comment_count` values.+- **Impact:** Posts would show incorrect comment counts indefinitely, breaking UX and violating data integrity+- **Solution:** Implemented reconciliation in post consumer (similar to existing pattern in comment consumer)+- Updates `comment_count` atomically: `SET comment_count = (SELECT COUNT(*) FROM comments WHERE parent_uri = $1)`+- **Initial Request:** Change `log.Printf("...%v", err)` to `log.Printf("...%w", err)` in vote consumer+- **Outcome:** No changes needed; error is properly returned on next line to preserve error chain+- **Issue:** Rich text facets, embeds, and labels are stored in database but not deserialized in API responses+- **Decision:** Per original Phase 2C plan, defer JSON field deserialization (already marked with TODO comments)+- **Rationale:** Phase 2C explicitly covers "complete record" population - no scope creep needed+- **Problem:** Taking address of type-asserted variables directly from type assertion could be risky during refactoring+- **Problem:** Function returned empty string for malformed URIs with no clear indication in documentation+- **Problem:** Query selected unused columns (`cid`, `created_at`) that weren't accessed by service+**Total Implementation Effort:** Phase 2B initial (5-7 hours) + PR hardening (6-8 hours) = **~11-15 hours**···-The comment system has successfully completed **Phase 1 (Indexing)** and **Phase 2A (Query API)**, providing a production-ready threaded discussion system for Coves:+The comment system has successfully completed **Phase 1 (Indexing)**, **Phase 2A (Query API)**, and **Phase 2B (Vote Integration)** with comprehensive production hardening, providing a production-ready threaded discussion system for Coves:The implementation provides a solid foundation for building rich threaded discussions in Coves while maintaining compatibility with the broader atProto ecosystem and following established patterns from platforms like Lemmy and Reddit.···TEST_DATABASE_URL="postgres://test_user:test_password@localhost:5434/coves_test?sslmode=disable" \+TEST_DATABASE_URL="postgres://test_user:test_password@localhost:5434/coves_test?sslmode=disable" \···+**Documentation:** Comprehensive implementation guide covering all phases, PR reviews, and production considerations