How mxhran-m/modular-ai works
Main Components
• Frontend: All UI rendering and interactions are handled in the React/TypeScript code contained in the /src directory. Notice that there are several subdirectories:
• components: Contains reusable UI elements (e.g., ui components such as buttons, dialogs, forms); agent-specific components (agent-builder and agent-canvas); chat components (ChatHistory) and other domain-specific parts (blocks, dashboard, layout).
• pages: Contains the main routes or views (Agents, Auth, Chat, Community, Dashboard, Editor, Index, NotFound, TemplateDetail, Templates). This shows that the project is using some kind of routing system.
• contexts and hooks: Custom hooks and context providers (e.g., AuthContext) used for state management and possibly authentication or responsiveness (see use-mobile, useToast, useChatWithGemini).
• lib and integrations: Utility functions and integrations with external services, specifically Supabase (with a dedicated subdirectory for supabase client configuration and types).
• Backend / Serverless Functions: Under the /supabase directory, there’s a configuration file (config.toml) and functions (notably gemini-chat) implemented in TypeScript. This indicates that specific backend operations (likely for chat functionalities) are built as serverless functions.
• Build and Configuration Tools: Files such as package.json, vite.config.ts, tsconfig files, tailwind.config.ts, and others reveal that Vite is used as the build tool and Tailwind CSS for styling.
• Public Assets: The /public directory (with index.html and robots.txt) indicates static assets that will be served directly.
Component Relationships and Interactions
• The Frontend interacts with external services (like Supabase) via the integration modules in /src/integrations.
• The various UI components are assembled in pages, with shared state managed through contexts and hooks. For example, pages like Chat or Agents might use the AuthContext and chat-related hooks.
• Serverless functions in the supabase/functions directory act as the backend endpoint for operations like gemini-chat. The frontend will make HTTP (or Supabase client) calls to these endpoints.
• The build process orchestrated by Vite packages all frontend resources, while the Supabase configuration and functions handle backend routing and business logic.
Architectural Patterns and Practices
• Component-based architecture: Every UI element, from simple buttons to complex chat and agent components, is modular and reusable.
• Separation of concerns: There is a distinct separation between the visual UI (in /components and /pages) and business logic/integration (in /contexts, /hooks, and /integrations).
• Client-server separation with hybrid serverless backend: Serverless functions (gemini-chat) are used to handle backend logic, allowing the frontend to remain decoupled and lean.
• Use of contexts and hooks indicates that state management and side effects are handled using React’s modern features.
• The project structure suggests the use of a design system or a consistent UI library given the comprehensive /components/ui directory with tailored components.
• Use clear labels for each component: For example, “React Frontend – Pages”, “React Frontend – UI Components”, “Supabase Serverless (gemini-chat)”, etc.
• From UI Pages/Components to State Management.
• From the Frontend to the Supabase integration layer and then to the Supabase serverless functions.