---
# System prepended metadata

title: Reddit

---

# Reddit

## User stories
* Any user can create a subreddit
* Any user can join a subreddit
* Any member in a subreddit can create a post in that subreddit
* Any member in a subreddit can read and comment on posts in that subreddit
* Any member can edit/remove their own posts
* Any member can cast up/down votes on any post or comment

How best to design these stories
* Moderator can remove inappropriate posts in its subreddit
* Moderators earn the role by creating subreddits or being nominated by another moderator
* Admin can edit/remove all posts


## Entry relationship diagram

```mermaid
graph TD
  subgraph Reddit DNA
    subgraph subreddit DNA
        Subreddit1
        Subreddit2
    end
    subgraph conversations zome
        subgraph comments 
            Comment1
            Comment2
        end
        subgraph posts
            Post1
            Post2
        end
    end
    subgraph user zome
        Alice
        Bob
        Chris
        David
    end
    Subreddit1 -- has_post --> Post1
    Subreddit2 -- has_post --> Post2   
    Post1 -- has_comment --> Comment1
    Post2 -- has_comment --> Comment2
    Comment1 -.for_post.-> Post1
    Comment2 -.for_post.-> Post2
    Alice -- creates --> Post1
    Bob -- creates --> Post2
    Chris -- creates --> Comment1
    Comment1 -.authored_by.-> Chris
    David -- creates --> Comment2
    Comment2 -.authored_by.-> David
    Alice -- member_of --> Subreddit1
    Bob -- member_of --> Subreddit2
    Post1 -.author.-> Alice
    Post1 -.for_subreddit.-> Subreddit1
    Post2 -.author.-> Bob
    Post2 -.for_subreddit.-> Subreddit2
  end
```

```rust
Entry "anchor" {
    struct Anchor {
        anchor_type: String,
        anchor_text: String
    }
    Links: {
        reddit->subreddit,
        users->user
    }
}


Entry "subreddit" {
    struct Subreddit {
        creator_address: Address,
        name: String,
        description: String
    }
    Links: {
        subreddit->post
    }
}

Entry "vote" {
    Enum Vote {
        UpVote,
        DownVote,
    }
    struct VoteCast {
        vote: Vote,
        voter: Address,
        timestamp: u64
    }
}
   
Entry "post" {
    struct Post {
        text: String,
        author: Address,
        subreddit: Address,
        timestamp: u64,
        votes: Vec<VoteCast>
    }
    Links: {
        post->comment 
    }    
}

Entry "comment" {
    struct Comment {
        post: Address,      // implicit link
        author: Address,    // implicit link
        text: String
        timestamp: u64,
        votes: Vec<VoteCast>
    }
    Links: {
    
    }
}

Entry "user" {
    struct User {
        name: String        
    }
    Links: {
        user->subreddit,
        user->post,
        user->comment
    }
}
```

Validation

Subreddit
create - must be a member of reddit

Post
create - must be a member of subreddit and post must be signed
edit - must be author of the post
delete - must be author of the post
read - must be a member of the subreddit??

Comment - must be a member of subreddit and comment must be signed

Vote
castVote -
* must be a member of subreddit to cast a vote
* can only upVote, downVote once per post or comment
* can remove a vote if the agent is the original voter

Reputation-
Influenced by aggregates of
* [Number of upVotes + number of downVotes] by post or comment
* voteCasts? - how do vote casting influence reputation?

Queries needed to support votes/reputation -
For each agent 
* votes (separated by up/down) received per authored post or comment 
* vote cast per post or comment authored by other agents
* trends over time?

Detect/Prevent abuse & gaming?
* votes accepted only validated according to the policy (e.g. one vote per post/comment from each agent)
* pattern of votes for (voter, author)
* pattern of votes from a voter
* pattern of votes from voter group?

TO prevent threats to system integrity from sybil attacks where an adversary tries to overcome the system’s validation rules by spawning a large number of compromised nodes.
We have to construct domain-specific membrane functions that validates an agent when it requests to join the network.

- nodes to inform others of bad actors
- nodes to validate agent before joining

Eventual Consistency - 
When do we know we've collected "all" votes?
* what's the cutoff signal? 





