Files
site11/services/news-engine-console/TODO.md
jungwoo choi 52c857fced feat: Complete backend implementation - Users, Applications, Monitoring
Phase 1 Backend 100% 완료:

 UserService (312 lines):
- 인증 시스템 (authenticate_user, JWT 토큰 생성)
- CRUD 전체 기능 (get, create, update, delete)
- 권한 기반 필터링 (role, disabled, search)
- 비밀번호 관리 (change_password, hash 검증)
- 상태 토글 및 통계 조회

 ApplicationService (254 lines):
- OAuth2 클라이언트 관리
- Client ID/Secret 자동 생성
- Secret 재생성 기능
- 소유권 검증 (ownership check)
- 통계 조회 (grant types별)

 MonitoringService (309 lines):
- 시스템 헬스 체크 (MongoDB, pipelines)
- 시스템 메트릭 (keywords, pipelines, users, apps)
- 활동 로그 조회 (필터링, 날짜 범위)
- 데이터베이스 통계 (크기, 컬렉션, 인덱스)
- 파이프라인 성능 분석
- 에러 요약

 Users API (11 endpoints + OAuth2 로그인):
- POST /login - OAuth2 password flow
- GET /me - 현재 사용자 정보
- GET / - 사용자 목록 (admin only)
- GET /stats - 사용자 통계 (admin only)
- GET /{id} - 사용자 조회 (자신 or admin)
- POST / - 사용자 생성 (admin only)
- PUT /{id} - 사용자 수정 (권한 검증)
- DELETE /{id} - 사용자 삭제 (admin only, 자기 삭제 방지)
- POST /{id}/toggle - 상태 토글 (admin only)
- POST /change-password - 비밀번호 변경

 Applications API (7 endpoints):
- GET / - 애플리케이션 목록 (admin: 전체, user: 자신 것만)
- GET /stats - 통계 (admin only)
- GET /{id} - 조회 (소유자 or admin)
- POST / - 생성 (client_secret 1회만 표시)
- PUT /{id} - 수정 (소유자 or admin)
- DELETE /{id} - 삭제 (소유자 or admin)
- POST /{id}/regenerate-secret - Secret 재생성

 Monitoring API (8 endpoints):
- GET /health - 시스템 헬스 상태
- GET /metrics - 시스템 메트릭
- GET /logs - 활동 로그 (필터링 지원)
- GET /database/stats - DB 통계 (admin only)
- GET /database/collections - 컬렉션 통계 (admin only)
- GET /pipelines/performance - 파이프라인 성능
- GET /errors/summary - 에러 요약

주요 특징:
- 🔐 역할 기반 접근 제어 (RBAC: admin/editor/viewer)
- 🔒 OAuth2 Password Flow 인증
- 🛡️ 소유권 검증 (자신의 리소스만 수정)
- 🚫 안전 장치 (자기 삭제 방지, 자기 비활성화 방지)
- 📊 종합적인 모니터링 및 통계
- 🔑 안전한 Secret 관리 (1회만 표시)
-  완전한 에러 핸들링

Backend API 총 45개 엔드포인트 완성!
- Keywords: 8
- Pipelines: 11
- Users: 11
- Applications: 7
- Monitoring: 8

다음 단계:
- Frontend 구현 (React + TypeScript + Material-UI)
- Docker & Kubernetes 배포
- Redis 통합
- 테스트 작성

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 16:58:02 +09:00

486 lines
11 KiB
Markdown

# News Engine Console - 구현 계획
다음 세션을 위한 상세 구현 계획
---
## 🎯 Phase 1: Backend 완성 (우선순위)
### 1.1 데이터 모델 구현
**models/keyword.py**
```python
class Keyword:
_id: ObjectId
keyword: str
category: str # 'people', 'topics', 'companies'
status: str # 'active', 'inactive'
pipeline_type: str # 'rss', 'translation', 'all'
priority: int # 1-10
metadata: dict
created_at: datetime
updated_at: datetime
created_by: str
```
**models/pipeline.py**
```python
class Pipeline:
_id: ObjectId
name: str
type: str # 'rss_collector', 'translator', 'image_generator'
status: str # 'running', 'stopped', 'error'
config: dict
schedule: str # cron expression
stats: PipelineStats
last_run: datetime
next_run: datetime
```
**models/user.py**
```python
class User:
_id: ObjectId
username: str (unique)
email: str (unique)
hashed_password: str
full_name: str
role: str # 'admin', 'editor', 'viewer'
disabled: bool
created_at: datetime
last_login: datetime
```
**models/application.py**
```python
class Application:
_id: ObjectId
name: str
client_id: str (unique)
client_secret: str (hashed)
redirect_uris: List[str]
grant_types: List[str]
scopes: List[str]
owner_id: str
created_at: datetime
```
### 1.2 Pydantic 스키마 작성
**schemas/keyword.py**
- KeywordCreate
- KeywordUpdate
- KeywordResponse
- KeywordList
**schemas/pipeline.py**
- PipelineCreate
- PipelineUpdate
- PipelineResponse
- PipelineStats
- PipelineList
**schemas/user.py**
- UserCreate
- UserUpdate
- UserResponse
- UserLogin
**schemas/application.py**
- ApplicationCreate
- ApplicationUpdate
- ApplicationResponse
### 1.3 서비스 레이어 구현
**services/keyword_service.py**
- `async def get_keywords(filters, pagination)`
- `async def create_keyword(keyword_data)`
- `async def update_keyword(keyword_id, update_data)`
- `async def delete_keyword(keyword_id)`
- `async def toggle_keyword_status(keyword_id)`
- `async def get_keyword_stats(keyword_id)`
**services/pipeline_service.py**
- `async def get_pipelines()`
- `async def get_pipeline_stats(pipeline_id)`
- `async def start_pipeline(pipeline_id)`
- `async def stop_pipeline(pipeline_id)`
- `async def restart_pipeline(pipeline_id)`
- `async def get_pipeline_logs(pipeline_id, limit)`
- `async def update_pipeline_config(pipeline_id, config)`
**services/user_service.py**
- `async def create_user(user_data)`
- `async def authenticate_user(username, password)`
- `async def get_user_by_username(username)`
- `async def update_user(user_id, update_data)`
- `async def delete_user(user_id)`
**services/application_service.py**
- `async def create_application(app_data)`
- `async def get_applications(user_id)`
- `async def regenerate_client_secret(app_id)`
- `async def delete_application(app_id)`
**services/monitoring_service.py**
- `async def get_system_health()`
- `async def get_service_status()`
- `async def get_database_stats()`
- `async def get_redis_stats()`
- `async def get_recent_logs(limit)`
### 1.4 Redis 통합
**core/redis_client.py**
```python
class RedisClient:
async def get(key)
async def set(key, value, expire)
async def delete(key)
async def publish(channel, message)
async def subscribe(channel, callback)
```
**사용 케이스**:
- 파이프라인 상태 캐싱
- 실시간 통계 업데이트 (Pub/Sub)
- 사용자 세션 관리
- Rate limiting
### 1.5 API 엔드포인트 완성
**keywords.py**
- [x] GET / - 목록 조회 (기본 구조)
- [ ] 필터링 (category, status, search)
- [ ] 페이지네이션
- [ ] 정렬 (created_at, priority)
- [ ] GET /{id}/stats - 키워드 통계
- [ ] POST /{id}/toggle - 활성화/비활성화
**pipelines.py**
- [x] GET / - 목록 조회 (기본 구조)
- [ ] GET /{id}/logs - 로그 조회
- [ ] POST /{id}/restart - 재시작
- [ ] PUT /{id}/config - 설정 업데이트
- [ ] GET /types - 파이프라인 타입 목록
**users.py**
- [x] GET / - 목록 조회 (기본 구조)
- [ ] PUT /{id} - 사용자 수정
- [ ] DELETE /{id} - 사용자 삭제
- [ ] POST /login - 로그인 (JWT 발급)
- [ ] POST /register - 회원가입
**applications.py**
- [x] GET / - 목록 조회 (기본 구조)
- [ ] GET /{id} - 상세 조회
- [ ] PUT /{id} - 수정
- [ ] DELETE /{id} - 삭제
- [ ] POST /{id}/regenerate-secret - 시크릿 재생성
**monitoring.py**
- [x] GET /system - 시스템 상태 (기본 구조)
- [ ] GET /services - 서비스별 상태
- [ ] GET /database - DB 통계
- [ ] GET /redis - Redis 상태
- [ ] GET /pipelines/activity - 파이프라인 활동 로그
---
## 🎨 Phase 2: Frontend 구현
### 2.1 프로젝트 설정
```bash
cd frontend
npm create vite@latest . -- --template react-ts
npm install @mui/material @emotion/react @emotion/styled
npm install @tanstack/react-query axios react-router-dom
npm install recharts date-fns
```
### 2.2 레이아웃 구현
**components/Layout/AppLayout.tsx**
- Sidebar with navigation
- Top bar with user info
- Main content area
**components/Layout/Sidebar.tsx**
- Dashboard
- Keywords
- Pipelines
- Users
- Applications
- Monitoring
### 2.3 페이지 구현
**pages/Dashboard.tsx**
- 전체 통계 요약
- 파이프라인 상태 차트
- 최근 활동 로그
- 키워드 활용도 TOP 10
**pages/Keywords.tsx**
- 키워드 목록 테이블
- 검색, 필터, 정렬
- 추가/수정/삭제 모달
- 활성화/비활성화 토글
- 키워드별 통계 차트
**pages/Pipelines.tsx**
- 파이프라인 카드 그리드
- 상태별 필터 (Running, Stopped, Error)
- 시작/중지 버튼
- 실시간 로그 스트림
- 통계 차트
**pages/Users.tsx**
- 사용자 목록 테이블
- 역할 필터 (Admin, Editor, Viewer)
- 추가/수정/삭제 모달
- 마지막 로그인 시간
**pages/Applications.tsx**
- Application 카드 그리드
- Client ID/Secret 표시
- 생성/수정/삭제
- Secret 재생성 기능
**pages/Monitoring.tsx**
- 시스템 헬스체크 대시보드
- 서비스별 상태 (MongoDB, Redis, etc.)
- CPU/메모리 사용량 차트
- 실시간 로그 스트림
### 2.4 API 클라이언트
**api/client.ts**
```typescript
import axios from 'axios';
const apiClient = axios.create({
baseURL: import.meta.env.VITE_API_URL || 'http://localhost:8100/api/v1',
headers: {
'Content-Type': 'application/json'
}
});
// Interceptors for auth token
apiClient.interceptors.request.use(config => {
const token = localStorage.getItem('access_token');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});
export default apiClient;
```
### 2.5 TypeScript 타입 정의
**types/index.ts**
- Keyword
- Pipeline
- User
- Application
- PipelineStats
- SystemStatus
---
## 🐳 Phase 3: Docker & Kubernetes
### 3.1 Backend Dockerfile
```dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8100
CMD ["python", "main.py"]
```
### 3.2 Frontend Dockerfile
```dockerfile
FROM node:18-alpine AS builder
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
```
### 3.3 Kubernetes 매니페스트
**k8s/namespace.yaml**
```yaml
apiVersion: v1
kind: Namespace
metadata:
name: site11-console
```
**k8s/backend-deployment.yaml**
- Deployment with 2 replicas
- ConfigMap for env vars
- Secret for sensitive data
- Service (ClusterIP)
**k8s/frontend-deployment.yaml**
- Deployment with 2 replicas
- Service (LoadBalancer or Ingress)
---
## 📊 Phase 4: 고급 기능
### 4.1 실시간 업데이트
- WebSocket 연결 (파이프라인 상태)
- Server-Sent Events (로그 스트림)
- Redis Pub/Sub 활용
### 4.2 알림 시스템
- 파이프라인 에러 시 알림
- 키워드 처리 완료 알림
- 이메일/Slack 통합
### 4.3 스케줄링
- Cron 기반 파이프라인 스케줄
- 수동 실행 vs 자동 실행
- 스케줄 히스토리
### 4.4 통계 & 분석
- 일/주/월별 처리 통계
- 키워드별 성과 분석
- 파이프라인 성능 메트릭
- CSV 다운로드
---
## 🧪 Phase 5: 테스트 & 문서화
### 5.1 Backend 테스트
- pytest fixtures
- API endpoint tests
- Integration tests
- Coverage report
### 5.2 Frontend 테스트
- React Testing Library
- Component tests
- E2E tests (Playwright)
### 5.3 API 문서
- OpenAPI/Swagger 자동 생성
- API 예시 코드
- 에러 응답 명세
---
## 🚀 우선순위
### 즉시 시작 (다음 세션)
1. **MongoDB 스키마 및 인덱스 생성**
- keywords, pipelines, users 컬렉션
- 인덱스 설계
2. **Pydantic 스키마 작성**
- Request/Response 모델
- 유효성 검증
3. **키워드 관리 기능 완성**
- KeywordService 구현
- CRUD API 완성
- 단위 테스트
4. **로그인 API 구현**
- JWT 토큰 발급
- User 인증
### 중기 목표 (1-2주)
1. 파이프라인 제어 API 완성
2. Frontend 기본 구조
3. Dashboard 페이지
4. Dockerfile 작성
### 장기 목표 (1개월)
1. Frontend 전체 페이지
2. Kubernetes 배포
3. 실시간 모니터링
4. 알림 시스템
---
## 📝 체크리스트
### Backend ✅ 완료!
- [x] 프로젝트 구조
- [x] 기본 설정 (config, database, auth)
- [x] API 라우터 기본 구조
- [x] Pydantic 스키마 (완료 - keyword, pipeline, user, application)
- [x] MongoDB 데이터 모델 (완료 - keyword, pipeline, user, application)
- [x] 서비스 레이어 구현 (완료 - 5개 전체)
- [x] KeywordService (CRUD + stats + toggle + bulk)
- [x] PipelineService (CRUD + control + logs + config)
- [x] UserService (인증 + CRUD + 권한 관리)
- [x] ApplicationService (OAuth2 + secret 관리)
- [x] MonitoringService (시스템 헬스 + 메트릭 + 로그)
- [x] Keywords API 완전 구현 (8 endpoints)
- [x] Pipelines API 완전 구현 (11 endpoints)
- [x] Users API 완전 구현 (11 endpoints + OAuth2 로그인)
- [x] Applications API 완전 구현 (7 endpoints + secret 재생성)
- [x] Monitoring API 완전 구현 (8 endpoints)
- [ ] MongoDB 컬렉션 및 인덱스 생성
- [ ] Redis 통합 (캐싱 + Pub/Sub)
- [ ] 고급 에러 핸들링
- [ ] 로깅 시스템 확장
### Frontend
- [ ] 프로젝트 설정
- [ ] 레이아웃 및 라우팅
- [ ] 로그인 페이지
- [ ] Dashboard
- [ ] Keywords 페이지
- [ ] Pipelines 페이지
- [ ] Users 페이지
- [ ] Applications 페이지
- [ ] Monitoring 페이지
### DevOps
- [ ] Backend Dockerfile
- [ ] Frontend Dockerfile
- [ ] docker-compose.yml
- [ ] Kubernetes 매니페스트
- [ ] CI/CD 설정
---
**다음 세션 시작 시**: 이 TODO.md를 확인하고 체크리스트 업데이트