A comprehensive AI-powered agent that wraps the Xero API to provide accounting and CFO assistant capabilities. This system automates bookkeeping tasks, provides financial analysis, and integrates with n8n for workflow automation.
- Xero API Integration: Seamless integration with Xero accounting platform
- Automated Bookkeeping: Bank reconciliation, transaction categorization, invoice automation
- Financial Analysis: KPI calculation, cash flow forecasting, anomaly detection
- n8n Integration: API endpoints and webhooks for workflow automation
- Security: Comprehensive security measures including input validation, CSRF protection, rate limiting, and data encryption
- Node.js (v16 or higher)
- npm (v7 or higher)
- Xero Developer account with API credentials
- n8n instance (optional, for workflow automation)
-
Clone the repository:
git clone https://github.com/your-username/xero-cfo-assistant.git cd xero-cfo-assistant -
Install dependencies:
npm install -
Create a
.envfile based on the provided.env.example:cp .env.example .env -
Update the
.envfile with your Xero API credentials and other configuration options. -
Initialize the database:
node scripts/init-db.js -
Start the application:
npm start
To connect with Xero, you need to set up OAuth 2.0 authentication:
- Create a Xero application at developer.xero.com
- Set the redirect URI to
https://your-app-url.com/api/auth/xero/callback - Copy the Client ID and Client Secret to your
.envfile - Update the
XERO_REDIRECT_URIin your.envfile to match your application URL
| Variable | Description | Default |
|---|---|---|
| NODE_ENV | Environment mode (development, production) | development |
| PORT | Server port | 3000 |
| JWT_SECRET | Secret key for JWT tokens | (required) |
| JWT_EXPIRY | JWT token expiry time | 24h |
| XERO_CLIENT_ID | Xero OAuth Client ID | (required) |
| XERO_CLIENT_SECRET | Xero OAuth Client Secret | (required) |
| XERO_REDIRECT_URI | Xero OAuth Redirect URI | (required) |
| DATABASE_URL | Database connection URL | sqlite:./database.sqlite |
| ENCRYPTION_KEY | Key for encrypting sensitive data | (required) |
| LOG_LEVEL | Logging level | info |
| RATE_LIMIT_WINDOW_MS | Rate limiting window in milliseconds | 900000 |
| RATE_LIMIT_MAX | Maximum requests per window | 100 |
| WEBHOOK_SECRET | Secret for webhook signatures | (required) |
The API is organized around RESTful principles. It accepts JSON request bodies, returns JSON responses, and uses standard HTTP response codes.
POST /api/auth/register- Register a new userPOST /api/auth/login- Login and get JWT tokenGET /api/auth/xero- Initiate Xero OAuth flowGET /api/auth/xero/callback- Handle Xero OAuth callbackGET /api/auth/profile- Get current user profilePUT /api/auth/profile- Update user profile
GET /api/xero/tenants- List connected Xero tenantsGET /api/xero/contacts- List Xero contactsGET /api/xero/accounts- List Xero accountsGET /api/xero/invoices- List Xero invoicesGET /api/xero/bills- List Xero billsGET /api/xero/bank-transactions- List Xero bank transactions
POST /api/bookkeeping/reconcile- Reconcile bank transactionsPOST /api/bookkeeping/categorize- Categorize transactionsGET /api/bookkeeping/categories- List transaction categoriesPOST /api/bookkeeping/categories- Create transaction categoryGET /api/bookkeeping/rules- List categorization rulesPOST /api/bookkeeping/rules- Create categorization rule
GET /api/analysis/kpis- Get financial KPIsGET /api/analysis/cash-flow/forecast- Get cash flow forecastGET /api/analysis/anomalies- Get financial anomaliesGET /api/analysis/reports- List financial reportsGET /api/analysis/reports/:id- Get specific financial report
GET /api/n8n/kpis- Get financial KPIs for n8nGET /api/n8n/cash-flow/forecast- Get cash flow forecast for n8nGET /api/n8n/cash-flow/issues- Get cash flow issues for n8nGET /api/n8n/anomalies- Get financial anomalies for n8nPOST /api/n8n/transactions/sync- Sync bank transactions for n8nGET /api/n8n/transactions/:transactionId/matches- Get transaction matches for n8nPOST /api/n8n/transactions/categorize- Categorize transactions for n8nGET /api/n8n/invoices/overdue- Get overdue invoices for n8nGET /api/n8n/contacts/:contactId/payment-reminder- Generate payment reminder for n8nPOST /api/n8n/contacts/:contactId/payment-reminder- Send payment reminder for n8nGET /api/n8n/bills/upcoming- Get upcoming bill payments for n8nGET /api/n8n/bills/payment-schedule- Generate payment schedule for n8n
POST /api/webhooks/xero- Handle Xero webhook eventsPOST /api/webhooks/register- Register a new webhookGET /api/webhooks/list- List registered webhooksPUT /api/webhooks/:webhookId- Update webhookDELETE /api/webhooks/:webhookId- Delete webhookPOST /api/webhooks/:webhookId/regenerate-secret- Regenerate webhook secretPOST /api/webhooks/:webhookId/test- Test webhook
The system includes pre-built n8n workflow templates for common automation tasks:
- Daily Bank Reconciliation - Automatically syncs and categorizes bank transactions
- Invoice Payment Reminder - Sends reminders for overdue invoices
- Monthly Financial Report - Generates and distributes monthly financial reports
To use these templates:
- Import the JSON files from the
n8n_workflowsdirectory into your n8n instance - Update the API endpoint URLs and API keys in the workflow
- Activate the workflow
- Create a new Replit project
- Upload the codebase or connect to your GitHub repository
- The included
.replitfile will configure the environment - Set up the required environment variables in Replit's Secrets tab
- Run the deployment script:
sh deploy.sh
- Ensure Node.js and npm are installed on your server
- Clone the repository to your server
- Install dependencies:
npm install --production - Set up environment variables
- Start the application:
npm start
For production environments, consider using a process manager like PM2:
npm install -g pm2
pm2 start src/app.js --name xero-cfo-assistant
The system implements several security measures:
- Input Validation: All incoming requests are validated against defined schemas
- CSRF Protection: Cross-Site Request Forgery protection with token verification
- Rate Limiting: Prevents abuse and brute force attacks
- Audit Logging: Records detailed logs of sensitive operations
- Data Encryption: Encrypts sensitive data using AES-256-GCM
- Secure Headers: Sets security-related HTTP headers to protect against common vulnerabilities
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit your changes:
git commit -am 'Add feature' - Push to the branch:
git push origin feature-name - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.