This project is a simple feedback system built using FastAPI, a high-performance web framework for Python, and TinyDB, a lightweight document-oriented database. The application allows users to submit feedback through a web form and view all submitted feedbacks.
web_app/
├── pycache/
├── Include/
├── Lib/
├── Scripts/
├── templates/
│ ├── form.html
│ └── feedbacks.html
├── db.json
├── Dockerfile
├── main.py
├── pyvenv.cfg
└── requirements.txt
This application uses a Python virtual environment to isolate project dependencies. Set up the virtual environment with:
python -m venv web_app
Activate the virtual environment:
-
On Unix/Linux:
source web_app/bin/activate
-
On Windows:
web_app\Scripts\activate.bat
The main.py
file sets up the FastAPI application with:
- FastAPI initialization and Jinja2 template setup
- TinyDB instance for data storage
- Routes:
GET "/"
: Renders the feedback submission formPOST "/submit/"
: Handles form submission and stores data in TinyDBGET "/view-feedbacks/"
: Retrieves and displays all submitted feedbacks
form.html
: Feedback submission formfeedbacks.html
: Displays all submitted feedbacks
Both templates use simple HTML structures with Jinja2 templating for dynamic content.
- TinyDB: Lightweight, file-based JSON database
- The database file (
db.json
) is created automatically when the first feedback is submitted.
The requirements.txt
file includes:
- FastAPI: Web framework for Python
- Uvicorn: ASGI server
- Jinja2: Templating engine
- TinyDB: Document datastore
- python-multipart: For form handling
The application is containerized using Docker. The Dockerfile
includes:
FROM python:3.11
WORKDIR /web_app
COPY ./requirements.txt /web_app/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /web_app/requirements.txt
COPY ./templates /web_app/templates
COPY ./main.py /web_app/main.py
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
- Uses Python 3.11 as the base image
- Sets the working directory to
/web_app
- Copies and installs the requirements
- Copies application files (templates and
main.py
) - Specifies the command to run the Uvicorn server
-
Install Docker:
sudo yum install docker # or sudo apt install docker
-
Create the requirements file:
pip freeze > requirements.txt
-
Create a
.dockerignore
file to exclude unnecessary files. -
Build the Docker image:
docker build -t vcc_assignment_web_app_lite .
-
Test the Docker container:
docker run -p 8000:8000 vcc_assignment_web_app_lite
The application will be accessible at http://localhost:8000.
-
To pull and run the Docker image:
docker pull pranav8s/vcc_assignment_web_app_lite docker run -d -p 8000:8000 --name vcc_assignment_web_app pranav8s/vcc_assignment_web_app_lite
The application will be accessible at http://localhost:8000.
This FastAPI/TinyDB application demonstrates a basic web app deployment using Docker. It showcases the use of FastAPI, TinyDB, and containerization techniques.