# Phase 2 - Desktop Local Dashboard Wiring

Status: completed  
Date: 2026-04-17  
Target: `WepAppOpusApiDesktop`

## 1) Objective

ต่อจาก Phase 1 bootstrap ให้เดสก์ท็อปใช้งานได้จริงด้วย local stack:
1. IPC <-> SQLite wired
2. Dashboard UI pages wired
3. CSV import pipeline wired
4. Build/lint/test ผ่าน

## 2) What was implemented

## 2.1 Main process

Integrated from stable desktop implementation:
1. `main/main.js`
2. `main/preload.js`
3. `main/ipc-handlers.js`
4. `main/database.js`
5. `main/csv-importer.js`

IPC channels available:
1. `db:get-stats`
2. `db:get-daily`
3. `db:get-campaigns`
4. `db:get-demographics`
5. `db:get-filters`
6. `db:get-import-logs`
7. `db:get-meta`
8. `csv:select-file`
9. `csv:preview`
10. `csv:import`
11. `export:pdf`

## 2.2 Renderer

Wired UI stack:
1. `App.jsx` (routes + filter flow)
2. Pages: Dashboard, Daily Trends, Campaign View, Demographics, Import Data, Settings
3. Components: charts, tables, filters, sidebar, export
4. Utils: API bridge client, chart setup, formatters

## 2.3 Build/tooling

Updated dependencies for runtime:
1. `better-sqlite3`
2. `csv-parse`
3. `chart.js`
4. `react-chartjs-2`
5. `react-router-dom`
6. `lucide-react`

Updated dev tooling:
1. `@tailwindcss/vite`
2. `tailwindcss`
3. `eslint-plugin-react`

Config fixes:
1. Vite config switched to CommonJS + `@tailwindcss/vite` default export
2. ESLint React rules configured for JSX usage without React-in-scope requirement

## 3) Verification

Commands executed:
1. `npm install`
2. `npm run lint`
3. `npm run test`
4. `npm run build:renderer`
5. `npm run build:win`

Result:
1. lint passed
2. test passed
3. renderer build passed
4. windows package passed (`nsis`, `portable`)

## 4) Output artifacts

Generated under `WepAppOpusApiDesktop/release`:
1. `WepAppOpusApiDesktop Setup 0.1.0.exe`
2. `WepAppOpusApiDesktop 0.1.0.exe`
3. `.blockmap` and unpacked folder

## 5) Next phase entry criteria

Phase 3 should focus on security hardening for token/profile:
1. keychain-backed token store
2. encrypted token profile reference in local DB
3. redaction and audit-safe logging
