feat: TK 안전관리 플랫폼 초기 구현
위험성평가, 안전 RAG Q&A, 안전점검 체크리스트를 통합한 안전관리자 전용 웹 플랫폼 전체 구현. - Next.js 15 (App Router) + TypeScript + Tailwind + shadcn/ui - Drizzle ORM + PostgreSQL 16 (12개 테이블) - 위험성평가 CRUD + 5x5 위험성 매트릭스 + 인쇄 내보내기 - 체크리스트 템플릿/점검/NCR 추적 - RAG 문서 파이프라인 (Tika + bge-m3 + Qdrant) - SSE 스트리밍 RAG 채팅 (qwen3.5:35b-a3b) - AI 어시스트 (위험요인 추천, 감소대책, 점검항목 생성) - 대시보드 통계/차트 (recharts) - 단일 사용자 인증 (HMAC 쿠키 세션) - 다크모드 지원 - Docker 멀티스테이지 빌드 (standalone) - 프로젝트 가이드 문서 (docs/) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
80
docs/development.md
Normal file
80
docs/development.md
Normal file
@@ -0,0 +1,80 @@
|
||||
# TK 안전관리 - 개발 가이드
|
||||
|
||||
## 로컬 개발 환경 설정
|
||||
|
||||
### 1. 의존성 설치
|
||||
```bash
|
||||
cd ~/docker/tk-safety
|
||||
npm install
|
||||
```
|
||||
|
||||
### 2. DB 실행 (Docker)
|
||||
```bash
|
||||
docker-compose up db -d
|
||||
```
|
||||
|
||||
### 3. DB 마이그레이션
|
||||
```bash
|
||||
npx drizzle-kit push
|
||||
```
|
||||
|
||||
### 4. 개발 서버 실행
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
→ http://localhost:3000
|
||||
|
||||
## 주요 패턴
|
||||
|
||||
### Server Actions
|
||||
모든 CRUD 작업은 `src/actions/` 디렉토리의 Server Actions로 구현됩니다.
|
||||
- `risk-assessment.ts` — 위험성평가 + 유해위험요인
|
||||
- `checklists.ts` — 템플릿 + 점검 + NCR
|
||||
- `rag.ts` — 문서 업로드/처리 + 대화
|
||||
|
||||
### AI API 라우트
|
||||
SSE 스트리밍이 필요한 AI 기능은 `src/app/api/ai/` 라우트로 구현됩니다.
|
||||
- `chat/route.ts` — RAG Q&A (SSE)
|
||||
- `suggest-hazards/route.ts` — 위험요인 추천 (JSON)
|
||||
- `suggest-controls/route.ts` — 감소대책 제안 (SSE)
|
||||
- `suggest-checklist/route.ts` — 점검항목 생성 (JSON)
|
||||
|
||||
### SSE 스트리밍
|
||||
클라이언트에서는 `src/hooks/use-streaming.ts` 훅을 사용합니다.
|
||||
```tsx
|
||||
const { isStreaming, content, sources, error, streamChat, reset } = useStreaming();
|
||||
await streamChat("/api/ai/chat", { question, conversationId });
|
||||
```
|
||||
|
||||
### 인증 시스템
|
||||
- HMAC 기반 쿠키 세션 (7일 유효)
|
||||
- `src/lib/auth.ts` — 세션 생성/검증
|
||||
- `src/middleware.ts` — 라우트 보호
|
||||
- `src/app/(authenticated)/layout.tsx` — 서버사이드 인증 확인
|
||||
|
||||
## DB 스키마 수정
|
||||
|
||||
1. `src/lib/db/schema.ts` 수정
|
||||
2. 마이그레이션 생성: `npx drizzle-kit generate`
|
||||
3. 마이그레이션 적용: `npx drizzle-kit push`
|
||||
|
||||
## 새 컴포넌트 추가
|
||||
|
||||
### shadcn/ui 컴포넌트
|
||||
```bash
|
||||
npx shadcn@latest add [component-name]
|
||||
```
|
||||
|
||||
### 커스텀 컴포넌트
|
||||
기능별 디렉토리에 배치:
|
||||
- `src/components/risk-assessment/` — 위험성평가 관련
|
||||
- `src/components/rag/` — RAG/채팅 관련
|
||||
- `src/components/checklists/` — 체크리스트 관련
|
||||
- `src/components/dashboard/` — 대시보드 관련
|
||||
|
||||
## 코드 컨벤션
|
||||
|
||||
- TypeScript strict 모드
|
||||
- Drizzle ORM 타입 추론 (`InferSelectModel<typeof table>`)
|
||||
- Server Actions에서 `revalidatePath()` 호출
|
||||
- 한국어 UI 텍스트 (상수는 `src/lib/constants.ts`에 정의)
|
||||
Reference in New Issue
Block a user