Post It is a social media API that allows users to create posts, share content, and reply to posts.
You can access the live API here
Documentation Endpoint You can find the API documentation here
Database Design Image Here's a visual representation of the database design:
FInd the database design here
The userSchema defines the properties of a user object, including name
, email
, password
, handle
, profilePicture
, bio
, posts
, isDeleted
, deletedAt
, resetPasswordExpires
, and resetPassword
.
- name, email, password, handle, profilePicture, isDeleted, and resetPassword are of type
String
- posts is of type
[Schema.Types.ObjectId]
and references thePost
model. email
andhandle
are required fields and must be unique.bio
has a maximum length of 250 characters.posts
is initialized with an empty array as a default value.isDeleted
is a boolean flag indicating whether the user has been deleted or not.deletedAt
andresetPasswordExpires
are timestamps indicating when the user was deleted or when their password reset request will expire.
The postSchema defines the properties of a post object, including content
, user
, replies
, likes
, isDeleted
, and deletedAt
.
content
is of typeString
.user
is a reference to aUser
object.replies
is an array of references to Reply objects.likes
is an array of references toUser
objects who have liked the post.isDeleted
is aboolean
flag indicating whether the post has been deleted or not.deletedAt
is atimestamp
indicating when the post was deleted.
Reply Schema
The replySchema defines the properties of a reply object, including content
, user
, likes
, isDeleted
, and deletedAt
.
content
is of typeString
.user
is a reference to aUser
object.likes
is an array of references toUser
objects who have liked the reply.isDeleted
is aboolean
flag indicating whether the reply has been deleted or not.deletedAt
is atimestamp
indicating when the reply was deleted.
The schema design is optimized for efficient querying. By using references to other models, rather than embedding all the data into a single document, it is easier to query for specific pieces of information. For example, to get all the replies to a particular post,the reply field on the postSchema can be used to filter the replies
By using references to other models, the schema reduces duplication of data. For example, instead of storing all the user information in every post document, the user field on the postSchema only stores the ID of the user who created the post. This reduces the amount of data stored in the database and helps to keep the data consistent.
The schema design allows for flexibility in data storage. For example, the posts field on the userSchema is an array of Post object IDs, which allows a user to have many posts. This design can easily scale as the number of posts per user increases, without running into limitations on document size.
The schema design makes it easy to maintain data consistency. By defining the relationships between models, Mongoose can automatically populate fields with data from related collections, which helps to ensure that the data is up-to-date and consistent.
when resources are deleted it is not actually deleted from the database, it is just marked as deleted. This is done to prevent the database from being cluttered with deleted resources. The resources are marked as deleted and are not returned in the response when a user tries to access them, except they have direct links to that resource.
Note that only the posts resource can be accessed for now after they have been deleted and the user has a direct link to that resource.(i could have extended this to other resources but i ran out of time), do not mistake that for the fact that the other resources cannot be soft deleted.
Also these deleted resouces would only be availble for a certain period of time, after which they would be permanently deleted from the database. this could be achieved using a cron job to periodically purge the database of deleted resources.(note that this was not implented in this project)
git clone https://github.com/Jonathanthedeveloper/post-it.git
cd post-it
npm install
add the following Variables to your .env file
ONLINE_URI
JWT_SECRET_TOKEN
JWT_EXPIRES_IN
EMAIL_ADDRESS
EMAIL_PASSWORD
npm start
or
npm run dev
The project would be hosted at 127.0.0.1:3000
To run this project, you will need to add the following environment variables to your .env file
API_KEY
ANOTHER_API_KEY
Install my-project with npm
npm install my-project
cd my-project