Express.js backend application for managing decentralized applications (Dex) in the OpenLedger ecosystem.
- RESTful API for application management
- PostgreSQL database with Sequelize ORM
- Authentication middleware (wallet-based)
- CORS enabled
- Error handling and logging
- Node.js (v14 or higher)
- PostgreSQL (v12 or higher)
- npm or yarn
- Clone the repository:
git clone <repository-url>
cd open_terminal_backend- Install dependencies:
npm install- Set up environment variables:
cp .env.example .envEdit .env file with your database credentials and configuration.
- Create the database:
# Connect to PostgreSQL
psql -U postgres
# Create database
CREATE DATABASE open_terminal;npm run devnpm startThe server will start on http://localhost:3000 (or the port specified in your .env file).
GET /health
Returns the server status.
POST /api/create_app
Headers:
- Content-Type: application/json
Request Body:
{
"name": "My Dex App",
"wallet": "0x1234567890abcdef...",
"sign": "signature_string",
"description": "A decentralized exchange application",
"networks": ["ethereum", "polygon"],
"brand_logo": "https://example.com/logo.png",
"brand_fav_icon": "https://example.com/favicon.ico",
"user_prompt": "Welcome to my Dex!",
"design_system_id": "design_123"
}Required Fields:
name: Application namewallet: Wallet address
Response (Success - 201):
{
"success": true,
"data": {
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"name": "My Dex App",
"description": "A decentralized exchange application",
"brand_logo": "https://example.com/logo.png",
"brand_fav_icon": "https://example.com/favicon.ico",
"is_enabled": true,
"created_at": "2026-01-28T10:30:00.000Z",
"updated_at": "2026-01-28T10:30:00.000Z"
}
}Response (Error - 400):
{
"success": false,
"error": "Missing required fields: name and wallet are required"
}- Get Chat History
GET /api/chat/:chat_id/history
- Purpose: Fetch complete conversation history for a specific chat
- Returns: All messages (user + AI responses) with metadata
- Example:
curl -H "x-wallet-address: emailAddress"
"http://localhost:4040/api/chat/jALjI5yl2uu/history"
- Get Single Application
GET /api/applications/:uuid
- Purpose: Fetch details of one specific application by UUID
- Returns: Full application details including chat_id, prompts, etc.
- Example:
curl -H "x-wallet-address: emailAddress"
"http://localhost:4040/api/applications/21b4f18f-bea3-440a-9224-dd5b766701b5"
- Get All Applications
GET /api/applications
- Purpose: Fetch all applications for a wallet
- Returns: List of all applications owned by the wallet
- Example:
curl -H "x-wallet-address: emailAddress"
"http://localhost:4040/api/applications"
| Field | Type | Nullable | Description |
|---|---|---|---|
| uuid | UUID | No | Primary key |
| name | STRING | No | Application name |
| wallet | STRING | No | Wallet address |
| description | TEXT | Yes | App description |
| type | STRING | Yes | Application type |
| networks | ARRAY | Yes | Supported networks |
| brand_logo | STRING | Yes | Logo URL |
| brand_fav_icon | STRING | Yes | Favicon URL |
| system_prompt | TEXT | Yes | System prompt |
| user_prompt | TEXT | Yes | User prompt |
| status | STRING | Yes | Application status |
| vercel_project_id | STRING | Yes | Vercel project ID |
| wallet_project_id | STRING | Yes | Wallet project ID |
| design_system_id | STRING | Yes | Design system ID |
| chat_init_response | TEXT | Yes | Chat initialization |
| is_enabled | BOOLEAN | No | Enable/disable flag |
| created_at | TIMESTAMP | No | Creation timestamp |
| updated_at | TIMESTAMP | No | Update timestamp |
open_terminal_backend/
├── config/
│ └── database.js # Database configuration
├── controllers/
│ └── applicationController.js # Application logic
├── middleware/
│ └── auth.js # Authentication middleware
├── models/
│ └── Application.js # Application model
├── routes/
│ └── applicationRoutes.js # API routes
├── .env.example # Environment variables template
├── .gitignore # Git ignore file
├── package.json # Dependencies
├── server.js # Application entry point
└── README.md # Documentation
The current implementation includes an authentication middleware that validates all requests. Currently, it returns true for all requests. To implement proper wallet signature verification, modify the middleware/auth.js file.
The application includes comprehensive error handling:
- Input validation errors (400)
- Authentication errors (401)
- Not found errors (404)
- Server errors (500)
- The database will auto-sync on server start in development mode
- Use
{ alter: true }for development to update tables without data loss - Never use
{ force: true }in production as it drops all tables
MIT