How hyer0705/study-assistant works
Project Type and Purpose
• This is a specialized bot application built on top of Discord.js.
• Its sole purpose is to automatically post next-week’s algorithm study problems (and presenters) into a Discord server.
• It uses Google authentication to fetch data (presumably from a Google Sheet or API) and exposes a minimal health‐check endpoint for uptime monitoring.
File-Structure Analysis
• Top level
• package.json, bun.lock, tsconfig.json → TypeScript project managed by Bun
• Dockerfile, .dockerignore → containerized deployment
• README.md → high-level description, usage
• src/ folder (all TypeScript source)
• auth/ → GoogleAuth integration (OAuth credentials, token handling)
• commands/ → slash-command definitions and implementations
– index.ts → loader for commands
– notify/problem.ts → “/문제공지” command logic
• events/ → event handlers for Discord.js
– ready.ts → on bot login
– interactionCreate.ts → on slash-command invocation
• deploy-command.ts → script to register slash commands with Discord API
• healthCheck.ts → simple HTTP server for liveness probes
• index.ts → entry point: initialize client, wire modules, start health-check
• types/ → shared TypeScript interfaces (Command, ExtendedClient, GoogleAuth)
Key Components
a. Bot Application (Node.js process running on Bun)
• Entry Module (index.ts)
• Command Registrar (deploy-command.ts)
• Health-Check Server (healthCheck.ts)
b. Discord Gateway (Discord API)
• Events channel (ready, interactionCreate)
• Slash-Command registration endpoint
c. Commands Subsystem
• Command Loader (commands/index.ts)
• Notify/Problem Command (commands/notify/problem.ts)
d. Events Subsystem
• Ready Handler
• Interaction Handler
e. Google Authentication Service
• OAuth flow modules in auth/google-auth.ts
• External Google APIs (Sheets, Drive, etc.)
f. Types Module (TypeScript interfaces, shared contracts)
g. Deployment Target
• Docker container
• Bun runtime
Relationships and Data Flows
• index.ts → initializes Discord client and HTTP server
• deploy-command.ts → on startup, registers slash commands with Discord
• Discord Gateway → emits “ready” and “interactionCreate” events → caught by events subsystem
• interactionCreate → routes to command handler via commands/index.ts → notify/problem → calls GoogleAuth → fetches next-week problems → returns data
• notify/problem → sends message payload back to Discord through the client
• healthCheck.ts → listens on a port; external load-balancer or k8s probes hit this endpoint
Architectural Patterns & Principles
• Modular separation (commands vs. events vs. auth vs. types)
• Single Responsibility Principle: each file/folder has one concern
• Asynchronous event-driven flow (Discord.js events driving business logic)
• Minimal external dependencies (only Docker, Bun, Discord.js, Google API)