npx create-vue@latest frontend --template vue --no-typescript
# Then manually add Pinia: cd frontend && npm i pinia
# But we'll provide full boilerplate below.
Below is a complete, minimal full-stack Todo app boilerplate using Vue 3 (Composition API + <script setup>), Vite, and Pinia for the frontend, paired with a Node.js + Express backend (in-memory storage for simplicity, no DB required).
It's a monorepo structure with separate frontend and backend folders. Features:
- CRUD for Todos (list, add, toggle complete, delete).
- Pinia store handles API calls and state.
- Vite dev server proxies
/api/* to backend (no CORS issues).
- Backend runs on
http://localhost:3001.
- Frontend runs on
http://localhost:5173.
Folder Structure
my-todo-app/
├── backend/
│ ├── package.json
│ ├── server.js
│ └── README.md (optional)
├── frontend/
│ ├── index.html
│ ├── package.json
│ ├── vite.config.js
│ ├── src/
│ │ ├── main.js
│ │ ├── App.vue
│ │ ├── style.css
│ │ └── stores/
│ └── todos.js
└── README.md
Setup Instructions (in README.md)
# Full-Stack Todo App Boilerplate (Vue 3 + Vite + Pinia + Express)
## Quick Start
1. `cd backend && npm install && npm run dev` (runs on http://localhost:3001)
2. `cd ../frontend && npm install && npm run dev` (runs on http://localhost:5173, proxies /api to backend)
## Features
- Frontend: Vue 3, Vite, Pinia (reactive store with API integration).
- Backend: Express REST API (/api/todos) with in-memory data.
- Proxy: No CORS issues in dev.
- Prod build: `cd frontend && npm run build` (outputs to `dist/`).
## Scripts
- Backend: `npm start` (prod), `npm run dev` (nodemon).
- Frontend: `npm run dev`, `npm run build`, `npm run preview`.
Backend Files
backend/package.json
{
"name": "backend",
"version": "1.0.0",
"type": "module",
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
},
"dependencies": {
"express": "^4.18.2",
"cors": "^2.8.5"
},
"devDependencies": {
"nodemon": "^3.0.2"
}
}
backend/server.js
import express from 'express';
import cors from 'cors';
const app = express();
const PORT = 3001;
app.use(cors());
app.use(express.json());
let todos = [
{ id: 1, text: 'Learn Vue 3', completed: false },
{ id: 2, text: 'Setup Pinia', completed: true },
{ id: 3, text: 'Build full-stack app', completed: false }
];
// GET /api/todos
app.get('/api/todos', (req, res) => {
res.json(todos);
});
// POST /api/todos
app.post('/api/todos', (req, res) => {
const newTodo = {
id: Date.now(),
text: req.body.text,
completed: false
};
todos.push(newTodo);
res.status(201).json(newTodo);
});
// PUT /api/todos/:id (toggle or edit)
app.put('/api/todos/:id', (req, res) => {
const id = parseInt(req.params.id);
const todo = todos.find(t => t.id === id);
if (!todo) return res.status(404).json({ error: 'Todo not found' });
todo.text = req.body.text || todo.text;
todo.completed = req.body.completed ?? todo.completed;
res.json(todo);
});
// DELETE /api/todos/:id
app.delete('/api/todos/:id', (req, res) => {
const id = parseInt(req.params.id);
const index = todos.findIndex(t => t.id === id);
if (index === -1) return res.status(404).json({ error: 'Todo not found' });
todos.splice(index, 1);
res.json({ success: true });
});
app.listen(PORT, () => {
console.log(`Backend server running on http://localhost:${PORT}`);
});
Frontend Files
frontend/package.json
{
"name": "frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.4.21",
"pinia": "^2.1.7"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.4",
"vite": "^5.2.0"
}
}
frontend/vite.config.js
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
plugins: [vue()],
server: {
proxy: {
'/api': {
target: 'http://localhost:3001',
changeOrigin: true
}
}
}
});
frontend/index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vue 3 + Vite + Pinia Todo App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
frontend/src/main.js
import { createApp } from 'vue';
import { createPinia } from 'pinia';
import App from './App.vue';
import './style.css';
const app = createApp(App);
app.use(createPinia());
app.mount('#app');
frontend/src/App.vue
<template>
<div id="app">
<h1>Todo App (Vue 3 + Pinia)</h1>
<div class="input-section">
<input
v-model="newTodoText"
@keyup.enter="addTodo"
placeholder="Enter a new todo..."
ref="inputRef"
/>
<button @click="addTodo">Add Todo</button>
</div>
<ul class="todo-list">
<li v-for="todo in todosStore.todos" :key="todo.id" class="todo-item">
<input
type="checkbox"
:checked="todo.completed"
@change="todosStore.toggleTodo(todo.id)"
/>
<span :class="{ completed: todo.completed }">{{ todo.text }}</span>
<button @click="todosStore.deleteTodo(todo.id)" class="delete-btn">Delete</button>
</li>
</ul>
<button @click="todosStore.fetchTodos" class="refresh-btn">Refresh</button>
<p v-if="todosStore.todos.length === 0">No todos yet!</p>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue';
import { useTodosStore } from './stores/todos.js';
const todosStore = useTodosStore();
const newTodoText = ref('');
const inputRef = ref(null);
const addTodo = () => {
const text = newTodoText.value.trim();
if (text) {
todosStore.addTodo(text);
newTodoText.value = '';
inputRef.value?.focus();
}
};
onMounted(() => {
todosStore.fetchTodos();
});
</script>
<style>
#app {
max-width: 600px;
margin: 0 auto;
padding: 2rem;
font-family: system-ui, sans-serif;
}
.input-section {
display: flex;
gap: 1rem;
margin-bottom: 2rem;
}
input[type="text"] {
flex: 1;
padding: 0.75rem;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 0.75rem 1.5rem;
background: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background: #0056b3;
}
.todo-list {
list-style: none;
padding: 0;
}
.todo-item {
display: flex;
align-items: center;
gap: 1rem;
padding: 1rem;
border: 1px solid #eee;
border-radius: 4px;
margin-bottom: 0.5rem;
}
.todo-item span {
flex: 1;
}
.completed {
text-decoration: line-through;
opacity: 0.6;
}
.delete-btn {
background: #dc3545;
}
.delete-btn:hover {
background: #c82333;
}
.refresh-btn {
background: #28a745;
margin-top: 1rem;
}
.refresh-btn:hover {
background: #218838;
}
</style>
frontend/src/style.css (empty or global styles if needed)
/* Global styles can go here */
frontend/src/stores/todos.js
import { defineStore } from 'pinia';
import { ref } from 'vue';
export const useTodosStore = defineStore('todos', () => {
const todos = ref([]);
const fetchTodos = async () => {
try {
const response = await fetch('/api/todos');
if (response.ok) {
todos.value = await response.json();
}
} catch (error) {
console.error('Failed to fetch todos:', error);
}
};
const addTodo = async (text) => {
try {
const response = await fetch('/api/todos', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text })
});
if (response.ok) {
const newTodo = await response.json();
todos.value.push(newTodo);
}
} catch (error) {
console.error('Failed to add todo:', error);
}
};
const toggleTodo = async (id) => {
const todo = todos.value.find(t => t.id === id);
if (!todo) return;
try {
const response = await fetch(`/api/todos/${id}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ completed: !todo.completed })
});
if (response.ok) {
todo.completed = !todo.completed;
}
} catch (error) {
console.error('Failed to toggle todo:', error);
}
};
const deleteTodo = async (id) => {
try {
const response = await fetch(`/api/todos/${id}`, {
method: 'DELETE'
});
if (response.ok) {
todos.value = todos.value.filter(t => t.id !== id);
}
} catch (error) {
console.error('Failed to delete todo:', error);
}
};
return { todos, fetchTodos, addTodo, toggleTodo, deleteTodo };
});
Next Steps
- Copy into folders as shown.
- Run setup commands.
- Extend: Add Vue Router, authentication, real DB (e.g., Prisma + SQLite), Tailwind CSS, etc.
- Prod: Build frontend and serve
dist/ from backend (add app.use(express.static('../frontend/dist'))).
This is production-ready for a starter, fully functional out-of-the-box! 🚀