# wahibonae/code-to-prompt architecture

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

- Interactive diagram: https://gitdiagram.com/wahibonae/code-to-prompt
- Repository: https://github.com/wahibonae/code-to-prompt

## Overview

##### Project Type and Purpose
- This is a full-stack web application built with Next.js, Tailwind CSS, and Shadcn/ui.
- Purpose: Allow users to upload single files or entire directories, automatically filter and combine code/text files into a well-formatted prompt, and then copy or download that prompt for use with AI platforms.

##### File Structure Analysis
- **src/app/**: Next.js App Router; defines pages (`page.tsx`), layout (`layout.tsx`), global styles, and an API route under `api/extract-text/route.ts`.
- **src/components/**: Presentational and container components (FileUpload, FileList, FilePreview, CodePreview, InfoDialog, theme components, OpenAI helper, UI primitives).
- **src/lib/** & **src/utils/**: Shared utility functions (file reading, filtering, transforming).
- **src/constants/** & **src/types/**: Application constants (ignored directories) and TypeScript type definitions.
- Config files: Next.js configs, ESLint, Tailwind, TypeScript.

##### Key Architectural Patterns
- **Separation of Concerns**:
- UI Layer (React components)
- Business Logic Layer (utils/lib for file processing)
- API Layer (Next.js serverless route)
- **Serverless Functions**: The `/api/extract-text` route handles the heavy lifting (reading file trees, filtering, formatting).
- **Client–Server Interaction**: Front end invokes the Extract-Text API via fetch.
- **Stateless Processing**: No database—each request independently processes the uploaded content and returns a prompt.

##### Main Components and Interactions
a. Client Browser
- Renders React UI; handles drag-and-drop or folder selection.
- Manages state (selected files/folders, generated prompt).
b. Next.js Frontend (SSR/CSR)
- Serves pages and static assets.
- Contains form elements and components for upload and preview.
c. API Route: `/api/extract-text`
- Accepts multipart/form data or file list payload.
- Uses utils to traverse directories, filter unwanted paths (node_modules, binaries), read file contents, and concatenate into a structured prompt.
- Optionally calls OpenAI or returns the text for client-side preview.
d. OpenAI Integration (optional)
- The component `openai.tsx` might wrap or configure requests to an AI service.
e. Static Asset Server
- Hosts screenshots and other public files.

##### Detailed Elements
- Component labels (“FileUpload,” “FileList,” “CodePreview”).
- Config files can be noted in a corner (Next.js config, ESLint) to indicate build/deployment setup.
- Data flows:
- File metadata & contents
- Generated prompt text
- Optional AI service calls

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client"
        direction TB
        Browser["User Browser\n(Drag & Drop UI)"]:::frontend
        FileUpload["FileUpload Component"]:::frontend
        FileList["FileList Component"]:::frontend
        FilePreview["FilePreview Component"]:::frontend
        CodePreview["CodePreview Component"]:::frontend
        InfoDialog["InfoDialog Component"]:::frontend
        ThemeProvider["theme-provider"]:::frontend
        ThemeToggle["theme-toggle"]:::frontend
        UIPrimitives["UI Primitives\n(buttons, cards, dialogs)"]:::frontend
    end

    subgraph "Server (Next.js & API)" 
        direction TB
        NextJS["Next.js Frontend\n(Pages & Layout)"]:::backend
        ApiRoute["API Route\n/api/extract-text"]:::backend
        subgraph "Utilities & Config"
            direction TB
            FilesUtil["files.ts\n(directory traversal, filtering)"]:::backend
            LibUtils["utils.ts\n(shared functions)"]:::backend
            IgnoredConfig["files.ts\n(ignored paths)"]:::backend
            TypeDefs["index.ts\n(type definitions)"]:::backend
        end
        ConfigFiles["Global Configs\n(next.config.js, tailwind.config.ts,\n tsconfig.json, .eslintrc.json)"]:::backend
    end

    subgraph "External Service"
        direction TB
        OpenAI["OpenAI REST API"]:::external
        StaticAssets["Static Assets\n(screenshots, icons)"]:::external
    end

    %% Connections
    Browser -->|"HTTP GET/POST"| NextJS
    NextJS -->|"FileList + Metadata"| ApiRoute
    ApiRoute -->|"Formatted Prompt"| NextJS
    ApiRoute -->|"AI Completion Request/Response"| OpenAI
    NextJS -->|"Serve Prompt\nRendered UI"| Browser

    %% Click events
    click NextJS "https://github.com/wahibonae/code-to-prompt/blob/main/src/app/page.tsx"
    click NextJS "https://github.com/wahibonae/code-to-prompt/blob/main/src/app/layout.tsx"
    click NextJS "https://github.com/wahibonae/code-to-prompt/blob/main/src/app/globals.css"
    click ApiRoute "https://github.com/wahibonae/code-to-prompt/blob/main/src/app/api/extract-text/route.ts"
    click FileUpload "https://github.com/wahibonae/code-to-prompt/blob/main/src/components/FileUpload.tsx"
    click FileList "https://github.com/wahibonae/code-to-prompt/blob/main/src/components/FileList.tsx"
    click FilePreview "https://github.com/wahibonae/code-to-prompt/blob/main/src/components/FilePreview.tsx"
    click CodePreview "https://github.com/wahibonae/code-to-prompt/blob/main/src/components/CodePreview.tsx"
    click InfoDialog "https://github.com/wahibonae/code-to-prompt/blob/main/src/components/InfoDialog.tsx"
    click ThemeProvider "https://github.com/wahibonae/code-to-prompt/blob/main/src/components/theme-provider.tsx"
    click ThemeToggle "https://github.com/wahibonae/code-to-prompt/blob/main/src/components/theme-toggle.tsx"
    click UIPrimitives "https://github.com/wahibonae/code-to-prompt/tree/main/src/components/ui/"
    click FilesUtil "https://github.com/wahibonae/code-to-prompt/blob/main/src/utils/files.ts"
    click LibUtils "https://github.com/wahibonae/code-to-prompt/blob/main/src/lib/utils.ts"
    click IgnoredConfig "https://github.com/wahibonae/code-to-prompt/blob/main/src/constants/files.ts"
    click TypeDefs "https://github.com/wahibonae/code-to-prompt/blob/main/src/types/index.ts"
    click StaticAssets "https://github.com/wahibonae/code-to-prompt/tree/main/public/screenshots/"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#0d47a1,color:#0d47a1,stroke-width:2px
    classDef backend fill:#c8e6c9,stroke:#1b5e20,color:#1b5e20,stroke-width:2px
    classDef external fill:#ffe0b2,stroke:#e65100,color:#e65100,stroke-width:2px
```
