This document tests an examinee's knowledge of PHP design principles and its implementations on the Laravel framework.
This project is about an image uploading system. The user will sign in and upload images.
The developer will do the project in 3 versions. The first two are required to complete the project, and the other is optional. You'll have one day to work on the project and decide how you're going to balance the things we care about (see below). Some people choose to do the required versions but keep the code as clean and high quality as possible, and some care about the task completion.
We care about:
- Code Quality & Standardization
- Optimization
- Security
- Tasks Progress
- Deadline
Note that:
- Everything is API-based. No need to write a single HTML/CSS/JS code.
- The instructions below are not necessarily complete nor explicit; You can use your ideas too.
You'll need to have your final code pushed into your own GitHub repository.
We need a Laravel application to let users sign up and sign in to allow them to upload images.
- Knowing your familiarity with Laravel core features.
- Getting familiar with how you use git.
- Implement sign up and sign in features using Laravel Sanctum
- Implement an endpoint to upload a new image and get the response
Use the following tables for your migrations:
mysql> show columns from `users`;
+-------------------+-----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+-----------------+------+-----+---------+----------------+
| id | bigint unsigned | NO | PRI | NULL | auto_increment |
| firstname | varchar(255) | NO | | NULL | |
| lastname | varchar(255) | NO | | NULL | |
| email | varchar(255) | NO | UNI | NULL | |
| password | varchar(255) | NO | | NULL | |
| created_at | timestamp | NO | | NULL | |
| updated_at | timestamp | YES | | NULL | |
+-------------------+-----------------+------+-----+---------+----------------+
mysql> show columns from `images`;
+-------------------+-----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+-----------------+------+-----+---------+----------------+
| id | bigint unsigned | NO | PRI | NULL | auto_increment |
| user_id | bigint unsigned | NO | FRI | NULL | |
| path | varchar(255) | NO | UNI | NULL | |
| title | varchar(255) | NO | UNI | NULL | |
| created_at | timestamp | NO | | NULL | |
| updated_at | timestamp | YES | | NULL | |
+-------------------+-----------------+------+-----+---------+----------------+
- Create a Laravel project
- Use Laravel Sanctum to implement SPA sign up and sign in features.
- Add an endpoint (
POST /api/images
) where the user can upload an image with its title and response its URL and title. Store the file in the local filesystem and save its path and title into the database. - Protect the endpoint from unauthorized access.
Now, we've decided to add another storage platform - S3. We need to configure the app and use either the local filesystem or the S3 instance.
- Getting familiar with your coding quality and standardization ideas.
- Implement a Strategy Pattern for uploading images to the local filesystem and S3 platform
- Create two drivers called
FilesystemStorage
andS3Storage
- Create a service called
ImageStorage
- Decide to use a driver by looking up a
IMAGE_STORAGE_DRIVER
environment variable as config.
Note: It's OK to use mocked S3 uploads. We don't want its real functionality for this testing project.
Hint: Write a new migration for
images
table and keep the strategy method used there.
Due to the high usage of our AA (Awesome Application!), we're getting substantial image uploads! We need to clean up old images periodically and optimize how we perform table scans during its process.
- Getting familiar with your research process
- Schedule a task to clean up old images.
- Consider optimizing the database for finding old records efficiently.
- Create a command called
images:cleanup
and remove images older than 3 days - Use the Laravel Scheduling mechanism to schedule the command every 20 seconds.
- Research how to efficiently optimize the
images
table to perform table scans during your SELECT query of the cleanup task. Consider that the table will have nearly 1,000,000,000 records!
Note: Command may take a long time. We don't need two instances of the scheduled command running simultaneously.