How meituan-project/project works
1. Overall shape
- This is a Next.js App Router repository for a “weekend arrangement” agent.
- It combines a user-facing product UI, a large set of JSON/TS-backed domain services, and a separate Cloudflare Workers MCP package for external tool access.
- The central architectural idea is: LLM handles intent and explanation; deterministic services handle planning, scoring, confirmation, execution, and evidence.
2. Primary product loop
- The main flow is: user input → plan generation → multi-person consensus or feedback → confirmation gate → controlled execution → receipt/export/log replay.
- Key endpoints in that flow are POST /api/plan, POST /api/confirm, POST /api/execute, POST /api/share-feedback, POST /api/export-run, and GET /api/runs/[traceId].
- The system is designed so that writing actions never happen directly from the model; they require a signed confirmation token.
3. UI surface and experience pages
- The app/ tree is mostly route-driven product surfaces: /agent, /demo/live, /demo/final, /ops/console, /plans, /receipt, /share/[scenario], /logs, /product, and several evaluation/demo pages.
- These pages are presentation shells for different phases of the same workflow: planning, review, consensus, execution, and evidence review.
- Shared styling lives in app/styles/ and global app layout in app/layout.tsx.
4. Agent runtime boundary
- lib/agent/ and components/agent/ form the conversational runtime layer.
- lib/agent/orchestrator.ts coordinates provider routing, component instructions, and tool/component selection.
- components/agent/* renders structured agent outputs such as trace timelines, score breakdowns, plan comparison cards, confirmation gates, recovery trees, and tool-call cards.
- This is not a plain chat UI; it is a componentized agent where the model emits structured artifacts that the UI renders deterministically.
5. Domain engine: TimeBank / local-life solver
- lib/timebank/ is the core domain engine for the product.
- It contains planning, scoring, readiness checks, route/time estimation, business value, consent/confirmation, consensus, evidence, recovery, and multimodal adapters.
- Important boundaries here:
- plan/scoring compute candidate arrangements.
- readiness and workflow-guard decide whether execution is blocked, needs replanning, or is safe.
- confirmation signs the executable arrangement.
- execution, event-log, trace, and persistence capture controlled runtime output.
- This layer is where the app’s “physical reality” constraints live: time, distance, queueing, weather, roles, and supply changes.
6. Consensus and feedback workflow
- The repository explicitly models multi-person decision making.
- app/api/consensus/* supports start, feedback, state, and finalize operations.
- app/api/share-feedback and the app/share/[scenario] pages let companions adjust preferences such as budget, queue tolerance, or venue type.
- The architecture supports incremental replanning instead of a one-shot recommendation, which is important because consensus status affects whether confirmation can be issued.
7. Execution safety and confirmation gate
- The execution boundary is strict: planning is allowed, writing is not unless the arrangement has been confirmed.
- app/api/confirm issues the signed confirmedArrangementId; app/api/execute validates it before any controlled action.
- Readiness severity is treated as a gate: hard constraints block execution, recoverable issues trigger replanning, and warnings are traced but not treated as success.
- This makes confirmation a first-class subsystem rather than a UI checkbox.
8. Model/provider abstraction
- lib/agent/llm-providers/ contains provider adapters for multiple models, with a router and factory.
- The architecture supports model portability across Claude, OpenAI, Gemini, Qwen, LongCat, and others, while keeping the rest of the app provider-agnostic.
- In practice, the LLM is used for interpretation, narration, and orchestration; deterministic engine modules remain the source of truth for business logic.
9. Multimodal and external signal adapters
- app/api/multimodal/speech and app/api/multimodal/vision feed into deterministic adapters in lib/timebank/multimodal/.
- Weather, map, Meituan, and mock-tool abstractions are also isolated in lib/timebank/ and related API routes.
- The repo clearly separates signal ingestion from decision logic: external inputs are normalized first, then scored/planned internally.
10. MCP / worker deployment
- workers/weekend-mcp/ is a separate Cloudflare Workers package that exposes the same product logic through MCP-compatible tooling.
- It includes adapters for map/weather/holiday/LBS, v2 planning tools, and widget output for host integrations such as ChatGPT App or Claude connector workflows.
- This is the external integration boundary of the system: the main Next.js app is the product shell, while the worker package is the portable tool surface.
11. Data, fixtures, and traceability
- data/ contains canonical fixtures, evaluation cases, multimodal samples, schemas, and run artifacts.
- data/runs/ is the runtime output location for exported traces; it is intentionally treated as ephemeral evidence storage.
- schemas/ and the JSON fixture files define the shape of run results and evaluation inputs, which supports deterministic replay and inspection.
12. Evaluation and verification pipeline
- scripts/ contains the repo’s operational quality gates: precheck, smoke tests, eval suites, integration verification, multimodal checks, persistence checks, and mock/live boundary validation.
- pnpm precheck appears to be the umbrella verification path tying together typecheck/build, data validation, evals, and integration sanity.
- This is a repo where evaluation is part of the architecture, not a separate concern.
13. Documentation and product artifacts
- docs/ is unusually important here: it contains the architecture narrative, API contracts, design briefs, eval reports, integration notes, and demo scripts.
- public/design/ holds static design artifacts that support the product story and likely the demo/marketing surfaces.
- The README positions these documents as part of the system’s evidence chain and not just reference material.
14. What to show in an architecture diagram
- A good diagram should center on: User/UI surfaces → API routes → TimeBank domain engine → confirmation/execution gate → trace/log/export.
- Add two side boundaries: LLM provider routing for interpretation/orchestration, and Cloudflare MCP worker for external tool exposure.
- Then show supporting bands for fixtures/data/eval scripts and docs/evidence, because those are integral to how the system is validated and replayed.
Main entry points: engine.ts TimeBank core · route.ts API routes · index.ts MCP tools · orchestrator.ts Agent runtime
Components 20
App UI
Route-driven product surfaces and shared presentation shells.
- App shell · Global layout and shared styling for the product UI.
app/layout.tsx - Surfaces · Primary user-facing pages for planning, demoing, ops, receipts, sharing, and logs.
app/page.tsx - API routes · HTTP boundary for planning, confirmation, execution, consensus, multimodal input, and exports.
app/api/plan/route.ts
Agent Runtime
Conversational orchestration, model routing, and structured output rendering.
- Agent runtime · Coordinates prompts, component selection, and provider-agnostic model use.
lib/agent/orchestrator.ts - Provider router · Routes requests across supported model providers through a common interface.
lib/agent/llm-providers/router.ts - Component registry · Maps model-emitted artifacts to deterministic UI components.
lib/agent/component-registry.ts - Agent cards · Timeline, consensus, scoring, confirmation, recovery, and tool-call views.
components/agent/cards/AgentTraceTimeline.tsx
TimeBank Engine
Deterministic domain logic for planning, scoring, consensus, confirmation, execution, and traces.
- TimeBank core · Central deterministic engine for local-life planning and execution logic.
lib/timebank/engine.ts - Plan & score · Generates candidate arrangements and evaluates business, time, and role tradeoffs.
lib/timebank/scoring-explain.ts - Consensus gate · Collects feedback, tracks state, and finalizes multi-person agreement.
lib/timebank/consensus.ts - Confirm & execute · Signs executable arrangements and validates confirmation before controlled actions.
lib/timebank/confirmation.ts - Trace store · Persists event logs, traces, replay data, and exported run artifacts.
lib/timebank/event-log.ts - Signals · Normalizes weather, map, Meituan, multimodal, and mock-tool inputs.
lib/timebank/adapters.ts - Readiness guard · Blocks unsafe execution, triggers replanning, and records recoverable issues.
lib/timebank/workflow-guard.ts
MCP Worker
Cloudflare Workers package exposing portable tools and widgets.
- MCP tools · Portable MCP-facing tool surface for external host integrations.
workers/weekend-mcp/src/index.ts - Worker planner · Worker-side planning, refinement, and receipt computation tools.
workers/weekend-mcp/src/tools/v2/plan.propose.ts - Worker adapters · Worker connectors for maps, weather, holiday, and location services.
workers/weekend-mcp/src/adapters/weather.ts
Support Data
Fixtures, schemas, docs, and verification assets that support replay and validation.
- Fixtures · Canonical evaluation cases, multimodal samples, run-result schemas, and exported artifacts.
data/eval-cases.json - Verification · Precheck, eval, smoke, and integration scripts that gate repo quality.
scripts/precheck.mjs - Docs & evidence · Architecture notes, API contracts, eval reports, and demo scripts.
docs/api.md
Connections 21
- Surfaces → API routes: invoke · UI surfaces call the HTTP workflow endpoints.
- Surfaces → Agent runtime: chat/ui · Agent pages mount the conversational runtime.
- Agent runtime → Provider router: route model · Runtime dispatches requests to provider adapters.
- Agent runtime → Component registry: emit artifacts · Structured model output is bound to UI component types.
- Component registry → Agent cards: render · Registry selects deterministic cards for presentation.
- API routes → TimeBank core: delegate · API handlers delegate domain work to the deterministic engine.
- TimeBank core → Plan & score: plan · Core planning and scoring compute candidate arrangements.
- TimeBank core → Consensus gate: consensus · Consensus workflow collects feedback and finalizes agreement.
- TimeBank core → Confirm & execute: gate · Confirmation signs and validates executable arrangements.
- TimeBank core → Readiness guard: check · Readiness policy decides block, replan, or proceed.
- TimeBank core → Trace store: persist · Execution and replay data are written as evidence.
- TimeBank core → Signals: normalize input · External signals are adapted before scoring and planning.
- Signals → API routes: multimodal · Speech and vision endpoints feed normalized signals into the app.
- API routes → Trace store: export/log · Routes expose run export and trace lookup.
- MCP tools → Worker planner: tool chain · Worker entrypoint exposes the planning tool pipeline.
- MCP tools → Worker adapters: external data · Worker tools call out to map, weather, holiday, and LBS adapters.
- MCP tools → TimeBank core: shared logic · Worker package mirrors the same product logic boundary.
- Fixtures → Verification: test inputs · Scripts consume canonical fixtures and schemas.
- Docs & evidence → Verification: report · Verification outputs are documented in repo reports.
- Docs & evidence → Surfaces: story · Docs and design artifacts inform the product surfaces.
- Verification → TimeBank core: validate · Quality gates exercise the deterministic engine and integrations.