# mxhran-m/modular-ai architecture

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

- Interactive diagram: https://gitdiagram.com/mxhran-m/modular-ai
- Repository: https://github.com/mxhran-m/modular-ai

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "React Frontend"
        %% Components Layer
        subgraph "Components"
            UIComp["UI Components"]:::frontend
            subgraph "Agent Components"
                AgentBuilder["agent-builder.tsx"]:::frontend
                AgentCanvas["agent-canvas.tsx"]:::frontend
            end
            subgraph "Chat Components"
                ChatHistory["ChatHistory.tsx"]:::frontend
            end
            subgraph "Dashboard Components"
                AgentCard["agent-card.tsx"]:::frontend
                TemplateCard["template-card.tsx"]:::frontend
            end
            subgraph "Blocks Components"
                BlockCard["block-card.tsx"]:::frontend
                BlockLibrary["block-library.tsx"]:::frontend
            end
            subgraph "Layout Components"
                Navbar["navbar.tsx"]:::frontend
            end
            subgraph "Pages/Views"
                AgentsPage["Agents.tsx"]:::frontend
                AuthPage["Auth.tsx"]:::frontend
                ChatPage["Chat.tsx"]:::frontend
                CommunityPage["Community.tsx"]:::frontend
                DashboardPage["Dashboard.tsx"]:::frontend
                EditorPage["Editor.tsx"]:::frontend
                IndexPage["Index.tsx"]:::frontend
                NotFoundPage["NotFound.tsx"]:::frontend
                TemplateDetailPage["TemplateDetail.tsx"]:::frontend
                TemplatesPage["Templates.tsx"]:::frontend
            end
        end

        %% State Management Layer
        subgraph "State Management"
            AuthContext["AuthContext.tsx"]:::frontend
            subgraph "Custom Hooks"
                useMobile["use-mobile.tsx"]:::frontend
                useToast["use-toast.ts"]:::frontend
                useChatWithGemini["useChatWithGemini.ts"]:::frontend
            end
        end

        %% Utilities and Integrations Layer
        subgraph "Utilities & Integrations"
            Utils["utils.ts"]:::frontend
            subgraph "Supabase Integration"
                Client["client.ts"]:::integration
                Types["types.ts"]:::integration
            end
        end
    end

    subgraph "Supabase Backend"
        subgraph "Serverless Functions"
            GeminiChat["index.ts (gemini-chat)"]:::backend
        end
        Config["config.toml"]:::backend
    end

    subgraph "Build Tools"
        Vite["vite.config.ts"]:::build
        Tailwind["tailwind.config.ts"]:::build
        Package["package.json"]:::build
    end

    %% Connections
    AgentsPage -->|"uses"| AuthContext
    AgentsPage -->|"calls"| Client
    UIComp -->|"utilizes"| Utils
    Client -->|"APIcall"| GeminiChat
    Client -->|"reads"| Config
    Vite -->|"bundles"| AgentsPage
    Tailwind -->|"styles"| UIComp

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef integration fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef backend fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef build fill:#fff3cd,stroke:#333,stroke-width:2px;

    %% Click Events
    click UIComp "https://github.com/mxhran-m/modular-ai/tree/main/src/components/ui"
    click AgentBuilder "https://github.com/mxhran-m/modular-ai/blob/main/src/components/agent/agent-builder.tsx"
    click AgentCanvas "https://github.com/mxhran-m/modular-ai/blob/main/src/components/agent/agent-canvas.tsx"
    click ChatHistory "https://github.com/mxhran-m/modular-ai/blob/main/src/components/chat/ChatHistory.tsx"
    click AgentCard "https://github.com/mxhran-m/modular-ai/blob/main/src/components/dashboard/agent-card.tsx"
    click TemplateCard "https://github.com/mxhran-m/modular-ai/blob/main/src/components/dashboard/template-card.tsx"
    click BlockCard "https://github.com/mxhran-m/modular-ai/blob/main/src/components/blocks/block-card.tsx"
    click BlockLibrary "https://github.com/mxhran-m/modular-ai/blob/main/src/components/blocks/block-library.tsx"
    click Navbar "https://github.com/mxhran-m/modular-ai/blob/main/src/components/layout/navbar.tsx"
    click AgentsPage "https://github.com/mxhran-m/modular-ai/blob/main/src/pages/Agents.tsx"
    click AuthPage "https://github.com/mxhran-m/modular-ai/blob/main/src/pages/Auth.tsx"
    click ChatPage "https://github.com/mxhran-m/modular-ai/blob/main/src/pages/Chat.tsx"
    click CommunityPage "https://github.com/mxhran-m/modular-ai/blob/main/src/pages/Community.tsx"
    click DashboardPage "https://github.com/mxhran-m/modular-ai/blob/main/src/pages/Dashboard.tsx"
    click EditorPage "https://github.com/mxhran-m/modular-ai/blob/main/src/pages/Editor.tsx"
    click IndexPage "https://github.com/mxhran-m/modular-ai/blob/main/src/pages/Index.tsx"
    click NotFoundPage "https://github.com/mxhran-m/modular-ai/blob/main/src/pages/NotFound.tsx"
    click TemplateDetailPage "https://github.com/mxhran-m/modular-ai/blob/main/src/pages/TemplateDetail.tsx"
    click TemplatesPage "https://github.com/mxhran-m/modular-ai/blob/main/src/pages/Templates.tsx"
    click AuthContext "https://github.com/mxhran-m/modular-ai/blob/main/src/contexts/AuthContext.tsx"
    click useMobile "https://github.com/mxhran-m/modular-ai/blob/main/src/hooks/use-mobile.tsx"
    click useToast "https://github.com/mxhran-m/modular-ai/blob/main/src/hooks/use-toast.ts"
    click useChatWithGemini "https://github.com/mxhran-m/modular-ai/blob/main/src/hooks/useChatWithGemini.ts"
    click Client "https://github.com/mxhran-m/modular-ai/blob/main/src/integrations/supabase/client.ts"
    click Types "https://github.com/mxhran-m/modular-ai/blob/main/src/integrations/supabase/types.ts"
    click Utils "https://github.com/mxhran-m/modular-ai/blob/main/src/lib/utils.ts"
    click GeminiChat "https://github.com/mxhran-m/modular-ai/blob/main/supabase/functions/gemini-chat/index.ts"
    click Config "https://github.com/mxhran-m/modular-ai/blob/main/supabase/config.toml"
    click Vite "https://github.com/mxhran-m/modular-ai/blob/main/vite.config.ts"
    click Tailwind "https://github.com/mxhran-m/modular-ai/blob/main/tailwind.config.ts"
    click Package "https://github.com/mxhran-m/modular-ai/blob/main/package.json"
```
