Skip to content

Architecture

Ian Turner edited this page Oct 19, 2024 · 78 revisions

Backend

The backend will be a Python API running in a Docker container that will access the MongoDB database.

Libraries and frameworks

  • Pip
    • Package manager for Python
    • Requirements kept in requirements.txt
  • Flask
  • PyMongo
    • Python API for MongoDB
  • Hashlib
    • Hashes passwords when authenticating for better security
  • Secrets
    • Generates random byte strings
    • Used to generate authentication tokens

API endpoints

POST /api/register

Creates a new user

Request

  • Username: string
  • Password: string

Response

  • Token: string

POST /api/login

Authenticates user and returns login token

Request

  • Username: string
  • Password: string

Response

  • Token: string

GET /api/events

GET /api/event/:id

POST /api/create-event

POST /api/update-event/:id

POST /api/delete-event/:id

GET /api/get-profile

POST /api/update-profile

Database

  • We will be using MongoDB as our database.

Users Collection

This collection will hold all information regarding the user and their account.

  • _id - the ID of the user, UUID generated by MongoDB: UUID
  • name - name of the user: String
  • username - username of the user: String
  • password - password for the user: String
  • bio - description the user can create: String
  • default_event_visibility - the default visibility of the user’s events: Bool (values: public = true, private = false)
  • followers - array of objects containing details about each follower:
    • follower_id - the ID of the follower: UUID
  • following - array of objects containing details about each user the current user is following:
    • following_id - the ID of the following: UUID

An example user object and how it would be stored in the database:

{
   "_id": "603d2149e2f8b9023d4a1f34",
   "name": "Hugh Gevent",
   "username": "hughgevent_",
   "password": "coffelovr44"
   "bio": "coffee lover",
   "default_event_visibility": true,
   "followers": [
      {
         "follower_id": "603d2149e2f8b9023d4a1f35"
      },
      {
         "follower_id": "603d2149e2f8b9023d4a1f36"
      }
   ],
   "following": [
      {
         "following_id": "603d2149e2f8b9023d4a1f37"
      },
      {
         "following_id": "603d2149e2f8b9023d4a1f38"
      }
   ]
}

Events Collection

This collection will hold all information pertaining to a specific event.

  • _id - the ID of the event, UUID generated by MongoDB: UUID
  • user_id - the ID of the user who created the event: UUID
  • title - the title of the event: String
  • description - description of the event: String
  • start_time - ISO 8601 formatted date for the start time: String
  • end_time - ISO 8601 formatted date for the end time: String
  • visibility - the visibility of the string, this will default to default_event_visibility of the user, but can be manually changed: Bool (values: public = true, private = false)
  • comments - array of objects containing comments for the event:
    • comment_id - the ID of the comment: UUID
    • user_id - the ID of the user who made the comment: UUID
    • text - the content of the comment: String
    • timestamp - ISO 8601 formatted date for when the comment was made: String

Example JSON object and how an event will be stored in the database:

{
   "_id": "603d2149e2f8b9023d4a1f39",
   "user_id": "603d2149e2f8b9023d4a1f34",
   "title": "Waterpark",
   "description": "Going to the waterpark",
   "start_time": "2024-10-18T14:00:00Z",
   "end_time": "2024-10-18T15:00:00Z",
   "visibility": true,
   "comments": [
      {
         "comment_id": "603d2149e2f8b9023d4a1f40",
         "user_id": "603d2149e2f8b9023d4a1f41",
         "text": "awesome",
         "timestamp": "2024-10-18T15:00:00Z"
      },
      {
         "comment_id": "603d2149e2f8b9023d4a1f42",
         "user_id": "603d2149e2f8b9023d4a1f43",
         "text": "nice dude",
         "timestamp": "2024-10-18T15:05:00Z"
      }
   ]
}

Queries

With MongoDB being a document oriented NoSQL database it does not use traditional SQL queries and no joins will be required, however to support CRUD operations we can call functions from PyMongo to query our database.

Users Collection PyMongo examples:

users_collection.insert_one(new_user) # adds a user

users_collection.find_one({"_id": user_id}) # find a user by ID

users_collection.update_one({"_id": user_id}, {"$set": {"bio": new_bio}}) # update a users bio

users_collection.delete_one({"_id": user_id}) # removes a user

users_collection.find() # finds all users

Events Collection PyMongo examples:

events_collection.insert_one(new_event) # adds an event

events_collection.find_one({"_id": event_id}) # finds an event by ID

events_collection.update_one({"_id": event_id}, {"$set": {"description": new_description}}) # update event description

events_collection.delete_one({"_id": event_id}) # delete an event

events_collection.find() # finds all events

Frontend

The frontend will be a React.js single page application (SPA).

Libraries and frameworks

URLs

Views/components

Deployment

The app will be deployed on DigitalOcean using Docker containers within a virtual machine.

Team roles

  • Ian - backend Python development/deployment
  • Jacob - backend Python development/Database construction

Clone this wiki locally