How byhow/matters-forum works
Main Components
• Frontend UI – Built with Next.js (using the App Router), incorporating pages for the feed, individual items (with comment and reply components), search, and RSS views.
• API Endpoints – Located under src/app/api, which includes subdirectories for IPFS, RSS, and webhook interactions.
• Cron Jobs – A specialized route in src/app/cron that periodically catches missed events.
• Blockchain and Wallet Connect – Integration using RainbowKit, Wagmi, and viem.sh for onchain interactions (e.g., curation events on Optimism).
• Database Layer – Managed via Drizzle ORM for Postgres (with the schema defining curations, comments, and users) hosted on Supabase.
• Other Libraries & Tools:
○ IPFS gateway integration for content fetching.
○ Rate limiting functionality implemented using Vercel KV/Redis.
○ Utility functions and hooks in src/lib to support business logic.
Interaction & Data Flow
• User Access:
• The user lands on a feed page (hackernews-esque interface), which fetches posts from the database.
• Navigation between sorting pages (/newest, /trend, /priciest) defines how data is retrieved, ordered, and presented.
• Post and Comment Interaction:
• Selecting a post leads to an individual item page that retrieves content from IPFS (via the unstable public gateway or a paid plan) and displays comments.
• Comment functionality requires wallet connect; the blockchain integration is kickstarted using RainbowKit/Wagmi.
• API Operations:
• API routes under src/app/api manage operations for IPFS data retrieval, RSS feed generation, and webhook processing.
• A cron endpoint is scheduled to fill any gaps missed by the event listener on Optimism (using viem.watchEvent) and update the database.
• Database & ORM:
• Drizzle ORM communicates with the Postgres database (schema found in src/lib/db/schema.ts) to persist curations, comments, and user data.
• Supporting Utilities:
• Hooks (e.g., useIsMounted) and libs (e.g., rate-limit, subscribe) play auxiliary roles in ensuring a smooth client and server experience with type safety (using Zod).
Architectural Patterns and Relationships
• Separation of Concerns:
• The client-facing interface is clearly separated from API logic; the Next.js app directory clearly splits server-side and client-side components.
• Event-Driven Updates:
• The integration with viem.sh to listen for onchain events and a complementary cron job demonstrate an event-driven design to update the database.
• Decentralized Interactions:
• The system leverages decentralized data (via IPFS) and blockchain wallet authentication, creating an interface that is both modern and decentralized.
• RESTful & SSG/SSR Renders:
• The API endpoints alongside the server-side rendering of different pages (feed, item, RSS) exhibit a mix of SSR and API-based interactions.