How blockchain-kami/lensview-beta works
Project Type & Purpose
• This is a full-stack Web3 application (“LensView”) that brings a decentralized comment layer to any webpage.
• It comprises three main pieces:
– A monolithic Node.js GraphQL backend (handles URL indexing, comment‐summaries, on-chain broadcasts, caching).
– A Svelte-based browser extension (popup UI for “in-page” commenting).
– A SvelteKit web application (full-page UI for search, profile, post threads).
• The entire system leverages the Lens Protocol GraphQL API, Polygon blockchain, IPFS for assets, AI services for summarization, and MongoDB for caching.
File-Structure–Driven Architecture
• Top-level folders:
– /backend: GraphQL server, controllers/services/utils, Dockerfile, MongoDB connection, jobs (puppeteer + IPFS + AI).
– /extension: Svelte popup UI, shared GraphQL fragments and queries, GraphQL codegen, browser manifest.
– /web-app: SvelteKit application, routes, components, GraphQL codegen, REST/axios services to “backend,” direct Lens GraphQL calls.
• Patterns & layers (backend):
– “src/controllers → src/services → src/utils” (MVC/clean-architecture).
– “src/graphql/schema + codegen.ts” drives GraphQL resolvers.
– “jobs” invocations for screenshot+IPFS.
– Environment/config modules for AI (Gemini, Ayfie), puppeteer, thirdweb clients.
Key Components
• Browser Extension (Svelte) – popup UI → GraphQL queries/mutations + REST calls to backend.
• Web Application (SvelteKit) – SPA pages → Lens Protocol GraphQL + backend REST for summarization, URL management.
• GraphQL Gateway – merges project schema (schema.graphql) with Lens Protocol GraphQL operations (via gql client).
• Controllers & Services – handle business logic (authenticate, create-post, comment, summary).
• Job Queue Modules – puppeteer screenshot, IPFS upload, AI summarization.
• Configuration modules – MongoDB connection, thirdweb client (signing), polygon-gas API.
• MongoDB – stores URL-metadata, comment summaries, publication records.
• Lens Protocol GraphQL API – on-chain social graph.
• Polygon Gas Price API.
• IPFS – storing images/screenshots.
• AI Summarization (Gemini, Ayfie).
• Puppeteer – headless browser for screenshot.
• ThirdWeb – wallet/sign-typed-data client.
1. User → Extension/Web-App UI: triggers login (challenge query) and obtains access token via Lens GraphQL.
2. UI → Lens Protocol: directly perform “authenticate,” “create-typed-data,” “broadcast” operations.
3. UI → Backend (REST or GraphQL):
– add-URL (URL indexing), request comment summaries, validate URL existence.
– subscribe to WebSocket (if implemented) or poll for summary/jobs status.
4. Backend → MongoDB: persist metadata and summary caches.
5. Backend → AI Services: request text-summary generation.
6. Backend → Puppeteer + IPFS: generate screenshot, upload to IPFS, return URI.
7. Backend → Lens Protocol: broadcast on-chain transactions for comments/posts via signed typed-data.
8. UI ← Lens Protocol / Backend: fetch published comments, publications, comment summaries.
Architectural Patterns & Principles
• Clean Separation of Concerns: controllers, services, and utils in backend.
• Shared GraphQL Fragments & Codegen: reduces duplication between extension & web-app.
• Monolithic Backend: single codebase handles all business, integration, and persistence.
• Event/Job-Driven Tasks: screenshot + IPFS + AI summarization offloaded to “jobs” layer.
Essential Elements
• Clear demarcation: UI layer, API layer, persistence & jobs layer, external blockchain & services.