# Task 006 — Market Database Module

## Objective

Deliver a browse/search/filter layer over imported market data — companies, people, contact points, service matches, duplicate review, and data quality issues. Manual CRUD is **not** in scope.

## Scope

- Protected API routes under `/api/market/*`
- `market.service.ts` server helpers
- UI: `/market` hub and sub-pages with AppShell
- Sidebar navigation for Market Database

**Out of scope:** Full manual CRUD, actual duplicate merge logic, campaign sending, inbox, AI classification.

## Requirements

1. Search and filter imported companies, people, and contact points.
2. Company detail aggregates related entities from import data.
3. Duplicate review and data quality issue status updates (status-only for merge).
4. Arabic RTL interface with Tailwind tables.

## Files created or modified

| Path | Action |
|------|--------|
| `src/server/services/market.service.ts` | Create |
| `src/lib/pagination.ts`, `src/lib/api-response.ts` | Create |
| `src/app/api/market/**` | Create |
| `src/app/market/**` | Create |
| `src/components/market/market-sub-nav.tsx` | Create |
| `src/components/layout/sidebar.tsx` | Update |
| `src/middleware.ts` | Update — protect `/market` |
| `docs/01-architecture.md`, `03-api-specification.md`, `04-ui-pages.md` | Update |
| `docs/13-decisions-log.md`, `14-roadmap.md`, `16-changelog.md` | Update |
| `tasks/README.md` | Update |

## Acceptance criteria

- [x] `/market` hub with stats and quick links
- [x] Companies list/detail with search and filters
- [x] People, contact points browse pages
- [x] Duplicate review and data quality lists with PATCH status
- [x] Protected routes; sidebar navigation
- [x] `npm run build` and `npm run lint` succeed
- [x] Documentation updated

## Documentation updates required

- `docs/01-architecture.md`
- `docs/03-api-specification.md`
- `docs/04-ui-pages.md`
- `docs/13-decisions-log.md`
- `docs/14-roadmap.md`
- `docs/16-changelog.md`
- `tasks/README.md`

## Status

**done** — Task 006 completed 2026-06-02.
