# aman-v114/as_tds_2 architecture

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

- Interactive diagram: https://gitdiagram.com/aman-v114/as_tds_2
- Repository: https://github.com/aman-v114/as_tds_2

## Overview

##### Main Components
- API Layer:
- A Flask server (/api/app.py) that exposes the /api/ endpoint.
- The entry point for handling POST requests which may include question strings and an optional file upload.
- Question Processing and Matching:
- A component (within the API route) that receives the question and, if provided, a file.
- The logic that processes and optionally uploads files (the "file processing" functionality, likely residing in the utils/file_process.py).
- The question matching module (located in utils/question_matching.py and utils/question_matching_regex.py) that applies cosine similarity to compare the incoming question to a set of predefined questions (stored in data/questions.json).
- Parameter Extraction:
- A component (in utils/openai_api.py and utils/function_definations_llm.py) that interacts with the OpenAI API to extract parameters needed by the matched function.
- Solution Functions:
- A set of solution functions (within utils/solution_functions.py) that are associated with specific questions. This part triggers the appropriate function call (e.g., vs_code_version, send_http_request) based on the matching result.
- Response Generation:
- The final step in the API that returns the answer as a JSON response.
- Infrastructure/Deployment Elements:
- Dockerfile, Procfile, and environment files (.env.example) indicate containerization and possibly orchestration for the deployment environment.
- Test suite (tests/test_api.py) to validate the API behavior.

##### Relationships and Data Flow
- From the /api/ entry point, the request is forwarded to the file processing block (if a file is included) and then to the Question Matching component.
- The Question Matching component consults the JSON data file and then calls the Parameter Extraction module.
- After parameters are extracted, the flow goes to the appropriate Solution Function which then generates the answer.
- Finally, the API sends this answer back to the client.

##### Architectural Patterns/Design Principles
- Separation of Concerns: Distinct modules for handling API routing, file processing, question matching, parameter extraction, and executing solution functions.
- Use of External Services: Incorporates the OpenAI API for parameter extraction.
- Modularity: The code is organized across several directories (api, utils, data, tests) which allows for easy extension with more functionality.
- Testing and Deployment: Presence of a tests folder for unit tests, Dockerfile and Procfile indicate readiness for container deployment and scaling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    A["User / Client"]:::client

    %% API Server
    B["Flask Server (/api/app.py)"]:::server

    %% Internal Processing Modules within API
    C["File Processing (utils/file_process.py)"]:::module
    D["Question Matching Module"]:::module
    D1["Primary Matching (utils/question_matching.py)"]:::module
    D2["Regex Matching (utils/question_matching_regex.py)"]:::module
    E["Questions Data (data/questions.json)"]:::database
    F["Parameter Extraction Module"]:::module
    F1["OpenAI API Integration (utils/openai_api.py)"]:::module
    F2["Function Definitions for LLM (utils/function_definations_llm.py)"]:::module
    G["Solution Function Executor (utils/solution_functions.py)"]:::module
    H["JSON Response"]:::module

    %% Deployment & Testing Subgraph
    subgraph "Deployment & Testing"
        I["Dockerfile"]:::external
        J["Procfile"]:::external
        K["Environment Config (.env.example)"]:::external
        L["Testing Suite (tests/test_api.py)"]:::external
    end

    %% Flow
    A -->|"sends HTTP request"| B
    B -->|"if file provided"| C
    B -->|"receives question"| D
    C -->|"processed file"| D
    D -->|"uses cosine similarity"| D1
    D -->|"uses regex"| D2
    D1 ---|"fetches questions"| E
    D2 ---|"fetches questions"| E
    D -->|"matched question"| F
    F -->|"calls OpenAI for params"| F1
    F -->|"loads function defs"| F2
    F -->|"extracts parameters"| G
    G -->|"executes solution"| B
    B -->|"returns answer"| H
    H -->|"sends JSON response"| A

    %% Deployment & Testing Support (dotted connections to API Server)
    I ---|"containerizes"| B
    J ---|"manages process"| B
    K ---|"configures API keys"| B
    L ---|"validates service"| B

    %% Click Events
    click B "https://github.com/aman-v114/as_tds_2/blob/main/api/app.py"
    click C "https://github.com/aman-v114/as_tds_2/blob/main/utils/file_process.py"
    click D1 "https://github.com/aman-v114/as_tds_2/blob/main/utils/question_matching.py"
    click D2 "https://github.com/aman-v114/as_tds_2/blob/main/utils/question_matching_regex.py"
    click E "https://github.com/aman-v114/as_tds_2/blob/main/data/questions.json"
    click F1 "https://github.com/aman-v114/as_tds_2/blob/main/utils/openai_api.py"
    click F2 "https://github.com/aman-v114/as_tds_2/blob/main/utils/function_definations_llm.py"
    click G "https://github.com/aman-v114/as_tds_2/blob/main/utils/solution_functions.py"
    click I "https://github.com/aman-v114/as_tds_2/tree/main/Dockerfile"
    click J "https://github.com/aman-v114/as_tds_2/tree/main/Procfile"
    click K "https://github.com/aman-v114/as_tds_2/blob/main/.env.example"
    click L "https://github.com/aman-v114/as_tds_2/blob/main/tests/test_api.py"

    %% Styles
    classDef client fill:#FFEA8A,stroke:#333,stroke-width:2px;
    classDef server fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef module fill:#A9DFBF,stroke:#333,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef external fill:#D7BDE2,stroke:#333,stroke-width:2px;
```
