# pandeyprashant123-coder/cotest architecture

> Architecture diagram of the GitHub repository pandeyprashant123-coder/cotest, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pandeyprashant123-coder/cotest
- Repository: https://github.com/pandeyprashant123-coder/cotest

## Overview

##### Project type and purpose
- This is a monorepo containing a full-stack code-analysis platform (“CoTest”).
- A Next.js-based React frontend (“client”).
- A Node.js-based API layer (Next.js API routes) with Bull/Redis queues and custom JS analysis modules.
- A Python microservice (“cotest_python”) exposing a REST API for Python code analysis.
- A standalone Node.js test harness (“Test”) for developing/testing ESLint-style plugins and rules.

##### File structure
- Top-level directories:
- client/ – Next.js frontend + API routes + Redis/Bull configuration
- cotest_python/ – Python code analyzer microservice
- Test/ – Node.js plugin/test framework for JS analyzers
- Key config files:
- client/compose.yaml, Dockerfile, .dockerignore → containerization/deployment
- client/src/pages/api/config/*.js → Redis and Bull queue setup
- cotest_python/requirements.txt → Python dependencies
- Test/eslint.config.mjs, Test/modules, Test/rules → custom ESLint-style modules & rules

##### README for additional insights
- Details how to run the client (Next.js + Redis), the Python service, and the Test harness.
- Mentions Redis as the queue backing service and how to execute code analyzers.
- Illustrates the intended “CoTest Workflow” across lexer/parser/analyzer/rules stages (conceptual).

##### Main system components & interactions
a. Frontend (client)
- Next.js React UI (pages, components)
- NextAuth authentication via pages/api/auth
- UI invokes “check” and “runtest” API routes
b. API layer (Next.js pages/api)
- Authentication middleware → NextAuth
- GitHub service (OAuth, repo fetch)
- Parser/ELOC services (calculateELOC.js, parser.js)
- Analyzer modules (customanalizer, detectCredentials, etc.)
- Bull/Redis queue → jobs enqueued for analysis
- Queue worker (in same Next.js app or separate process)
c. Python microservice
- Exposes REST endpoints (api.py)
- Implements ELOC calculation, rule engine, reviewer functionality
- Loads Python rule modules (cotest_python/rules/*.py)
- Returns JSON reports
d. Node.js Test harness
- Allows local plugin development & testing
- Uses ESLint engine and custom rule definitions

e. External Services
- Redis (job queue)
- GitHub API

##### Architectural patterns & design principles
- Modular analyzers: JS and Python rule modules are pluggable.
- Queue-based processing: decouples request handling from heavy analysis work.
- Microservices: Python analyzer runs independently of Node.js stack.
- Next.js serverless functions: thin API layer that orchestrates work.
- Separation of concerns: UI / API / Worker / Rule Engine.

- Clear labels: “Next.js UI”, “Auth (NextAuth)”, “GET/POST /get-report”, “Bull Queue”, “JS Worker”, “Python Analyzer API”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        UI["Next.js UI"]:::frontend
        Auth["Auth (NextAuth)"]:::frontend
        UI -->|"interacts with"| Auth
        UI -->|"invoke get-report & runtest"| API_Gateway
    end

    %% Server Layer
    subgraph "Server Layer (Node.js API)"
        API_Gateway["API Gateway<br/>(Next.js API Routes)"]:::api
        GetReport["GET/POST /get-report"]:::api
        RunTest["POST /runtest"]:::api
        Config["Config (Redis & Bull)"]:::api
        GitHubService["GitHub Service"]:::api
        ParserELOC["Parser/ELOC Module"]:::api
        Orchestrator["Analyzer Orchestrator"]:::api

        API_Gateway -->|"route to get-report"| GetReport
        API_Gateway -->|"route to runtest"| RunTest
        API_Gateway --> Config
        API_Gateway --> GitHubService
        API_Gateway --> ParserELOC
        API_Gateway --> Orchestrator
        API_Gateway -->|"enqueue job"| Redis
    end

    %% Redis Queue
    Redis["Redis (Bull Queue)"]:::db

    %% Worker Layer
    subgraph "Worker Layer"
        JSWorker["JS Worker"]:::worker
        JSModules["JS Analyzer Modules"]:::worker

        Redis -->|"dequeue & analyze"| JSWorker
        JSWorker --> JSModules
        JSWorker -->|"result"| API_Gateway
    end

    %% Python Microservice
    subgraph "Python Microservice" 
        PyAPI["Python Analyzer API"]:::python
        PyELOC["Python ELOC Module"]:::python
        PyReviewer["Reviewer Engine"]:::python
        PyModels["Models & Constants"]:::python
        PyRules["Python Rule Modules"]:::python

        API_Gateway -->|"HTTP request"| PyAPI
        PyAPI --> PyELOC
        PyAPI --> PyReviewer
        PyReviewer --> PyModels
        PyReviewer --> PyRules
        PyAPI -->|"JSON report"| API_Gateway
    end

    %% External Services
    ExternalGit["GitHub API"]:::external
    API_Gateway -->|"fetch repo"| ExternalGit

    %% Click Events
    click UI "https://github.com/pandeyprashant123-coder/cotest/tree/main/client/src/pages"
    click Auth "https://github.com/pandeyprashant123-coder/cotest/blob/main/client/src/pages/api/auth/[...nextauth].js"
    click GetReport "https://github.com/pandeyprashant123-coder/cotest/blob/main/client/src/pages/api/get-report.js"
    click RunTest "https://github.com/pandeyprashant123-coder/cotest/blob/main/client/src/pages/api/runtest.js"
    click Config "https://github.com/pandeyprashant123-coder/cotest/tree/main/client/src/pages/api/config"
    click GitHubService "https://github.com/pandeyprashant123-coder/cotest/blob/main/client/src/pages/api/services/GithubActions.js"
    click ParserELOC "https://github.com/pandeyprashant123-coder/cotest/blob/main/client/src/pages/api/modules/calculateELOC.js"
    click Orchestrator "https://github.com/pandeyprashant123-coder/cotest/tree/main/client/src/pages/api/services"
    click JSWorker "https://github.com/pandeyprashant123-coder/cotest/blob/main/Test/index.js"
    click JSModules "https://github.com/pandeyprashant123-coder/cotest/tree/main/Test/modules"
    click PyAPI "https://github.com/pandeyprashant123-coder/cotest/blob/main/cotest_python/api.py"
    click PyRules "https://github.com/pandeyprashant123-coder/cotest/tree/main/cotest_python/rules"

    %% Styles
    classDef frontend fill:#ccffcc,stroke:#006600,color:#003300
    classDef api fill:#cce5ff,stroke:#004080,color:#00264d
    classDef worker fill:#e6f7ff,stroke:#006d9c,color:#003f56
    classDef python fill:#ffe5cc,stroke:#cc6600,color:#803d00
    classDef db fill:#dddddd,stroke:#888888,color:#333333
    classDef external fill:#f2f2f2,stroke:#aaaaaa,color:#555555
```
