Standalone, resource-agnostic comments module.
Provides polymorphic commenting for any resource type (posts, entities, tickets, etc.) with unlimited threading, likes/dislikes, and moderation support.
Architecture
Comments are linked to resources via resource_type (string) + resource_uuid (UUID).
No foreign key constraints on the resource side — any module can use comments.
Resource Handler Callbacks
Modules that consume comments can register handlers to receive notifications when comments are created or deleted. Configure in your app:
config :phoenix_kit, :comment_resource_handlers, %{
"post" => PhoenixKit.Modules.Posts
}Handler modules should implement on_comment_created/3 and on_comment_deleted/3.
Core Functions
System Management
enabled?/0- Check if Comments module is enabledenable_system/0- Enable the Comments moduledisable_system/0- Disable the Comments moduleget_config/0- Get module configuration with statistics
Comment CRUD
create_comment/4- Create a comment on a resourceupdate_comment/2- Update a commentdelete_comment/1- Delete a commentget_comment/2,get_comment!/2- Get by IDlist_comments/3- Flat list for a resourceget_comment_tree/2- Nested tree for a resourcecount_comments/3- Count comments for a resource
Moderation
approve_comment/1- Set status to publishedhide_comment/1- Set status to hiddenbulk_update_status/2- Bulk status changeslist_all_comments/1- Cross-resource listing with filterscomment_stats/0- Aggregate statistics
Like/Dislike
Summary
Functions
Sets a comment's status to published.
Bulk-updates status for multiple comment UUIDs.
Checks if a user has disliked a comment.
Checks if a user has liked a comment.
Returns aggregate statistics for all comments.
Counts comments for a resource.
Creates a comment on a resource.
Deletes a comment.
Disables the Comments module.
User dislikes a comment. Creates dislike record and increments counter.
Enables the Comments module.
Checks if the Comments module is enabled.
Gets a single comment by ID with optional preloads.
Gets a single comment by ID with optional preloads.
Gets nested comment tree for a resource.
Gets the Comments module configuration with statistics.
Returns the configured maximum comment depth.
Returns the configured maximum comment length.
Sets a comment's status to hidden.
User likes a comment. Creates like record and increments counter.
Lists all comments across all resource types with filters.
Lists all dislikes for a comment.
Lists all likes for a comment.
Lists comments for a resource (flat list).
Resolves resource context (title and admin path) for a list of comments.
User removes dislike from a comment. Deletes dislike record and decrements counter.
User unlikes a comment. Deletes like record and decrements counter.
Updates a comment.
Functions
Sets a comment's status to published.
Bulk-updates status for multiple comment UUIDs.
Checks if a user has disliked a comment.
Checks if a user has liked a comment.
Returns aggregate statistics for all comments.
Counts comments for a resource.
Creates a comment on a resource.
Automatically calculates depth from parent. Invokes resource handler callback if configured.
Parameters
resource_type- Type of resource (e.g., "post")resource_uuid- UUID of the resourceuser_uuid- UUID of commenterattrs- Comment attributes (content, parent_uuid, etc.)
Deletes a comment.
Cascades to child comments. Invokes resource handler callback if configured.
Disables the Comments module.
User dislikes a comment. Creates dislike record and increments counter.
Enables the Comments module.
Checks if the Comments module is enabled.
Gets a single comment by ID with optional preloads.
Returns nil if not found.
Gets a single comment by ID with optional preloads.
Raises Ecto.NoResultsError if not found.
Gets nested comment tree for a resource.
Returns all published comments organized in a tree structure.
Gets the Comments module configuration with statistics.
Returns the configured maximum comment depth.
Returns the configured maximum comment length.
Sets a comment's status to hidden.
User likes a comment. Creates like record and increments counter.
Lists all comments across all resource types with filters.
Options
:resource_type- Filter by resource type:status- Filter by status:user_uuid- Filter by user:search- Search in content:page- Page number (default: 1):per_page- Items per page (default: 20)
Lists all dislikes for a comment.
Lists all likes for a comment.
Lists comments for a resource (flat list).
Options
:preload- Associations to preload:status- Filter by status
Resolves resource context (title and admin path) for a list of comments.
Returns a map of {resource_type, resource_uuid} => %{title: ..., path: ...}
by delegating to registered comment_resource_handlers that implement
resolve_comment_resources/1.
User removes dislike from a comment. Deletes dislike record and decrements counter.
User unlikes a comment. Deletes like record and decrements counter.
Updates a comment.
Parameters
comment- Comment to updateattrs- Attributes to update (content, status)