Foundations
Architecture
The layers of the template and how data travels from a provider to the screen.
Every screen in the template follows the same path. Once you know it, you know where any piece of code lives and what you can replace without breaking the rest.
types/models/<module>.ts The data contract
│
mocks/<module>.mock.ts A provider that returns demo data
│
composables/use<Module>.ts State, loading and actions (save, remove…)
│
utils/<module>.ts Pure rules: filters, totals, statuses (unit tested)
│
pages/<route>.vue Reads the composable, wires the components
│
components/ Base* primitives and page components
Each layer has one job
Layer | Job | Knows about |
|---|---|---|
types/models/ | Describes the records: an order, a task, an email. | Nothing else. |
mocks/ | Builds believable demo data from new Date(), so dates are always fresh. | The models. |
composables/ | Loads data with useAsyncData or useState, exposes it and its actions. | The provider and the rules. |
utils/ | Pure functions with no Vue: derive a status, sum totals, match a filter. | Only its inputs. |
pages/ | Reads the composable and lays out the components. | The composable and the components. |
components/ | Renders what it receives through props and slots. | Its props. |
Providers make the backend swappable
The six apps (email, chat, calendar, kanban, tasks and files) and the business modules (orders, products, customers, invoices and learning) go one step further: their composable receives a provider, an object with the operations it needs.
export interface EmailProvider {
list: () => Promise<EmailMessage[]>
update: (ids: string[], patch: EmailMessagePatch) => Promise<void>
send: (message: EmailMessage) => Promise<void>
}
useEmail() uses createEmailMockProvider() by default. To connect your API you write a provider with the same three functions and pass it in. The page, the list, the reader and the composer do not change.
const email = useEmail({ provider: createEmailApiProvider() })
The Connect your API guide shows the whole process.
Server rendering is the default
Every page renders on the server, so the first paint already has the user, the theme and the data. Three rules keep the server and the browser in agreement:
- Cookies, not localStorage. The session, the theme, the customizer choices and the view preferences (for example the email reading pane) are cookies, which the server can read.
- Demo data is loaded once, on the server. Providers run during server rendering (
useAsyncDatain the apps,useProviderState()in the modules) and the browser reuses the same records from the payload, so nothing changes during hydration. - Time-dependent labels wait for the browser. Relative dates such as “5 minutes ago” render after mount through
useRelativeDay(), because the server may sit in another time zone.
useMounted(), never with import.meta.client in a v-if. A v-if that differs between server and browser shifts every useId() after it and breaks the label links of the form fields.Rules are pure and tested
Business rules live in utils/ as plain functions: invoiceStatus(), orderAttention(), kanbanDueState(), securityLevel()… They take data and return data, with no reactivity, so they are easy to test and reuse. Every file in utils/ has its tests in tests/unit/.
Configuration is data
Things you are likely to change are not hidden in components. Folders, labels, views, thresholds and links live in config/ as typed constants: EMAIL_FOLDERS, ORDER_URGENT_VIEWS, CUSTOMER_AT_RISK_DAYS, SETTINGS_TABS… Change the constant and every screen that uses it follows.