How aliases1538/logist_anti works
This is a monolithic Flask web application that serves:
• Server-rendered UI (Jinja templates in backend/templates/)
• Static frontend assets (Vanilla JS/CSS in backend/static/)
• JSON APIs consumed by the frontend JS (routes under backend/routes/)
• AI/optimization services implemented in-process (backend/services/)
• Persistence via SQLAlchemy models (backend/models.py) targeting SQLite by default (DATABASE_URL=sqlite:///logistics.db)
• External integrations: OSRM for routing, OpenRouter for chatbot, plus an image proxy for image lookup.
Browser (User)
• Loads HTML pages
• Runs main.js, map.js, chatbot.js
Flask Application Server (backend/app.py with create_app)
• Registers routes/blueprints from backend/routes/*
• Serves templates + JSON APIs + static files
• Applies JWT auth
Database (SQLite by default)
• Defined by DATABASE_URL
• Models in backend/models.py
External Services
• OSRM Public API (route calculation)
• OpenRouter API (chatbot completions)
API/Route layer (Blueprint-like modules)
From backend/routes/:
• auth.py: login/register, JWT issuance and validation flows
• admin.py: admin-only stats/user mgmt endpoints (needs “Admin authorization gate”)
• vehicles.py: vehicles CRUD + state changes
• shipments.py: shipments CRUD + tracking/status
• optimization.py: route computation endpoint(s)
• chatbot.py: OpenRouter proxy endpoint(s)
• image_proxy.py: image fetching proxy endpoint(s)
Service / domain logic layer
From backend/services/:
• ai_optimizer.py: route/assignment optimization logic (Haversine, Dijkstra noted)
• ml_model.py: time/fuel prediction (scikit-learn)
• traffic_service.py: traffic/congestion enrichment (even if stubbed, it’s an explicit component)
Data access layer
• config.py: config/env wiring (SECRET_KEY, DB URL, API keys)
Authentication
• Browser → routes/auth.py → DB (models.py)
• auth.py → issues JWT → Browser stores token
• Browser → subsequent API calls include Authorization: Bearer <JWT>
Vehicles / Shipments CRUD
• Browser (JS main.js) → routes/vehicles.py / routes/shipments.py → models.py → SQLite
• Responses feed UI tables/forms (templates + JS)
Map & Routing
• Browser (JS map.js + Leaflet) → routes/optimization.py
• optimization.py → calls:
• OSRM API (for real-road routing)
• services/ai_optimizer.py (graph/path logic)
• services/ml_model.py (ETA/fuel estimates)
• services/traffic_service.py (traffic adjustments)
• Returns route geometry/steps/metrics → Browser renders on map
AI Chatbot
• Browser (chatbot.js) → routes/chatbot.py
• chatbot.py → OpenRouter API → response → Browser chat UI
Image Lookup
• Browser → routes/image_proxy.py
• image_proxy.py → External Image Search API → Browser displays image
Admin-only
• Browser → routes/admin.py (JWT + admin check) → DB queries → admin dashboards
Architectural patterns/design principles to call out
• Monolith with layered modularization:
• Routes (controller-like) → Services (business logic) → Models (persistence)
• Server-rendered + API hybrid:
• Jinja templates for page shells, JS fetch for dynamic CRUD/interactive map/chat
• External API façade/proxy pattern:
• chatbot.py and image_proxy.py shield keys/CORS and standardize responses
• App factory pattern:
• create_app() in backend/app.py (important for deploy via WSGI and testing)
• Goal: show *what depends on what*.
• Split Flask app internals into:
• Web UI (Templates/Static)
• API routes module group
• Services module group
• ORM/Models
• Browser loading templates/static from Flask, then calling JSON endpoints.
• models.py as a shared dependency
• optimization.py → ai_optimizer.py, ml_model.py, traffic_service.py, OSRM
• chatbot.py → OpenRouter
• image_proxy.py → Image API
• vehicles.py / shipments.py / admin.py / auth.py → models.py → DB
This matches the repo structure closely and avoids hand-wavy grouping.
Deployment/hosting element to include (because README mentions it)
A small deployment annotation:
• “WSGI entry (cPanel / passenger_wsgi.py) → create_app()”