---
# System prepended metadata

title: Database Schema Design

---

# Database Schema Design

![Database Schema Design](https://svgshare.com/i/1Awv.svg)

### User Collection
Here we'll save the user related data. In future, we'll either save settings info here itself or a new collection will be made

```json
{
    _id: ObjectId()    // userId
    name: string       // full name
    email: string
    image: string?
    role: string       // [user, admin]
    emailVerified: timestamp
}
```

### Course Collection
To save details about the whole course (might be uploaded from admin panel)

```json
{
    _id: ObjectId()        // couseId
    name: string           // course title (ex: MongoDB Basics)
    brief: string          // course description/brief
    modules: [...moduleIds]
    statistics: {
        rating: float,
        completitionRate: float,
        price: float,
        lastUpdated: timestamp
    }
    cardImageUrl: string
    bannerImageUrl: string
    draft: boolean
    createdBy: ObjectId()
}
```

### Module Collection

Different modules that can be added in a particular course

```json
{
    title: string      // module title (ex: logical operators)
    learn: string      // markdown (all material related to that module, would remain common between it's problems)
    problems: [...problemIds]
}
```

### Problem Collection
Each individual problem will be added here

```json
{
    _id: ObjectId()    // problemId
    title: string      // problem title
    desc: string       // (markdown) problem statement/description
    type: string       // enum of MONGODB_FIND, MONGODB_AGGREGATE, ...
    difficulty: string // enum of easy/medium/hard
    draft: boolean
    createdBy: ObjectId()
}
```

### Submission Collection
Each submission for a problem by a user will be recorded here

```json
{
    _id: ObjectId()        // submissionId
    userId: ObjectId()
    problemId: ObjectId()
    code: string           // code submission
    result: string         // maybe log or output something
    status: string         // enum of NOT_ATTEMPTED, IN_QUEUE, INCORRECT, ACCEPTED
    submittedAt: timestamp   // time of submission
}
```


## TODO/Future

- Subscription Model (need to discuss)
- Review Model (rating/comments/testimonial)
- Compatible with other lang/framework
- Leaderboard model