Skip to content

Latest commit

 

History

History
347 lines (282 loc) · 9.17 KB

File metadata and controls

347 lines (282 loc) · 9.17 KB

CodedForum Architecture

System Overview

CodedForum is a decentralized Web3 Learn-to-Earn community forum built with modern web technologies and blockchain integration.

Architecture Diagram

┌─────────────────────────────────────────────────────────────┐
│                         Frontend                             │
│                    React.js + Web3                           │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────┐   │
│  │   Home   │  │  Posts   │  │ Profile  │  │Leaderboard│   │
│  └──────────┘  └──────────┘  └──────────┘  └──────────┘   │
│         │              │              │              │       │
└─────────┼──────────────┼──────────────┼──────────────┼─────┘
          │              │              │              │
          └──────────────┴──────────────┴──────────────┘
                         │
                    REST API
                         │
┌─────────────────────────┴────────────────────────────────────┐
│                      Backend                                  │
│                  Node.js + Express                            │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────┐    │
│  │  Users   │  │  Posts   │  │ Comments │  │ Rewards  │    │
│  └──────────┘  └──────────┘  └──────────┘  └──────────┘    │
└──────────────────────┬────────────────────┬─────────────────┘
                       │                    │
           ┌───────────┴───────┐    ┌──────┴──────┐
           │                   │    │             │
    ┌──────▼──────┐    ┌──────▼────▼──┐   ┌─────▼─────┐
    │   Database  │    │  IPFS Storage │   │ Blockchain│
    │  (In-Memory)│    │ (Decentralized)│   │  (EVM)    │
    └─────────────┘    └───────────────┘   └───────────┘

Technology Stack

Frontend

  • React.js - UI framework
  • React Router - Client-side routing
  • Ethers.js - Ethereum interaction
  • Axios - HTTP client
  • CSS3 - Styling

Backend

  • Node.js - Runtime environment
  • Express.js - Web framework
  • CORS - Cross-origin resource sharing
  • Body-parser - Request parsing

Blockchain

  • Solidity - Smart contract language
  • Hardhat - Development environment
  • OpenZeppelin - Smart contract libraries
  • ERC20 - Token standard

Storage

  • IPFS - Decentralized file storage
  • In-memory storage - Development database (migrate to MongoDB for production)

Component Architecture

Frontend Components

1. App.js

  • Main application component
  • Handles Web3 provider initialization
  • Manages wallet connection state
  • Routing configuration

2. Header

  • Navigation bar
  • Wallet connection button
  • User address display
  • Route links

3. Home

  • Post listing
  • Category filtering
  • Recent discussions
  • Hero section

4. CreatePost

  • Post creation form
  • Category selection
  • Content input
  • IPFS upload integration

5. PostDetail

  • Full post display
  • Comment section
  • Voting mechanism
  • Author information

6. Leaderboard

  • Top users ranking
  • Token earnings display
  • Reputation scores
  • Earning methods guide

7. Profile

  • User statistics
  • Token balance
  • Reputation score
  • Claim rewards functionality

Backend Architecture

API Routes

User Routes (/api/users)

  • POST /register - Create new user with wallet address
  • GET /:walletAddress - Retrieve user profile

Post Routes (/api/posts)

  • GET / - List all posts
  • POST / - Create new post
  • GET /:id - Get specific post
  • POST /:id/comments - Add comment to post
  • POST /:id/vote - Vote on post

Reward Routes (/api/rewards)

  • GET /leaderboard - Get top 10 users
  • POST /claim - Claim earned tokens

Category Routes (/api/categories)

  • GET / - List all categories

Smart Contract Architecture

CodedForumToken.sol

Inheritance:

  • ERC20 (OpenZeppelin)
  • Ownable (OpenZeppelin)

Key Features:

  • Token minting for rewards
  • Reputation tracking
  • Batch reward distribution
  • Reward claiming mechanism

Constants:

  • POST_REWARD: 10 tokens
  • COMMENT_REWARD: 2 tokens
  • UPVOTE_REWARD: 1 token

Functions:

  • rewardPost(address) - Mint tokens for post creation
  • rewardComment(address) - Mint tokens for commenting
  • rewardUpvote(address) - Mint tokens for receiving upvotes
  • getReputation(address) - Get user reputation
  • getTotalRewards(address) - Get total rewards claimed

Data Models

User

{
  walletAddress: String,
  username: String,
  reputation: Number,
  tokensEarned: Number,
  postsCount: Number,
  joinedAt: Date
}

Post

{
  id: String,
  title: String,
  content: String,
  author: String,
  category: String,
  ipfsHash: String,
  upvotes: Number,
  downvotes: Number,
  comments: Array,
  createdAt: Date,
  updatedAt: Date
}

Comment

{
  id: String,
  content: String,
  author: String,
  upvotes: Number,
  createdAt: Date
}

Security Considerations

Frontend

  • Input validation
  • XSS prevention
  • Wallet signature verification
  • Secure Web3 interactions

Backend

  • Rate limiting (to be implemented)
  • CORS configuration
  • Input sanitization
  • SQL injection prevention (when using database)

Smart Contracts

  • Access control (Ownable pattern)
  • Reentrancy protection
  • Integer overflow protection (Solidity 0.8+)
  • Gas optimization

Scalability

Current Implementation

  • In-memory storage (development)
  • Suitable for MVP and testing

Production Recommendations

  1. Database: Migrate to MongoDB or PostgreSQL
  2. Caching: Implement Redis for performance
  3. Load Balancing: Use Nginx or cloud load balancers
  4. CDN: Cloudflare for static assets
  5. Microservices: Split into separate services as needed

IPFS Integration

Use Cases

  1. Post content storage
  2. Media file storage
  3. Immutable content archival

Implementation

  • Client-side upload
  • Server-side verification
  • Hash storage in database
  • Gateway access for retrieval

Web3 Integration

Wallet Connection Flow

  1. User clicks "Connect Wallet"
  2. MetaMask prompts for permission
  3. User approves connection
  4. Wallet address retrieved
  5. User registered in backend
  6. Session established

Transaction Flow

  1. User performs action (post, comment, vote)
  2. Backend validates action
  3. Reputation/tokens calculated
  4. Smart contract called (optional)
  5. Tokens minted to user address
  6. Database updated

Future Enhancements

Phase 1 (Q2 2025)

  • ✅ MVP with basic forum
  • ✅ Wallet integration
  • ✅ Token rewards
  • MongoDB integration
  • User authentication with JWT

Phase 2 (Q3 2025)

  • On-chain reputation storage
  • NFT badges for achievements
  • Staking mechanism
  • Governance voting

Phase 3 (Q4 2025)

  • Mobile app
  • Advanced analytics
  • AI content moderation
  • Multi-chain support

Performance Optimization

Frontend

  • Code splitting
  • Lazy loading
  • Image optimization
  • Bundle size reduction

Backend

  • Database indexing
  • Query optimization
  • Caching strategy
  • Connection pooling

Blockchain

  • Gas optimization
  • Batch transactions
  • Layer 2 integration
  • Efficient data structures

Monitoring & Analytics

Recommended Tools

  • Frontend: Google Analytics, Sentry
  • Backend: PM2, New Relic
  • Blockchain: Etherscan, The Graph
  • Infrastructure: Prometheus, Grafana

Deployment

Frontend

  • Vercel, Netlify, or AWS S3 + CloudFront
  • Environment variables configuration
  • Build optimization

Backend

  • Heroku, AWS EC2, or DigitalOcean
  • Environment configuration
  • Process management (PM2)
  • Reverse proxy (Nginx)

Smart Contracts

  • Hardhat deployment scripts
  • Network configuration
  • Contract verification on Etherscan

Testing Strategy

Frontend

  • Component testing (Jest)
  • Integration testing
  • E2E testing (Cypress)

Backend

  • Unit testing (Mocha/Chai)
  • API testing (Supertest)
  • Load testing (Artillery)

Smart Contracts

  • Unit testing (Hardhat)
  • Integration testing
  • Security audits
  • Gas profiling