This document outlines the architectural principles, patterns, and rules that govern the Veza frontend. It supersedes previous ad-hoc audit reports.
---
## 1. Core Philosophy: "Visual First"
> "If it can't be rendered in Storybook, it is architecturally broken."
We follow a **Storybook-Driven Development** (SDD) approach.
- **Isolation:** Every component must be renderable in isolation. Dependencies (Providers, Router, Store) must be explicit.
- **Verification:** Storybook is our primary verification tool for UI logic and layout.
---
## 2. State Management Strategy
We distinguish three types of state. Mixing them is strictly forbidden.
### 2.1. Server State (Data) -> `React Query`
Data that belongs to the backend (Users, Tracks, Playlists).
- **Tool:** `@tanstack/react-query`
- **Rule:** Never copy server data into a global store (Zustand) unless strictly necessary for client-side manipulation (e.g., a complex audio editor buffer).
- **Caching:** Managed automatically by query keys.
### 2.2. Client Global State (App) -> `Zustand`
Data that is truly global to the client session (Auth Token, Shopping Cart, Audio Player Status).
- **Tool:** `zustand`
- **Rule:** Use atomic selectors to prevent render-thrashing.
- **Structure:**
-`authStore`: User session.
-`cartStore`: E-commerce state (Items, Total).
-`playerStore`: Audio playback state.
**Legacy Note:** `React Context` is BANNED for high-frequency state updates. It is reserved for dependency injection (Theme, i18n).
### 2.3. UI Local State -> `useState` / `useReducer`
Ephemeral state specific to a component (Modal Open/Close, Form Inputs).
- **Rule:** If it doesn't need to persist when navigating away, it stays local.
---
## 3. Component Engineering
We adhere to the **Smart vs Dumb** (Container vs Presentational) separation to ensure testability.
### 3.1. Dumb Components (UI)
- **Role:** Render props into HTML. Emit events via callbacks.
- **Dependencies:** ZERO. No explicit side-effects, no API calls, no Context consumers (except Theme).