# copier-org/copier architecture

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

## Overview

##### Core Components
- CLI / Entry Point: The project exposes a command‐line interface (see copier/cli.py and copier/__main__.py). This component handles user inputs and invokes the main template-rendering routines.
- Core Engine: This is represented by copier/main.py that ties the project’s functions together. It coordinates reading configurations, rendering templates (copier/template.py), and managing overall execution.
- Template Rendering & Questionnaire Modules: Templates, questionnaires, and settings are core concepts. The copier/template.py, copier/settings.py, and copier/user_data.py modules capture the logic for reading configuration (copier.yml) in templates, posing questions to the user, and rendering template files (often with Jinja extensions; see copier/jinja_ext.py).
- Error & Tools Handling: With dedicated modules like copier/errors.py and copier/tools.py, separate these as utility components that support the primary workflow.

##### Interactions and Data Flow
- From the CLI, indicate calls to the “Core Engine” where configurations and template data are loaded.
- The “Core Engine” should interact with “Questionnaire & Settings” to prompt for or extract required answers.
- Then, illustrate the Workflow: Core Engine → Template Renderer → (Jinja Extensions for file templating) → File System operations (generating/updating a project).
- Integration with VCS: When copying templates, the engine might consult the “VCS Integration” component to handle repositories accessed by Git URL.

##### Architectural Patterns and Design Aspects
- Separation of Concerns: Clearly distinguish modules handling user interaction (CLI), core logic (main/template engine), configuration (settings and user data), and utilities (tools and error handling).
- Reusability: Emphasize that the same code path is used when invoking through a CLI command or programmatically through functions like run_copy.

##### Relevant Technologies and Frameworks
- Python 3.9+: The entire project runs on Python, and mypy static typing is enabled (py.typed).
- Jinja2: This is used for templating as indicated by the copier/jinja_ext.py file and usage in example template files in the tests directory.
- Git: Integration through VCS modules implies usage of Git (and possibly other source control systems).

- Do not over-simplify: Even though having many components might seem complex, in this case it is best to represent all modules (like copier/settings.py, copier/user_data.py, copier/subproject.py, etc.) as nodes that contribute to the overall template rendering process.
- Grouping related modules into larger blocks (for instance, group all “Template & Questionnaire” related modules together).

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% High-level entities
    U["User"]:::cli

    %% Interface Layer
    subgraph "Interface Layer"
        CLI1["CLI - Entry (copier/cli.py)"]:::cli
        CLI2["CLI - Entry (copier/__main__.py)"]:::cli
        API["Programmatic API Usage"]:::cli
    end

    %% Core Processing
    CoreEngine["Core Engine"]:::core

    %% Template Processing Subgraph
    subgraph "Template Processing"
        TemplateRenderer["Template Renderer"]:::module
        JinjaExtensions["Jinja Extensions"]:::module
        FilesystemOps["File System Operations"]:::module
    end

    QSettings["Questionnaire & Settings"]:::module
    VCSIntegration["VCS Integration"]:::integration

    %% Utilities Subgraph
    subgraph "Utilities"
        ErrorHandling["Error Handling Utilities"]:::utility
        ToolsUtilities["Tools Utilities"]:::utility
    end

    %% Data Flow Connections
    U --> CLI1
    U --> CLI2
    U --> API
    CLI1 --> CoreEngine
    CLI2 --> CoreEngine
    API --> CoreEngine

    CoreEngine --> TemplateRenderer
    TemplateRenderer --> JinjaExtensions
    JinjaExtensions --> FilesystemOps

    CoreEngine --> QSettings
    CoreEngine --> VCSIntegration
    CoreEngine --> ErrorHandling
    CoreEngine --> ToolsUtilities

    %% Click Events for Component Mapping
    click CLI1 "https://github.com/copier-org/copier/blob/master/copier/cli.py"
    click CLI2 "https://github.com/copier-org/copier/blob/master/copier/__main__.py"
    click CoreEngine "https://github.com/copier-org/copier/blob/master/copier/main.py"
    click TemplateRenderer "https://github.com/copier-org/copier/blob/master/copier/template.py"
    click QSettings "https://github.com/copier-org/copier/blob/master/copier/settings.py"
    click QSettings "https://github.com/copier-org/copier/blob/master/copier/user_data.py"
    click JinjaExtensions "https://github.com/copier-org/copier/blob/master/copier/jinja_ext.py"
    click VCSIntegration "https://github.com/copier-org/copier/blob/master/copier/vcs.py"
    click ErrorHandling "https://github.com/copier-org/copier/blob/master/copier/errors.py"
    click ToolsUtilities "https://github.com/copier-org/copier/blob/master/copier/tools.py"

    %% Styles
    classDef cli fill:#b3e5fc,stroke:#0277bd,stroke-width:2px;
    classDef core fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef module fill:#fff9c4,stroke:#fbc02d,stroke-width:2px;
    classDef integration fill:#d1c4e9,stroke:#512da8,stroke-width:2px;
    classDef utility fill:#ffcdd2,stroke:#c62828,stroke-width:2px;
```
