Architerecture

Below is an overview of the architecture behind OnChainBrain—a next-generation, Solana-based web3 agent integrator that brings together blockchain, cloud services, and advanced AI models. This documentation is written in plain language to help both developers and non-technical stakeholders understand how everything fits together.


Overview

OnChainBrain is a feature-rich platform that allows users to create, deploy, and interact with AI agents on the Solana blockchain. The platform supports wallet-based authentication, advanced agent management, and a credit-based payment system. It leverages the power of multiple large language models (LLMs)—including OpenAI, Deepseekr1, Meta, Luma, and Grok—to provide robust AI capabilities. The system is also designed to work seamlessly with a CLI interface, making it easy for users to interact with the blockchain either through a GUI or programmatically.

We’re also excited to share that OnChainBrain will soon incorporate an innovative OCB Framework and an OLLM BrainChain model. This will provide even more flexibility and power, allowing our users to interact with the Solana blockchain and our suite of AI agents in a variety of ways—all within a secure cloud architecture.


Architecture Layers

1. Frontend Layer (Next.js App Router)

The frontend is built on Next.js 13+ using the App Router, enabling:

  • Server-side rendering for faster load times and SEO benefits.

  • Client-side interactivity to deliver a dynamic, responsive user experience.

  • Easy route handling and layout management to keep your code organized.

Here’s a snippet of our root layout:

tsxCopyexport default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html lang="en">
      <body>
        <Providers>
          {children}
        </Providers>
      </body>
    </html>
  );
}

2. Wallet Integration

To ensure smooth, secure blockchain interactions, we’ve integrated the Solana Wallet Adapter. This integration supports:

  • Phantom Wallet for popular and secure wallet connectivity.

  • Transaction signing and public key management to secure your interactions on the blockchain.

Here’s a brief look at our wallet provider:

tsxCopyexport function WalletProvider({ children }: WalletProviderProps) {
  const network = WalletAdapterNetwork.Devnet;
  const endpoint = useMemo(() => clusterApiUrl(network), [network]);
  const wallets = useMemo(() => [new PhantomWalletAdapter()], []);

  return (
    <ConnectionProvider endpoint={endpoint}>
      <BaseWalletProvider wallets={wallets} autoConnect>
        {children}
      </BaseWalletProvider>
    </ConnectionProvider>
  );
}

3. Database & Cloud Layer (Supabase & Cloud Architecture)

We use Supabase as our database layer, structured to manage user data, deployed agents, and transaction history. Our tables are designed to store only what’s necessary, ensuring no sensitive details (such as full database operations) are exposed. The core tables include:

  • Users: Stores wallet-based authentication data and credit balances.

  • Agents: Manages deployed AI agent metadata.

  • Transaction History: Keeps track of credit purchases and usage.

The system is built with a cloud-first approach to scale seamlessly and to ensure high availability and security.

4. AI Integration & OLLM BrainChain

OnChainBrain stands out by integrating multiple AI models via the Replicate API and other advanced ML frameworks. Our platform will soon support the OCB Framework and the OLLM BrainChain—a unified large language model interface that allows:

  • Custom AI agent personalities tailored to user needs.

  • Chat-based interfaces for natural and engaging interactions.

  • Integration with multiple LLMs (like OpenAI, Deepseekr1, Meta, Luma, and Grok) to offer diverse and powerful AI responses.

5. State & Blockchain Management

Our application uses Redux Toolkit to manage state across user authentication, agent data, and transaction histories.

At the blockchain level, the system is responsible for:

  • Token creation and management.

  • Transaction signing and validation.

  • Fetching and displaying blockchain data in real time.


Key Features

Credit System

  • SOL to Credits Conversion: Users can easily convert SOL into platform credits.

  • Transaction Tracking: Every credit purchase and usage is logged, ensuring transparency.

  • Balance Management: Real-time credit balance updates keep users informed.

Agent Management

  • Creation & Deployment: Easily create and deploy AI agents with just a few clicks.

  • Metadata Storage: All agent metadata is securely stored for future reference.

  • Interaction Tracking: Monitor how your agents are performing and interacting with users.

Authentication & Security

  • Wallet-based Authentication: Leverage your existing Solana wallet for secure sign-ins.

  • Row Level Security (RLS): Enforced at the database level to protect sensitive user data.

  • API Route Protection: Only authorized users can access and modify critical resources.

  • Environment Variable Management: Securely manage your configurations without exposing secrets.


Future Enhancements

We’re continually improving OnChainBrain. Some planned features include:

  • Multi-wallet support: Beyond Phantom, we’re looking to integrate other popular wallets.

  • Advanced Agent Customization: More tools for users to tailor their AI agents.

  • Enhanced Analytics: Deeper insights into agent performance and user engagement.

  • Credit Package System: Flexible credit packages to suit various user needs.

  • Social Features Integration: Enable community and social features to boost collaboration.

  • CLI Interface: A powerful command-line interface (CLI) for advanced blockchain interactions, perfect for developers and power users.


Data Flow

User Authentication Flow

mermaidCopygraph LR
    A[User] --> B[Connect Wallet]
    B --> C[Authenticate]
    C --> D[Create User Record]
    D --> E[Grant Access]

Agent Creation Flow

mermaidCopygraph LR
    A[User] --> B[Submit Agent Creation Form]
    B --> C[Validate Credits]
    C --> D[Deploy Agent]
    D --> E[Store Agent Metadata]

These diagrams provide a high-level overview of the main user flows, ensuring that every step—from wallet connection to agent deployment—is both smooth and secure.


Final Thoughts

OnChainBrain is more than just a platform; it’s a robust framework designed to harness the power of blockchain and AI in a user-friendly manner. By combining modern web technologies with advanced cloud and blockchain integration, we’re paving the way for innovative use cases in decentralized applications.

As we continue to add features—like the OCB Framework, OLLM BrainChain, and support for multiple AI models—we remain committed to building a secure, scalable, and intuitive platform that empowers users to explore the next frontier of web3 and AI technology.

Feel free to reach out if you have questions or suggestions. We’re excited to see what you build with OnChainBrain! Happy coding! 😀

Last updated