How quangngonz/mini_cs50x_answer_api works
Main Components
• API Server (Express Application)
• Entry point: index.js
• Controllers: Handle endpoints for adding hints, getting questions, ranking, team-related actions, and answer submissions.
• Middleware: Authentication (authenticate.js) that intercepts requests requiring a valid JWT.
• Database (Supabase)
• Tables include questions, teams_progress, submissions, hints_given, and team_info.
• Utility Scripts
• Scripts such as pushQuestions.js, pushTeams.js, and randomTeamResults.js for seeding and simulating progress.
• Swagger Documentation
• Publicly available API documentation (swagger.html and swagger.json) to interact with the API.
• Deployment Configuration
• Vercel configuration (vercel.json) indicates a serverless deployment model.
Out Relationships and Interactions
• Requests from clients hit index.js which routes them to appropriate controllers based on HTTP methods and endpoints.
• Each controller handles request-specific logic (input validation, answer checking, hint processing) and communicates with Supabase via the supabaseService.js.
• The authentication middleware verifies and parses JWT tokens before protected controllers (e.g., get-team-name) process the request.
• Utility scripts are run externally (or as part of initial seed processes) to populate or simulate data in Supabase.
• Swagger UI (served from the public folder) provides an interactive interface for exploring API endpoints; it references the auto-generated swagger.json.
Architectural Patterns / Design Principles
• Separation of concerns: Distinct directories for controllers, middleware, services, and utilities keep business logic, authentication, database access, and support scripts modular.
• RESTful design: Endpoints are clearly defined (GET, POST) with predictable responses.
• Middleware pattern: Authentication middleware intercepts requests for protected endpoints.
• Externalized configuration: Environment variables (via .env) and vercel.json for deployment make the application highly configurable.
• Documentation-first: Integrated Swagger docs for developer accessibility and testing.
Relevant Technologies
• Node.js, Express for the server and routing.
• Supabase for cloud database interactions.
• JWT (JSON Web Tokens) for authentication.
• Swagger for API documentation.
• Vercel for serverless deployment.
• Utility libraries (e.g., moment for time handling) for business logic.