Skip to content

mindongdong/LabSc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lab Schedule Management System

연구실 구성원의 일정 관리를 위한 웹 애플리케이션과 Discord 봇 통합 시스템입니다.

핵심 기능

Web Application

일정 관리

  • 월별 캘린더 UI (components/calendar.tsx)
  • 이벤트 생성/수정/삭제 (admin 권한)
  • 이벤트 타입: 휴가, 미팅, 학회 등

사용자 인증

  • Discord OAuth2 자동 로그인
  • 역할 기반 권한 관리 (admin/user)
  • 세션 관리 (NextAuth.js)

Discord Bot

일정 명령어

  • /일정조회 [날짜] - 특정 날짜의 모든 일정 조회
  • /내일정 - 본인이 참여하는 일정만 조회
  • /웹사이트접속 - 5분 유효 자동 로그인 링크 생성

API 엔드포인트

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

기술 스택

Frontend

  • 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

Backend

  • Node.js
  • Next.js API Routes
  • PostgreSQL 8.16.3
  • NextAuth.js 4.24.11

Discord Integration

  • Discord.js 14.21.0
  • Slash Commands API

Development & Deployment

  • 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/events GET: withAuth()
  • /api/events POST/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

Docker 환경

# 개발 환경
./scripts/start-dev.sh

# 프로덕션 환경
./scripts/start-prod.sh

# 로그 확인
pnpm docker:logs

# 종료
docker-compose down

배포

Docker Compose 구성

services:
  postgres:       # PostgreSQL 14
  redis:          # Redis (session store)
  app:            # Next.js application
  discord-bot:    # Discord bot
  nginx:          # Reverse proxy

환경별 설정

Development

  • 포트: 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.sql

개발 명령어

pnpm 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors