This Flask application communicates with the BTC Map API for area management functionality. It can be deployed to various platforms including Railway, Render, Fly.io, and others.
-
Push to GitHub - Ensure your code is in a GitHub repository
-
Create Railway Project
- Go to railway.app
- Click "New Project" → "Deploy from GitHub repo"
- Select your repository
-
Configure Environment Variables In Railway dashboard → Variables, add:
SECRET_KEY=<generate-a-random-32-char-string> -
Deploy - Railway will automatically:
- Detect Python project via
pyproject.toml - Install dependencies
- Run the app using the
railway.tomlconfiguration
- Detect Python project via
-
Get Your URL - Railway provides a public URL like
your-app.up.railway.app
railway.toml- Railway-specific configuration (start command, health checks)Procfile- Generic Python web app start command (also works for Heroku/Render)
The app exposes a /health endpoint that returns {"status": "healthy"} for container orchestration.
- Connect GitHub repo
- Set build command:
uv sync(or let it detectpyproject.toml) - Set start command:
gunicorn app:app - Add
SECRET_KEYenvironment variable
fly launch
fly secrets set SECRET_KEY=your-secret-key
fly deployheroku create
heroku config:set SECRET_KEY=your-secret-key
git push heroku mainThe application can also run on Replit with the following settings:
- Python Version: 3.11
- Host: 0.0.0.0 (accessible to external connections)
- Port: 5000 (mapped to external ports 80/443)
- Debug Mode: Enabled in development
Core dependencies managed through pyproject.toml:
flask- Web frameworkflask-session- Session managementrequests- HTTP client for RPC callsgeojson-rewind- GeoJSON orientation correctionshapely- Geometric operationspyproj- Map projections for area calculation
System dependencies (managed by Nix):
geos- Geometry engine for Shapelyproj- Cartographic projections libraryglibcLocales- Locale support
- Base URL:
https://api.btcmap.org - Protocol: JSON-RPC 2.0
- Authentication: Bearer token (user password)
- Timeout: 20 seconds per request
- User enters password on login page
- Password stored in Flask session
- Password used as Bearer token for all RPC calls
- Session expires after 30 minutes of inactivity
/
├── app.py # Main Flask application
├── main.py # Application entry point
├── pyproject.toml # Python dependencies
├── .replit # Replit configuration
├── static/ # Static assets
│ ├── css/
│ │ ├── style.css # Main styles
│ │ └── map.css # Map-specific styles
│ └── js/
│ ├── script.js # Main JavaScript
│ └── validation.js # Validation utilities
├── templates/ # Jinja2 templates
│ ├── base.html # Base layout
│ ├── login.html # Authentication
│ ├── select_area.html # Area search
│ ├── show_area.html # Area details/editing
│ ├── add_area.html # New area creation
│ └── error.html # Error display
└── flask_session/ # Session storage (auto-generated)
- Type: Filesystem-based sessions
- Location:
./flask_session/directory - Lifetime: 30 minutes
- Security: Random 24-byte secret key
password: User's authentication tokenpermanent: True for extended sessions
- All routes protected except
/loginand/static - Automatic redirect to login for unauthenticated users
- Session-based authentication with timeout
- CSRF protection through proper form handling
- Input validation on all user data
- Secure session configuration
- Bearer token authentication for API calls
- Bootstrap 5.1.3: UI framework
- Leaflet 1.7.1: Interactive maps
- OpenStreetMap: Map tiles
- Tile Server:
https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png - Attribution: OpenStreetMap contributors
- Default View: World view (0,0) at zoom level 2
- Use the Run button (configured to start Flask server)
- Application starts on
http://localhost:5000 - External access via Replit's port forwarding
The application uses Replit's workflow system:
- Primary Workflow: "Flask Server"
- Command:
python3 main.py - Port: 5000 (auto-forwarded)
- Flask development server (not production-ready)
- Single-threaded request handling
- File-based session storage
- In-memory session storage
- No load balancing
- Single instance deployment
- Flask logging to console
- Request logging enabled
- Error tracking through application logs
Authentication Failures
- Check password/token validity
- Verify API endpoint accessibility
- Review session timeout settings
Map Display Issues
- Verify Leaflet CDN accessibility
- Check GeoJSON format validity
- Ensure OpenStreetMap tile availability
RPC Communication Errors
- Check internet connectivity
- Verify API endpoint status
- Review timeout settings (20s default)
Enable debug logging by checking Flask console output:
- Request/response logging
- RPC call debugging
- GeoJSON validation details
- Error stack traces
- Sessions stored in
./flask_session/ - Automatic cleanup of expired sessions
- No persistent user data stored locally
- All configuration in version-controlled files
- No database or external storage
- Stateless application design