How tan-oi/tracker works
Project Type and Core Purpose
• This is a full-stack web application that aggregates contest data from multiple competitive programming platforms (LeetCode, CodeChef, Codeforces).
• Its main functionality is to display upcoming and past contests, provide filtering options, manage bookmarks locally, and incorporate solution video links fetched both manually and via automated processes.
• The platform includes both a frontend (built with React/Vite) and a backend (built using Express.js, with Node-cron for scheduled tasks and MongoDB as the database).
Main System Components
A. Frontend (React + Vite):
• Contains all UI elements, including reusable components (contest cards, navbar, filter bar, dialogs, etc.).
• Manages client-side state with localStorage (for bookmarks and JWT authentication) and may later use state management libraries (Zustand/React-Query) as mentioned in the README.
• Interacts with the backend via RESTful APIs.
B. Backend (Express.js Server):
• Organized with a clear separation of concerns:
• Controllers: Handling API requests for contest retrieval, video addition, and admin access.
• Routes: Defining endpoints (like /contests, /leetcode, /codechef, /codeforces, /addVideo, /access).
• Services: Encapsulate business logic such as fetching contest data from external coding platforms, updating contest statuses, and integrating with the YouTube API.
• Middlewares: Includes authentication checks and other request validations (e.g., checkUser.ts for admin verification).
• Database Integration: Although not explicitly visible in the file tree, the existence of a “db.ts” file indicates connection logic (MongoDB).
• Cron Jobs: Automated scripts (found in src/scripts and services) manage periodic data fetching and updates.
C. External Services & APIs:
• Coding contest APIs on LeetCode, CodeChef, and Codeforces.
• YouTube API for fetching video links for contest solutions.
• Cron mechanism using “node-cron” for scheduled updates.
Relationships and Data Flow
• Frontend → Backend: The UI makes API calls to the backend to fetch contest lists, filtered data, and to perform admin actions such as adding video links.
• Backend → Database: The Express server reads from and writes contest data to MongoDB, while implementing security measures like JWT authentication.
• Backend → External APIs: Services in the backend periodically fetch new contest data and solution video links, with workflows initiated by cron jobs.
• User Authentication: When an admin authentically adds video links, the backend validates the secret key and issues JWT tokens, which the frontend stores and uses to maintain sessions.
Architectural Patterns & Design Principles
• Separation of Concerns: Controllers handle incoming requests, services encapsulate business logic, and middleware provides reusability (e.g., authorization).
• Layered Architecture: The system is organized into distinct layers (UI layer, API gateway, business logic, data persistence, external communication) that communicate via clear interfaces.
• Scheduled Tasks: Use of cron jobs for background processing to keep contest data up to date.
• Consistent API Design: RESTful endpoints grouped under meaningful routes (exposing contest data and admin-specific functionalities).
– Users/Clients interacting with the Frontend.
– The Frontend connecting to the Backend API.
– The Backend comprising:
• API Controllers & Routes.
• Service Layer (includes modules for contest fetching, video updates, admin access).
• Middleware (authentication, request validations).
– A separate component for the Database (MongoDB).
– External Services (Coding Contest APIs and YouTube API) connected to backend services.
– Scheduled Cron Job module triggering service updates.