# pinak3748/nox-cli architecture

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

- Interactive diagram: https://gitdiagram.com/pinak3748/nox-cli
- Repository: https://github.com/pinak3748/nox-cli

## Overview

##### Project Type and Purpose
- Nox is a command-line application (written in Go) whose sole responsibility is to generate a boilerplate web project with React, TypeScript, Tailwind CSS, Redux Toolkit, and shadcn/ui.
- It also supports future extension points like dynamic component creation and OpenAI-powered features.

##### Main Architectural Components
a. **CLI Frontend**
- `main.go` + `cmd/` folder: parses user flags (`--page`, `--version`, etc.) and routes commands to the core logic.
b. **Core Engine (“Content” Layer)**
- `content/` package: holds the logic for generating pages, prompts, slices (Redux), types—basically the scaffolding recipes.
c. **Helper/Support Packages**
- `packages/`: handles auxiliary tasks—reading/writing config (OpenAI key), dynamic component logic, page management.
d. **Template Assets & Binary Delivery**
- `binary/`: prebuilt executables for distribution.
- `buildBinary.sh`: build scripts for generating those binaries.
e. **External Services**
- (Optional) OpenAI API: used when generating AI-driven components or playground.

##### Interactions and Data Flow
1. User invokes `nox` CLI with flags.
2. **CLI Frontend** parses input, then calls the appropriate function in the **Core Engine** (e.g., `content/main.go`).
3. Engine consults **Helper Packages** to fetch or store configuration (e.g., OpenAI key via `packages/getOpenAIKey.go`).
4. Engine uses templates and generation logic (`content/*.go`) to create new files and folders in the user’s project directory.
5. If an AI feature is requested, the engine makes HTTP calls to the **OpenAI API**, retrieves generated code snippets, then incorporates them into the scaffold.
6. The new boilerplate is written to disk; CLI reports success or errors to the user.

##### Architectural Patterns & Principles
- **Modular Separation**:
- `cmd/` isolates CLI concerns (flag parsing and help text).
- `content/` isolates domain logic (scaffold definitions).
- `packages/` isolates cross-cutting concerns (config, dynamic components).
- **Single Responsibility**: Each package focuses on one aspect of generation.
- **Extensibility Points**: Clear package boundaries make it easy to add new commands (e.g., `--dynamic-component`) or services.

##### Detailed Steps to Sketch It Out
- **Helper Modules** (`packages/`)
- **Build & Distribution** (`buildBinary.sh` → `binary/`)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Entities
    User["User / Terminal"]:::external

    %% CLI Frontend
    subgraph "CLI Frontend"
        MainGo["main.go"]:::internal
        CmdRoot["cmd/root.go"]:::internal
        CmdInit["cmd/init.go"]:::internal
        CmdPageCmd["cmd/page.go"]:::internal
        CmdVersion["cmd/version.go"]:::internal
    end

    %% Core Generation Engine
    subgraph "Core Generation Engine"
        ContentMain["content/main.go"]:::internal
        ContentIndex["content/index.go"]:::internal
        ContentActions["content/actions.go"]:::internal
        ContentPrompt["content/prompt.go"]:::internal
        ContentSlices["content/slices.go"]:::internal
        ContentTypes["content/types.go"]:::internal
    end

    %% Helper Modules
    subgraph "Helper Modules"
        PkgInit["packages/init.go"]:::internal
        PkgPage["packages/page.go"]:::internal
        PkgDynComp["packages/dynamicComponent.go"]:::internal
        PkgGetKey["packages/getOpenAIKey.go"]:::internal
        PkgSetKey["packages/setOpenAIKey.go"]:::internal
    end

    %% External Services
    subgraph "External Services"
        OpenAI["OpenAI API"]:::external
    end

    %% File System
    FS["File System (Output Dir)"]:::fs

    %% Build & Distribution
    subgraph "Build & Distribution"
        BuildScript["buildBinary.sh"]:::binary
        BinMac["binary/nox_v0.1_mac_amd64"]:::binary
        BinWin["binary/nox_v0.1_windows_amd64.exe"]:::binary
    end

    %% Data Flows
    User -->|"invoke nox CLI"| MainGo
    MainGo -->|"parse flags"| ContentMain
    CmdRoot --> ContentMain
    CmdInit --> ContentMain
    CmdPageCmd --> ContentMain
    CmdVersion --> ContentMain

    ContentMain -->|"generate scaffold"| PkgInit
    ContentMain --> PkgPage
    ContentMain --> PkgDynComp
    ContentMain -->|"fetch config"| PkgGetKey
    ContentMain -->|"store config"| PkgSetKey

    ContentMain -->|"write scaffold"| FS

    ContentPrompt -->|"HTTP request to OpenAI"| OpenAI
    OpenAI -->|"AI response"| ContentPrompt

    MainGo -->|"trigger build"| BuildScript
    ContentMain -->|"include in build"| BuildScript
    BuildScript --> BinMac
    BuildScript --> BinWin

    %% Click Events
    click MainGo "https://github.com/pinak3748/nox-cli/blob/main/main.go"
    click CmdRoot "https://github.com/pinak3748/nox-cli/blob/main/cmd/root.go"
    click CmdInit "https://github.com/pinak3748/nox-cli/blob/main/cmd/init.go"
    click CmdPageCmd "https://github.com/pinak3748/nox-cli/blob/main/cmd/page.go"
    click CmdVersion "https://github.com/pinak3748/nox-cli/blob/main/cmd/version.go"
    click ContentMain "https://github.com/pinak3748/nox-cli/blob/main/content/main.go"
    click ContentIndex "https://github.com/pinak3748/nox-cli/blob/main/content/index.go"
    click ContentActions "https://github.com/pinak3748/nox-cli/blob/main/content/actions.go"
    click ContentPrompt "https://github.com/pinak3748/nox-cli/blob/main/content/prompt.go"
    click ContentSlices "https://github.com/pinak3748/nox-cli/blob/main/content/slices.go"
    click ContentTypes "https://github.com/pinak3748/nox-cli/blob/main/content/types.go"
    click PkgInit "https://github.com/pinak3748/nox-cli/blob/main/packages/init.go"
    click PkgPage "https://github.com/pinak3748/nox-cli/blob/main/packages/page.go"
    click PkgDynComp "https://github.com/pinak3748/nox-cli/blob/main/packages/dynamicComponent.go"
    click PkgGetKey "https://github.com/pinak3748/nox-cli/blob/main/packages/getOpenAIKey.go"
    click PkgSetKey "https://github.com/pinak3748/nox-cli/blob/main/packages/setOpenAIKey.go"
    click BuildScript "https://github.com/pinak3748/nox-cli/blob/main/buildBinary.sh"
    click BinMac "https://github.com/pinak3748/nox-cli/blob/main/binary/nox_v0.1_mac_amd64"
    click BinWin "https://github.com/pinak3748/nox-cli/blob/main/binary/nox_v0.1_windows_amd64.exe"

    %% Styles
    classDef internal fill:#AEDFF7,stroke:#06719c,color:#000;
    classDef external fill:#F7D6AE,stroke:#a65a00,color:#000;
    classDef fs fill:#DFF7AE,stroke:#5c7d00,color:#000;
    classDef binary fill:#E3AEF7,stroke:#5b0f5c,color:#000;
```
