Installing the AI Coding Rules Backend Plugin#
This guide will help you install and set up the AI Coding Rules backend plugin in your Backstage instance.
Prerequisites#
Before installing the plugin, ensure you have:
- A working Backstage backend instance
- Properly configured SCM integrations (GitHub, GitLab, etc.)
- Access to repositories containing AI coding rules
- Node.js and yarn package manager
Installation Steps#
1. Add the Package#
Install the plugin package using yarn:
2. Add to Backend#
Add the plugin to your backend in packages/backend/src/index.ts
:
import { createBackend } from '@backstage/backend-defaults';
const backend = createBackend();
// ... other plugins
backend.add(import('@terasky/backstage-plugin-ai-rules-backend'));
backend.start();
3. Configure SCM Integrations#
Ensure your SCM integrations are properly configured in app-config.yaml
:
integrations:
github:
- host: github.com
token: ${GITHUB_TOKEN}
gitlab:
- host: gitlab.com
token: ${GITLAB_TOKEN}
# Add other SCM integrations as needed
Configuration#
Basic Configuration#
Add AI Rules configuration to your app-config.yaml
:
Environment Variables#
Set up required environment variables:
# For GitHub integration
export GITHUB_TOKEN=your_github_token
# For GitLab integration
export GITLAB_TOKEN=your_gitlab_token
# For other SCM providers
export AZURE_TOKEN=your_azure_token
export BITBUCKET_TOKEN=your_bitbucket_token
Verification#
1. Check Backend Logs#
Start your backend and check for successful plugin registration:
Look for log entries indicating the plugin has loaded:
[ai-rules-backend] Plugin loaded successfully
[ai-rules-backend] API routes registered at /api/ai-rules
2. Test API Endpoints#
Test the API endpoints directly:
# Replace with your backend URL and valid entity reference
curl "http://localhost:7007/api/ai-rules/rules?entityRef=component:default/my-service"
Expected response format:
3. Check Entity Resolution#
Verify that entities with source locations are properly resolved:
# Test with an entity that has a source location
curl "http://localhost:7007/api/ai-rules/rules?entityRef=component:default/my-service&ruleTypes=cursor,copilot"
Troubleshooting#
Common Issues#
Plugin Not Loading#
-
Missing Package: Verify the package is installed in package.json
-
Import Error: Check the import statement in backend/src/index.ts
-
Backend Startup Issues: Check backend logs for detailed error messages
API Endpoints Not Working#
- Check Route Registration: Look for API routes in backend logs
- Verify URL: Ensure you're using the correct API path
/api/ai-rules/rules
- CORS Issues: Check if frontend can access the backend API
Repository Access Issues#
-
SCM Integration: Verify SCM integrations are configured correctly
-
Token Permissions: Ensure tokens have read access to repositories
- Private Repository Access: Verify authentication for private repositories
Entity Resolution Problems#
-
Invalid Entity Reference: Check entity reference format
-
Missing Source Location: Verify entities have source location annotations
-
Catalog Sync: Ensure entities are properly ingested into the catalog
Debug Mode#
Enable debug logging to troubleshoot issues:
Or set environment variable:
Network Issues#
If experiencing network connectivity problems:
- Firewall: Check if backend can access external repositories
- Proxy: Configure proxy settings if behind corporate firewall
- DNS: Verify DNS resolution for repository hosts
Performance Issues#
For performance optimization:
- Network Latency: Monitor repository access times
- File Size: Check for unusually large rule files
- Rate Limiting: Monitor API rate limits for SCM providers
Next Steps#
After successful installation:
- Install and configure the frontend plugin
- Review configuration options for customization
- Set up monitoring and logging as needed
- Test with your specific repository structures
Security Considerations#
Token Management#
- Store tokens securely using environment variables
- Use minimal required permissions for tokens
- Regularly rotate authentication tokens
- Monitor token usage and access logs
Repository Access#
- Review which repositories the backend can access
- Ensure proper authentication for private repositories
- Monitor for unauthorized access attempts
- Implement proper error handling to avoid information leakage
For detailed configuration options, proceed to the Configuration Guide.