Version 1.0
The SocialAi system is a lightweight, AI‑powered social discovery and identity claim network built on a parallel, auto‑healing, one‑file node architecture powered by Healdec and SmartBrain.
This document is the canonical architecture reference for the repository. It describes:
- High‑level system topology
- Core components and their responsibilities
- Data model and flows
- Worker orchestration
- Security and operational concerns
- Future extension plans
- High-Level System Overview
- Backend Architecture
- Frontend Architecture
- Data Model
- Worker Orchestration
- API Gateway
- Security Considerations
- Future Extensions
flowchart TD
subgraph PublicLayer["Public Layer (Astro + Vite)"]
P1[SEO Pages]
P2[Profiles]
P3[Timelines]
P4[Claim Flow]
P5[Landing Pages]
end
subgraph AdminLayer["Admin Layer (Angular)"]
A1[Feature Flags]
A2[Sync Controls]
A3[Worker Health]
A4[System Dashboard]
A5[Abuse Controls]
end
subgraph Backend["One‑File SocialAi Node"]
B1[Healdec Engine]
B2[Worker Manager]
B3[API Gateway]
B4[SSR Renderer]
B5[SmartBrain Integration]
end
subgraph Workers["Parallel Workers"]
W1[Farcaster Worker]
W2[Reddit Worker]
W3[Ethereum RPC]
W4[BASE RPC]
W5[Solana RPC]
W6[Search Worker]
W7[AI Worker]
end
subgraph Database["Database (Postgres)"]
D1[Users]
D2[Profiles]
D3[Posts]
D4[External Posts]
D5[Follows]
D6[Likes]
D7[Claims]
D8[Embeddings]
D9[Feature Flags]
D10[Settings]
end
PublicLayer --> Backend
AdminLayer --> Backend
Backend --> Workers
Workers --> Database
The SocialAi system consists of five major layers:
- Public Layer - User-facing web application for social discovery
- Admin Layer - Administrative console for system management
- Backend - One-file node orchestrator managing all backend services
- Workers - Parallel workers for data synchronization and processing
- Database - PostgreSQL database with vector extensions for AI features
The backend is built as a one-file orchestrator (socialai.node.js) that manages all backend subsystems. This design simplifies deployment and maintenance while providing powerful orchestration capabilities.
The Healdec Engine provides auto-healing capabilities to ensure system reliability:
flowchart TD
A[Dependency Scan] --> B[Health Check]
B --> C{Healthy?}
C -->|Yes| D[Continue Monitoring]
C -->|No| E[Safe Update/Restart]
E --> F[Rebuild]
F --> G[Validation]
G --> H{Valid?}
H -->|Yes| D
H -->|No| I[Rollback]
I --> D
Key Features:
- Dependency Scanning: Continuously monitors worker health
- Safe Updates: Validates changes before applying them
- Auto-Rebuild: Rebuilds workers when needed
- Validation: Ensures changes don't break the system
- Rollback: Automatically reverts problematic changes
- Health Checks: Runs every 30 seconds
- Max Restarts: Limits restart attempts to 3 per worker
The Worker Manager orchestrates parallel workers with automatic restart capabilities:
Responsibilities:
- Start and stop workers
- Monitor worker health
- Restart failed workers with exponential backoff
- Maintain worker state
- Log worker activity
Configuration:
workers: {
farcaster: { enabled: true, path: '../workers/farcaster.worker.js' },
reddit: { enabled: false, path: '../workers/reddit.worker.js' },
ethereum: { enabled: true, path: '../workers/ethereum.worker.js' },
base: { enabled: true, path: '../workers/base.worker.js' },
solana: { enabled: true, path: '../workers/solana.worker.js' },
search: { enabled: true, path: '../workers/search.worker.js' },
ai: { enabled: true, path: '../workers/ai.worker.js' }
}The API Gateway provides RESTful endpoints with authentication and rate limiting:
Features:
- REST API endpoints for all operations
- Farcaster authentication (Sign-In with Farcaster)
- SIWE (Sign-In with Ethereum) support
- Rate limiting (100 requests/minute default)
- CORS configuration
- Helmet security headers
- Request logging
Core Endpoints:
/api/users- User management/api/profiles- Profile operations/api/posts- Post CRUD operations/api/timeline- Timeline feeds/api/search- Search functionality/api/claims- Identity claims/api/admin/*- Admin operations
Server-Side Rendering integration with Astro for optimal SEO:
Capabilities:
- Pre-renders public pages
- Dynamic profile pages
- Timeline generation
- Claim flow pages
- SEO optimization
- Fast initial page load
AI-powered features using vector embeddings and LLM processing:
Features:
- Content summaries
- Personalized recommendations
- Topic clustering
- Profile optimization
- Semantic search
- Vector similarity matching
Technology Stack:
- Astro for SSR and static generation
- Vite for fast development and building
- TypeScript for type safety
- Zero JavaScript by default (progressive enhancement)
Key Pages:
index.astro- Landing pageprofiles.astro- Profile directoryprofile/[username].astro- Individual profiletimeline.astro- Social timelineclaim.astro- Identity claim flow
Architecture Pattern:
- Static Site Generation (SSG) for landing pages
- Server-Side Rendering (SSR) for dynamic content
- Minimal client-side JavaScript
- Progressive enhancement
- SEO-first approach
Technology Stack:
- Angular 17+ for reactive UI
- TypeScript for type safety
- RxJS for reactive programming
- Angular Material for UI components
Key Components:
- Dashboard Component: System overview and metrics
- Feature Flags Component: Toggle system features
- Sync Controls Component: Manage data synchronization
- Worker Health Component: Monitor worker status
- Abuse Controls Component: Content moderation
Services:
- API Service: Backend communication
- Auth Service: Authentication management
- State Service: Application state management
Architecture Pattern:
- Component-based architecture
- Reactive data flow with RxJS
- Lazy loading for performance
- HTTP interceptors for auth
- Route guards for access control
erDiagram
USERS ||--o{ PROFILES : has
USERS ||--o{ POSTS : creates
USERS ||--o{ FOLLOWS : follows
USERS ||--o{ LIKES : likes
USERS ||--o{ CLAIMS : claims
PROFILES ||--o{ CLAIMS : verified_by
POSTS ||--o{ LIKES : receives
POSTS ||--o{ POSTS : replies_to
EXTERNAL_POSTS ||--o{ LIKES : receives
PROFILES ||--|| USERS : belongs_to
EMBEDDINGS ||--o{ POSTS : represents
EMBEDDINGS ||--o{ EXTERNAL_POSTS : represents
EMBEDDINGS ||--o{ PROFILES : represents
Primary user accounts linked to blockchain identities.
CREATE TABLE users (
id UUID PRIMARY KEY,
farcaster_id BIGINT UNIQUE,
ethereum_address VARCHAR(42) UNIQUE,
ens_name VARCHAR(255),
created_at TIMESTAMP,
updated_at TIMESTAMP
);User profile information, claimable by identity verification.
CREATE TABLE profiles (
id UUID PRIMARY KEY,
user_id UUID REFERENCES users(id),
username VARCHAR(255) UNIQUE NOT NULL,
display_name VARCHAR(255),
bio TEXT,
avatar_url TEXT,
banner_url TEXT,
website_url TEXT,
twitter_handle VARCHAR(255),
claimed BOOLEAN DEFAULT FALSE,
verified BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP,
updated_at TIMESTAMP
);Internal posts created by users.
CREATE TABLE posts (
id UUID PRIMARY KEY,
user_id UUID REFERENCES users(id),
content TEXT NOT NULL,
media_urls TEXT[],
parent_id UUID REFERENCES posts(id),
root_id UUID REFERENCES posts(id),
reply_count INTEGER DEFAULT 0,
recast_count INTEGER DEFAULT 0,
like_count INTEGER DEFAULT 0,
created_at TIMESTAMP,
updated_at TIMESTAMP
);Posts synced from external sources (Farcaster, Reddit, etc.).
CREATE TABLE external_posts (
id UUID PRIMARY KEY,
external_id VARCHAR(255) UNIQUE NOT NULL,
source VARCHAR(50) NOT NULL,
author_id VARCHAR(255),
author_name VARCHAR(255),
content TEXT,
media_urls TEXT[],
url TEXT,
parent_id VARCHAR(255),
reply_count INTEGER DEFAULT 0,
like_count INTEGER DEFAULT 0,
metadata JSONB,
created_at TIMESTAMP,
synced_at TIMESTAMP
);Social graph connections between users.
CREATE TABLE follows (
id UUID PRIMARY KEY,
follower_id UUID REFERENCES users(id),
following_id UUID REFERENCES users(id),
created_at TIMESTAMP,
UNIQUE(follower_id, following_id)
);User interactions with posts.
CREATE TABLE likes (
id UUID PRIMARY KEY,
user_id UUID REFERENCES users(id),
post_id UUID REFERENCES posts(id),
external_post_id UUID REFERENCES external_posts(id),
created_at TIMESTAMP,
CHECK (post_id IS NOT NULL OR external_post_id IS NOT NULL)
);Identity verification records.
CREATE TABLE claims (
id UUID PRIMARY KEY,
user_id UUID REFERENCES users(id),
profile_id UUID REFERENCES profiles(id),
claim_type VARCHAR(50) NOT NULL,
claim_value VARCHAR(255) NOT NULL,
verified BOOLEAN DEFAULT FALSE,
signature TEXT,
created_at TIMESTAMP,
verified_at TIMESTAMP
);Vector embeddings for AI-powered features.
CREATE TABLE embeddings (
id UUID PRIMARY KEY,
content_id UUID NOT NULL,
content_type VARCHAR(50) NOT NULL,
embedding vector(1536),
metadata JSONB,
created_at TIMESTAMP
);System feature toggles.
CREATE TABLE feature_flags (
id UUID PRIMARY KEY,
flag_name VARCHAR(255) UNIQUE NOT NULL,
enabled BOOLEAN DEFAULT FALSE,
description TEXT,
created_at TIMESTAMP,
updated_at TIMESTAMP
);System configuration.
CREATE TABLE settings (
id UUID PRIMARY KEY,
key VARCHAR(255) UNIQUE NOT NULL,
value JSONB NOT NULL,
description TEXT,
created_at TIMESTAMP,
updated_at TIMESTAMP
);flowchart LR
WM[Worker Manager] --> FW[Farcaster Worker]
WM --> RW[Reddit Worker]
WM --> EW[Ethereum RPC]
WM --> BW[BASE RPC]
WM --> SW[Solana RPC]
WM --> SEW[Search Worker]
WM --> AW[AI Worker]
FW --> DB[(Database)]
RW --> DB
EW --> DB
BW --> DB
SW --> DB
SEW --> DB
AW --> DB
Syncs data from Farcaster Hub:
- User profiles
- Casts (posts)
- Reactions
- Follows
- Syncs every 5 minutes (configurable)
Syncs data from Reddit API:
- Subreddit posts
- Comments
- User profiles
- Currently disabled by default
Monitors Ethereum blockchain:
- ENS lookups
- Wallet balances
- Transaction history
- Smart contract interactions
Monitors BASE blockchain:
- Wallet balances
- Transaction history
- BASE-specific features
Monitors Solana blockchain:
- Wallet balances
- Transaction history
- NFT metadata
Maintains search indexes:
- Full-text search
- Profile search
- Post search
- Tag search
Processes AI tasks:
- Generate embeddings
- Create summaries
- Provide recommendations
- Topic clustering
- Profile optimization
Workers communicate with the database directly and do not communicate with each other. This design ensures:
- Loose coupling: Workers are independent
- Fault isolation: Worker failures don't cascade
- Scalability: Workers can scale independently
- Simplicity: No complex message passing
sequenceDiagram
participant User
participant Frontend
participant API
participant Farcaster
participant Database
User->>Frontend: Click "Sign In"
Frontend->>Farcaster: Request signature
Farcaster->>Frontend: Return signature
Frontend->>API: POST /api/auth/farcaster
API->>API: Verify signature
API->>Database: Create/update user
Database->>API: User data
API->>Frontend: JWT token
Frontend->>User: Authenticated
Default configuration:
- 100 requests per minute per IP
- Configurable via settings table
- 429 status code on limit exceeded
- Exponential backoff recommended
Current version: v1
Base path: /api/v1/*
Future versions will use separate paths to maintain backward compatibility.
- Farcaster Sign-In: Cryptographic signature verification
- SIWE: Ethereum wallet signature verification
- JWT Tokens: Stateless authentication
- Token Expiration: 24-hour default lifetime
- Refresh Tokens: Not yet implemented (future)
- Role-Based Access: Admin vs. User roles
- Profile Ownership: Users can only edit claimed profiles
- Feature Flags: Admin-only access
- Sync Controls: Admin-only access
- PostgreSQL Encryption: Data at rest
- HTTPS: Data in transit (production)
- Input Validation: All API endpoints
- SQL Injection Protection: Parameterized queries
- XSS Protection: Content sanitization
- CSRF Protection: Token validation
- Request rate limiting
- IP-based throttling
- Exponential backoff
- Cloudflare integration (production)
- Admin abuse controls
- Content flagging system
- User blocking
- Automated content filtering (future)
- Lens Protocol: Social graph and content
- Bluesky: Decentralized social network
- Zora: NFT and creator content
- Mastodon: Federated social network
- Advanced recommendation algorithms
- Content quality scoring
- Spam detection
- Sentiment analysis
- Automated moderation
- Horizontal Scaling: Multiple backend nodes
- Worker Distribution: Separate worker servers
- Database Sharding: Partition by user/region
- CDN Integration: Static asset delivery
- Caching Layer: Redis for hot data
- Real-time Updates: WebSocket support
- Push Notifications: Mobile and web
- Advanced Search: Filters and facets
- Analytics Dashboard: User and system metrics
- API Webhooks: Event notifications
- GraphQL API: Alternative to REST
- Mobile Apps: Native iOS and Android
- API Documentation: OpenAPI/Swagger
- SDK Libraries: JavaScript, Python, Go
- Testing Framework: Integration tests
- Local Development: Docker Compose setup
- CI/CD Pipeline: Automated deployment
For more information, see:
- Documentation Index - Complete documentation table of contents
- Installation Guide - Setup and environment configuration
- UI/UX Specifications - Frontend design guidelines
- API Reference - REST API endpoints
- Development Guide - Development workflow for architecture components
- Deployment Guide - Production architecture and scaling
The SocialAi architecture is designed for simplicity, reliability, and extensibility. The one-file node orchestrator simplifies deployment while the parallel worker architecture enables scalability. The system is built with modern web technologies and follows best practices for security, performance, and maintainability.
For UI/UX specifications, see UIUXSPECTS.md.
For API documentation, see API.md.
For installation instructions, see INSTALLATION.md
Last Updated: 2026-02-07