How meslopes/portal_entregador works
Purpose and deployment shape
muv.log is a multi-role delivery-management SaaS: logistics admins operate marketplaces (“praças”), establishments create and track deliveries, and drivers accept and complete them. It is a React SPA deployed to Vercel, calling a Flask REST API on Render, backed by Render PostgreSQL; SQLite is present for local development at instance/app.db.
Application entry points
• Frontend bootstraps through portal-frontend/src/main.jsx, with routing, role-specific screens, and application shell in portal-frontend/src/App.jsx.
• Production backend is served as Gunicorn target portal-backend/src/main_production.py:app; the alternate/general app entry is portal-backend/src/main.py.
• Render deployment metadata is in portal-backend/render.yaml; frontend hosting rules are in portal-frontend/vercel.json.
Frontend identity, authorization, and tenant context
The SPA separates driver, establishment/client, admin, own-driver, and platform experiences. Authentication state and JWT-bearing API access originate in portal-frontend/src/contexts/AuthContext.jsx and portal-frontend/src/lib/api.js. Route access is enforced by portal-frontend/src/components/ProtectedRoute.jsx and portal-frontend/src/components/OwnDriverProtectedRoute.jsx.
“Square”/praça selection is client-side context in portal-frontend/src/contexts/SquareContext.jsx, forming a key scope boundary for operational views.
Backend API composition and persistence
Flask route modules express the API’s business boundaries: identity/user lifecycle in portal-backend/src/routes/auth.py and portal-backend/src/routes/user.py; delivery lifecycle in portal-backend/src/routes/order.py and portal-backend/src/routes/driver.py; admin/platform operation in portal-backend/src/routes/admin.py and portal-backend/src/routes/platform.py.
SQLAlchemy entities are centralized in portal-backend/src/models/portal_models.py, with user-specific models in portal-backend/src/models/user.py. Configuration, including production database and JWT secrets, is loaded through portal-backend/src/config.py.
Order dispatch and delivery execution
Establishments use client pages such as portal-frontend/src/pages/client/NewOrderPage.jsx and portal-frontend/src/pages/client/ClientOrdersPage.jsx to submit and monitor orders. The order API persists, offers, accepts/rejects, and advances delivery status through portal-backend/src/routes/order.py.
Drivers consume available/active deliveries and report activity via portal-frontend/src/pages/OrdersPage.jsx, portal-frontend/src/pages/ActiveDeliveryPage.jsx, and portal-backend/src/routes/driver.py. Driver location and route/map experiences span portal-frontend/src/pages/DriverRouteMap.jsx and portal-frontend/src/pages/TrackPage.jsx.
Operations, finance, and incentives
Admin operational control is concentrated in portal-frontend/src/pages/admin/AdminDashboardPage.jsx, portal-frontend/src/pages/admin/AdminOrdersPage.jsx, and portal-frontend/src/pages/admin/AdminSquaresPage.jsx, backed by portal-backend/src/routes/admin.py. This includes live tracking, establishments, drivers, pricing, and praça administration.
Financial reporting, payments, and withdrawals are separated server-side in portal-backend/src/routes/finance.py; bonus/ranking workflows are in portal-backend/src/routes/bonus.py. The pricing model derives freight from distance and praça pricing, then allocates driver earnings, bonus pool, and platform revenue.
Integrations and asynchronous boundaries
External adapter boundaries are explicit: payment/billing through portal-backend/src/services/asaas_service.py; iFood and Open Delivery ingestion through portal-backend/src/services/ifood_service.py and portal-backend/src/services/open_delivery_service.py; geocoding via OpenStreetMap/Nominatim in portal-backend/src/services/geocoding.py; and WhatsApp Business communication in portal-backend/src/services/whatsapp_service.py.
Inbound provider events belong in portal-backend/src/routes/webhooks.py. Background processing is isolated in portal-backend/src/utils/background_tasks.py, preventing notification/integration work from being solely coupled to synchronous request handling.
Main entry points: App.jsx Role application shell · portal_models.py Delivery domain models · order.py Order dispatch · background_tasks.py Background processing
Components 22
React SPA
Vercel-hosted role-specific portal.
- SPA bootstrap & routes
portal-frontend/src/main.jsx - Role application shell
portal-frontend/src/App.jsx - Auth & API client · Maintains session state and authenticated API access.
portal-frontend/src/contexts/AuthContext.jsx - Role route guards
portal-frontend/src/components/ProtectedRoute.jsx - Praça scope · Client-side selected praça boundary.
portal-frontend/src/contexts/SquareContext.jsx - Establishment orders · Creates and monitors deliveries.
portal-frontend/src/pages/client/NewOrderPage.jsx - Driver delivery flow · Available and active delivery execution.
portal-frontend/src/pages/ActiveDeliveryPage.jsx - Tracking & route maps
portal-frontend/src/pages/DriverRouteMap.jsx - Admin operations · Operational, praça, pricing, and live-tracking control.
portal-frontend/src/pages/admin/AdminDashboardPage.jsx
Flask API
Render-hosted REST API and business logic.
- Production API
- API configuration · Loads database and JWT production settings.
portal-backend/src/config.py - Identity & users
portal-backend/src/routes/auth.py - Order dispatch · Persists orders, offers work, and advances delivery status.
portal-backend/src/routes/order.py - Driver activity
portal-backend/src/routes/driver.py - Admin, finance & incentives · Controls operations and calculates reporting, payments, and bonuses.
portal-backend/src/routes/admin.py - Delivery domain models
portal-backend/src/models/portal_models.py
External services
Provider adapters and asynchronous work.
- Provider webhooks · Receives inbound provider events.
portal-backend/src/routes/webhooks.py - Payment & order adapters · Asaas billing plus iFood and Open Delivery ingestion.
portal-backend/src/services/asaas_service.py - Geocoding adapter
portal-backend/src/services/geocoding.py - Background processing · Decouples notifications and integration work from requests.
portal-backend/src/utils/background_tasks.py - WhatsApp Business
portal-backend/src/services/whatsapp_service.py
Other components
- Render PostgreSQL · Production system of record.
Connections 26
- SPA bootstrap & routes → Role application shell: mounts
- Role application shell → Auth & API client: uses
- Role application shell → Role route guards: enforces access
- Role application shell → Praça scope: scopes views
- Role application shell → Establishment orders: serves
- Role application shell → Driver delivery flow: serves
- Role application shell → Tracking & route maps: serves
- Role application shell → Admin operations: serves
- Auth & API client → Production API: JWT REST calls
- Production API → Identity & users: routes
- Production API → Order dispatch: routes
- Production API → Driver activity: routes
- Production API → Admin, finance & incentives: routes
- Production API → Provider webhooks: routes inbound events
- API configuration → Production API: configures
- Identity & users → Delivery domain models: manages users
- Order dispatch → Delivery domain models: manages orders
- Driver activity → Delivery domain models: updates execution
- Admin, finance & incentives → Delivery domain models: operates & reports
- Delivery domain models → Render PostgreSQL: persists
- Order dispatch → Background processing: dispatches async work
- Provider webhooks → Background processing: queues processing
- Background processing → Payment & order adapters: integrates
- Background processing → WhatsApp Business: sends notifications
- Order dispatch → Geocoding adapter: resolves locations
- Admin, finance & incentives → Payment & order adapters: billing & ingestion