# mori-yang/create-mori architecture

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

## Overview

##### Main Components
a. CLI Entry Point – The tool’s execution starts at the entry point (index.ts) where command-line arguments (e.g., which template to generate) are parsed. This component handles invoking the appropriate functions based on user inputs.
b. Core Engine/Template Generator – The “common” folder contains modules like constant.ts, create-template.ts, and utils.ts that likely implement the core logic for processing and performing global replacements in files. This is the heart of the template creation logic.
c. Template Repository – The “templates” directory is extensive and structured into subfolders (such as eslint-plugin, npm-package, and various Vite-React combinations). Each subfolder contains the template’s own configuration files (like package.json, tsconfig.json, build.config.ts, etc.), source files, and additional assets. This repository represents the vault of predefined project layouts that the generator can scaffold.
d. Configuration and Metadata – Files such as package.json, eslint.config.mjs, and supported-templates.ts provide metadata about the project, configuration for linting and building, and a mapping of the templates that are supported. These are essential for ensuring that both the CLI and the generator engine behave correctly according to the chosen template type.

##### Relationships and Interactions
- The CLI component accepts user commands and, based on the selected template (via parameters like “-t” or aliases such as “ve” for vscode-extension), directs the flow to the core engine.
- The core engine then loads the corresponding template from the Template Repository. It leverages utility functions in the “common” folder to adjust template-specific details (like performing global text replacement for placeholders such as [name] and [repo]).
- The Template Repository is organized by template type, so it can be viewed as a collection of “blueprints” that the engine instantiates.
- Configuration files ensure that linting, build behavior, and project-specific settings are consistently applied across the generated projects.

##### Architectural Patterns and Principles
- Modularity: The project cleanly separates concerns by isolating the CLI, core engine, and template definitions in different parts of the directory structure.
- Template-based Scaffolding: The engine is built around a template mechanism where templates are stored as standalone project directories, enabling easy expansion and maintenance.
- Reusability: Shared logic in the “common” directory demonstrates DRY principles for tasks like text replacement and template building.

##### Detailed Component Breakdown
- CLI Entry (index.ts): Initiates the application; receives user input and passes template parameters.
- Core Logic (common directory): Contains shared functionality such as templating logic, global text replacement for placeholders, and utility functions.
- Templates (templates directory): Represents multiple supported project templates (e.g., for ESLint plugins, packages, and various React template variants). Emphasize how each sub-template itself can have its internal structure (src, assets, config files) that reflects a mini-application architecture.
- Auxiliary Configuration: Files like package.json and ESLint configuration ensure that both the CLI tool itself and the generated projects adhere to proper standards.

## Diagram (Mermaid)

```mermaid
flowchart TD
    user["User Input"]:::user

    subgraph "CLI Layer"
        cli["CLI Entry Point (index.ts)"]:::cli
    end

    subgraph "Core Engine"
        engine["Core Engine/Template Generator (common)"]:::engine
    end

    subgraph "Template Repository"
        repo["Template Repository (templates)"]:::repo
    end

    subgraph "Configuration and Metadata"
        conf1["package.json (root)"]:::config
        conf2["eslint.config.mjs (root)"]:::config
        conf3["supported-templates.ts (root)"]:::config
    end

    user -->|"input"| cli
    cli -->|"invokes"| engine
    engine -->|"loads template"| repo
    repo -->|"updates/processes"| engine

    conf1 ---|"provides config"| cli
    conf1 ---|"influences"| engine
    conf2 ---|"provides linting config"| cli
    conf2 ---|"influences"| engine
    conf3 ---|"maps templates"| engine

    classDef user fill:#E1F5FE,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef cli fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef engine fill:#C1E1C1,stroke:#333,stroke-width:2px;
    classDef repo fill:#FFECB3,stroke:#333,stroke-width:2px;
    classDef config fill:#F8D7DA,stroke:#333,stroke-width:2px;

    click cli "https://github.com/mori-yang/create-mori/blob/master/index.ts"
    click engine "https://github.com/mori-yang/create-mori/tree/master/common/"
    click repo "https://github.com/mori-yang/create-mori/tree/master/templates/"
    click conf1 "https://github.com/mori-yang/create-mori/blob/master/package.json"
    click conf2 "https://github.com/mori-yang/create-mori/blob/master/eslint.config.mjs"
    click conf3 "https://github.com/mori-yang/create-mori/blob/master/supported-templates.ts"
```
