# shivamguys/irctc-cypress-automation architecture

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

- Interactive diagram: https://gitdiagram.com/shivamguys/irctc-cypress-automation
- Repository: https://github.com/shivamguys/irctc-cypress-automation

## Overview

This project is an automation tool for booking IRCTC tatkal tickets using Cypress for end-to-end browser automation and a Python-based captcha solver that leverages EasyOCR models. The overall purpose is to simulate user interactions on the IRCTC website—including login, form filling (with multiple passengers), captcha handling, and even payment steps—while bypassing the captcha through server-side image processing.

##### Main Components
- Cypress Test Runner:
- Located in the "cypress" folder: contains tests (under e2e), fixtures (passenger_data.json), support files for custom commands, and configuration scripts (cypress.config.js and cypress.env.json).
- This component handles the simulation of user actions, verification, and orchestration of the ticket booking workflow.

- Python Captcha Solver Server:
- Found under "irctc-captcha-solver" (and a duplicate copy in "irctc-captcha-solve-server", showing support for Python caching).
- Contains app-server.py and requirements.txt, running a server that exposes an endpoint (/extract-text) for solving captchas using OCR (with EasyOCR, along with related model files like craft_mlt_25k.pth and english_g2.pth).

- OCR Model Component:
- Represented by the EasyOCR folder and its model files within the captcha solver.
- Acts as a helper library to process and extract text from images.

- External IRCTC Web System:
- Although not part of the repository, the automation targets the IRCTC website.

- CI/CD Pipeline:
- Utilizes GitHub Actions workflows defined under the ".github/workflows" directory (e.g., irctc.yml) for automated testing or deployment processes.

##### Relationships and Interactions
- The Cypress Test Runner drives the browser automation:
- It loads configuration and test data (from "cypress.env.json" and "cypress/fixtures/passenger_data.json").
- Directs the workflow for logging in and booking tickets on the IRCTC web interface.
- When a captcha needs to be solved:
- The Cypress tests make an API request to the Python Captcha Solver Server (running on localhost) by posting the base64 string of the captcha image.
- The Python Captcha Solver Server calls upon the OCR Model Component (EasyOCR with its pre-trained models) to process the image and extract text.
- The response (captcha text) is then sent back to the Cypress tests so that the automation can proceed with the correct captcha code.
- A CI/CD pipeline ensures that the tests are automatically triggered and the components work as expected.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- Browser automation is fully separated from captcha processing. The Cypress tests focus on user interaction, while the Python server specializes in OCR.
- Modularization:
- Configuration files (JSON), test scripts, and server scripts are all separated into dedicated directories.
- External Integration:
- Clear dependency on external systems such as NodeJS for Cypress and Python for OCR processing.

- "Cypress Test Runner" (with sub-components: Test Scripts, Fixtures, and Configurations).
- "Python Captcha Solver Server" (include labels for app-server.py, endpoint /extract-text).
- "OCR Engine (EasyOCR)" (along with model files like craft_mlt_25k.pth and english_g2.pth).
- "IRCTC Website" (as the target web interface for booking).
- "CI/CD Pipeline" (representing GitHub Actions triggered by the .github/workflows configuration).

- From Cypress Test Runner to the IRCTC Website showing user interaction.
- From the Cypress Test Runner to the Python Captcha Solver Server when requesting captcha text.
- From the Python Server to the OCR Engine for image processing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD Pipeline
    CI["CI/CD Pipeline"]:::ci

    %% Cypress Test Runner Components
    subgraph "Cypress Test Runner"
        TS["Test Scripts"]:::frontend
        F["Fixtures"]:::frontend
        CC["cypress.config.js"]:::frontend
        CE["cypress.env.json"]:::frontend
        SC["Support Commands"]:::frontend
        SE["Support E2E"]:::frontend
    end

    %% External IRCTC Website
    IRCTC["IRCTC Website"]:::external

    %% Python Captcha Solver Server Components
    subgraph "Python Captcha Solver Server"
        PS["app-server.py"]:::backend
        PR["requirements.txt"]:::backend
    end

    %% OCR Engine Components (EasyOCR)
    subgraph "OCR Engine (EasyOCR)"
        O1["craft_mlt_25k.pth"]:::ocr
        O2["english_g2.pth"]:::ocr
    end

    %% Connections
    CI -->|"triggers"| TS
    TS -->|"user_action"| IRCTC
    TS -->|"captcha_request"| PS
    PS -->|"calls_OCR"| O1
    PS -->|"calls_OCR"| O2
    PS -->|"captcha_response"| TS

    %% Click Events
    click TS "https://github.com/shivamguys/irctc-cypress-automation/blob/main/cypress/e2e/irctc.cy.js"
    click F "https://github.com/shivamguys/irctc-cypress-automation/blob/main/cypress/fixtures/passenger_data.json"
    click CC "https://github.com/shivamguys/irctc-cypress-automation/blob/main/cypress.config.js"
    click CE "https://github.com/shivamguys/irctc-cypress-automation/blob/main/cypress.env.json"
    click SC "https://github.com/shivamguys/irctc-cypress-automation/blob/main/cypress/support/commands.js"
    click SE "https://github.com/shivamguys/irctc-cypress-automation/blob/main/cypress/support/e2e.js"
    click PS "https://github.com/shivamguys/irctc-cypress-automation/blob/main/irctc-captcha-solver/app-server.py"
    click PR "https://github.com/shivamguys/irctc-cypress-automation/blob/main/irctc-captcha-solver/requirements.txt"
    click O1 "https://github.com/shivamguys/irctc-cypress-automation/blob/main/EasyOCR/craft_mlt_25k.pth"
    click O2 "https://github.com/shivamguys/irctc-cypress-automation/blob/main/EasyOCR/english_g2.pth"
    click CI "https://github.com/shivamguys/irctc-cypress-automation/blob/main/.github/workflows/irctc.yml"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#F08080,stroke:#000,stroke-width:2px;
    classDef external fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef ci fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef ocr fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
