Lillo is built on a serverless-first architecture using Next.js 15 and Vercel, designed for scalable AI agent deployment and management.
Copy Lillo Framework
├── Frontend (Next.js 15 App Router)
├── API Layer (Vercel Edge Functions)
├── Service Layer
│ ├── LLM Factory
│ ├── Agent Configuration
│ └── Model Preferences
├── Storage Layer
│ ├── Vercel Postgres
│ └── Redis KV Store
└── Integration Layer
├── Telegram Bot API
├── OpenAI API
└── External Services
Copy src / app / # Next .js 15 App Router
├── api / # API Routes
│ ├── webhook / # Webhook handlers
│ ├── telegram / # Telegram endpoints
│ ├── openai / # AI endpoints
│ ├── market / # Market data
│ ├── dalle / # Image generation
│ ├── weather / # Weather data
│ ├── token / # Token management
│ ├── session / # Session handling
│ ├── rpc / # RPC endpoints
│ └── redis / # KV store access
├── hooks / # React hooks
└── layout .tsx # Root layout
Copy src / lib / services / # Core Services
├── LLMFactory .ts # Multi - model LLM integration
│ ├── OpenAI
│ ├── DeepSeek
│ ├── Gemini
│ └── Function Calling
├── AgentConfigService .ts # Agent management
│ ├── Configuration
│ ├── State Management
│ └── Secure Storage
└── ModelPreferences .ts # Model settings
src / utils / # Utility Services
├── prompts .ts # Prompt management
├── telegram .ts # Telegram integration
├── nlp .ts # Natural language processing
├── market .ts # Market data processing
├── kv .ts # Key - value storage
├── encryption .ts # Security utilities
├── adminCheck .ts # Permission system
└── image .ts # Image generation
Copy src / lib / db / # Database Layer
├── schema .ts # Table definitions
├── data .ts # Data operations
├── metrics .ts # Analytics
└── migrations / # Schema updates
Copy graph LR
A[Telegram Message] --> B[Webhook Handler]
B --> C[Message Processor]
C --> D[LLM Factory]
D --> E[Function Calling]
E --> F[Response Handler]
Copy graph TD
A[Agent State] --> B[Redis KV Store]
B --> C[PostgreSQL]
C --> D[Cache Layer]
Copy const tools = [{
type : "function" ,
function : {
name : "generate_image" ,
description : "Generate an image based on the user's request" ,
parameters : {
type : "object" ,
properties : {
prompt : {
type : "string" ,
description : "The description of the image to generate"
}
} ,
required : [ "prompt" ]
}
}
} ,
{
type : "function" ,
function : {
name : "get_weather" ,
description : "Get current weather data" ,
parameters : {
type : "object" ,
properties : {
location : {
type : "object" ,
description : "Location details" ,
properties : {
name : { type : "string" } ,
country : { type : "string" } ,
coordinates : {
type : "object" ,
properties : {
lat : { type : "number" } ,
lon : { type : "number" }
}
}
}
}
}
}
}
}]
Copy // Multi-layer auth system
├── API Authentication
│ ├── Vercel Edge Config
│ └── Environment Variables
├── User Authentication
│ ├── Telegram Verification
│ └── Admin Role System
└── Agent Authentication
├── Encrypted Configs
└── Secure Storage
Copy export enum AdminRole {
USER = 'user' , // Regular user
MODERATOR = 'moderator' , // Can delete messages
ADMIN = 'admin' , // Can manage users
OWNER = 'owner' // Can change group info
}
Copy src /
├── app / # Next .js application
├── lib / # Core libraries
├── utils / # Utilities
├── types / # TypeScript types
├── data / # Static data
└── telegram / # Bot implementation
Copy // Strict type checking
{
"compilerOptions" : {
"strict" : true ,
"target" : "ES2022" ,
"lib" : [ "dom" , "dom.iterable" , "esnext" ] ,
"module" : "esnext" ,
"moduleResolution" : "bundler" ,
"jsx" : "preserve" ,
"noEmit" : true
}
}