Part 1: Setting up a full-stack application
Let’s build a small web application for organizing votes. We will be able to create a poll with a question and a set of possible answers, share it with other people and see the results change as votes come in. We will also be able to edit a poll and return to it later without losing the results.
The interesting part is not the voting application itself, but how we get from a simple interactive web page to an application that several people can use together.
We will use Vue to build the interface that runs in the browser and FastAPI to implement the backend in Python. Along the way, we will encounter the need for shared application state, communication between browsers and the server, and permanent storage. Rather than designing all of these into the application from the beginning, we will introduce each as we discover why we need it.
The tutorial consists of five parts:
- Setup (this part). Generate a project with Vue and FastAPI, get both running together and see how to package the application for production.
- Vue and Pinia. Build a usable voting interface entirely in the browser. We will use Pinia to manage reactive state shared between Vue components, without involving the backend yet.
- FastAPI and WebSockets. Discover why a browser-local application cannot serve several users together. Move poll data to the server, retrieve and modify it over HTTP, and use WebSockets for live communication between the server and connected browsers.
- Structured data and Kanta. Discover what happens to our data when connections close or the server restarts. Introduce msgspec structures, make our shared data persistent with Kanta and complete the application’s creation, voting and editing functionality.
- Building and deploying. Package the completed application with its frontend, run it independently of the source checkout and see how to deploy it on another machine.
This is the architecture we will build toward. Vue renders the interface, Pinia manages browser state, FastAPI provides the shared API and live connections, and Kanta preserves the server-side data:
We will use ordinary JavaScript in the frontend and Python in the backend. Some familiarity with both languages will be helpful, but previous experience with these particular frameworks is not necessary. This is a tutorial about building a full-stack application, rather than a comprehensive introduction to either language or framework.
Bringing Vue and FastAPI together
Vue and FastAPI serve quite different purposes. Vue runs in the browser, where it renders our interface and responds to user interactions. FastAPI runs on the server, where we can implement operations that clients need to perform and manage data shared between them.
We could set up each independently, but we would then need to configure how the browser reaches our backend during development, how to run the two development servers together, and how to distribute the built frontend with our Python application for production.
fastapi-vue-setup takes care of this initial setup. It generates a Python project with a FastAPI application and uses Vue’s own create-vue tool to generate the frontend. It also configures the connection between the two, provides a development server script and integrates the frontend build into the Python packaging process.
The result is an ordinary Vue project alongside an ordinary FastAPI application. We will be working with their usual components, stores and endpoints, rather than learning another application framework.
1. Getting the tools
We need two development environments: Python for FastAPI, and Node.js for the tools that build our Vue application.
Install uv to manage our Python project and its dependencies. It can also install Python itself, so there is no need to set up Python separately.
For Node.js, we recommend fnm (Fast Node Manager). Follow its installation and shell setup instructions for your operating system, then open a new terminal and run:
fnm install --lts --use
This installs and activates a current long-term support release of Node.js, including npm. If you already have a modern Node.js installation, you can use that instead.
There is no need to install FastAPI, Vue or Pinia globally. Each project will have its own dependencies.
2. Creating the project
Choose a directory in which to keep your projects and run:
uvx fastapi-vue-setup voting-app
uvx runs the setup tool without requiring us to install it permanently. We give the new project the name voting-app.
The setup tool launches Vue’s interactive project generator. Enable Pinia for state management and otherwise accept the defaults. Keep JavaScript rather than TypeScript, and retain the example application if asked whether to skip the example code.
The example gives us components, assets, a layout and a stylesheet to start with. In Part 2, we will turn this interface into our voting application and discover why Pinia is useful.
Once the setup finishes, enter the new project directory:
cd voting-app
The setup tool creates the project and installs its Python dependencies. Take a look at the generated directory. These are the files and directories we will work with most often:
voting-app/
├── backend/voting_app/
│ ├── app.py # FastAPI application
│ └── __main__.py # The voting-app command
├── frontend/
│ ├── src/
│ │ ├── main.js # Vue and Pinia initialization
│ │ ├── App.vue # Root Vue component
│ │ ├── components/ # Other Vue components
│ │ └── stores/ # Pinia stores
│ ├── vite.config.js # Frontend development and build settings
│ └── package.json # Frontend dependencies and commands
├── scripts/devserver.py # Starts both development servers
└── pyproject.toml # Python project configuration
The frontend and backend have their own source files and dependency configurations, but they belong to the same application.
3. Running the application during development
During development, we want to see changes to our frontend as soon as we edit a file, without having to build the entire application again. Vue’s development tooling, Vite, provides this functionality. Meanwhile, we also need FastAPI running so that the frontend can reach our API.
The generated project includes a script that starts both servers for us. From the voting-app directory, run:
uv run scripts/devserver.py
The script installs the frontend dependencies if necessary. Open http://localhost:3100 once the servers have started.
You should see the generated Vue welcome page, with the heading You did it! and a FastAPI: ✅ indicator below it.
We can already see the frontend running, but how do we know it is actually communicating with FastAPI?
Open http://localhost:3200/api/health in another tab. This address belongs to the backend, and instead of a web page it returns a small JSON object:
{"status":"ok"}
Now try http://localhost:3100/api/health. We get the same response, even though port 3100 belongs to Vite rather than FastAPI.
This is because the setup tool has configured Vite to forward requests under /api/ to our backend on port 3200. The frontend can simply use an address such as /api/health without having to know which port the backend is using.
The generated Vue component does exactly this (with an additional from=frontend query parameter) to check that the backend is reachable. The green check therefore confirms not just that Vue is running, but that a request can travel from the browser through Vite to FastAPI and back.
If the indicator shows an error, check the terminal output of the development server before continuing.
4. Running the application in production
Vite is convenient when we are developing the interface, but the users of our finished application do not need a separate frontend development server. They only need the built HTML, JavaScript and CSS files that their browsers will load.
The generated project lets us build these assets and package them together with our Python backend. This means that we can distribute the application as a Python package and serve both the frontend and API from FastAPI.
Stop the development server with Ctrl+C and run:
uv build
As part of the Python build process, the build hook installs the frontend dependencies, runs Vite’s production build and places the resulting browser assets inside the Python package. The finished packages should appear under dist/, for example:
dist/voting_app-0.1.0.tar.gz
dist/voting_app-0.1.0-py3-none-any.whl
Now start the application through the command generated for our project:
uv run voting-app
Open http://localhost:3100 again. The application looks the same, and the FastAPI indicator should still be green. But this time we are not running Vite. FastAPI serves both the built frontend and its API endpoints directly.
Notice that the frontend didn’t need to change its API address between development and production. In development, Vite forwards the request; in production, FastAPI handles it directly.
Node.js is necessary when building the frontend, but a machine running the already-built Python wheel does not need Node.js or a separate Vite server.
We will return to development mode for the rest of the tutorial. Stop the application with Ctrl+C, then run:
uv run scripts/devserver.py
Keep http://localhost:3100 open as we work on the application in the following parts.
Where we are now
We have a working Vue application that can communicate with a FastAPI backend, a development environment that runs them together, and a way to build and run the finished application as a Python package. We haven’t implemented any voting functionality yet.
Before moving on, make sure the generated page loads, the FastAPI indicator is green and the production build works. These manual checks are all we need at this stage.
Optional: Automated milestone checks
You can follow the entire tutorial using just your browser and the experiments described in each part. We also provide a ready-made set of end-to-end checks for those who would like to verify their progress automatically. They use Playwright to open our running application in a browser and check that it behaves as expected at each milestone. You do not need to write, understand or modify any test code for this tutorial, and none of these checks is required to continue.
If you would like to use them, download the tutorial test files and extract the archive. Copy the supplied playwright.config.js into voting-app/frontend/ and the supplied Part 1 file vue.spec.js into voting-app/frontend/e2e/ (create the e2e directory if necessary). Use the matching milestone’s test files as you progress through the tutorial.
Install the optional test dependencies from the project directory:
cd frontend
npm install -D @playwright/test
npx playwright install chromium
Keep the application running at http://localhost:3100 in another terminal. Run the supplied Part 1 checks from frontend/:
npx playwright test e2e/vue.spec.js
At this milestone, both checks should pass: the example page connects successfully to FastAPI, and the health endpoint returns the expected response. The browser check also saves light- and dark-mode screenshots under frontend/test-results/.
The supplied configuration uses the running full-stack application, so the same checks can be run against the development server or the production build. If you have changed the port, set PLAYWRIGHT_BASE_URL to the address you are using. You can also set SCREENSHOT_DIR to choose where the screenshots are saved.
Return to the voting-app directory before continuing (cd ..).
In Part 2: Vue reactivity and browser-local state, we will turn the generated welcome page into a voting application. We will leave the backend as it is for now and see how far we can get using Vue and Pinia alone.