The BTC Map Area Administration tool follows a traditional Flask MVC pattern with additional layers for API communication and data validation.
The main application file contains:
- Route Handlers: All HTTP endpoints for the web interface
- API Integration: RPC communication with BTC Map backend
- Validation Logic: Server-side data validation functions
- Session Management: Authentication and session handling
- Session-based authentication using Flask-Session
- Password protection for all routes (except login)
- 30-minute session timeout for security
/- Home redirect to area selection/select_area- Search and browse areas/show_area/<id>- View/edit specific area/add_area- Create new areas
/api/search_areas- Search functionality/api/set_area_tag- Update area properties/api/remove_area_tag- Remove area properties/api/remove_area- Delete areas
The rpc_call() function handles all communication with the BTC Map backend:
- JSON-RPC 2.0 protocol
- Bearer token authentication
- Error handling and timeout management
- Endpoint:
https://api.btcmap.org/rpc
- User Request → Flask Route Handler
- Authentication Check → Session validation
- Data Processing → Validation and formatting
- Backend Communication → RPC call to BTC Map API
- Response Processing → Format and return to client
- Frontend Update → JavaScript handles UI updates
- Type-specific validation functions
- Area type requirements enforcement
- GeoJSON geometry validation
- URL, email, and phone format validation
- Real-time form validation
- Interactive feedback
- GeoJSON preview and editing
- Map-based geographical validation
The application supports different area types with specific requirements:
- Community Areas: Full metadata with population, contacts, etc.
- Country Areas: Basic geographical and political information
Each type has:
- Required fields that must be present
- Optional fields that can be added
- Custom fields for additional metadata
- Type-specific validation rules
base.html- Common layout and navigationlogin.html- Authentication interfaceselect_area.html- Area search and selectionshow_area.html- Area details and editingadd_area.html- New area creationerror.html- Error handling page
css/style.css- Main application stylescss/map.css- Map-specific stylingjs/script.js- Main application JavaScriptjs/validation.js- Validation utilities
- Modular functions for different features
- Event-driven UI updates
- AJAX communication with backend
- Map integration with Leaflet.js
- Real-time validation feedback
- Session-based authentication
- CSRF protection through Flask-WTF patterns
- Input validation on both client and server
- Secure RPC communication with bearer tokens
- Timeout handling for all external requests