OptiFlow is an enterprise-grade Operations Research system and ERP built to solve the Flexible Job Shop Scheduling Problem (FJSP) for high-volume manufacturing and print environments.
Moving beyond legacy heuristic/CRUD rule-based systems, OptiFlow V2 utilizes Constraint Programming (CP-SAT) via Google OR-Tools to mathematically optimize factory throughput while strictly enforcing physical manufacturing constraints (Directed Acyclic Graphs).
- System Architecture
- Key Features
- Project Directory Structure
- The Mathematical Engine
- Database Schema
- REST API Structure
- Local Installation & Setup
- Agile Methodology
OptiFlow V2 is built using a decoupled, API-first architecture, allowing high-performance mathematical modeling on the backend and cross-platform flexibility on the frontend.
- The Backend (Python/FastAPI): A highly modular REST API handling all data validation (Pydantic), PostgreSQL transactions, and heavy algorithmic calculations.
- The Frontend (Flutter): A 100% single-codebase UI utilizing responsive
LayoutBuilderlogic to serve two distinct experiences:- Desktop Manager App: A wide-screen dashboard featuring dynamic DAG form builders, Skills Matrix configuration, and an interactive Gantt chart schedule.
- Mobile Worker App: A narrow-screen, mobile-first telemetry application used by factory floor workers to receive, start, and complete scheduled tasks.
Print orders are no longer treated as flat entities. Managers can dynamically build multi-step manufacturing pipelines (e.g., Print
A single click triggers the C++ CP-SAT solver. The engine evaluates millions of schedule permutations to find the optimal assignment of machines and workers, balancing processing speed against operational costs to minimize the overall Makespan.
A highly relational tracking system mapping Resources (humans and machines) to specific Capabilities (e.g., CMYK Printing, Binding), enforcing strict data integrity for processing speeds (units/hr) and financial overhead.
A dedicated mobile interface strictly partitioned by Row-Level/Application logic. Workers only see tasks mathematically assigned to them, allowing them to shift states from SCHEDULED IN_PROGRESS COMPLETED seamlessly.
e22-co2060-OptiFlow/
├── README.MD # Main project documentation
├── optiflow_back/ # Backend (Python / FastAPI / OR-Tools)
│ ├── main.py # App entrypoint, middleware, & legacy routes
│ ├── route.py # CRUD operations & Optimization router
│ ├── optimizer.py # Google OR-Tools CP-SAT scheduler algorithm
│ ├── models.py # Pydantic input validation models
│ ├── databse.py # Supabase PostgreSQL client initializer
│ ├── booking_manager.py # Resource booking & conflict check helpers
│ ├── seed_db.py # Minimal DB seed script (human resources)
│ ├── seed_pitch_data.py # Complete database clear & pitch data seed script
│ ├── requirements.txt # Python dependency manifest
│ └── .env.local # Local environment secrets (ignored by git)
└── optiflow_front/ # Frontend (Flutter / Riverpod)
├── lib/
│ ├── main.dart # App entrypoint (initializes Supabase/Theme/Router)
│ ├── core/ # Shared models, services, & utilities
│ │ ├── services/ # http API service & Supabase Authentication client
│ │ └── models/ # App-wide Dart data representations (Job, Task, etc.)
│ ├── mobile/ # Worker Telemetry Interface (Mobile screens & widgets)
│ └── slices/ # Manager Interface Slices (Admin, Engine, Order)
├── assets/ # Images, icons, and fonts
├── pubspec.yaml # Flutter project dependencies
└── run_dashboard.bat # Convenience launch script for Windows target
The core brain of OptiFlow (optimizer.py) is powered by Google OR-Tools.
The algorithm dynamically ingests the factory's current state from PostgreSQL and constructs a mathematical universe:
- Optional Intervals: Creates Boolean "switches" for every capable machine/worker, forcing the solver to pick exactly one execution path per task.
-
Chronology Enforcement: Translates the PostgreSQL DAGs into strictly enforced linear time dependencies (
$Start_{B} \ge End_{A} + Wait$ ). -
Disjunctive Constraints: Utilizes
AddNoOverlap()primitives to prevent machine double-booking. - Objective Function: Aggressively minimizes the maximum completion time across the entire board.
Hosted on Supabase (PostgreSQL), the architecture relies on a normalized 7-table schema to maintain data integrity:
profiles: Application-level user roles.operation_types: Dictionary of factory capabilities.resources: Active registry of machines and human workers.resource_capabilities: The junction table defining the Skills Matrix.jobs: Overarching client orders.tasks: Atomic sub-components targeted by the scheduling engine.task_dependencies: The DAG edges enforcing chronological integrity.
The backend application contains two main route layers exposed by FastAPI:
-
Standard App Routes (
main.py): Exposed directly under the root context (no/apiprefix). These routes handle legacy booking systems and direct job claims:POST /book_machineGET /jobsPOST /claim_jobPOST /create_job
-
Core Router Endpoints (
route.py): Grouped under the/apiprefix (configured viaapp.include_router(router, prefix="/api")). These handle core capabilities and optimization requests:GET|POST|PUT|DELETE /api/operation-typesGET|POST|PUT|DELETE /api/resourcesGET|POST|PUT /api/capabilitiesPOST /api/optimize/{job_id}— Triggers the CP-SAT solver for a specific job order.
- Python 3.10+
- Flutter SDK (Stable Channel)
- Supabase Project (URL & Anon/Service Keys)
-
Navigate to the backend directory:
cd optiflow_back -
Create a virtual environment & activate it:
- On Windows:
python -m venv venv .\venv\Scripts\activate
- On macOS/Linux:
python3 -m venv venv source venv/bin/activate
- On Windows:
-
Install python dependencies:
pip install -r requirements.txt
-
Environment Variables: Create a
.env.localfile inside theoptiflow_back/folder:SUPABASE_URL="your_supabase_project_url" SUPABASE_KEY="your_supabase_service_role_key"
-
Seed the database (Optional but Recommended):
- Minimal Seed: Check and populate standard team members (HUMAN resources):
python seed_db.py
- Full Reset & Pitch Seed: Clear existing records and populate a fresh, complete set of demo jobs, tasks, operation types, capabilities, and dependencies:
python seed_pitch_data.py
- Minimal Seed: Check and populate standard team members (HUMAN resources):
-
Run the API server:
uvicorn main:app --reload
- The live API documentation will be available at http://127.0.0.1:8000/docs.
-
Navigate to the frontend directory:
cd optiflow_front -
Get packages and dependencies:
flutter pub get
-
Run the application:
- Windows Desktop:
Ensure Windows Developer Mode is enabled, then run:
(Alternatively, you can double-click or execute the convenience script
flutter run -d windows
./run_dashboard.bat). - Web (Chrome):
flutter run -d chrome
- Mobile / Other Target Devices:
flutter run
- Windows Desktop:
Ensure Windows Developer Mode is enabled, then run:
The development process of OptiFlow V2 followed rigorous Agile standards, split into critical engineering cycles:
- Sprint Planning & Backlog Grooming: Translating operational challenges into granular tickets.
- Decoupled Slice Architecture: Dividing features into discrete backend routers and frontend components (e.g. Admin Capabilities, Engine Optimization, Orders DAG form builders) to allow parallel work streams.
- Frequent Releases & Integration Testing: Validating API request shapes through rigorous Pydantic contracts and Flutter telemetry logs.