# shubhs-singh/code---flowchart architecture

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

- Interactive diagram: https://gitdiagram.com/shubhs-singh/code---flowchart
- Repository: https://github.com/shubhs-singh/code---flowchart

## Overview

##### Project Type and Purpose
- This is a web application built with Streamlit that analyzes Python code and generates visual flowcharts.
- It uses Google Gemini (Gemini 1.5 Pro) for code logic analysis, produces a structured JSON flowchart, and visualizes it using Graphviz.
- The application supports features like file upload, sample code demonstration, and downloading DOT files.

##### Analyzing the File Structure
- The top-level files include:
- README.md – Contains project overview, features, installation, and usage instructions.
- main.py – Likely the entry point for the Streamlit web application, containing both UI and backend logic.
- requirements.txt – Lists dependencies such as Streamlit, Graphviz, python-dotenv, and possibly libraries for the Gemini API integration.
- A single file (main.py) as the entry point means the project is relatively small, but the architecture should still clearly separate concerns despite the minimal file structure.

##### Key Components to Highlight
a. Frontend/UI Layer:
- Streamlit Interface: Manages user interactions.
- File Upload Widget: Accepts Python files or sample code.
- Areas: For rendering the JSON output and flowchart visualizations.
b. Backend/Processing Layer:
- Python Code Analyzer: Parses the uploaded or provided Python code to identify functions, loops, conditionals, and data flow.
- Gemini API Integration: Sends code to Google Gemini for analysis and receives a JSON-based flowchart.
- Flowchart Generator: Converts the analysis results into a DOT file and leverages Graphviz for visual rendering.
c. Configuration & Environment Management:
- Use of python-dotenv: Loads sensitive configurations such as the GEMINI_API_KEY from a .env file.
d. External Services/Dependencies:
- Google Gemini: Acts as the AI model for in-depth code analysis.
- Graphviz: Handles visualization and generation of flowchart graphics.

##### Relationships and Interactions
- The user interacts with the frontend (Streamlit UI) to either upload Python code or use sample inputs.
- On submission, the code is sent to a backend process in main.py where initial parsing occurs.
- The parsed code is forwarded to Google Gemini’s API to get a detailed, structured analysis.
- The resulting JSON is then processed to generate a corresponding DOT description.
- Graphviz is used to render the visual flowchart from the DOT file.

## Diagram (Mermaid)

```mermaid
graph TD
    A["User"]:::user
    B["Streamlit UI (File Upload & Display)"]:::frontend
    C["Python Code Analyzer"]:::backend
    D["Gemini API Integration (Google Gemini)"]:::external
    E["Config Manager (python-dotenv)"]:::backend
    F["Flowchart Generator (DOT Conversion)"]:::backend
    G["Graphviz Visualization"]:::external
    H["UI Output (Visualization & Download)"]:::frontend

    A -->|"uploads"| B
    B -->|"sendsCode"| C
    C -->|"forwardsCode"| D
    E -->|"providesConfig"| D
    D -->|"returnsJSON"| F
    F -->|"generatesDOT"| G
    G -->|"rendersFlowchart"| H

    subgraph "Project Files"
        I["Project Documentation"]:::doc
        J["Dependency Management"]:::doc
    end

    click B "https://github.com/shubhs-singh/code---flowchart/blob/main/main.py"
    click C "https://github.com/shubhs-singh/code---flowchart/blob/main/main.py"
    click D "https://github.com/shubhs-singh/code---flowchart/blob/main/main.py"
    click E "https://github.com/shubhs-singh/code---flowchart/blob/main/main.py"
    click F "https://github.com/shubhs-singh/code---flowchart/blob/main/main.py"
    click I "https://github.com/shubhs-singh/code---flowchart/blob/main/README.md"
    click J "https://github.com/shubhs-singh/code---flowchart/blob/main/requirements.txt"

    classDef user fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#FCF3CF,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
    classDef doc fill:#F5CBA7,stroke:#D35400,stroke-width:2px;
```
