v1.0.12 · Release snapshot

Documentation comes from this release commit, without inheriting newer content. Commit: 35589c6fda.

Recipe — Adding a new feature

A short, opinionated playbook for adding a brand-new domain to the app. No feature in the repo currently ships the full api → mappers → queries → store → screens stack (the former reference, features/tracks, kept only its types.ts and ephemeral store.ts), so the layering below and data-fetching.md are the reference.

Decision tree

Step-by-step

1. Scaffold the folder

src/features/<name>/
  api.ts          # optional: server data
  mappers.ts      # optional: DTO -> domain
  types.ts        # always
  queries.ts      # optional: react-query hooks
  store.ts        # optional: zustand
  screens/
    <Name>Screen.tsx
  components/

Naming: kebab-case folder, PascalCase screens/components.

2. Define types first

In types.ts:

export interface ThingDto {
  id: string;
  title: string;
  created_at: string;
}

export interface Thing {
  id: string;
  title: string;
  createdAt: string;
}

Snake_case for DTO, camelCase for domain. Always two distinct interfaces.

3. Write the api + mapper

// api.ts
import { apiClient } from '@services/apiClient';
import type { ThingDto } from './types';

export const fetchThings = async () => {
  const { data } = await apiClient.get<ThingDto[]>('/things');
  return data;
};

export const fetchThing = async (id: string) => {
  const { data } = await apiClient.get<ThingDto>(`/things/${id}`);
  return data;
};
// mappers.ts
import type { Thing, ThingDto } from './types';

export const toThing = (dto: ThingDto): Thing => ({
  id: dto.id,
  title: dto.title,
  createdAt: dto.created_at,
});

4. Wrap them in queries

// queries.ts
import { useQuery } from '@tanstack/react-query';
import { fetchThing, fetchThings } from './api';
import { toThing } from './mappers';
import type { Thing } from './types';

export const thingsKeys = {
  all: ['things'] as const,
  list: () => [...thingsKeys.all, 'list'] as const,
  detail: (id: string) => [...thingsKeys.all, 'detail', id] as const,
};

export const useThingsQuery = () =>
  useQuery<Thing[]>({
    queryKey: thingsKeys.list(),
    queryFn: async () => {
      const dtos = await fetchThings();
      return dtos.map(toThing);
    },
  });

export const useThingQuery = (id: string | undefined) =>
  useQuery<Thing>({
    queryKey: id ? thingsKeys.detail(id) : ['things', 'detail', 'none'],
    queryFn: async () => {
      if (!id) throw new Error('Missing id');
      return toThing(await fetchThing(id));
    },
    enabled: Boolean(id),
  });

5. Add client state (if needed)

Only if the screen has filters, selected items, or other UI state that should outlive a single component:

// store.ts
import { create } from 'zustand';

interface ThingsUiState {
  filter: string;
  setFilter: (v: string) => void;
}

export const useThingsStore = create<ThingsUiState>((set) => ({
  filter: '',
  setFilter: (filter) => set({ filter }),
}));

Persist only if a returning user should see the value (rare for UI filters; common for tutorials, user prefs).

6. Build the screen

// screens/ThingsScreen.tsx
import { LegendList } from '@legendapp/list/react-native';
import { Screen } from '@components/Screen';
import { useThingsQuery } from '../queries';

export const ThingsScreen = () => {
  const { data, isLoading } = useThingsQuery();
  if (isLoading || !data) return <Screen center>Loading...</Screen>;
  return (
    <Screen>
      {/* A list that can outgrow a screen recycles its cells (docs/architecture.md#lists). */}
      <LegendList recycleItems data={data} keyExtractor={(t) => t.id} renderItem={({ item }) => ...} />
    </Screen>
  );
};

7. Wire the route

// app/(app)/(tabs)/things.tsx
import { ThingsScreen } from '@features/things/screens/ThingsScreen';
export default ThingsScreen;

If it's a tab, also add it to (tabs)/_layout.tsx. If it's a detail under another tab, add app/(app)/things/[id].tsx.

Checklist before merging

  • Feature-scoped tests pass: bun test src/features/<name> (or cd packages/<pkg> && bun test for package work).
  • Global suite passes: bun run test (packages + app shards in parallel), bun run typecheck (tsc --noEmit), bun run lint (biome check) — all three required. Requires Bun ≥ 1.3.13.
  • No hardcoded colors — use theme.colors.*.
  • No useEffect+useState to fetch — use useQuery.
  • No imports of other features' screens/ or components/.
  • DTO and domain types are separate.
  • Mutations invalidate the right query keys.

Visual recap