Skip to content

NEARBuilders/cyborg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

100 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Legion social

Legion Social - The Social Layer for Builders on NEAR

A hybrid platform leveraging the best of NEAR's builder ecosystem to create a comprehensive social layer through AI chat, directory services, and meaningful connections.

Live Demo: legion social


🎯 What It Does

Legion social is a social platform for NEAR ecosystem builders that solves three core problems:

  1. High Friction Social Interactions - Do you ever ask who is on near who actualy build stuff not just the yapper on X who actualy in the trenches? social proof builders builds some of them cant even yap on x there to busy what if they could have there quiet spot to share there journee and still be seen
  2. *AI integration - Google but for legionnaire.

✨ Key Features

πŸ€– AI Chat with NEAR AI Cloud

  • Streaming responses from GLM-4.6 model via NEAR AI Cloud
  • Persistent conversation history - never lose context
  • No API keys needed - platform handles authentication
  • NEAR-aware - trained on NEAR ecosystem documentation
  • Tool calling - AI can query and interact with your application data

Use case: find people from there intrest and project / nft ?

πŸ‘₯ Builder Discovery & Profiles

  • Browse NEAR Legion NFT holders - discover who's building in the ecosystem
  • View builder profiles with projects, skills, and social links
  • NFT-based reputation badges (Legendary, Epic, Rare, Common)
  • Profile data stored on NEAR Social blockchain

Use case: Find collaborators, explore projects, see who holds NEAR Legion NFTs.

πŸ”’ Privacy-Preserving Payment Keys

⚠️ PROOF OF CONCEPT - imagine being able to interact with the blockchain with a prepaid key?

πŸ“ Project Management

  • Create and showcase projects with cover images, descriptions, and status
  • Store on-chain via FastData protocol (contextual.near)
  • Status tracking - mark projects as active, completed, or archived
  • Optional payment key fast path - update projects instantly without signing

Use case: Build your portfolio and show off your work to the community.

🌐 Social Graph Integration

  • Follow/unfollow other builders
  • FastData protocol integration for scalable social graph indexing
  • Payment key execution for instant follows (optional)
  • Follower/following counts with real-time updates

Use case: Build your network and stay updated with builders you follow.


πŸ—οΈ How It Works

Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Cyborg Architecture                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                               β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚   Frontend       β”‚         β”‚   Payment Keys   β”‚         β”‚
β”‚  β”‚   React 19       β”‚         β”‚   Client-Side    β”‚         β”‚
β”‚  β”‚   TanStack       │◄─────────   Encryption     β”‚         β”‚
β”‚  β”‚   Router         β”‚         β”‚   (AES-GCM)      β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚           β”‚                                                      β”‚
β”‚           β–Ό                                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚   API Routes (Hono.js)                                  β”‚   β”‚
β”‚  β”‚                                                          β”‚   β”‚
β”‚  β”‚  /chat/*           β†’ AI chat streaming                  β”‚   β”‚
β”‚  β”‚  /builders/*       β†’ Builder directory                  β”‚   β”‚
β”‚  β”‚  /projects/*       β†’ Project CRUD                       β”‚   β”‚
β”‚  β”‚  /social/*         β†’ Follow/following                   β”‚   β”‚
β”‚  β”‚  /payment-keys/*   β†’ Gasless execution                  β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚           β”‚                                                      β”‚
β”‚           β–Ό                                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚   Services & Integrations                               β”‚   β”‚
β”‚  β”‚                                                          β”‚   β”‚
β”‚  β”‚  NEAR AI Cloud (GLM-4.6)                                    β”‚   β”‚
β”‚  β”‚  NEAR Social (profiles)                                 β”‚   β”‚
β”‚  β”‚  NEARBlocks API (NFT data)                              β”‚   β”‚
β”‚  β”‚  FastData (social graph + projects)                     β”‚   β”‚
β”‚  β”‚  OutLayer (payment key execution)                       β”‚   β”‚
β”‚  β”‚  D1 Database (SQLite)                                   β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Infrastructure: FastKV Protocol

Credit to FastNear this part of the project would not have been possible without there effort!

This infrastructure solves a key friction point in the NEAR ecosystem: while NEAR Social requires users to deposit NEAR tokens for storage, creating barriers to entry, FastKV allows users to store and retrieve key-value data on NEAR without having to deposit NEAR for storage, only transaction fees. Instead of storing data in contract state, FastKV indexes the arguments of prefixed function calls (e.g., __fastdata_kv) directly from the transaction ledger. This works for any contract, even one without that method, because NEAR logs function call arguments regardless of whether the call succeeds. We provide contextual.near as a default receiver with a no-op method. Each entry is keyed by (predecessor_account_id, current_account_id, key), supports overwrites, and retains full version history. The FastKV API exposes this data through REST endpoints for lookups, prefix scans, and history queries.

How It Works

Indexing: Scans transaction ledger for prefixed function calls (e.g., __fastdata_kv)

No storage deposits: Only pay transaction fees, not rent - eliminating the barrier created by NEAR Social's deposit requirements

Universal compatibility: Works with any contract, even ones without the method

Full history: Retains complete version history of all changes

Key structure: (predecessor_account_id, current_account_id, key)

Benefits

  • 10-50x cheaper than traditional contract storage
  • Instant queries via REST API
  • No gas for reads - data served from indexed ledger
  • Unlimited storage - scales with NEAR blockchain throughput
  • Zero deposit barrier - unlike NEAR Social, no upfront NEAR deposit required for storage
#### Components

- **near.garden API server** - High-performance KV lookup service
  - Repository: https://github.com/MultiAgency/fastkv-server

- **FastData indexer** - Real-time blockchain indexing
  - Repository: https://github.com/MultiAgency/fastdata-indexer

- **near.directory frontend** - User interface for browsing indexed data
  - Repository: https://github.com/MultiAgency/fastdata-social

- **No-op FastKV contract** - Contract for function call logging
  - Repository: https://github.com/MultiAgency/fd_contract

### Data Flow

**AI Chat:**
1. User sends message β†’ API
2. API streams response from NEAR AI Cloud
3. Conversation saved to database

**Builder Directory:**
1. Fetch user user from database from indexed data 
2. Fetch profiles from NEAR Social blockchain
3. Display with NFT rank badges 

**Projects:**
1. Create/update β†’ prepare transaction for FastData contract
2. If payment key exists β†’ execute instantly (fast path)
3. Otherwise β†’ user signs with wallet (default path)

---

## πŸ› οΈ Developer Tools & Infrastructure

### RPC Load Balancing

This project uses **[near-balancer](https://github.com/Kampouse/near-balancer)** for intelligent RPC request distribution:

- **Round-robin rotation** across multiple NEAR RPC endpoints
- **Automatic retry logic** for failed requests
- **Reduced rate limiting** by distributing load
- **Improved reliability** with fallback endpoints

**Philosophy:** *"Don't fight RPC, use them"* - balance requests across multiple nodes instead of relying on a single endpoint.

### Data Sync Scripts (`/worker/scripts`)

Comprehensive tooling for syncing NEAR blockchain data to D1 database for fast, cached queries:

**Sync Strategies:**
- `sync-simple.ts` - Reliable NFT holder sync with conservative defaults
- `sync-fast.ts` - Maximum throughput sync for quick updates
- `sync-profiles.ts` - NEAR Social profile caching with 24h TTL
- `sync-all.ts` - Combined sync of holders and profiles

**Features:**
- **Resumable syncs** - Progress saved to state files, safe to restart
- **Concurrent requests** - Parallel fetching with configurable limits
- **Endpoint rotation** - Distributes load across RPC nodes
- **Exponential backoff** - Handles rate limits gracefully
- **Batch database writes** - Optimized for D1 performance

**Performance Impact:**

Without Cache: Request β†’ RPC β†’ 200-500ms β†’ Response With Cache: Request β†’ D1 β†’ 10-50ms β†’ Response


**10-50x faster** response times for cached data.

**Database Tables:**
- `legion_holders` - NFT holdings across multiple contracts
- `near_social_profiles` - Cached user profiles with extracted fields
- `legion_nft_images` - NFT metadata and image URLs

See [`/worker/scripts/README.md`](/worker/scripts/README.md) for detailed documentation and usage examples.

---

## 🎯 NEARCON Innovation Sandbox Alignment

### Decentralized AI βœ…
- **NEAR AI Cloud integration** for private, secure AI conversations
- **Streaming responses** from GLM-4.6 model
- **NEAR-specific context** trained on ecosystem documentation
- **Platform authentication** - no API key exposure

### Privacy-Preserving Consumer Apps βœ…
- **privacy on chain** (theory) have private profile on chain
- **Gasless interactions** - pre-authorized spending without signing
- **User-controlled data** stored on NEAR Social
- **FastKV protocol** integration for scalable data(cheap / fast)
---

## πŸš€ Getting Started

### Prerequisites

```bash
# Install Bun
curl -fsSL https://bun.sh/install | bash

Installation

# Clone and install
git clone https://github.com/NEARBuilders/cyborg.git
cd cyborg
bun install

# Run database migrations
bun db:migrate

# Start development
bun dev

yes about that..  current setup  only work deployed since i was always testing on the live app

Environment Setup

Create .env file:

# Required
NEAR_AI_API_KEY=sk-xxx          # Get from https://cloud.near.ai

# Optional (with defaults)
BETTER_AUTH_URL=http://localhost:3001
NEAR_AI_BASE_URL=https://cloud-api.near.ai/v1
NEAR_AI_MODEL=glm/glm-4-plus
NEAR_RPC_URL=https://rpc.mainnet.near.org

πŸ“Έ Screenshots

Landing Page

Landing Page

Welcome page with feature overview and sign-in button.

near.email + Ai chat

Chat Interface AI chat

Streaming chat with conversation history and markdown support.

Builder Profiles

Builder Profile

Builders Directory

Builders directory

Project Creation

Project Creation

Create projects with cover images and descriptions.


πŸ› οΈ Development

# Type checking
bun typecheck

# Run tests
bun test

# Build for production
bun build

# Database operations
bun db:push          # Push schema changes
bun db:studio        # Open Drizzle Studio
bun db:generate      # Generate migrations

πŸ”§ What's Inside

Frontend (ui/)

  • React 19 with TypeScript
  • TanStack Router - file-based routing
  • TanStack Query - server state management
  • Tailwind CSS v4 - styling
  • shadcn/ui - component library

Backend (worker/)

  • Hono.js - web framework
  • Drizzle ORM - database
  • D1 (SQLite) - data storage
  • Better-Auth - authentication
  • better-near-auth - NEAR wallet integration

Key Integrations

  • NEAR AI Cloud - GLM-4.6 model
  • NEAR Social - profile storage
  • NEARBlocks API - NFT holder data
  • FastData - social graph + projects
  • OutLayer - payment key execution / near.email

πŸ“œ License

MIT


πŸ™ Acknowledgments

Built with innovative technologies from the NEAR ecosystem:


Built for NEARCON 2026 Innovation Sandbox

Private. Intelligence. Yours. 🌐

About

No description, website, or topics provided.

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •