# pre-tesh/cph architecture

> Architecture diagram of the GitHub repository pre-tesh/cph, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pre-tesh/cph
- Repository: https://github.com/pre-tesh/cph

## Overview

##### Main Components
- VS Code Extension Host: The extension’s entry point is in src/extension.ts where commands are registered and activated.
- Core Functionality Modules: These include components such as:
- Compilation (src/compiler.ts)
- Execution and Judging (src/executions.ts, src/judge.ts, src/runTestCases.ts)
- Parsing & Testcase Handling (src/parser.ts)
- Preferences/Configuration (src/preferences.ts, src/config.ts)
- Telemetry (src/telmetry.ts)
- UI/Webview Components:
- These are under src/webview, including JudgeView.ts and webview/frontend (with React components like App.tsx and CaseView.tsx) for displaying results and interacting with the user.
- Testing Infrastructure:
- Located in src/tests and configuration in jest.config.js.
- External Integration Layers:
- Integration with external tools such as Competitive Companion for testcase downloads.
- Optional integrations for auto-submit with platforms like CodeForces and Kattis, referenced both in the README and in companion modules.

##### Relationships and Data Flow
- The Extension Host (src/extension.ts) acts as the central orchestrator that listens for user commands (e.g., running testcases via keyboard shortcuts).
- Upon activation, it delegates tasks to the core modules:
- When a user triggers “Run Testcases”, commands flow to the Compiler (src/compiler.ts) and then the Execution and Judging modules (src/executions.ts, src/judge.ts).
- The Parser (src/parser.ts) processes testcases that are either downloaded (from Competitive Companion) or provided locally.
- Simultaneously, telemetry events are recorded (src/telmetry.ts) and sent out or logged based on user preferences.
- For interactive user experiences, certain actions spawn a webview:
- The webview frontend (React-based, e.g., App.tsx) receives data from backend processes, updates the UI, and provides feedback (e.g., through src/webview/JudgeView.ts).

##### Architectural Patterns and Design Principles
- Modularity: The system splits core functions (compilation, judging, parsing) into individual modules.
- Separation of Concerns: There’s a clear separation between the extension’s backend logic and its frontend (webview) components.
- Event-Driven Architecture: The extension reacts to commands (keyboard shortcuts, file events) and calls appropriate modules which then propagate results to the UI.
- Integration Patterns: External integrations (Competitive Companion, CodeForces auto-submit) are handled in discrete modules, making it easier to understand their points of interaction.

##### Relevant Technologies and Frameworks
- TypeScript is used throughout the project (indicated by tsconfig.json and .ts files).
- The frontend leverages React (as evident from App.tsx and the overall structure within src/webview/frontend).
- Testing is conducted using Jest (see jest.config.js and src/tests).
- Build and bundling are managed by Webpack (webpack.config.js and webpack.frontend.config.js).
- Tooling used for quality and formatting include ESLint and Prettier.

##### Additional Detail
- Stress the importance of noting event triggers (e.g., keyboard shortcuts, browser events from Competitive Companion) that initiate the flow.
- Document any error handling or telemetry capturing steps—this might include a note that the telemetry module (src/telmetry.ts) monitors key events and relays analytics data.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Core Backend Modules"
        EH("VS Code Extension Host (extension.ts)"):::backend
        CM("Compiler Module (compiler.ts)"):::backend
        EJ("Executor/Judge Module (executions.ts, judge.ts, runTestCases.ts)"):::backend
        PT("Parser & Testcase Manager (parser.ts)"):::backend
        PC("Preferences & Config (preferences.ts, config.ts)"):::backend
        TM("Telemetry Module (telmetry.ts)"):::backend
    end

    subgraph "Webview UI"
        WB("Webview Backend UI (JudgeView.ts)"):::frontend
        WF("Webview Frontend UI (App.tsx, CaseView.tsx)"):::frontend
    end

    subgraph "External Integrations"
        EI("External Integration (Competitive Companion & Auto-submit)"):::integration
    end

    subgraph "Testing & Configuration"
        TI("Testing Infrastructure (tests & jest.config.js)"):::testing
    end

    %% Core flow
    EH -->|"registersCommand"| CM
    EH -->|"triggersExecution"| EJ
    EH -->|"invokesParsing"| PT
    EH -->|"loadsConfig"| PC
    EH -->|"logsTelemetry"| TM

    CM -->|"passesOutput"| EJ
    EJ -->|"sendsResults"| WB
    WB -->|"updates"| WF

    EH -->|"requestsIntegration"| EI
    EI -->|"providesTestcases"| PT

    TI -->|"runsTestsOn"| EH

    %% Styling Classes
    classDef backend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef frontend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef integration fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef testing fill:#D3D3D3,stroke:#000,stroke-dasharray:5,5;

    %% Click Events
    click EH "https://github.com/pre-tesh/cph/blob/main/src/extension.ts"
    click CM "https://github.com/pre-tesh/cph/blob/main/src/compiler.ts"
    click EJ "https://github.com/pre-tesh/cph/blob/main/src/executions.ts"
    click EJ "https://github.com/pre-tesh/cph/blob/main/src/judge.ts"
    click EJ "https://github.com/pre-tesh/cph/blob/main/src/runTestCases.ts"
    click PT "https://github.com/pre-tesh/cph/blob/main/src/parser.ts"
    click PC "https://github.com/pre-tesh/cph/blob/main/src/preferences.ts"
    click PC "https://github.com/pre-tesh/cph/blob/main/src/config.ts"
    click TM "https://github.com/pre-tesh/cph/blob/main/src/telmetry.ts"
    click WB "https://github.com/pre-tesh/cph/blob/main/src/webview/JudgeView.ts"
    click WF "https://github.com/pre-tesh/cph/blob/main/src/webview/frontend/App.tsx"
    click WF "https://github.com/pre-tesh/cph/blob/main/src/webview/frontend/CaseView.tsx"
    click EI "https://github.com/pre-tesh/cph/blob/main/src/companion.ts"
    click EI "https://github.com/pre-tesh/cph/blob/main/src/submit.ts"
    click TI "https://github.com/pre-tesh/cph/tree/main/src/tests"
    click TI "https://github.com/pre-tesh/cph/blob/main/jest.config.js"
```
