How asiertxo09/obradoriq works
1. Repository shape
- This is a single full-stack product: a FastAPI backend plus a React/Vite frontend.
- The backend is the system of record and business logic; the frontend is a thin dashboard that consumes /api.
- Persistence is relational (local dev DB plus PostgreSQL in deployment).
2. Primary architectural boundary
- The repo is organized around a strict split between:
- a deterministic recommender core that computes all numeric recommendations,
- and an LLM layer that only phrases, routes, or explains those grounded outputs.
- This is the key design constraint in the product: the model cannot invent numbers.
3. Data ingestion and enrichment
- backend/app/data_hub/ handles ingestion of daily bakery data and external context.
- Inputs include sales, waste, products, and sites from CSV/POS-style files, plus:
- weather from Open-Meteo
- holiday flags from a Madrid calendar
- generate_data.py and seed.py support synthetic/demo dataset creation and initial population.
4. Domain model and persistence
- backend/app/models/ defines the persisted entities; schemas/ defines API-facing shapes.
- service.py appears to coordinate domain operations over the database layer.
- Tests emphasize multi-tenant / cross-tenant isolation, so the DB boundary matters: data must stay scoped by bakery/site/account.
5. Deterministic recommendation engine
- backend/app/recommender/ is the core analytics engine.
- It includes:
- forecast.py for demand prediction,
- newsvendor.py for production quantity optimization,
- production.py for daily production planning,
- reallocation.py for cross-site plan redistribution,
- intraday.py for live-day adjustments,
- signals.py for weather/holiday/confidence features,
- backtest.py and intraday_backtest.py for evaluation.
- This layer is explicitly designed to be pure Python and deterministic.
6. Trust and grounding layer
- backend/app/trust/layer.py is the architectural guardrail.
- It masks sensitive fields, checks that LLM output matches computed values, and rejects outputs that drift from grounded numbers.
- This means the LLM is treated as a phrase generator, not a calculator.
7. Agent and orchestration layer
- backend/app/llm/ contains the conversational agent stack:
- orchestrator.py for higher-level agent flow,
- router.py for model/tool routing and fallback,
- agents.py and tools.py for tool-backed actions.
- The assistant can answer questions, draft production sheets, and import messy input by calling recommender functions as tools.
- The LLM provider is pluggable and can be Anthropic, Groq, NVIDIA, or another OpenAI-compatible endpoint.
8. API surface
- backend/app/api/ exposes the backend to the UI and external callers.
- routes.py defines endpoints; deps.py handles shared dependencies such as auth/context.
- core/security.py suggests authenticated access, including an admin-gated data generation path mentioned in the README.
9. Frontend role
- frontend/ is a TypeScript React app built with Vite.
- It provides the user-facing tabs for:
- landing/onboarding,
- live intraday planning,
- simulation/reallocation,
- conversational “Ask ObradorIQ”.
- In production, the frontend is built statically and served by the FastAPI service.
10. Operational data flows
- The main flow is:
- ingest sales/waste/site context,
- enrich with weather/holiday signals,
- compute forecast and production recommendations,
- optionally reallocate across sites,
- phrase through the trust-checked LLM,
- persist recommendations and user decisions.
- A second flow supports the intraday/live plan, where minute-stamped sales events are used to revise the plan during the day.
11. Evaluation and feedback loop
- Backtests are first-class artifacts in the repo, not an afterthought.
- They measure historical and walk-forward performance for baseline, forecast, newsvendor, and intraday strategies.
- User decisions, recommendation audits, and weekly summaries create a feedback loop for the owner and for system evaluation.
12. Deployment and engineering support
- Dockerfile, docker-compose.yml, and render.yaml show two deployment modes: local containerized and Render-hosted.
- GitHub Actions runs the full test suite in CI.
- The tests/ directory is broad and architecture-relevant: API/auth, agent trust, backtests, intraday behavior, CSV validation, and end-to-end smoke coverage.
Main entry points: forecast.py Recommender core · App.tsx Dashboard · entities.py Entities · ingest.py Data hub
Components 27
Backend
FastAPI service, domain logic, and persistence.
- App entry · Bootstraps the backend service and wires the API application.
backend/app/main.py - API layer · Exposes backend endpoints and shared request dependencies.
backend/app/api/routes.py - Security · Authentication and access-control helpers for protected operations.
backend/app/core/security.py - Domain service · Coordinates business operations over the database and models.
backend/app/service.py - Entities · Persisted bakery, site, sales, waste, and recommendation entities.
backend/app/models/entities.py - Schemas · Request and response shapes exposed by the API.
backend/app/schemas/schemas.py - Data hub · Imports bakery data and enriches it with external context.
backend/app/data_hub/ingest.py - Weather · Fetches Open-Meteo weather features used for enrichment.
backend/app/data_hub/weather.py - Holiday calendar · Adds Madrid holiday flags and calendar context.
backend/app/data_hub/calendar.py - Recommender core · Pure Python forecasting and optimization engine for grounded numeric recommendations.
backend/app/recommender/forecast.py - Forecasting · Predicts demand from historical sales and signals.
backend/app/recommender/forecast.py - Production opt · Computes production quantities from forecasts and uncertainty.
backend/app/recommender/newsvendor.py - Intraday · Revises plans using minute-stamped sales and live signals.
backend/app/recommender/intraday.py - Reallocation · Redistributes production across sites when inventory or demand shifts.
backend/app/recommender/reallocation.py - Trust layer · Masks sensitive fields and verifies LLM output matches computed values.
backend/app/trust/layer.py - Agent layer · Routes prompts, tools, and fallback behavior for conversational actions.
backend/app/llm/orchestrator.py - Model router · Selects or falls back between pluggable LLM providers.
backend/app/llm/router.py - Tools · Wraps recommender and data operations for agent use.
backend/app/llm/tools.py
Frontend
React/Vite dashboard for operators.
- Dashboard · Thin operator UI for live planning, simulation, and chat.
frontend/src/App.tsx - Live planning · Intraday planning surface for revising the day’s production.
frontend/src/Live.tsx - Simulation · Reallocation and what-if planning interface.
frontend/src/Simulate.tsx - Ask ObradorIQ · Conversational interface for grounded assistant interactions.
frontend/src/Tour.tsx - API client · Frontend wrapper for calling backend endpoints.
frontend/src/api.ts
Ops & data
Data fixtures, deployment, and CI support.
- Seed data · Creates initial or demo data for local environments.
backend/app/seed.py - Synthetic data · Generates synthetic bakery datasets for demos and tests.
backend/app/generate_data.py - CSV fixtures · Representative sales, waste, products, and sites inputs.
data/sales.csv - CI pipeline · Runs the test suite in GitHub Actions and containerized checks.
.github/workflows/ci.yml
Connections 31
- App entry → API layer: mounts · The app entrypoint exposes the API layer through FastAPI.
- API layer → Security: uses · Endpoints rely on shared auth and context dependencies.
- API layer → Domain service: calls · Route handlers delegate business operations to the service layer.
- Domain service → Entities: persists · Domain operations read and write persisted entities.
- Domain service → Schemas: shapes · Service-facing payloads are exposed through API schemas.
- Data hub → CSV fixtures: ingests · Structured bakery inputs originate from CSV-style source files.
- Data hub → Weather: enriches with · Daily context is augmented with weather features.
- Data hub → Holiday calendar: enriches with · Holiday signals are added to the daily dataset.
- Data hub → Entities: loads · Ingested data is stored in the domain model boundary.
- Recommender core → Forecasting: includes · Demand forecasting is a core substage of the engine.
- Recommender core → Production opt: includes · Production optimization is a core substage of the engine.
- Recommender core → Intraday: includes · Live-day planning adjusts recommendations during operations.
- Recommender core → Reallocation: includes · Cross-site redistribution is part of the optimization flow.
- Forecasting → Weather: uses · Forecasting consumes external signals as features.
- Forecasting → Holiday calendar: uses · Holiday context informs demand prediction.
- Production opt → Entities: reads · Optimization uses stored history and current state.
- Intraday → Entities: reads · Intraday adjustments use live operational data.
- Agent layer → Model router: routes through · The agent stack delegates provider selection and fallback.
- Agent layer → Tools: uses · Agents invoke grounded tools for data and recommendation actions.
- Tools → Recommender core: calls · Tools wrap deterministic recommendation functions.
- Agent layer → Trust layer: checked by · LLM outputs are validated against grounded values.
- Trust layer → Recommender core: verifies against · The guardrail compares phrasing to computed recommendations.
- Dashboard → API client: calls · UI pages use a shared backend API adapter.
- Dashboard → Live planning: contains · The dashboard includes intraday planning views.
- Dashboard → Simulation: contains · The dashboard includes simulation and reallocation views.
- Dashboard → Ask ObradorIQ: contains · The dashboard includes the conversational assistant view.
- API client → API layer: requests · Frontend interactions are served through backend endpoints.
- Seed data → Entities: populates · Seed scripts initialize the database with baseline entities.
- Synthetic data → CSV fixtures: creates · Synthetic generation produces demo-ready source data.
- CI pipeline → App entry: tests · Continuous integration exercises the backend service entrypoint.
- CI pipeline → Dashboard: tests · CI also covers the UI build and frontend behavior.