This project was part of a take home challenge.
I was asked to build from scratch a fullstack project with an API in Python, Elasticsearch as the DB and any frontend framework as the front.
Before this test, I had only used Python for some web scraping projects, and I had never used Elasticsearch before, so I had to learn on the go. This challenge was meant to test my ability to adapt to new technologies.
The API initially had to consists of the following endpoints (In the end I added some additional ones)
bulk
(to import a csv)getAll
getById
update
delete
The tech stack I decided to use is this one:
Backend:
- Python 3.11
- Poetry
- Fastapi
- Elasticsearch-py
- pandas
- numpy
- pytest
Frontend:
- Typescript
- Vite
- Vitest
- Biomejs
- React
- React Tanstack Query
- React Tanstack Router
- Zod
- Tailwindcss
- Shadcn
Maybe someone else will find this project useful as a starting point for this tech stack.
This README file serves as a guide to help you understand the structure of the project, how to set it up, and how to get started with development.
To get started with the project, follow these steps:
- Clone the repository
git clone git@github.com:Javimtib92/elasticsearch-fullstack-async.git <project_name>
- Navigate to the project directory
cd <project_name>
- Run docker-compose
docker-compose up
⚠️ Remember to start Docker Desktop first. To install docker-compose follow this guideline: https://docs.docker.com/compose/install/#installation-scenarios
This command will start all the services defined in the docker-compose.yml
file.
☕ Sit down and drink a relaxing cup of cafe con leche because this will take a while the first time it has to pull the images
I use Docker Compose to simplify the setup and deployment of the project. Below is the configuration for Docker Compose:
# docker-compose.yml
volumes:
certs:
driver: local
esdata01:
driver: local
kibanadata:
driver: local
networks:
default:
name: elastic
external: false
services:
backend:
# Backend service configuration...
backend_test:
# Backend Test service configuration...
frontend:
# Frontend service configuration...
elastic_setup:
# Elasticsearch setup service configuration...
es01:
# Elasticsearch service configuration...
kibana:
# Kibana service configuration...
After setting up the project using Docker Compose, you can access the following services:
- Frontend Service:
- URL: http://localhost:3000
- Port: 3000
- Backend Service:
- URL: http://localhost:8080
- Port: 8080
- Elasticsearch:
- URL: https://localhost:`<ES_PORT>`
- Port:
<ES_PORT>
- Kibana:
- URL: http://localhost:`<KIBANA_PORT>`
- Port:
<KIBANA_PORT>
Make sure to replace <ES_PORT>
and <KIBANA_PORT>
with the ports defined in your docker-compose.yml file for Elasticsearch and Kibana respectively.
- Ensure you have set the required environment variables in the
.env
file. You can copy.env.local
. - Modify the Docker Compose configuration (
docker-compose.yml
) as needed for your environment, such as adjusting ports or memory limits.
There is a sample of a data file to import located in
data/import.csv
- Navigate to
http://localhost:3000
- Click on
Import CSV
- Select the
csv
file.
To see the Import CSV button the index should not exist, to remove it you have to go to kibana at http://localhost:<KIBANA_PORT> and delete the
politicians
index
We'll use /docs
endpoint as if it was our "postman" to execute each endpoint.
- Navigate to
http://localhost:8080/docs
- If the
bulk
was executed previously make sure to clear the index with/clear_index/${index_name}
endpoint settingpoliticians
as theindex_name
. - Expand
POST /bulk
, click onTry it out
button. - Select
csv
file on thefile
field. - Click on
Execute
- Navigate to
http://localhost:5601/
and enter your username and password for Kibana - Expand sidebar and navigate to
Content
- In available indices you should see
politicians
index with4095
docs. - Click on the index and the overview page will appear
- Select the
Documents
tab to see the inserted documents.
- Elasticsearch Documentation: https://www.elastic.co/guide/index.html
- Kibana Documentation: https://www.elastic.co/guide/kibana/index.html
- Docker Compose Documentation: https://docs.docker.com/compose