How polkassembly/polkassembly works
Project type and purpose
• This is a full-stack, serverless Next.js application (“polkassembly”) for browsing, discussing, and voting on Polkadot/Kusama governance proposals.
• The frontend is a React/Next.js UI with server-side rendering (SSR) + static generation.
• The backend consists of Next.js API routes plus standalone Firebase Cloud Functions for background jobs (analytics, search indexing).
High-level file-structure overview
• “pages/” → Next.js pages (UI routes) and API routes under pages/api/v1/…
• “src/” → shared client & server utilities, React components, Redux store, hooks, auth, services.
• “cloud-functions/” → Firebase Cloud Functions for scheduled/indexing tasks (trackLevelAnalytics, updateNewProposalsInAlgolia).
• Config & infra: firebase.json, .firebaserc, next.config.js, tsconfig.json.
Key README insights
• A Next.js full-stack app deployed to Vercel or Firebase Hosting.
• API routes are under pages/api and ephemeral Cloud Functions handle heavy or scheduled backend work.
Main components
1. Client (browser or mobile web)
2. CDN/Hosting layer (Vercel or Firebase Hosting + Cloud Front)
3. Next.js Serverless Functions
• SSR/SSG renderer (handles pages/*)
• API endpoints (pages/api/v1/*)
4. Firebase Cloud Functions (cloud-functions folder)
• Analytics jobs (trackLevelAnalytics)
• Search indexing jobs (updateNewProposalsInAlgolia)
5. Data stores & caches
• Firestore (primary document DB for posts, comments, profiles, notifications)
• Redis (short-lived caching, auth token storage)
6. External blockchain & data APIs
• Polkadot/Substrate RPC via polkadot.js
• Subsquid & Subscan for on-chain query data
7. Third-party services
• Algolia (search index)
• Sentry (error tracking)
• Google Analytics / instrumentation.ts
• Email/2FA/Social callbacks for auth
8. Client-side state store
• Redux (store.ts) for in-app state management
Component relationships & data flows
• Browser → CDN/Hosting → Next.js SSR Function → Firestore / Redis / Blockchain RPC → returns fully-rendered page.
• Browser (SPA navigation) → Next.js API Function → Firestore + external APIs → JSON response.
• Cloud Functions (scheduled or HTTP-triggered) → Subsquid/Subscan → compute analytics → update Firestore or Algolia.
• On-chain events (via Firestore triggers or schedules) → Cloud Functions → update search index.
• User actions (vote/comment) → Next.js API → Firestore writes → in-app notification updates.
Architectural patterns & design principles
• Serverless JAMstack: SSR pages + static pages + lightweight API endpoints.
• Microservices-style separation: UI/API vs. background Cloud Functions.
• Single-page app navigation with client-side hydration (Redux).
• CQRS-lite: user requests handled by API; analytics/indexing offloaded to separate functions.
Technologies & frameworks
• Frontend: Next.js, React, TypeScript, Redux, Tailwind CSS.
• Backend (serverless API): Next.js API routes (Node.js/Express style), Firebase Cloud Functions (TypeScript).
• Data: Firebase Firestore, Redis.
• External: Polkadot.js RPC, Subsquid, Subscan.
• Search: Algolia.
• Monitoring: Sentry, Google Analytics.
• Auth: JWT, MetaMask, WalletConnect, email+2FA.