How ogpulpy/routegraph-app works
Purpose and Entry Points
RouteGraph is a server-rendered Flask application for finding routes across a modeled Lagos rail/BRT network stored in a Neo4j-compatible CognoDB graph. Local startup enters through run.py; production runs Gunicorn via Procfile. App construction and dependency wiring begin in app/__init__.py.
Application Composition
The Flask app factory initializes configuration, database access, and HTTP routing. The primary UI is a route-finder page, with supporting station and informational pages. HTTP handlers are isolated from graph-query implementation in:
• app/__init__.py
• app/routes/views.py
• app/queries/routes.py
Request and Rendering Flow
A browser loads full HTML pages from the views blueprint. Route searches submit through HTMX, allowing the server to return only a result fragment rather than a full document reload. Views validate request inputs, select the requested optimization mode, invoke the query layer, and render success, empty, or error fragments.
• app/templates/index.html
• app/templates/partials/route_result.html
• app/templates/partials/route_empty.html
Graph Query Boundary
app/queries/routes.py owns parameterized Cypher and is the sole application boundary for route computation and transit lookups. The two central operations are:
1. “Fastest”: directed shortestPath traversal, yielding a minimum-hop path and summed edge durations.
2. “Fewest transfers”: directed allShortestPaths traversal, then line-sequence comparison to minimize line changes, with travel time as a tie-breaker.
Directed traversal is material: connections are stored in both directions, and avoiding undirected traversal limits BFS expansion on CognoDB.
Transit Graph Model and Seeding
The persistent model uses Station and Line nodes. Directed CONNECTS_TO relationships hold duration_minutes and line name; ON_LINE relationships represent station membership in one or more lines. Transfer stations and the CMS–Marina walking link are encoded as graph connectivity, not application-side special cases. The repeatable dataset bootstrap is:
• scripts/seed.py
• app/queries/routes.py
Database Lifecycle and External Service
CognoDB is the external managed graph database, accessed with a Neo4j-compatible Bolt driver. Database connection setup, environment-derived credentials, and driver lifecycle/health responsibilities are centralized rather than embedded in routes or queries.
• app/db/connection.py
• .env.example
• app/db/__init__.py
The service depends on COGNODB_URI, COGNODB_USER, and COGNODB_PASSWORD; Flask session/security configuration uses FLASK_SECRET_KEY.
Deployment Boundary
The application is deployable as a Python web process, with Render-specific deployment configuration and a Gunicorn process command. CognoDB remains a separately provisioned cloud dependency, so database seeding is an explicit operational step rather than part of request-time initialization.
• Procfile
• render.yaml
• requirements.txt
Main entry points: views.py Views blueprint · __init__.py Flask app factory · connection.py Database connection · routes.py Route query layer
Components 17
Web application
- Local entry point
run.py - Flask app factory · Initializes configuration, database access, and routing.
app/__init__.py - Views blueprint · Validates inputs and selects route optimization.
app/routes/views.py - Route finder page
app/templates/index.html - Route result fragment
app/templates/partials/route_result.html - Empty route fragment
app/templates/partials/route_empty.html
Graph data
- Route query layer · Computes fastest and fewest-transfer routes and transit lookups.
app/queries/routes.py - Database connection · Builds and manages the Neo4j-compatible driver.
app/db/connection.py - Database integration
app/db/__init__.py - CognoDB · Separately provisioned Neo4j-compatible graph service.
- Transit network · Stations, lines, directed connections, and transfer connectivity.
Operations
- Dataset seeding · Explicitly loads the repeatable Lagos transit dataset.
scripts/seed.py - Environment contract · Defines CognoDB credentials and Flask secret configuration.
.env.example - Gunicorn web process
Procfile - Render deployment
render.yaml - Python dependencies
requirements.txt
Other components
- Browser
Connections 20
- Browser → Views blueprint: full-page and HTMX requests
- Local entry point → Flask app factory: creates app
- Gunicorn web process → Flask app factory: serves app
- Flask app factory → Views blueprint: registers routes
- Flask app factory → Database integration: initializes database
- Views blueprint → Route finder page: renders page
- Views blueprint → Route query layer: route search and lookups
- Views blueprint → Route result fragment: renders successful HTMX result
- Views blueprint → Empty route fragment: renders empty result
- Route query layer → Database connection: executes parameterized Cypher
- Database integration → Database connection: exposes driver access
- Database connection → CognoDB: Bolt connection
- CognoDB → Transit network: persists
- Dataset seeding → Route query layer: uses query boundary
- Dataset seeding → CognoDB: loads dataset
- Environment contract → Flask app factory: Flask secret configuration
- Environment contract → Database connection: CognoDB credentials
- Render deployment → Gunicorn web process: deploys web process
- Python dependencies → Flask app factory: runtime packages
- Python dependencies → Gunicorn web process: production server package