Challenge app - MongoDB Atlas Hackathon 2022 and my first Dev Post
Tags: atlashackathon22, mongodb, javascript, node
Published: 2022-12-08 19:59:29

Hello there, and welcome to my first DEV post!
My name is David and I have built a project for my first ever Hackathon.

## What I built
Have you ever heard of #100daysofcode or #30daysoftechnicalwriting? There are chances that you have participated in a challenge before even though it's not any of the challenges I mentioned. What is the main purpose of a challenge? to help improve one's skills, and to help someone to build a good habit, usually on every day of a challenge people write down their progress either on a notebook or share it on twitter for people to see. You understand the Idea? Now I'll share what I've built, I've built a social media API to help users keep track of their progress on any challenge they are on, so that you can share your progress with friends and read it later to see how far you have gone.
My tech stack: 

- Database: MongoDB Atlas

- Server: NodeJS, ExpressJS and JavaScript

- Authentication: JWTs, bcrypt and @hapi/joi library


### Category Submission:

The category is "Choose Your Own Adventure".

### How does it work?

For this API, I wrote a few schemas for different collections for the database, such as

- The user collection: To store users

- The challenge collection: To store all challenges

- The progress collection: To store all progress

- The Image collection: To store all Images(with their encoded data)


![Database Dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4n34a10sukz90w43khy7.png)

### Some Important API endpoints

- **/user/signup** : Creates a new User and stores the information in the user collection.

**Sample document**

![Sample document](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yjr8zx0ue2e0ux6xxg7u.png)


- **/user/login** : Loges in a user


- **/challenges/new** : Creates a new challenge

**Sample document**

![Sample document](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nczfoouzne6wspjslv7g.png)



- **/challenges/me** : Returns all the challenges of the user logged in


- **/challenges/public** : Returns all the challenges whose visibility is true, how other users described it and how many other users are on the challenge. Cool right?

**Sample response**

![Sample response](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zpvf1m8msgd79dyhg89w.png)

- **/challenge/:challengeId** : Returns a challenge and all its progress from the Progress collection


![Sample response](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ln8opump7xue9217obk.png)



- **/challenge/progress/:challengeId** : Adds an Image to the Image collection and adds a progress to the progress collection with reference to its challenge and the Id of the image for the progress

**Sample document**

![Sample document](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yu4rrgu4z9sgvbv8d0yu.png)



### Description
In this app you have the power to create public/private challenges, write your progress for challenges with attachements such as links and images, view public challenges, and share your progress with friends.

### Link to Source Code

https://github.com/dovidmoishe/challenge-app-backend

### Permissive License
MIT license


## Background
The first ever challenge I took was #100 pushups a day for 30days and I thought to myself wouldn't it be awesome for me to be able to go back and look at how far I've come?. Thank you mongodb for giving me this amazing opportunity to learn while build an amazing project like this.

## My future plans for this app
This is not the end of this project yet, I will create a React + TailwindCSS frontend soon and create a full tutorial on how I created this app on DEV


### Additional Resources/Info
This video gave me some information that I didn't know about mongodb, for example, that MongoDB documents have a 16MB size limit, this was what encouraged me to create different collections for the progress and the images(because encoded images can take a bit of space)

{% embed https://www.youtube.com/watch?v=QAqK-R9HUhc %}