Design Proposal
Design Proposal
Introduction
This document presents a proposed architectural design for the Photo Recap feature of
Afinidata's application. The aim is to offer users a platform where they can submit images of
their personal milestones during a course, and receive a video compilation of all the photos
they've submitted once they finish the course. It is important to note that users may go through
the course multiple times, and the video compilation must only include images related to the
current iteration of the course.
This proposal assumes that a Kubernetes cluster is already deployed, and any necessary pods
would be added to this cluster. Furthermore, the application already has a JWT implementation
in place, and the payload includes a unique user ID (userId).
2
Architecture
This proposal outlines an architectural design for the Photo Recap feature of Afinidata's
application. The proposed solution involves a Kubernetes cluster consisting of separate video
processing and backend API pods. This separation ensures that video creation resources do
not slow down the main backend, resulting in a more efficient system. The cluster is connected
to an AWS RDS database running on postgres and a cloud object storage, which is used for
storing records and images when necessary.
Kubernetes architecture
Video Processing
The proposed architecture for the video processing system involves a simple API that receives
commands to create videos on demand and store them in our bucket. To process video, there
are two options: using Python with a video editing library (MoviePy and OpenCV-python), or a
bash script to automate the video editing software, FFMPEG. While Python is faster to develop
since we already have developers experienced in the language, it requires more computing
power than directly using the video editing software. Additionally, it's worth noting that MoviePy
is no longer being actively maintained since 2021.
Backend API
The main backend API will handle all requests and call the video processing node when a
request for a video is received. I recommend using Node.js with express to design the API,
which is defined on page 7.
3
Storage bucket
To store images and videos, we will use cloud object storage. Cloudflare's R2 storage is the
most cost-effective option for serving a large number of photos and videos. However, if you
prefer not to manage multiple cloud services, Amazon S3 is a viable option. To conserve space,
videos will be stored for only one day in the bucket.
Database
For the database we will use AWS RDS on its Postgres engine. The database definition is on
page 7.
API Gateway
The API Gateway will serve as the entry point for our microservice, ensuring that only the
relevant part of the service is reachable. It will also verify the JWT and forward requests to the
Backend API. This will provide DDoS protection, as well as easy monitoring and analytics.
4
API proposal
The API is designed to handle the input and management of images. It is assumed that JWT
token authentication will be used to obtain both the user's permissions and ID for all requests.
Unless specified otherwise, the API will respond with the following HTTP status codes:
●
● 200 if the request is successful
● 201 if a new resource is created
● 204 if a resource is deleted
● 400 if required fields are missing or conflicting
● 401 if the user is unauthorized
● 403 if there is no user
● 404 if the requested resource is not found
It is important to note that this API only handles the image-related functionality, and any
additional validation or error handling will need to be implemented separately in the final
product.
This API endpoint allows users to upload images to commemorate an event. The request must
be sent as "multipart/form-data". The required "date" field specifies the date the image was
taken, and can be inferred from the date of the POST request. The required “iterationId” field is
used to differentiate the different times a user participates on a course. The optional "milestone"
field can indicate the event or milestone that the image represents.
Request: GET
/v1/images?dateStart={datetime}&dateend={datetime}&milestone={string}&courseId={string}&ite
rationId={string}&start={int}?limit={int}
This API endpoint allows users to search for images that have been saved to commemorate
events, using flexible search criteria. The returned images are sorted in chronological order, with
the oldest image listed first. Pagination is recommended for this operation, given the potential
large number of images that could be returned.
dateStart The inclusive start date for the query. Cannot datetime
be after dateEnd
dateEnd The inclusive end date for the query. Cannot datetime
be before dateStart
Response:
{
"total": 3,
"images":[
{
"uuid": "afd5ba47-4bfa-4da7-b993-aac3c54e0c0c",
"milestone": "exampleMilestone1",
"url": "exampleurl.com/exampleposturl/example.png",
"date": "2022-04-22 10:34:23"
},
{
"uuid": "103856e3-b303-4143-aa9c-cac2b2e2399b",
"milestone": "exampleMilestone2",
"url": "exampleurl.com/exampleposturl/example2.png",
"date": "2022-05-22 10:34:23"
6
},
{
"uuid": "34f69f43-2009-4307-95b8-ec446af7aefa",
"milestone": "exampleMilestone3",
"url": "exampleurl.com/exampleposturl/example3.png",
"date": "2022-06-22 10:34:23"
}]
}
This API endpoint facilitates the creation of a video by utilizing an array of imageIds provided by
the user. The courseId parameter serves to determine the appropriate style of the video, given
that each course will feature varying durations and textual information displayed alongside the
images.
Database Proposal
Images Table
Field type
id uuid
userId string
courseId string
iterationId string
milestone string
url string
date datetime
Video Table
Field type
id uuid
userId string
courseId string
iterationId string
url string