# nicoalbanese/kirimase architecture

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

- Interactive diagram: https://gitdiagram.com/nicoalbanese/kirimase
- Repository: https://github.com/nicoalbanese/kirimase

## Overview

##### Main Components
a. CLI Entrypoint
- `bin/kirimase` (not shown in file tree but defined in package.json “bin”)
- Invokes `src/index.ts`
b. Command Dispatcher / Parser
- Uses a command‐parsing library (e.g. Commander or Oclif)
- Analyzes `process.argv` and routes to handlers
c. Command Handlers
- `src/commands/init`
- `src/commands/add`
- `src/commands/generate`
- (Plus `filePaths`, shared utils)
d. Sub‐Command Generators
– add/auth/* (clerk, next-auth, lucia, kinde)
– add/orm/* (drizzle, prisma)
– add/componentLib/shadcn-ui
– add/misc/* (stripe, resend, trpc, navbar, defaultStyles)
– generate/generators/(model, views, apiRoute, serverActions, trpcRoute)
e. Shared Utilities
- `src/utils.ts`, `src/commands/*/utils.ts`, `src/types.d.ts`
- Template resolution, file path computation, prompts, file I/O
f. File System / Templates
- Template files (embedded in generator code)
- Output into the user’s Next.js project folder
g. External Dependencies
- Node.js FS module, Chalk, Inquirer/Prompts, TS-Node, ESM commonjs loader

##### Relationships & Data Flows
- User types `kirimase <command> [options]` →
→ CLI Entrypoint → Command Parser → Selected Command Handler
- Handler loads relevant sub‐command modules →
→ Sub‐Command Generators orchestrate:
- Read templates & config
- Prompt user (if interactive)
- Transform/generate code (TypeScript AST or string templates)
- Write files to disk
- Update package.json, .env, tsconfig.json, etc.
- Shared Utilities support all handlers with:
- Path resolution
- Logging/progress
- Option parsing

##### Architectural Patterns & Principles
- Command Pattern: each top‐level command (`init`, `add`, `generate`) and sub‐commands implement a common interface (e.g., `run()` method)
- Modular Architecture: one folder per command, one file per generator
- Single Responsibility: each generator focuses on a single feature (e.g., “add/auth/clerk”)
- Dependency Injection (implicit): shared utils imported by handlers
- Template-Driven Code Generation

##### Key Technologies & Libraries
- TypeScript for code safety
- Node.js CLI (shebang + ESM)
- Commander or similar for parsing (inferred)
- FS + Path modules for file operations
- Zod (indirectly, when scaffolding drizzle/prisma)
- External CLIs: drizzle-kit, prisma, next-auth, clerk, lucia, kinde, trpc
- Prettier / ESLint configurations

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Input
    User["User CLI Input"]:::external
    User -->|"kirimase <command> [options]"| CLI

    %% Core Modules
    subgraph "Core Modules"
        direction TB
        CLI["CLI Entrypoint\n(src/index.ts)"]:::core
        Parser["Command Parser\n(src/index.ts)"]:::core
    end
    CLI -->|"invoke"/bin/kirimase| Parser
    click CLI "https://github.com/nicoalbanese/kirimase/blob/master/src/index.ts"
    click Parser "https://github.com/nicoalbanese/kirimase/blob/master/src/index.ts"
    click CLI "https://github.com/nicoalbanese/kirimase/blob/master/package.json"

    %% Command Handlers
    subgraph "Top-Level Commands"
        direction TB
        Init["Init Command\n(src/commands/init/index.ts)"]:::command
        Add["Add Command\n(src/commands/add/index.ts)"]:::command
        Generate["Generate Command\n(src/commands/generate/index.ts)"]:::command
    end
    Parser -->|"dispatch"| Init
    Parser -->|"dispatch"| Add
    Parser -->|"dispatch"| Generate
    click Init "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/init/index.ts"
    click Add "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/index.ts"
    click Generate "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/generate/index.ts"

    %% Add Sub-Commands
    subgraph "Add → Auth Generators"
        direction TB
        Clerk["Clerk\n(src/commands/add/auth/clerk/index.ts)"]:::command
        NextAuth["Next-Auth\n(src/commands/add/auth/next-auth/index.ts)"]:::command
        Lucia["Lucia\n(src/commands/add/auth/lucia/index.ts)"]:::command
        Kinde["Kinde\n(src/commands/add/auth/kinde/index.ts)"]:::command
        SharedAuth["Shared Auth Logic\n(src/commands/add/auth/shared/index.ts)"]:::utils
    end
    Add -->|"load auth modules"| Clerk
    Add --> NextAuth
    Add --> Lucia
    Add --> Kinde
    Add --> SharedAuth
    click Clerk "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/auth/clerk/index.ts"
    click NextAuth "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/auth/next-auth/index.ts"
    click Lucia "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/auth/lucia/index.ts"
    click Kinde "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/auth/kinde/index.ts"
    click SharedAuth "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/auth/shared/index.ts"

    %% Add → ORM
    subgraph "Add → ORM Generators"
        direction TB
        Drizzle["Drizzle\n(src/commands/add/orm/drizzle/index.ts)"]:::command
        Prisma["Prisma\n(src/commands/add/orm/prisma/index.ts)"]:::command
        SharedORM["Shared ORM Helpers\n(src/commands/add/orm/utils.ts)"]:::utils
    end
    Add --> Drizzle
    Add --> Prisma
    Add --> SharedORM
    click Drizzle "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/orm/drizzle/index.ts"
    click Prisma "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/orm/prisma/index.ts"
    click SharedORM "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/orm/utils.ts"

    %% Add → Component Library
    subgraph "Add → ComponentLib"
        direction TB
        Shadcn["Shadcn-UI\n(src/commands/add/componentLib/shadcn-ui/index.ts)"]:::command
    end
    Add --> Shadcn
    click Shadcn "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/componentLib/shadcn-ui/index.ts"

    %% Add → Misc
    subgraph "Add → Misc Generators"
        direction TB
        DefaultStyles["Default Styles\ngenerators.ts"]:::command
        Navbar["Navbar\ngenerators.ts"]:::command
        Resend["Resend\n(src/commands/add/misc/resend/index.ts)"]:::command
        Stripe["Stripe\n(src/commands/add/misc/stripe/index.ts)"]:::command
        TRPCAdd["tRPC\n(src/commands/add/misc/trpc/index.ts)"]:::command
    end
    Add --> DefaultStyles
    Add --> Navbar
    Add --> Resend
    Add --> Stripe
    Add --> TRPCAdd
    click DefaultStyles "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/misc/defaultStyles/generators.ts"
    click Navbar "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/misc/navbar/generators.ts"
    click Resend "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/misc/resend/index.ts"
    click Stripe "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/misc/stripe/index.ts"
    click TRPCAdd "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/misc/trpc/index.ts"

    %% Generate Sub-Commands
    subgraph "Generate Generators"
        direction TB
        APIRoute["API Route\ngenerators/apiRoute.ts"]:::command
        ServerActions["Server Actions\ngenerators/serverActions.ts"]:::command
        TRPCRoute["tRPC Route\ngenerators/trpcRoute.ts"]:::command
        Views["Views\ngenerators/views.ts"]:::command
        ViewsSA["Views w/ServerActions\ngenerators/views-with-server-actions.ts"]:::command
        Model["Model Generator\n(generators/model/index.ts)"]:::command
    end
    Generate --> APIRoute
    Generate --> ServerActions
    Generate --> TRPCRoute
    Generate --> Views
    Generate --> ViewsSA
    Generate --> Model
    click APIRoute "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/generate/generators/apiRoute.ts"
    click ServerActions "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/generate/generators/serverActions.ts"
    click TRPCRoute "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/generate/generators/trpcRoute.ts"
    click Views "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/generate/generators/views.ts"
    click ViewsSA "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/generate/generators/views-with-server-actions.ts"
    click Model "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/generate/generators/model/index.ts"

    %% Shared Utilities
    subgraph "Shared Utilities"
        direction TB
        UtilsCore["Core Utils\n(src/utils.ts)"]:::utils
        Types["Types\n(src/types.d.ts)"]:::utils
        AddUtils["Add Utils\n(src/commands/add/utils.ts)"]:::utils
        Prompts["Prompts\n(src/commands/add/prompts.ts)"]:::utils
        FilePaths["File Paths\n(src/commands/filePaths/index.ts)"]:::utils
        GenUtils["Generate Utils\n(src/commands/generate/utils.ts)"]:::utils
        InitUtils["Init Utils\n(src/commands/init/utils.ts)"]:::utils
    end
    Init --> InitUtils
    Add --> AddUtils
    Add --> Prompts
    Generate --> GenUtils
    Parser --> UtilsCore
    Parser --> FilePaths
    Parser --> Types
    click UtilsCore "https://github.com/nicoalbanese/kirimase/blob/master/src/utils.ts"
    click Types "https://github.com/nicoalbanese/kirimase/blob/master/src/types.d.ts"
    click AddUtils "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/utils.ts"
    click Prompts "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/add/prompts.ts"
    click FilePaths "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/filePaths/index.ts"
    click GenUtils "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/generate/utils.ts"
    click InitUtils "https://github.com/nicoalbanese/kirimase/blob/master/src/commands/init/utils.ts"

    %% File System & Templates
    FS["File System / Templates"]:::storage
    subgraph "Template Assets" 
        direction TB
        Templates["Embedded Templates"]:::storage
    end
    Clerk -->|"read/write files"| FS
    NextAuth --> FS
    Lucia --> FS
    Drizzle --> FS
    Prisma --> FS
    APIRoute --> FS
    Model --> FS
    FS -->|"generate to project"| Project["User Project FS"]:::storage

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        NodeFS["Node FS Module"]:::external
        Chalk["Chalk"]:::external
        PromptsLib["Inquirer/Prompts"]:::external
        TSNode["TS-Node"]:::external
        CLILoader["ESM/CommonJS Loader"]:::external
        ExternalCLIs["External CLIs\n(drizzle-kit, prisma, etc.)"]:::external
    end
    Parser --> NodeFS
    Parser --> TSNode
    CLI --> CLILoader
    Clerk --> ExternalCLIs
    Drizzle --> ExternalCLIs
    Prisma --> ExternalCLIs
    Generate --> ExternalCLIs
    Parser --> Chalk
    Parser --> PromptsLib

    %% Styles
    classDef core fill:#daf1ff,stroke:#3399ff,color:#000
    classDef command fill:#e0f7da,stroke:#28a745,color:#000
    classDef utils fill:#fff4cc,stroke:#e6b800,color:#000
    classDef storage fill:#f0f0f0,stroke:#999999,color:#000
    classDef external fill:#ffe6cc,stroke:#ff9933,color:#000
```
