How maanassehgal/codeforces-lite works
Project type and purpose
• Codeforces Lite is a browser extension (Chrome, Firefox, Edge, Brave) that augments the Codeforces website with an embedded code editor, UI tweaks, theming, and an integrated “run code” execution pipeline.
File structure
• Top-level:
• package.json, build configs (vite.config.ts, webpack.config.ts, tsconfig*), README, manifest files under public.
• src/ contains the React/TypeScript app:
– main UI (App.tsx, main.tsx, components/*)
– option page UI under components/options/*
– global state (src/zustand/useCFStore.ts)
– utilities: DOM helpers, theme utils, storage/submission services, custom hooks.
• themes/ houses JSON theme definitions loaded at runtime.
README for additional insights
• Core features: Monaco editor embedded in page, test-run via external API, code storage, dark-theme customizer, UI improvements, options page, local persistence, and theming.
• Architecture implicitly: content scripts inject the sidebar, React mounts into it, service worker handles background tasks (e.g. persistent extension events), storageService abstracts browser storage, submissionService orchestrates HTTP calls to Sulu API.
a. Main components
1. Browser Host
• Extension Manager / Browser runtime
• Background/service worker (public/serviceWorker.js)
• Content scripts (public/assets/scripts/*.js + content.js + extractTestcases.js)
2. In-Page Sidebar UI
• sidebar.html / sidebar.js stub
• React app bundle (App.tsx → dist/js)
• Monaco Editor component
3. Options Page UI
• options HTML + React components under src/components/options
4. State & Data Layer
• Zustand store (useCFStore)
• storageService (sync chrome.storage or localStorage)
• Queue.ts for eviction logic
5. External Services
• Code execution API (Sulu platform) via submissionService
• Possible analytics / usageDataHelper
6. Theming & Assets
• themes JSON files
• CSS pipeline (Tailwind, PostCSS)
b. Relationships & interactions
• Content script scans problem page DOM → extracts metadata (problem name, testcases) → injects sidebar container.
• Sidebar UI mounts React; user writes code → React state updates Zustand store → storageService persists code.
• On “Run” user action → submissionService sends HTTP request to external API → receives compilation/execution results → React UI displays results.
• Dark theme toggle and theme selection → themeUtils + CSS classes applied across components.
• Options page shares the same state/services but scoped to extension’s settings UI.
• Background/service worker handles long-lived events (e.g. alarm, cross-component messaging) if needed.
c. Architectural patterns & principles
• MV* front-end: React components (View), Zustand store (State), services/hooks (Controller/Model).
• Sidebar and options page as two separate “micro-apps” sharing common code.
• Separation of concerns:
• DOM extraction (utils/dom)
• Business logic (hooks, services)
• Presentation (components)
• Modular theming: JSON theme files + themeUtils loader.
d. Key technologies & frameworks
• React + TypeScript
• Vite (or Webpack) build pipeline
• Monaco Editor
• Zustand for state management
• Chrome/Firefox Extension APIs (manifest v3, serviceWorker)
• Tailwind CSS / PostCSS