This document serves as a cheat sheet for developers to get started quickly. There are no fancy things -- if you already know Python, Poetry,NPM, LangChain, FastAPI, … 🥸 But finding the right information might not be easy when working with so much different technology. This document tries to summarize a few things.
- Quick Start
- Technology Choices
- Poetry Package Management
- NPM and esbuild
- Building the Distribution Package
The following tools must be available on your development machine:
- Python
- Node.js
Then you can install all dependent libraries:
cd backend
poetry install
cd ../frontend
npm install
cd ..
npm installFrom the root of the repository you can run the following command to start the frontend and backend:
npm run startThis will start a development setup with the following things:
- Uvicorn webserver in watch mode (listening on localhost:8000)
- Esbuild in watch mode (listening on localhost:8888)
In a typical production environment you might want to deploy the frontend on a static webserver like Apache or Caddy (recommended) and also use the webserver as a reverse-proxy in front of the backend to handle logging, load-balancing, TLS termination and so on. In that case you only need to run the backend process like so:
cd backend
poetry run ./main.pyWe try to keep things simple for this small application. Yet we need to glue together a few things to make everything work.
- Python - Programming Language
- Poetry - Package Management
- FastAPI - Web framework
- LangChain - AI/LLM functionality
- Node.js - Runtime environment
- TypeScript - Type annotations for JavaScript
- Svelte - Component framework
- Esbuild - Bundler
Python dependencies are managed with Poetry, which is similar in spirit
to NPM for Node.js developers. It handles installation and upgrades of all required external Python
packages, which for this reason need to be declared in the backend/pyproject.toml file,
plus it fully automates the usage of virtual environments. Here is a brief overview of the most important
commands. Run them from within the backend directory.
poetry init- Start a new project with the Poetry package manager (already done of course 🙂)poetry install- Install all dependencies specified in backend/pyproject.tomlpoetry add xyz- Add another dependency to libraryxyzpoetry remove xyz- Remove dependency to libraryxyzagainpoetry show --tree- Show all direct and indirect dependenciespoetry shell- Start a new shell with the Python environment enabledpoetry run xyz- Run console commandxyzin the Python environmentpoetry list- Show all available sub-commandspoetry env use $(which python)- Create new virtual Python environmentpoetry env list- List available environmentspoetry env remove xyz- Delete environment
Of course everyone knows npm, at least when call yourself a web developer. If not, here is quick
rundown. The file frontend/package.json in the frontend directory declares the
frontend project, defining its dependencies and run-scripts for typical developer actions. It
allows you to run the following commands from within the frontend directory.
npm run build- Build distribution filesnpm run clean- Delete distribution filesnpm run watch- Start watch mode for automatic rebuildsnpm run check- Run all checks and tests: eslint, TypeScript, unit testsnpm run startornpm start- Run from built distribution filesnpm run tsc- Check source code with TypeScript only
First, commit and push all developments, because the build process will package the latest HEAD from git – not the latest local changes!
Then run npm run dist from the root directory. This should rebuild everything and create
a new file in the dist/ directory. This requires the git and zip command on your machine,
hence it is not 100% cross-platform compatible.
For the time being this file is then manually renamed and copied to https://wpvs.de/repo/elisa-quiz.