# molecularai/aizynthfinder architecture

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

- Interactive diagram: https://gitdiagram.com/molecularai/aizynthfinder
- Repository: https://github.com/molecularai/aizynthfinder

## Overview

##### Main components
- Core Modules:
- Chem Module: Classes for molecules, reactions, and serialization (located in aizynthfinder/chem).
- Context Module: Handles configuration, reaction expansion policies, filter strategies, scoring, and stock queries (under aizynthfinder/context). This module manages the various settings and models (neural networks or static policies) that drive the search algorithms.
- Search Module: Houses several search algorithms (MCTS, breadth-first, DFPN, retrostar) that implement retrosynthetic tree search strategies (located in aizynthfinder/search and its sub-folders). Each subdirectory corresponds to a different algorithmic approach.
- Analysis Module: Provides tools for visualizing and analyzing the reaction tree (found in aizynthfinder/analysis) and includes templates for rendering reaction trees.
- Interfaces Module: Comprises user-facing integrations including CLI (aizynthfinder/interfaces/aizynthcli.py), a GUI (aizynthfinder/interfaces/gui), and an app interface (aizynthfinder/interfaces/aizynthapp.py). This is the layer through which end-users interact with the tool.
- Tools & Utilities: Scripts for various supportive actions (like downloading data or generating stocks) in aizynthfinder/tools and utilities in aizynthfinder/utils.

- Auxiliary Components:
- Plugins: Additional customization points/extensions (in the plugins directory).
- Data/Templates: Default configuration files (in aizynthfinder/data) and documentation (in docs).
- CI/CD Infrastructure: GitHub workflows for tests, docs generation, and package publishing (in .github/workflows).
- Testing Suite: A robust test suite (in tests directory) covering each module and integration aspects.

##### Relationships and interactions
- Configuration & Setup: Show a block for “Configuration/Context” feeding into both the search module (by guiding policies, scorers, and stock queries) and core algorithm execution.
- Search Engine:
- “Retrosynthetic Search Engine” which is at the heart of the system. Inside it, indicate the different algorithms (MCTS, breadth-first, DFPN, retrostar) and show that they all operate on a central “Reaction Tree” (which can be represented as a central shared data structure).
- Link the “Chem” components to this engine to signal that molecule definitions, reactions, and serialization flow into the search process.
- Analysis & Visualization:
- An Analysis component that takes the output from the search engine (the generated reaction trees) and, using utility components (such as tree visualization templates), creates visual representations.
- External Data Dependency:
- Tools/Utility Functions: Auxiliary services (e.g., make_stock, download_public_data) which integrate with the main system for setup and maintenance tasks.

##### Architectural/Design Patterns and Technologies
- That the design leverages a modular and component-based architecture, which eases extensibility (plugins, multiple search strategies).
- Separation of concerns: Each module (e.g., chem, context, search, interfaces) has a well-defined purpose.
- Mention that the system follows a fairly layered design, where the front-end (interfaces) interacts with the business logic (search algorithms and policy components), which in turn relies on domain-specific modules (chemistry operations, scoring, and analysis).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interfaces
    subgraph "User Interfaces"
        A1["CLI"]:::interfaces
        A2["GUI"]:::interfaces
        A3["App Interface"]:::interfaces
    end

    %% Configuration/Context
    subgraph "Configuration/Context"
        B1["Configuration & Context"]:::config
    end

    %% Retrosynthetic Search Engine
    subgraph "Retrosynthetic Search Engine"
        C1["Search Module"]:::core
        C2["Chem Module"]:::core
        C3["Reaction Tree"]:::core
        subgraph "Search Strategies"
            S1["MCTS"]:::core
            S2["Breadth-First"]:::core
            S3["DFPN"]:::core
            S4["Retro*"]:::core
        end
    end

    %% Analysis & Visualization
    subgraph "Analysis & Visualization"
        D1["Analysis Module"]:::core
        DT1["Reaction Tree Analysis"]:::core
        D2["Visualization Tools"]:::core
    end

    %% Tools & Utilities
    subgraph "Tools & Utilities"
        E1["Tools"]:::utility
        E2["Utilities"]:::utility
    end

    %% Auxiliary Components
    subgraph "Auxiliary Components"
        F1["Plugins"]:::auxiliary
        F2["Data"]:::auxiliary
        F3["Templates"]:::auxiliary
        F4["CI/CD"]:::auxiliary
        F5["Testing Suite"]:::auxiliary
    end

    %% External Data
    X["External Data (Models,Stock,Templates)"]:::auxiliary

    %% Connections
    A1 -->|"triggers"| C1
    A2 -->|"triggers"| C1
    A3 -->|"triggers"| C1

    B1 -->|"configures"| C1
    X  -->|"provides_data"| B1

    C2 -->|"supplies_models"| C1

    S1 -->|"builds"| C3
    S2 -->|"builds"| C3
    S3 -->|"builds"| C3
    S4 -->|"builds"| C3
    C1 -->|"generates"| C3

    C3 -->|"analyzed_by"| D1
    C3 -->|"analyzed_by"| DT1

    E1 -->|"supports"| B1
    E2 -->|"supports"| D1

    F1 -->|"customizes"| C1
    F2 -->|"provides_defaults"| B1
    F3 -->|"supplies_templates"| D1
    F4 -->|"ensures_quality"| F5
    F5 -->|"validates"| C1

    %% Click Events
    click C2 "https://github.com/molecularai/aizynthfinder/tree/master/aizynthfinder/chem"
    click B1 "https://github.com/molecularai/aizynthfinder/tree/master/aizynthfinder/context"
    click C1 "https://github.com/molecularai/aizynthfinder/tree/master/aizynthfinder/search"
    click S1 "https://github.com/molecularai/aizynthfinder/tree/master/aizynthfinder/search/mcts"
    click S2 "https://github.com/molecularai/aizynthfinder/tree/master/aizynthfinder/search/breadth_first"
    click S3 "https://github.com/molecularai/aizynthfinder/tree/master/aizynthfinder/search/dfpn"
    click S4 "https://github.com/molecularai/aizynthfinder/tree/master/aizynthfinder/search/retrostar"
    click D1 "https://github.com/molecularai/aizynthfinder/tree/master/aizynthfinder/analysis"
    click DT1 "https://github.com/molecularai/aizynthfinder/blob/master/aizynthfinder/analysis/reactiontree.py"
    click A1 "https://github.com/molecularai/aizynthfinder/blob/master/aizynthfinder/interfaces/aizynthcli.py"
    click A2 "https://github.com/molecularai/aizynthfinder/tree/master/aizynthfinder/interfaces/gui"
    click A3 "https://github.com/molecularai/aizynthfinder/blob/master/aizynthfinder/interfaces/aizynthapp.py"
    click E1 "https://github.com/molecularai/aizynthfinder/tree/master/aizynthfinder/tools"
    click E2 "https://github.com/molecularai/aizynthfinder/tree/master/aizynthfinder/utils"
    click F1 "https://github.com/molecularai/aizynthfinder/tree/master/plugins"
    click F2 "https://github.com/molecularai/aizynthfinder/tree/master/aizynthfinder/data"
    click F3 "https://github.com/molecularai/aizynthfinder/tree/master/aizynthfinder/data/templates"
    click F4 "https://github.com/molecularai/aizynthfinder/tree/master/.github/workflows"
    click F5 "https://github.com/molecularai/aizynthfinder/tree/master/tests"

    %% Styles
    classDef interfaces fill:#f9c74f,stroke:#000,stroke-width:2px;
    classDef config fill:#f9844a,stroke:#000,stroke-width:2px;
    classDef core fill:#90be6d,stroke:#000,stroke-width:2px;
    classDef utility fill:#577590,stroke:#000,stroke-width:2px;
    classDef auxiliary fill:#7209b7,stroke:#fff,stroke-width:2px;
```
