A quickstart tool for creating a FastAPI project with Jinja2, TailwindCSS, Flowbite, HTMX, and AlpineJS.
MIT License
Welcome to the quickstart tool for creating a FastAPI
project with the following stack:
The default pip packages installed include:
fastapi
uvicorn[standard]
sqlalchemy
jinja2
python-dotenv
poetry
Note: all libraries and packages are automatically installed to their latest versions when running the tool.
Creating a project from scratch can be a tedious process. So, I wanted to simplify it! This tool is ideal for those that are looking to quickly prototype a project without worrying about JavaScript
frameworks, such as Backend Developers
and ML Engineers
.
The tool does the following:
PIP
and installs the required packages.env
filebackend
directory with a basic application template for FastAPI
frontend
directory with some basic Jinja2
template files
_base.html
and index.html
frontend/public
files directory for storing css
, js
, and img
files locally
TailwindCSS
, Flowbite
, HTMX
, and AlpineJS
static filesnode_modules
(if your OS supports TailwindCSS standalone CLI), venv
and package.json
filesThe tool is intended to be dynamic and aims to install the most recent packages where possible. To do this, we require NodeJS, NPM
and Python to be installed on your local machine, with the latest stable versions.
We use node_modules
and PIP
to maintain the latest versions of the core stack, and remove the node_modules
after creation to simplify the project folder.
Fortunately, Tailwind
has a Standalone CLI that allows us to watch and minify files without needing NodeJS
!
All files added to the project are stored in setup_assets
. If you want add files, feel free but it is recommended not to mess with the file structure. Here a few things to note:
project
root directorysetup_assets/frontend/static
folderfrontend/static
-> frontend/public
For configuration customisation go to config.py
in the root directory. Here you have three options:
DATABASE_URL
, defaults to a SQLite local database.ADDITIONAL_PIP_PACKAGES
.env
file variables -> ENV_FILE_ADDITIONAL_PARAMS
Note: the last two options are treated as python list
objects that accept strings
only.
create
with a name
(e.g., my_project
) argument inside a poetry shell
. This creates a new project inside the parent
directory of the fastapi-quickstart
directory:git clone https://github.com/Achronus/fastapi-quickstart.git
cd fastapi-quickstart
poetry shell
create my_project # Replace me with custom name!
For example, if you have a parent folder called projects
and are making a project called todo_app
the project is created in projects/todo_app
instead of projects/fastapi-quickstart/todo_app
.
Everything is setup with a blank template ready to start building a project from scratch. Run the following commands to run the docker development
server and watch TailwindCSS
locally!
Not got Docker? Follow these instructions from the Docker website.
cd ../my_project # Replace me with custom name!
docker-compose up -d --build dev
poetry shell
poetry install
watch
Then access the site at localhost:8080.
Docker also comes configured with a production variant. Inside the my_project
folder run:
docker-compose up -d --build prod
Then you are good to go!
The newly created project should look similar to the following:
project_name
└── config
| └── docker
| | └── Dockerfile.backend
└── project_name
| └── backend
| | └── database
| | └── __init__.py
| | └── crud.py
| | └── models.py
| | └── schemas.py
| └── frontend
| | └── public
| | | └── css
| | | | └── flowbite.min.css
| | | | └── input.css
| | | | └── style.min.css
| | | └── imgs
| | | | └── avatar.svg
| | | └── js
| | | └── alpine.min.js
| | | └── flowbite.min.js
| | | └── htmx.min.js
| | | └── theme-toggle.js
| | └── templates
| | └── components
| | | └── navbar.html
| | └── _base.html
| | └── index.html
| └── tests
| | └── __init__.py
| └── .env
| └── .gitignore
| └── build.py
| └── main.py
| └── tailwind.config.js
| └── tailwindcss OR tailwindcss.exe
└── .dockerignore
└── database.db
└── docker-compose.base.yml
└── docker-compose.yml
└── poetry.lock
└── pyproject.toml
└── README.md