---
estimated_steps: 61
estimated_files: 12
skills_used: []
---

# T01: Split public-client.ts into domain API modules with barrel re-export

## Description

The 945-line `public-client.ts` monolith contains all API functions across 10 domains. Split it into focused domain modules under `frontend/src/api/` with a barrel `index.ts` that re-exports everything for backward compatibility.

## Steps

1. Read `frontend/src/api/public-client.ts` fully to identify exact domain boundaries and shared infrastructure.
2. Create `frontend/src/api/client.ts` with shared infrastructure: `request<T>()` helper, `ApiError` class, `AUTH_TOKEN_KEY`, base URL config, and the auto-inject Authorization header logic.
3. Create domain modules, each importing `request` and `ApiError` from `./client`:
   - `search.ts` — searchApi, fetchSuggestions, fetchPopularSearches + related types
   - `techniques.ts` — fetchTechniques, fetchTechnique, fetchRandomTechnique, versions + types
   - `creators.ts` — fetchCreators, fetchCreator + types
   - `topics.ts` — fetchTopics, fetchSubTopicTechniques + types
   - `stats.ts` — fetchStats + types
   - `reports.ts` — submitReport, fetchReports, updateReport + types
   - `admin-pipeline.ts` — all pipeline admin functions + types (largest group, ~15 functions)
   - `admin-techniques.ts` — fetchAdminTechniquePages + types
   - `auth.ts` — authRegister, authLogin, authGetMe, authUpdateProfile + types
4. Create `frontend/src/api/index.ts` barrel that re-exports everything from all modules.
5. Delete `frontend/src/api/public-client.ts`.
6. Update the 16 consumer files to import from `../api` (barrel) instead of `../api/public-client`. The barrel preserves all names, so only the import path changes.
7. Run `npm run build` and fix any TypeScript errors.

## Must-Haves

- [ ] `request<T>()` helper and `ApiError` class in shared `client.ts` — not duplicated
- [ ] Authorization header auto-injection logic stays in `client.ts`
- [ ] `AUTH_TOKEN_KEY` exported from `client.ts` for `AuthContext.tsx`
- [ ] Barrel `index.ts` re-exports all functions and types
- [ ] `public-client.ts` deleted — no stale copy
- [ ] All 16 consumers import from barrel (no `public-client` references remain)
- [ ] `npm run build` passes with zero errors

## Verification

- `npm run build` exits 0 with zero TypeScript errors
- `! rg 'public-client' frontend/src/ -g '*.ts' -g '*.tsx'` — no references to old file
- `test -f frontend/src/api/index.ts && test -f frontend/src/api/client.ts` — core files exist
- `ls frontend/src/api/*.ts | wc -l` — at least 11 files (client + 9 domain + index)

## Inputs

- `frontend/src/api/public-client.ts` — the monolith to split
- `frontend/src/context/AuthContext.tsx` — imports AUTH_TOKEN_KEY from public-client
- `frontend/src/pages/TopicsBrowse.tsx` — consumer
- `frontend/src/pages/Home.tsx` — consumer
- `frontend/src/pages/SearchResults.tsx` — consumer
- `frontend/src/pages/AdminPipeline.tsx` — consumer
- `frontend/src/pages/AdminTechniquePages.tsx` — consumer
- `frontend/src/pages/AdminReports.tsx` — consumer
- `frontend/src/pages/CreatorsBrowse.tsx` — consumer
- `frontend/src/pages/CreatorDetail.tsx` — consumer
- `frontend/src/pages/CreatorSettings.tsx` — consumer
- `frontend/src/pages/TechniquePage.tsx` — consumer
- `frontend/src/components/SearchAutocomplete.tsx` — consumer
- `frontend/src/components/ReportIssueModal.tsx` — consumer
- `frontend/src/components/TableOfContents.tsx` — consumer
- `frontend/src/utils/citations.tsx` — consumer

## Expected Output

- `frontend/src/api/client.ts` — shared request helper, ApiError, AUTH_TOKEN_KEY, base URL
- `frontend/src/api/search.ts` — search domain functions
- `frontend/src/api/techniques.ts` — technique CRUD functions
- `frontend/src/api/creators.ts` — creator browse/detail functions
- `frontend/src/api/topics.ts` — topics/subtopics functions
- `frontend/src/api/stats.ts` — stats endpoint function
- `frontend/src/api/reports.ts` — report CRUD functions
- `frontend/src/api/admin-pipeline.ts` — pipeline admin functions
- `frontend/src/api/admin-techniques.ts` — admin technique functions
- `frontend/src/api/auth.ts` — auth endpoint functions
- `frontend/src/api/index.ts` — barrel re-exporting all modules

## Inputs

- `frontend/src/api/public-client.ts`
- `frontend/src/context/AuthContext.tsx`
- `frontend/src/pages/TopicsBrowse.tsx`
- `frontend/src/pages/Home.tsx`
- `frontend/src/pages/SearchResults.tsx`
- `frontend/src/pages/AdminPipeline.tsx`
- `frontend/src/pages/AdminTechniquePages.tsx`
- `frontend/src/pages/AdminReports.tsx`
- `frontend/src/pages/CreatorsBrowse.tsx`
- `frontend/src/pages/CreatorDetail.tsx`
- `frontend/src/pages/CreatorSettings.tsx`
- `frontend/src/pages/TechniquePage.tsx`
- `frontend/src/components/SearchAutocomplete.tsx`
- `frontend/src/components/ReportIssueModal.tsx`
- `frontend/src/components/TableOfContents.tsx`
- `frontend/src/utils/citations.tsx`

## Expected Output

- `frontend/src/api/client.ts`
- `frontend/src/api/search.ts`
- `frontend/src/api/techniques.ts`
- `frontend/src/api/creators.ts`
- `frontend/src/api/topics.ts`
- `frontend/src/api/stats.ts`
- `frontend/src/api/reports.ts`
- `frontend/src/api/admin-pipeline.ts`
- `frontend/src/api/admin-techniques.ts`
- `frontend/src/api/auth.ts`
- `frontend/src/api/index.ts`

## Verification

cd frontend && npm run build && cd .. && ! rg 'public-client' frontend/src/ -g '*.ts' -g '*.tsx' && ls frontend/src/api/*.ts | wc -l
