Home / examples / backends / README

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
View PHP Documentation โ†’

๐ŸŸข 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
View Node.js Documentation โ†’

๐Ÿ 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
View Python Documentation โ†’

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:

  • Change all secrets and JWT keys
  • Disable demo mode
  • Use HTTPS everywhere
  • Configure proper CORS origins
  • Set up proper database authentication
  • Enable logging and monitoring
  • Use environment variables (not .env files)
  • Review and harden security settings
  • Contributing

    When adding new backend functionality:

  • Implement in PHP first (as the reference)
  • Port to Node.js and Python
  • Ensure consistent API interfaces
  • Update all three README files
  • Test with the example HTML files
  • License

    MIT ยฉ LARC Contributors