How wahibonae/code-to-prompt works
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