Skip to main content

title: “Ward Community Module” description: “Architecture and implementation guide for the hyper-local community social feed.”

Ward Community Module

The Ward Community module provides a hyper-local social layer for the Visita Intelligence Platform, enabling residents, businesses, and councillors to interact within a specific geographic ward.

Overview

We build critical infrastructure, not social networks. Every community feature must serve awareness and civic participation. The community feed is designed to facilitate discussion, report local issues, and connect citizens with their ward representatives.

Schema Configuration

The module extends the visita_myward schema with two primary tables:

community_posts

Authoritative record for all community discussions and reports.
ColumnTypeDescription
idUUIDPrimary key.
ward_idUUIDFK referencing visita_myward.communities.
user_idUUIDFK referencing auth.users.
contentTEXTPost body content.
media_urlsTEXT[]Array of image URLs stored in Supabase Storage.
categoryEnumgeneral, safety, service_delivery, business.
issue_typeTEXTSpecific type for service delivery (e.g., ‘pothole’).
issue_statusEnumopen, resolved, null.

community_comments

ColumnTypeDescription
idUUIDPrimary key.
post_idUUIDFK referencing community_posts.
user_idUUIDFK referencing auth.users.
contentTEXTComment body.

Error Handling Strategy

The module implements a robust, multi-layer error handling strategy as defined in @/lib/error-handler.ts.

1. Standardized Response Format

All server actions return a consistent ActionResponse<T> object:
export type ActionResponse<T> = {
    success: boolean;
    data?: T;
    error?: {
        code: string;
        message: string;
        layer: string;
        category: string;
        context?: any;
    };
};

2. Schema-Specific Logging

Errors are logged with schema and operation context to facilitate debugging and monitoring:
logSchemaError('visita_myward', 'community_posts', 'INSERT', error);

3. User-Safe Messages

Internal database errors are caught and transformed into user-friendly messages while preserving technical context for developers.

Component Architecture

The module follows the 3-Column Layout pattern:
  1. Left Sidebar: Navigation and global filtering.
  2. Main Feed: Post creation widget and infinite scroll feed.
  3. Right Sidebar: Contextual ward information (Councillor profile, Ward health stats).

Security & Governance

Row Level Security (RLS)

  • Select: Anyone (including anonymous users) can view community posts.
  • Insert: Restricted to authenticated users.
  • Update/Delete: Restricted to the post author.

Role-Based Actions

The markIssueResolved action implements governance rules:
  • Authors can mark their own issues as resolved.
  • Councillors can mark any issue in their ward as resolved to facilitate service delivery oversight.

Implementation Status (Prototype Mode)

  • UI Architecture (3-Column Layout)
  • Mock Data Visualization (Enabled)
  • Next Step: Connect WardCommunityBoard to visita_myward database.
    • Posts Source: visita_myward.posts
    • Councillor Source: public.wards
    • Stats Source: Aggregated count of issue_status = 'open'

Future Roadmap

  • Multi-image carousel support.
  • Real-time feed updates via Supabase Realtime.
  • AI-assisted issue categorization and sentiment analysis.