A Node.js/Express backend service for Flowmatic that provides Smart Scan functionality to discover and manage Flow Agents using the Find Labs API.
- Smart Scan: Automatically discover active Flow Agents for users
- Agent Management: Store and manage agent metadata
- User Profiles: User management with Flow address integration
- Scan History: Track scan operations and results
- RESTful API: Clean API endpoints for frontend integration
- Node.js - Runtime environment
- Express.js - Web framework
- Prisma - Database ORM
- MongoDB - Database
- Axios - HTTP client for Find Labs API
- Helmet - Security middleware
- CORS - Cross-origin resource sharing
- Rate Limiting - API protection
cd backend
npm installCopy the example environment file and configure:
cp env.example .envEdit .env with your configuration:
# Database
DATABASE_URL="mongodb+srv://username:password@cluster.mongodb.net/Flowmatic"
# Find Labs API
FIND_LABS_API_URL="https://api.find.xyz"
FIND_LABS_USERNAME="your_username"
FIND_LABS_PASSWORD="your_password"
# Server
PORT=5000
NODE_ENV=developmentGenerate Prisma client and push schema:
npm run db:generate
npm run db:pushnpm run db:seednpm run devThe server will start on http://localhost:5000
- POST
/api/sync- Scan for active agents - GET
/api/sync/status/:address- Get scan status
- GET
/api/agents/:userId- Get user's agents - GET
/api/agents/agent/:agentId- Get specific agent - PUT
/api/agents/agent/:agentId- Update agent metadata - DELETE
/api/agents/agent/:agentId- Deactivate agent - GET
/api/agents/stats/:userId- Get agent statistics
- GET
/api/users/:address- Get user profile - PUT
/api/users/:address- Update user profile - GET
/api/users/:address/scan-history- Get scan history - GET
/api/users/:address/dashboard- Get dashboard data
id- Unique identifieraddress- Flow address (unique)nickname- User-defined nicknameemail- Optional emailcreatedAt- Creation timestampupdatedAt- Last update timestamp
id- Unique identifierscheduledTxId- Find Labs scheduled transaction IDownerAddress- User's Flow addresshandlerContract- Contract address and namestatus- Current status (scheduled, executed, etc.)scheduledAt- Next execution timepriority- Execution priorityexecutionEffort- Computational effortfees- Transaction feesnickname- User-defined nicknamedescription- User-defined descriptiontags- Array of tagsisActive- Active statuscreatedAt- Creation timestampupdatedAt- Last update timestamp
id- Unique identifieruserAddress- User's Flow addressagentsFound- Number of agents foundscanType- Type of scan (initial, rescan, manual)success- Scan success statuserrorMessage- Error message if failedcreatedAt- Scan timestamp
- Receive Request: User provides Flow address
- Upsert User: Find or create user in single atomic operation
- Query Find Labs API: Fetch scheduled transactions for the address
- Filter Results: Only include active/scheduled transactions
- Parallel Upsert Agents: Process all agents concurrently using upsert operations
- Store Scan History: Record successful scan operation
- Return Response: Send processed data to frontend
- Time-based Caching: Avoids API calls when data is fresh (configurable interval)
- State Reconciliation: Only processes changes instead of reprocessing everything
- Upsert Operations: Single database call instead of find + create/update
- Parallel Processing: All agent operations run concurrently with
Promise.all - Centralized Prisma Client: Prevents connection pool exhaustion
- Atomic Operations: Ensures data consistency during concurrent requests
The API includes comprehensive error handling for:
- Validation Errors: Invalid request data
- Database Errors: Prisma/database issues
- API Errors: Find Labs API failures
- Rate Limiting: Too many requests
- Authentication: Missing credentials
- Helmet: Security headers
- CORS: Cross-origin protection
- Rate Limiting: Request throttling
- Input Validation: Request validation
- Error Sanitization: Safe error responses
npm start- Start production servernpm run dev- Start development server with nodemonnpm run db:generate- Generate Prisma clientnpm run db:push- Push schema to databasenpm run db:studio- Open Prisma Studionpm run db:seed- Seed database with sample datanpm run test:connection- Test database connectivitynpm run test:upsert- Test upsert performance optimizationsnpm run test:cache- Test caching and reconciliation performance
backend/
├── src/
│ ├── middleware/
│ │ ├── errorHandler.js
│ │ └── validation.js
│ ├── routes/
│ │ ├── sync.js
│ │ ├── agents.js
│ │ └── users.js
│ ├── services/
│ │ └── agentScannerService.js
│ ├── scripts/
│ │ └── seed.js
│ └── server.js
├── prisma/
│ └── schema.prisma
├── package.json
├── env.example
└── README.md
- Set
NODE_ENV=production - Configure production database URL
- Set up proper Find Labs API credentials
- Configure CORS for production domain
- Set up monitoring and logging
- Use process manager (PM2) for production
- Database Connection: Check
DATABASE_URLin.env - Find Labs API: Verify credentials and API availability
- CORS Issues: Check
CORS_ORIGINconfiguration - Rate Limiting: Adjust limits in production
The application logs important events:
- Scan operations
- API calls
- Database operations
- Errors and warnings
- Follow the existing code structure
- Add proper error handling
- Include input validation
- Update documentation
- Test thoroughly
MIT License - see LICENSE file for details