- Build a basic web app with a simple input field that takes an English (EN) input translates it to Spanish (ES).
- When a new translation is requested it should add to a list below the input field (showing one of three status: requested, pending or translated) - (note: always request human translation)
- The list should be dynamically ordered by the size of the translated messages
- Use Flask web framework
- Use PostgreSQL
- Create a scalable application.
- Only use Unbabel's Translation API on sandbox mode
- Have tests
- Page load time shouldnt exceed 1 second
- Set up infrastructure [OK]
- Development of forms.py [OK]
- Development of models.py [OK]
- Implementing of database migrations [OK]
- Development of views.py [OK]
- Unit tests [OK]
- Real time table [OK]
- Documentation [OK]
- Unbabel's API: http://developers.unbabel.com/
- Clone the repository:
git clone https://github.com/aabramos/backend-coding-challenge
cd backend-coding-challenge
- Install dependencies:
And create a database on PostgreSQL.
- Run install.sh (or install.cmd if using Windows):
./install.sh
- Initialize database:
flask db migrate
flask db upgrade
- Create a environment
.env
file using the following syntax:
SECRET_KEY=YourSecretKey
SANDBOX_USERNAME=YourUnbabelAPISandboxUsername
SANDBOX_KEY=YourUnbabelAPISandboxKey
POSTGRES_USER=YourPostgresUser
POSTGRES_PW=YourPostgresConfiguration
POSTGRES_DB=YourPostgresConfiguration
POSTGRES_HOST=YourPostgresConfiguration
POSTGRES_PORT=YourPostgresConfiguration
POSTGRES_USER_TEST=YourPostgresTestConfiguration
POSTGRES_PW_TEST=YourPostgresTestConfiguration
POSTGRES_DB_TEST=YourPostgresTestConfiguration
POSTGRES_HOST_TEST=YourPostgresTestConfiguration
POSTGRES_PORT_TEST=YourPostgresTestConfiguration
- Run Celery:
celery -A app.tasks worker -B --loglevel=info
- Open another terminal to run the application:
./run.sh
And access http://localhost:5000 on your browser.
-
After a translation request is made by submitting the text on the frontend, an Unbabel-py API request is made in the backend, sending a human translation request to The Unbabel server;
-
Note:The folder /Unbabel contains a local customized Unbabel-py API. The original wasn't compatible with Python 3.6. Check out my fork;
-
All requests are made using a job queue, with Celery as the background processor and Redis as the broker;
-
The first request saves the translation in the database, and the subsequent jobs ask the status of the translation with Unbabel server every 30 seconds, updating the information on the database if necessary;
-
The communication between the frontend and the backend are made with Socket.io, updating the table below the submit field without refreshing the page and sorting the list using the translated messages length.
Commands:
python -m unittest app.test.test_set_up
python -m unittest app.test.test_celery
python -m unittest app.test.test_unbabel
Notes:
- test_set_up: Tests if the app and the SQLAlchemy is working correctely. This test will also send db commands like drop_all() to your test database, so migrate and upgrade the test database after this test if needed;
- test_celery: test if celery/redis is working correctely. Run celery in another terminal for this test;
- test_unbabel: make a test request to unbabel, validating the response data.