Vue Template
The Vue template creates a project with two parts:
Vue frontend
Vix C++ backendUse it when you want a modern browser UI powered by Vue, while keeping the backend in C++ with Vix. Create a Vue project with:
vix new dashboard --template vueWhat this template is for
Use the Vue template when you want:
- a Vue frontend
- a Vix C++ backend
- API routes under
/api - Vite development server
- frontend hot reload
- C++ backend performance
- one project containing both frontend and backend
- dashboards, SaaS apps, admin panels, internal tools, or customer portals
This template is different from the web template. The web template renders HTML on the server with Vix templates. The Vue template renders the UI in the browser with Vue.
Design used by this template
The Vue template uses a frontend + backend architecture.
The project is split into two clear parts:
frontend/ -> Vue application
src/main.cpp -> Vix C++ backendThe development flow is:
browser
-> Vite dev server
-> Vue app
-> fetch("/api/hello")
-> Vite proxy
-> Vix backend on http://localhost:8080This gives you a modern frontend workflow while keeping backend logic in C++.
Quick start
Create the project:
vix new dashboard --template vueEnter the project:
cd dashboardInstall frontend dependencies:
cd frontend
npm install
cd ..Start development mode:
vix devThen open the Vue dev server URL shown by Vite.
If you want to run frontend and backend manually, start the backend first:
vix runThen start Vue in another terminal:
cd frontend
npm run devGenerated structure
A Vue project generated with:
vix new dashboard --template vuehas this structure:
dashboard/
├── src/
│ └── main.cpp
├── frontend/
│ ├── index.html
│ ├── package.json
│ ├── vite.config.js
│ └── src/
│ ├── main.js
│ └── App.vue
├── tests/
├── vix.app
├── vix.json
└── README.mdSome projects may also include .env and .env.example depending on the selected options and current generator version.
What each part does
| File or folder | Role |
|---|---|
src/main.cpp | Vix C++ backend entry point. |
frontend/ | Vue frontend application. |
frontend/src/ | Vue source files. |
frontend/src/App.vue | Main Vue component. |
frontend/src/main.js | Vue application mount point. |
frontend/vite.config.js | Vite configuration and API proxy. |
frontend/package.json | Frontend dependencies and scripts. |
vix.app | Vix backend build manifest. |
vix.json | Project metadata, frontend config, tasks, and dependency metadata. |
tests/ | Backend tests. |
Backend role
The backend is the Vix C++ part.
It handles API routes.
The generated frontend calls:
GET /api/helloDuring development, the Vue app calls:
fetch("/api/hello");That request is proxied by Vite to:
http://localhost:8080So the browser talks to Vue, and Vue talks to the Vix backend through /api.
Frontend role
The frontend is the Vue application in:
frontend/It owns:
- pages
- components
- browser UI
- frontend state
- CSS
- frontend routing if you add Vue Router later
- calls to the backend API
The generated App.vue loads a message from the backend:
const response = await fetch("/api/hello");
const data = await response.json();
message.value = data.message || "Hello from Vix";This confirms that the frontend and backend are connected.
Vite proxy
The generated Vite config contains:
export default defineConfig({
clearScreen: false,
plugins: [vue()],
server: {
host: "0.0.0.0",
proxy: {
"/api": "http://localhost:8080",
},
},
});This means:
frontend request: /api/hello
real backend: http://localhost:8080/api/helloThis avoids CORS issues during local development.
The browser sees one frontend origin.
Vite forwards API requests to the backend.
Development mode
Use:
vix devFor Vue projects, Vix can detect the Vue frontend from vix.json and frontend/package.json.
When detected, the dev session can start the Vue dev server and run the Vix backend together.
The project detection is based on:
vix.json contains "template": "vue"
vix.json contains "frontend"
frontend/package.json existsIf you prefer manual control, run two terminals:
Terminal 1:
vix runTerminal 2:
cd frontend
npm run devfrontend/package.json
The generated frontend package contains:
{
"name": "dashboard-frontend",
"private": true,
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@vitejs/plugin-vue": "latest",
"vite": "latest",
"vue": "latest"
},
"devDependencies": {}
}Useful commands:
cd frontend
npm install
npm run dev
npm run build
npm run previewfrontend/src/main.js
This file mounts Vue into the browser page.
import { createApp } from "vue";
import App from "./App.vue";
createApp(App).mount("#app");The target element is in:
frontend/index.html<div id="app"></div>frontend/src/App.vue
App.vue is the first Vue component.
It shows the frontend and backend connection.
The generated component:
- creates a reactive
message - calls
/api/hello - displays the backend response
- shows a fallback if the backend cannot be reached
This is the first place to edit when building your UI.
src/main.cpp
src/main.cpp is the Vix backend entry point.
It should expose API routes used by the Vue frontend.
A simple backend can look like this:
#include <vix.hpp>
using namespace vix;
int main()
{
App app;
app.get("/api/hello", [](Request &, Response &res) {
res.json({
"message", "Hello from the Vix backend"
});
});
app.run();
return 0;
}Keep API routes under:
/apiThis matches the Vite proxy and keeps frontend pages separate from backend APIs.
vix.json
vix.json stores the Vue project metadata.
The generated file includes a frontend section:
{
"frontend": {
"framework": "vue",
"dir": "frontend",
"dev": "npm run dev",
"build": "npm run build",
"dist": "frontend/dist"
}
}It also includes useful tasks:
{
"tasks": {
"frontend:install": {
"description": "Install Vue dependencies",
"command": "npm install",
"cwd": "frontend"
},
"frontend:dev": {
"description": "Start Vue dev server",
"command": "npm run dev",
"cwd": "frontend"
},
"frontend:build": {
"description": "Build Vue frontend",
"command": "npm run build",
"cwd": "frontend"
},
"backend:dev": {
"description": "Start Vix backend",
"command": "vix run"
},
"backend:build": {
"description": "Build Vix backend",
"command": "vix build --preset ${preset}"
}
}
}Run tasks with:
vix task frontend:install
vix task frontend:dev
vix task frontend:build
vix task backend:dev
vix task backend:buildvix.app
vix.app describes the backend target.
It is for the C++ backend, not the Vue frontend.
The Vue frontend is managed by:
frontend/package.json
frontend/vite.config.jsThe backend is managed by:
vix.app
vix.json
src/main.cppSimple rule:
vix.app -> C++ backend build
package.json -> Vue frontend build
vix.json -> project orchestrationHow frontend and backend talk
The generated app uses this path:
/api/helloFrontend code:
const response = await fetch("/api/hello");Backend route:
app.get("/api/hello", [](Request &, Response &res) {
res.json({
"message", "Hello from the Vix backend"
});
});During development:
Vue frontend -> Vite proxy -> Vix backendIn production, you usually serve the built frontend and backend behind the same domain or reverse proxy.
Build the frontend
Run:
cd frontend
npm run buildThis creates:
frontend/dist/The dist folder contains the production frontend assets.
Build the backend
From the project root:
vix buildFor release:
vix build --preset releaseRun the backend
From the project root:
vix runThe backend should listen on the port configured by the environment.
Common default:
http://localhost:8080Recommended development workflow
For daily development:
vix devIf automatic Vue dev mode is not available on your platform, use two terminals.
Terminal 1:
vix runTerminal 2:
cd frontend
npm run devThen open the Vite dev server URL.
Recommended production workflow
Build the frontend:
cd frontend
npm run build
cd ..Build the backend:
vix build --preset releaseThen deploy:
backend executable
frontend/dist
environment variables
reverse proxy configurationA common production setup is:
Nginx
-> serves frontend static files
-> proxies /api to the Vix backendThis keeps the browser UI fast while Vix handles backend API requests.
How to add a new API route
Add a route in src/main.cpp:
app.get("/api/status", [](Request &, Response &res) {
res.json({
"ok", true,
"service", "dashboard"
});
});Call it from Vue:
const response = await fetch("/api/status");
const data = await response.json();Because the path starts with /api, Vite will proxy it to the backend during development.
How to add Vue pages
For a small project, you can continue editing:
frontend/src/App.vueWhen the UI grows, add:
frontend/src/components/
frontend/src/pages/
frontend/src/api/Recommended structure:
frontend/src/
├── api/
│ └── client.js
├── components/
│ └── AppCard.vue
├── pages/
│ └── DashboardPage.vue
├── App.vue
└── main.jsUse frontend/src/api/ for functions that call the backend.
Example:
export async function getStatus() {
const response = await fetch("/api/status");
return response.json();
}How to add frontend routing
When the UI grows, install Vue Router:
cd frontend
npm install vue-routerThen create:
frontend/src/router/
frontend/src/pages/Use Vue Router for browser navigation.
Keep backend routes under /api.
How to organize backend code
The generated Vue template starts with a simple backend.
That is intentional.
If the backend grows, you can split routes into files:
src/main.cpp
src/routes.cpp
src/routes.hppIf the backend becomes a serious API, move to the backend template structure:
vix new api --template backendUse the backend template when you need:
- controllers
- middleware registries
- route registries
- application layer
- domain layer
- infrastructure layer
- migrations
- production diagnostics
Vue template vs web template
Use the Vue template when Vue renders the UI in the browser.
Use the web template when Vix renders HTML on the server.
| Need | Template |
|---|---|
| Vue SPA frontend | vue |
| Server-rendered HTML | web |
| Frontend hot reload | vue |
| HTML templates rendered by C++ | web |
| Browser-side components | vue |
| Backend-rendered pages | web |
Vue template vs backend template
Use the Vue template when the frontend is a major part of the product.
Use the backend template when the main product is a backend service or API.
| Need | Template |
|---|---|
| Vue frontend + C++ backend | vue |
| Production-oriented JSON API | backend |
| Vite frontend workflow | vue |
| Controllers, middleware, health checks, migrations | backend |
| Browser UI first | vue |
| API/service first | backend |
A Vue project can call a backend API.
A backend project can serve static files.
The difference is the main development strategy.
Common mistakes
Starting the frontend before installing dependencies
Run this first:
cd frontend
npm installCalling the backend without /api
During development, the proxy is configured for:
/apiPrefer API routes like:
/api/hello
/api/users
/api/orders
/api/statusHardcoding backend URLs in Vue
Avoid this in normal development:
fetch("http://localhost:8080/api/hello");Prefer:
fetch("/api/hello");This lets Vite proxy the request in development and makes production easier.
Forgetting to start the backend
If Vue shows:
Could not reach the Vix backendStart the backend:
vix runor:
vix devMixing frontend build and backend build
Use the right command for each side:
npm run build -> builds Vue frontend
vix build -> builds Vix backendPutting backend logic in Vue
Vue should call APIs.
Backend logic belongs in C++.
Example:
Vue component
-> fetch("/api/orders")
-> Vix backend
-> database or service logicWhat you should remember
The Vue template gives you:
Vue frontend
+ Vix C++ backend
+ Vite proxy for /api
+ project tasks in vix.jsonThe development flow is:
Vue app
-> fetch("/api/...")
-> Vite proxy
-> Vix backendCreate a Vue project:
vix new dashboard --template vue
cd dashboard
cd frontend
npm install
cd ..
vix devUse:
vix task frontend:dev
vix task frontend:build
vix task backend:dev
vix task backend:buildwhen you want task-based workflows.
Next steps
Continue with: