This document serves as a comprehensive technical guide to the NRT decentralized application. It is intended for developers to fully understand the project's architecture, deployment, core features, and file structure.
The project is a monorepo containing two primary components:
- React Frontend: The main decentralized application (dApp) for user interaction. It handles donations, DAO voting, and the authentication UI. This component is deployed on Netlify.
- Node.js Backend: A dedicated server whose sole purpose is to securely handle user authentication for the Discourse forum via the OpenID Connect (OIDC) protocol and crypto wallet signatures. This component is deployed on Render.
- Node.js:
v22.18.0or a compatible22.xversion. - Yarn:
v1.22.22. - Crypto Wallet: MetaMask or another WalletConnect-compatible wallet.
- Clone the repository:
git clone https://github.com/NRT314/donate-vite.git cd donate-vite - Install frontend dependencies:
yarn install
- Install backend dependencies:
cd backend yarn install cd ..
The project requires .env files for storing keys and environment variables. Create them based on the .env.example templates.
- Frontend (
./.envfile):VITE_PROJECT_ID="..." # Your Project ID from WalletConnect VITE_POLYGON_RPC_URL="..." # Your private Polygon RPC URL VITE_API_URL="http://localhost:10000" # The backend server URL for local development - Backend (
./backend/.envfile):# OIDC Provider OIDC_ISSUER="http://localhost:10000" OIDC_CLIENT_SECRET="..." # The secret generated for the OIDC client in Discourse OIDC_COOKIE_SECRET="..." # A random string for signing cookies # Discourse DISCOURSE_URL="..." # The URL of your Discourse forum # Redis REDIS_URL="..." # The connection URL for your Redis server # Server PORT=10000
- Start the backend server:
cd backend yarn start - In a new terminal window, start the frontend:
yarn dev
The frontend is configured for continuous deployment from the main branch on GitHub.
- Build Command:
yarn run build - Publish Directory:
dist - Node.js Build Version:
22.x
The backend is deployed as a Web Service on Render, with auto-deploy enabled on commits to the main branch.
- Build Command:
yarn install - Start Command:
yarn start - Environment Variables: Secrets from
backend/.envmust be securely added to the service settings on Render.
- Donation System: A two-step process (
approveanddonate) with on-chain recipient management via a secure admin panel. - Governance & DAO System: Features gasless voting where users sign an EIP-712 message, and a relayer submits the transaction. Data fetching is optimized to reduce blockchain queries.
- Discourse SSO & OIDC Authentication: A hybrid authentication system allowing users to log in to a Discourse forum with a crypto wallet. The system is built on the OpenID Connect (OIDC) protocol, with the Node.js backend acting as the Identity Provider.
- Contract Addresses: All deployed contract addresses are stored in
src/constants.js. - ABIs: The JSON Application Binary Interfaces (ABIs) for all contracts are also located in
src/constants.js.
Below is a description of key files and directories within the project.
package.json: Defines frontend project metadata, dependencies (react,wagmi,viem), and npm scripts.index.html: The main HTML entry point for the single-page application.
server.js: The entry point for the backend Express server.oidc.js: The core of the OIDC service, configuring theoidc-providerlibrary and defining the custom wallet authentication logic.walletAuth.js: A utility module to cryptographically verify signed messages.redisAdapter.js: A custom adapter to store all OIDC session and grant data in a Redis database.
main.tsx: The application's entry point, configuringwagmiandRainbowKit.App.jsx: The central component that sets up React Router and manages global UI state.constants.js: A central file for contract addresses, ABIs, and other static data.organizations.js: A file that acts as the source of truth for the list of recipient organizations displayed in the UI.
DiscourseAuth.jsx: The dedicated UI page for the wallet authentication flow.AdminPage.jsx: A secure, owner-only page that performs an on-chain check before rendering administrative components.VotingPage.jsx: The main page for displaying the list of all governance proposals.ProposalView.jsx: The detailed view for a single proposal, handling the gasless voting workflow.