LARC/PAN Backend Examples
Backend API implementations for LARC/PAN in multiple languages. Choose the language you're most comfortable with!
Available Languages
๐ฆ PHP (Recommended for Examples)
Location:backends/php/
PHP backends are recommended for the examples because they run directly with PHP's built-in server without requiring a separate process. Perfect for quick prototyping and learning.
- โ No separate server process needed
- โ
Works with
php -S localhost:8000 - โ Commonly available on shared hosting
- โ Simple deployment
๐ข Node.js
Location:backends/nodejs/
Modern JavaScript backend implementations using native Node.js HTTP server (no Express). Great for JavaScript developers who want to keep everything in one language.
- โ Same language as frontend
- โ Non-blocking I/O
- โ Rich npm ecosystem
- โ Great for real-time apps
๐ Python
Location:backends/python/
Flask-based implementations perfect for Python developers and data science workflows. Python's simplicity makes these backends very approachable for beginners.
- โ Extremely readable code
- โ Built-in SQLite support
- โ Flask is lightweight and simple
- โ Great for data-driven apps
Backend APIs
Each language implements the same set of APIs:
1. Legacy API (Simple Database API)
- Port: 3000
- No authentication
- List resources, get data, describe tables
- Perfect for getting started
2. Secure API (Production-Ready)
- Port: 3001
- Authentication required
- CSRF protection, rate limiting
- Resource whitelisting
- Security headers
3. Authentication API
- Port: 3002
- JWT token-based auth
- Login, logout, refresh, check status
- Demo credentials provided
4. SSE Server (Real-Time Events)
- Port: 3003
- Server-Sent Events for PAN messaging
- Subscribe to topics with wildcards
- Publish and broadcast events
- File-backed persistence
Quick Start
PHP
cd backends/php
php -S localhost:3000 api-legacy.php
Node.js
cd backends/nodejs
npm install
npm run all # Runs all servers
Python
cd backends/python
pip install -r requirements.txt
python3 api-legacy.py
Database Configuration
All backends share the same .env configuration format:
[db]
type=mysql # or sqlite
host=localhost
user=root
pass=
db=test
# For SQLite
# type=sqlite
# file=pan_demo.db
[demo]
mode=true
[security]
jwt_secret=change-this-secret-in-production
Which Language Should You Choose?
Choose PHP if:
- You're running the examples for learning
- You want the simplest setup
- You have shared hosting
- You don't want to manage server processes
Choose Node.js if:
- You're already using JavaScript for frontend
- You want non-blocking I/O
- You're building real-time applications
- You prefer the npm ecosystem
Choose Python if:
- You're a Python developer
- You're working with data science/ML
- You want the most readable code
- You're building data-driven applications
Feature Comparison
| Feature | PHP | Node.js | Python | |---------|-----|---------|--------| | Setup Simplicity | โญโญโญโญโญ | โญโญโญโญ | โญโญโญโญ | | Built-in Server | โ | โ | โ (dev) | | MySQL Support | โ | โ | โ | | SQLite Support | โ | โ | โ (built-in) | | Shared Hosting | โ | Limited | Limited | | Real-time | โ | โญโญโญโญโญ | โญโญโญโญ | | Async/Await | โ | โ (native) | โ | | Type Safety | โ (8.0+) | โ (TypeScript) | โ (type hints) |
Example HTML Files
The HTML examples in the parent directory use PHP backends by default because they're the easiest to get started with. To use Node.js or Python backends instead, simply change the API URLs in the HTML files:
// Default (PHP)
const API_URL = 'api.php';
// Node.js
const API_URL = 'http://localhost:3001/';
// Python
const API_URL = 'http://localhost:3001/';
Production Deployment
PHP
# With Apache/Nginx + PHP-FPM
# Or use PHP's built-in server (dev only)
php -S 0.0.0.0:8000 api.php
Node.js
# With PM2
npm install -g pm2
pm2 start api.js --name "larc-api"
Python
# With Gunicorn
pip install gunicorn
gunicorn -w 4 -b 0.0.0.0:3000 api-legacy:app
Security Notes
โ ๏ธ Important: These examples are configured for development use. Before deploying to production:
.env files)Contributing
When adding new backend functionality:
License
MIT ยฉ LARC Contributors