How joshwrn/scribble-ai works
Main Components
• Frontend (Client Side):
• Next.js App: Note components like src/app/layout.tsx and src/app/page.tsx which form the entry points of your application.
• UI Components: The src/components directory is rich with components that implement resizable windows (Window/*), context menus, toolbars, debug tools, and an infinite canvas (likely represented by components like Space/Space.tsx and Window/Canvas/Canvas.tsx). Also include smaller UI elements (e.g., ContextMenu, DropDownMenu, ItemList, etc.).
• Client State Management: The src/state directory holds state modules that manage UI state (canvas, windows, notifications, etc.) across the app.
• Backend / API Layer:
• API Routes: Under src/app/api, you have endpoints dealing with tasks like image URL to Base64 conversion, scenario management, and a proxy route for “fal” (potentially a custom AI or generative art feature).
• Server Utilities: In src/server, there are additional endpoints and logic (like imageUrlToBase64/fetchImageUrlToBase64.ts and scenario/fetchScenario.ts) that are likely used by API routes to process data.
• External Service Interactions: Even though this is mostly a client-side interactive experimental app, the presence of API routes indicates interactions with backend logic for generative art or image conversion.
• Utility and Supporting Layers:
• Logic: The src/logic folder contains functions for layout, image processing (convertImageToBase64, resizeImage), and mathematical utilities (rotatePoint, findCenterPoint, etc.).
• Fal Module: A dedicated area (src/fal) appears to be handling the “fal” aspect, with optimized latency logic and workflows (src/fal/workflows), possibly managing AI or generative art processing.
• Mock Data: The src/mock folder provides mock endpoints/data which likely support testing and development.
• Scripts: The src/scripts folder is used to auto-generate API routes and stores, helping to keep the codebase synchronized with architectural changes.
• Testing: The tests folder contains end-to-end tests (like window-resize.spec.ts) to ensure the dynamic UI behaves as expected.
Relationships and Data Flow
a. User Interaction Flow:
• A user’s browser initiates a request that is managed by Next.js. The browser loads the UI from src/app and the individual UI components. These components then interact with the state management modules.
• When a user action requires data processing (e.g., converting an image URL or invoking an AI art process), the component calls an API endpoint (e.g., api/imageUrlToBase64/route.ts or api/scenario/route.ts).
b. API Interactions:
• The API endpoints in src/app/api forward requests to server-side functions located in src/server. They may also depend on logic functions (in src/logic) for processing data and return responses back to the client.
• The fal system also uses its own workflow (src/fal/workflows) to optimize latency during these operations.
c. State and Utility Integration:
• UI components listen to changes in state objects within src/state. Global functions, helpers, and utilities from src/utils and src/logic support the business logic and ensure consistency in user interactions.
Important Architectural Patterns & Technologies
• Next.js Folder-based Routing: The use of src/app, with layout.tsx and API routes, indicates that routing and page assembly follow Next.js conventions.
• Component-Based UI: The separation of UI into many specialized components (windows, menus, toolbars) follows modern React design principles.
• Modular State Management: The src/state folder serves to globally manage UI and application state, ensuring state synchronization across the dynamic components.
• Separation of Concerns: Clearly separated directories for UI, business logic, server-side endpoints, and scripts demonstrate clean modularization.
• Test-Driven Development: The tests directory shows an effort to verify the behavior of interactive components (e.g., window resizing).
Detailing Architectural Elements
• All interaction flows from user actions in the client browser to corresponding API calls and back-end server processing.
• The modular separation of UI components with grouped directories (like Window components grouped together, context menus grouped, etc.).
• The use of Next.js intrinsic routing and API construction as central to the architecture.
• The integration of AI/generative art functionalities (possibly under “fal”) to illustrate how specific workflows tie into the overall system.