The Vue Architect designs Vue 3 applications with the Composition API and TypeScript. The Composition API's composable pattern is Vue's most powerful architectural tool - it enables logic reuse that the Options API cannot match. All patterns here use <script setup> syntax and TypeScript for type safety.
Composable Pattern
// composables/useCounter.ts
import { ref, computed } from 'vue';
export function useCounter(initial = 0) {
const count = ref(initial);
const doubled = computed(() => count.value * 2);
function increment() { count.value++; }
function decrement() { count.value--; }
function reset() { count.value = initial; }
return { count, doubled, increment, decrement, reset };
}
// Usage in a component
<script setup lang="ts">
const { count, doubled, increment } = useCounter(10);
</script>
<template>
<button @click="increment">{{ count }} ({{ doubled }})</button>
</template>
Pinia State Management
// stores/cart.ts
import { defineStore } from 'pinia';
import { ref, computed } from 'vue';
export const useCartStore = defineStore('cart', () => {
// State
const items = ref<CartItem[]>([]);
// Getters (computed)
const total = computed(() =>
items.value.reduce((sum, item) => sum + item.price * item.quantity, 0)
);
const itemCount = computed(() =>
items.value.reduce((sum, item) => sum + item.quantity, 0)
);
// Actions
function addItem(product: Product) {
const existing = items.value.find(i => i.id === product.id);
if (existing) {
existing.quantity++;
} else {
items.value.push({ ...product, quantity: 1 });
}
}
function removeItem(id: string) {
items.value = items.value.filter(i => i.id !== id);
}
return { items, total, itemCount, addItem, removeItem };
});
Async Data with useAsyncData (Nuxt 3)
// pages/products/[id].vue
<script setup lang="ts">
const route = useRoute();
const { data: product, status } = await useAsyncData(
`product-${route.params.id}`, // Cache key
() => $fetch(`/api/products/${route.params.id}`)
);
useSeoMeta({
title: () => product.value?.name ?? 'Product',
ogDescription: () => product.value?.description,
});
</script>
<template>
<div v-if="status === 'pending'">Loading...</div>
<div v-else-if="product">{{ product.name }}</div>
</template>