# suyash-purwar/hackerrank-vscode architecture

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

- Interactive diagram: https://gitdiagram.com/suyash-purwar/hackerrank-vscode
- Repository: https://github.com/suyash-purwar/hackerrank-vscode

## Overview

##### Project's Main Components
- VS Code Extension Interface: This is the entry point (src/extension.ts) that integrates the extension into the VS Code ecosystem.
- Challenge and API Handling Modules: Include modules such as Challenge.ts, ChallengesProvider.ts, Hackerrank.ts, and Database.ts. These components interact with HackerRank’s internal endpoints—fetching challenges, processing protected routes, and managing API requests.
- Template Rendering: Represent the use of EJS templates (in src/templates) that are rendered to display challenge details, submission results, run outputs, and compilations.
- Utility Functions: Include the API poller (src/utils/apiPoller.ts) which likely manages periodic API calls for status updates.
- Local Data Management: Illustrate how user data (tokens, cookies, and solution files) are saved locally in the .hackerrankrc and the folder structure under the user’s configuration directory.

##### Relationships and Interactions
- First, a GET request to obtain CSRF token and cookies.
- Then, a POST request (with the CSRF token and user credentials) to log in.
- Dual-token mechanism (initially received and then updated post-login) in the flow.
- API-handling modules with the challenge rendering process:
- The ChallengesProvider fetches challenges from HackerRank.
- Challenge and Language modules transform this data into a format for VS Code.
- That the Template Renderer takes API data and uses EJS templates (for challenges, submissions, etc.) to display the content.
- File system branch where solution codes and user data (defined in the README) are stored (e.g., inside the hackerrank folder with .hackerrankrc and user directories).

##### Architectural Patterns and Design Principles
- Modular Design: Emphasize the separation of concerns by showing distinct modules (authentication, challenges, templating, utilities) and their interfaces (note the ‘src/modules/interface’ with type definitions).
- Template-Based Rendering: Indicate the use of EJS templates to create a clear separation between data handling and user presentation.
- Local Storage Management: Note the pattern where configuration (.hackerrankrc) and solution files are maintained within a structured file system.

##### Relevant Technologies, Frameworks, and Libraries
- TypeScript is the main language used (tsconfig.json present).
- VS Code Extension API – since the project is built as a VS Code extension.
- EJS templating for rendering challenge and submission views.
- Node.js and NPM (indicated by package.json and package-lock.json) for dependency management.
- ESLint and Prettier are used for code quality.
- Git for version control, as seen by .gitignore.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side Subgraph
    subgraph "Client Side"
        VSExt("VS Code Extension (UI)"):::client
        Auth("Authentication Module"):::client
        Temp("Template Renderer"):::template
        Local("Local Data Manager (.hackerrankrc & Solutions)"):::client
        Poller("API Poller Utility"):::utility
        Interfaces("Module Interfaces (Type Definitions)"):::utility
    end

    %% External Services Subgraph
    subgraph "External Integration"
        HGateway("((HackerRank API Gateway))"):::external
        HHandler("HackerRank API Handler"):::external
        ChallengesProvider("Challenges Provider"):::external
        ChallengeManager("Challenge Manager"):::external
        DB("Database Module"):::external
        Lang("Language Handling Module"):::external
    end

    %% Flow: User Login and API Auth Flow
    VSExt -->|"InitiatesLogin"| Auth
    Auth -->|"GET:LoginPage+CSRF"| HGateway
    HGateway -->|"Response:CSRF/Cookies"| Auth
    Auth -->|"POST:UserAuth"| HGateway
    HGateway -->|"AuthSuccess"| Auth
    Auth -->|"StoreTokens"| Local

    %% Flow: Challenge Retrieval & Rendering
    Auth -->|"FetchChallenges"| ChallengesProvider
    ChallengesProvider -->|"APIcall"| HHandler
    HHandler -->|"TransformData"| ChallengeManager
    ChallengeManager -->|"ParseLanguage"| Lang
    ChallengesProvider -->|"StoreData"| DB
    ChallengesProvider -->|"RenderChallenges"| Temp
    Temp -->|"DisplayResults"| VSExt

    %% Auxiliary: API Poller monitors external API
    Poller -->|"Poll:APIStatus"| HGateway

    %% Module Interfaces (Type Definitions) integration
    Auth -->|"UsesTypes"| Interfaces
    HHandler -->|"UsesTypes"| Interfaces
    ChallengesProvider -->|"UsesTypes"| Interfaces
    ChallengeManager -->|"UsesTypes"| Interfaces
    Lang -->|"UsesTypes"| Interfaces
    DB -->|"UsesTypes"| Interfaces

    %% Click Events
    click VSExt "https://github.com/suyash-purwar/hackerrank-vscode/blob/master/src/extension.ts"
    click Auth "https://github.com/suyash-purwar/hackerrank-vscode/blob/master/src/modules/Authentication.ts"
    click ChallengesProvider "https://github.com/suyash-purwar/hackerrank-vscode/blob/master/src/modules/ChallengesProvider.ts"
    click ChallengeManager "https://github.com/suyash-purwar/hackerrank-vscode/blob/master/src/modules/Challenge.ts"
    click HHandler "https://github.com/suyash-purwar/hackerrank-vscode/blob/master/src/modules/Hackerrank.ts"
    click DB "https://github.com/suyash-purwar/hackerrank-vscode/blob/master/src/modules/Database.ts"
    click Lang "https://github.com/suyash-purwar/hackerrank-vscode/blob/master/src/modules/Language.ts"
    click Interfaces "https://github.com/suyash-purwar/hackerrank-vscode/tree/master/src/modules/interface"
    click Temp "https://github.com/suyash-purwar/hackerrank-vscode/tree/master/src/templates"
    click Poller "https://github.com/suyash-purwar/hackerrank-vscode/blob/master/src/utils/apiPoller.ts"

    %% Styles
    classDef client fill:#8FBC8F,stroke:#333,stroke-width:2px;
    classDef external fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef utility fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef template fill:#FFA07A,stroke:#333,stroke-width:2px;
```
