# flipkart-incubator/astra architecture

> Architecture diagram of the GitHub repository flipkart-incubator/astra, 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/flipkart-incubator/astra
- Repository: https://github.com/flipkart-incubator/astra

## Overview

##### Main components
- Web API Server: Represented by the API folder. This component (using Flask) exposes endpoints and hooks into the backend scanning logic. Files like api.py, dbconnection.py, and scanstatus.py are part of this layer.
- Dashboard (Frontend): The Dashboard folder contains static assets (CSS, JavaScript) and HTML templates for the user interface where users can initiate scans and view reports.
- Vulnerability Scanning Modules: Several directories and modules (modules, core, utils, and parts of SSRFmap) implement the actual scanning logic. Each module (for SQL injection, SSRF, XSS, etc.) is encapsulated in its own Python file, making it easier to identify and modularize.
- CLI (Command Line Interface): The astra.py file (and associated command line argument handling) along with celery_app.py reflect the CLI usage for security testing.
- Task Queue and Asynchronous Job Processor: Based on the README, Celery and RabbitMQ are used. A separate "celery_app.py" indicates asynchronous scanning tasks that run off the main process.
- Supporting Utilities: The utils folder (with its configuration, logger, and email sending components) supports various auxiliary functionalities useful across multiple parts of the system.
- Deployment: Dockerfiles in the root and within SSRFmap, along with configuration files (e.g., .dockerignore, .gitignore), indicate containerization support.

##### Relationships and interactions
- The API server acts as an orchestrator that invokes various vulnerability scanning modules (from core and modules directories) based on the user’s input.
- The CLI provides another entry point to trigger scans: it directly calls into the scanning modules (through astra.py), similar to the API.
- The API and modules interact with the database (MongoDB) to store scan results and logs.
- The SSRFmap module acts in a similar fashion as a specialized component, with its own set of scanning and payload modules. It can either operate independently or integrate its findings back into the main system.

##### Architectural patterns and design principles
- Modularity: Components are clearly separated (API, Dashboard, modules, utils, SSRFmap) making it easier to isolate functionalities.
- Separation of Concerns: The structure distinguishes between user interface (Dashboard), business logic and scanning (core, modules), and system orchestration (celery_app, API).
- Asynchronous Processing: Incorporation of Celery and RabbitMQ reflects a design that handles potentially long-running scan operations asynchronously.
- Extensibility: The modular design (with individual scanning modules and separate payload definitions) supports future extensions and easier maintenance.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Dashboard_Templates["Dashboard Templates"]:::frontend
        Dashboard_Static["Dashboard Static Assets"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        WebAPI["Web API Server"]:::backend
    end

    %% CLI Interface
    subgraph "CLI Interface"
        CLI["CLI Interface"]:::cli
    end

    %% Scanning Engine
    subgraph "Scanning Engine"
        Scanning["Vulnerability Scanning Modules"]:::backend
        Utils["Supporting Utilities"]:::utils
    end

    %% SSRF Mapping Component
    subgraph "SSRF Mapping Component"
        SSRF["SSRF Mapper"]:::backend
    end

    %% Asynchronous Processing
    subgraph "Asynchronous Processing"
        TaskQueue["Task Queue & Async Processor"]:::worker
    end

    %% Database
    Database["Database (MongoDB)"]:::database

    %% Deployment & Containerization
    Deployment["Deployment & Containerization"]:::container

    %% Connections
    Dashboard_Templates -->|"initiates"| WebAPI
    Dashboard_Static -->|"interacts"| WebAPI

    WebAPI -->|"invokes"| Scanning
    WebAPI -->|"enqueues"| TaskQueue
    WebAPI -->|"integrates"| SSRF
    WebAPI -->|"logs"| Database
    WebAPI ---|"utilizes"| Utils

    CLI -->|"triggers"| Scanning
    CLI -->|"enqueues"| TaskQueue
    CLI ---|"uses"| Utils

    TaskQueue -->|"processes"| Scanning

    Scanning -->|"stores"| Database
    Scanning ---|"utilizes"| Utils

    SSRF -->|"stores"| Database

    %% Deployment relationships
    Deployment ---|"containers"| WebAPI
    Deployment ---|"containers"| CLI
    Deployment ---|"containers"| SSRF
    Deployment ---|"containers"| TaskQueue
    Deployment ---|"containers"| Database

    %% Click Events
    click WebAPI "https://github.com/flipkart-incubator/astra/blob/master/API/api.py"
    click Dashboard_Templates "https://github.com/flipkart-incubator/astra/tree/master/Dashboard/templates"
    click Dashboard_Static "https://github.com/flipkart-incubator/astra/tree/master/Dashboard/static"
    click Scanning "https://github.com/flipkart-incubator/astra/tree/master/modules/"
    click SSRF "https://github.com/flipkart-incubator/astra/blob/master/SSRFmap/ssrfmap.py"
    click CLI "https://github.com/flipkart-incubator/astra/blob/master/astra.py"
    click TaskQueue "https://github.com/flipkart-incubator/astra/blob/master/celery_app.py"
    click Database "https://github.com/flipkart-incubator/astra/blob/master/utils/db.py"
    click Utils "https://github.com/flipkart-incubator/astra/tree/master/utils/"
    click Deployment "https://github.com/flipkart-incubator/astra/tree/master/Dockerfile"

    %% Styles
    classDef frontend fill:#a4d7f5,stroke:#333,stroke-width:2px;
    classDef backend fill:#f5a4a4,stroke:#333,stroke-width:2px;
    classDef cli fill:#f5e6a4,stroke:#333,stroke-width:2px;
    classDef utils fill:#a4f5b3,stroke:#333,stroke-width:2px;
    classDef worker fill:#d7a4f5,stroke:#333,stroke-width:2px;
    classDef database fill:#f5d7a4,stroke:#333,stroke-width:2px;
    classDef container fill:#d7f5a4,stroke:#333,stroke-width:2px;
```
