연구실 구성원의 일정 관리를 위한 웹 애플리케이션과 Discord 봇 통합 시스템입니다.
일정 관리
- 월별 캘린더 UI (components/calendar.tsx)
- 이벤트 생성/수정/삭제 (admin 권한)
- 이벤트 타입: 휴가, 미팅, 학회 등
사용자 인증
- Discord OAuth2 자동 로그인
- 역할 기반 권한 관리 (admin/user)
- 세션 관리 (NextAuth.js)
일정 명령어
/일정조회 [날짜]- 특정 날짜의 모든 일정 조회/내일정- 본인이 참여하는 일정만 조회/웹사이트접속- 5분 유효 자동 로그인 링크 생성
Authentication & Users
├── POST /api/auth/[...nextauth] # NextAuth endpoints
├── POST /api/auth/register-user # User registration
├── POST /api/auth/discord-verify # Discord verification
├── GET /api/users # List users
├── GET /api/users/[id] # User details
└── PUT /api/user/update-name # Update user name
Events
├── GET /api/events # List events (with filters)
├── POST /api/events # Create event (admin)
├── PUT /api/events # Update event (admin)
└── DELETE /api/events # Delete event (admin)
Discord Integration
├── POST /api/discord/login-token # Generate auto-login token
├── POST /api/discord/user # Get user by Discord ID
├── POST /api/discord/update-nickname # Sync Discord nickname
├── POST /api/discord/reminder # Send event reminder
├── POST /api/discord/test-reminder # Test reminder
└── GET /api/discord/events # Events for Discord bot
Health
├── GET /api/health # Application health
└── GET /api/health/db # Database health
- Next.js 15.2.4 (App Router)
- React 19
- TypeScript 5
- Radix UI (UI primitives)
- Tailwind CSS 3.4.17
- date-fns 4.1.0
- Node.js
- Next.js API Routes
- PostgreSQL 8.16.3
- NextAuth.js 4.24.11
- Discord.js 14.21.0
- Slash Commands API
- pnpm (package manager)
- Docker Compose
- Nginx (reverse proxy)
app/
├── api/ # API Routes
│ ├── events/ # 일정 API
│ ├── users/ # 사용자 API
│ ├── auth/ # 인증 API
│ ├── discord/ # Discord 통합 API
│ └── health/ # 헬스체크 API
├── auth/ # 인증 페이지
└── page.tsx # 메인 페이지
components/
├── admin-dashboard.tsx # 관리자 대시보드
├── calendar.tsx # 캘린더 컴포넌트
├── event-modal.tsx # 이벤트 모달
├── detail-panel.tsx # 상세 패널
├── header.tsx # 헤더
├── login-modal.tsx # 로그인 모달
└── ui/ # Radix UI 기반 컴포넌트
lib/
├── db.ts # PostgreSQL 연결 (retry logic, pooling)
├── auth.ts # NextAuth configuration
├── auth-middleware.ts # API authentication middleware
├── discord-bot.js # Discord bot implementation
└── env-validation.ts # Environment validation
scripts/
├── start-dev.sh # Development startup
├── start-prod.sh # Production startup
└── cleanup.sh # Docker cleanup
types/
├── index.ts # Event, User types
├── next-auth.d.ts # NextAuth type extensions
└── global.d.ts # Global type definitions
Authentication Flow:
Discord OAuth → NextAuth Callback → PostgreSQL User Registration → JWT Session
Event Management Flow:
Web UI → POST /api/events → PostgreSQL → Discord Bot Reminder (optional)
users
├── id (PRIMARY KEY)
├── name
├── discord_id (UNIQUE)
├── discord_username
├── email
├── role (admin/user)
└── avatar
events
├── id (PRIMARY KEY)
├── title
├── type (vacation/meeting/conference)
├── start_date
├── end_date
├── participants (TEXT[])
├── location
├── description
└── created_by (FK → users.id)// lib/auth-middleware.ts
withAuth() # 로그인 필수 (모든 인증된 사용자)
withAdminAuth() # 관리자 권한 필수
canAccessResource() # 소유자 또는 관리자 권한 체크적용 예시:
/api/eventsGET: withAuth()/api/eventsPOST/PUT/DELETE: withAdminAuth()
- Node.js 18+
- PostgreSQL 14+
- pnpm 8+
- Discord Application (Bot Token, OAuth Client)
# 의존성 설치
pnpm install
# 환경 변수 설정 (.env)
DATABASE_URL=postgresql://user:password@localhost:5432/labschedule
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-secret-key
DISCORD_CLIENT_ID=your-client-id
DISCORD_CLIENT_SECRET=your-client-secret
DISCORD_BOT_TOKEN=your-bot-token
DISCORD_GUILD_ID=your-guild-id
NODE_ENV=development# Next.js 개발 서버
pnpm dev
# Discord 봇 (별도 터미널)
pnpm bot
# 또는 nodemon으로 자동 재시작
pnpm dev:bot애플리케이션: http://localhost:3000
# 개발 환경
./scripts/start-dev.sh
# 프로덕션 환경
./scripts/start-prod.sh
# 로그 확인
pnpm docker:logs
# 종료
docker-compose downservices:
postgres: # PostgreSQL 14
redis: # Redis (session store)
app: # Next.js application
discord-bot: # Discord bot
nginx: # Reverse proxyDevelopment
- 포트: 3000 (HTTP)
- Hot reload 활성화
- 상세 로그 출력
Production
- 포트: 80 (HTTP), 443 (HTTPS)
- Nginx reverse proxy
- SSL/TLS 인증서 (Let's Encrypt)
- 로그 레벨: error
# 백업
pg_dump labschedule > backups/backup_$(date +%Y%m%d_%H%M%S).sql
# 복구
psql labschedule < backups/backup_20250811_173015.sql
# 긴급 복구 스크립트
psql labschedule < scripts/emergency-recovery.sqlpnpm dev # Next.js 개발 서버 (localhost:3000)
pnpm build # 프로덕션 빌드
pnpm start # 프로덕션 서버 실행
pnpm lint # ESLint 실행
pnpm bot # Discord 봇 실행
pnpm dev:bot # Discord 봇 (nodemon)
pnpm docker:dev # Docker 개발 환경 시작
pnpm docker:prod # Docker 프로덕션 환경 시작
pnpm docker:cleanup # Docker 리소스 정리
pnpm docker:logs # Docker 로그 확인
pnpm docker:stop # Docker 컨테이너 중지- Discord OAuth2 인증
- JWT 세션 관리
- API 미들웨어 기반 권한 체크
- SQL injection 방지 (parameterized queries)
- Rate limiting (auto-login token generation)
- PostgreSQL connection pooling (max: 10 connections)
- Connection retry logic (3 attempts, exponential backoff)
- Optimized database queries with indexes
- Next.js automatic code splitting
- Database connection health checks
- Graceful shutdown handling (SIGINT/SIGTERM)
- Error boundary components
- Comprehensive error logging
Private project for research lab use.