# meituan-project/project architecture

> Architecture diagram of the GitHub repository meituan-project/project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/meituan-project/project
- Repository: https://github.com/meituan-project/project

## Overview

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: [`lib/timebank/engine.ts`](https://github.com/meituan-project/project/blob/main/lib/timebank/engine.ts) (TimeBank core), [`app/api/plan/route.ts`](https://github.com/meituan-project/project/blob/main/app/api/plan/route.ts) (API routes), [`workers/weekend-mcp/src/index.ts`](https://github.com/meituan-project/project/blob/main/workers/weekend-mcp/src/index.ts) (MCP tools), [`lib/agent/orchestrator.ts`](https://github.com/meituan-project/project/blob/main/lib/agent/orchestrator.ts) (Agent runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["App UI"]
  node_app_shell["App shell<br/>Next.js app<br/>[layout.tsx]"]
  node_app_surfaces["Surfaces<br/>Route pages<br/>[page.tsx]"]
  node_app_api["API routes<br/>Route handlers<br/>[route.ts]"]
end

subgraph group_agent["Agent Runtime"]
  node_agent_runtime["Agent runtime<br/>Orchestration layer<br/>[orchestrator.ts]"]
  node_provider_router["Provider router<br/>LLM adapters<br/>[router.ts]"]
  node_component_registry["Component registry<br/>Structured UI schema"]
  node_agent_cards["Agent cards<br/>Structured renderers"]
end

subgraph group_engine["TimeBank Engine"]
  node_timebank_core["TimeBank core<br/>Domain engine<br/>[engine.ts]"]
  node_plan_scoring["Plan & score<br/>Planner/scorer<br/>[scoring-explain.ts]"]
  node_consensus_gate["Consensus gate<br/>Consensus workflow<br/>[consensus.ts]"]
  node_confirmation_exec["Confirm & execute<br/>Safety gate<br/>[confirmation.ts]"]
  node_trace_store["Trace store<br/>Evidence/logging<br/>[event-log.ts]"]
  node_signals_adapters["Signals<br/>Adapters<br/>[adapters.ts]"]
  node_runtime_guard["Readiness guard<br/>Execution policy<br/>[workflow-guard.ts]"]
end

subgraph group_worker["MCP Worker"]
  node_worker_tools["MCP tools<br/>Cloudflare worker<br/>[index.ts]"]
  node_worker_planner["Worker planner<br/>Tool pipeline<br/>[plan.propose.ts]"]
  node_worker_adapters["Worker adapters<br/>External adapters<br/>[weather.ts]"]
end

subgraph group_support["Support Data"]
  node_fixtures["Fixtures<br/>Data/schema<br/>[eval-cases.json]"]
  node_scripts_verify["Verification<br/>Scripts<br/>[precheck.mjs]"]
  node_docs_evidence["Docs & evidence<br/>Documentation<br/>[api.md]"]
end

node_app_surfaces -->|"invoke"| node_app_api
node_app_surfaces -->|"chat/ui"| node_agent_runtime
node_agent_runtime -->|"route model"| node_provider_router
node_agent_runtime -->|"emit artifacts"| node_component_registry
node_component_registry -->|"render"| node_agent_cards
node_app_api -->|"delegate"| node_timebank_core
node_timebank_core -->|"plan"| node_plan_scoring
node_timebank_core -->|"consensus"| node_consensus_gate
node_timebank_core -->|"gate"| node_confirmation_exec
node_timebank_core -->|"check"| node_runtime_guard
node_timebank_core -->|"persist"| node_trace_store
node_timebank_core -->|"normalize input"| node_signals_adapters
node_signals_adapters -->|"multimodal"| node_app_api
node_app_api -->|"export/log"| node_trace_store
node_worker_tools -->|"tool chain"| node_worker_planner
node_worker_tools -->|"external data"| node_worker_adapters
node_worker_tools -.->|"shared logic"| node_timebank_core
node_fixtures -->|"test inputs"| node_scripts_verify
node_docs_evidence -->|"report"| node_scripts_verify
node_docs_evidence -.->|"story"| node_app_surfaces
node_scripts_verify -->|"validate"| node_timebank_core

click node_app_shell "https://github.com/meituan-project/project/blob/main/app/layout.tsx"
click node_app_surfaces "https://github.com/meituan-project/project/blob/main/app/page.tsx"
click node_app_api "https://github.com/meituan-project/project/blob/main/app/api/plan/route.ts"
click node_agent_runtime "https://github.com/meituan-project/project/blob/main/lib/agent/orchestrator.ts"
click node_provider_router "https://github.com/meituan-project/project/blob/main/lib/agent/llm-providers/router.ts"
click node_component_registry "https://github.com/meituan-project/project/blob/main/lib/agent/component-registry.ts"
click node_agent_cards "https://github.com/meituan-project/project/blob/main/components/agent/cards/AgentTraceTimeline.tsx"
click node_timebank_core "https://github.com/meituan-project/project/blob/main/lib/timebank/engine.ts"
click node_plan_scoring "https://github.com/meituan-project/project/blob/main/lib/timebank/scoring-explain.ts"
click node_consensus_gate "https://github.com/meituan-project/project/blob/main/lib/timebank/consensus.ts"
click node_confirmation_exec "https://github.com/meituan-project/project/blob/main/lib/timebank/confirmation.ts"
click node_trace_store "https://github.com/meituan-project/project/blob/main/lib/timebank/event-log.ts"
click node_signals_adapters "https://github.com/meituan-project/project/blob/main/lib/timebank/adapters.ts"
click node_runtime_guard "https://github.com/meituan-project/project/blob/main/lib/timebank/workflow-guard.ts"
click node_worker_tools "https://github.com/meituan-project/project/blob/main/workers/weekend-mcp/src/index.ts"
click node_worker_planner "https://github.com/meituan-project/project/blob/main/workers/weekend-mcp/src/tools/v2/plan.propose.ts"
click node_worker_adapters "https://github.com/meituan-project/project/blob/main/workers/weekend-mcp/src/adapters/weather.ts"
click node_fixtures "https://github.com/meituan-project/project/blob/main/data/eval-cases.json"
click node_scripts_verify "https://github.com/meituan-project/project/blob/main/scripts/precheck.mjs"
click node_docs_evidence "https://github.com/meituan-project/project/blob/main/docs/api.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_shell,node_app_surfaces,node_app_api toneBlue
class node_agent_runtime,node_provider_router,node_component_registry,node_agent_cards toneAmber
class node_timebank_core,node_plan_scoring,node_consensus_gate,node_confirmation_exec,node_trace_store,node_signals_adapters,node_runtime_guard toneMint
class node_worker_tools,node_worker_planner,node_worker_adapters toneRose
class node_fixtures,node_scripts_verify,node_docs_evidence toneIndigo
```

## Components

### App UI

Route-driven product surfaces and shared presentation shells.

- [App shell](https://github.com/meituan-project/project/blob/main/app/layout.tsx): Next.js app · Global layout and shared styling for the product UI. · `app/layout.tsx`
- [Surfaces](https://github.com/meituan-project/project/blob/main/app/page.tsx): Route pages · Primary user-facing pages for planning, demoing, ops, receipts, sharing, and logs. · `app/page.tsx`
- [API routes](https://github.com/meituan-project/project/blob/main/app/api/plan/route.ts): Route handlers · 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](https://github.com/meituan-project/project/blob/main/lib/agent/orchestrator.ts): Orchestration layer · Coordinates prompts, component selection, and provider-agnostic model use. · `lib/agent/orchestrator.ts`
- [Provider router](https://github.com/meituan-project/project/blob/main/lib/agent/llm-providers/router.ts): LLM adapters · Routes requests across supported model providers through a common interface. · `lib/agent/llm-providers/router.ts`
- [Component registry](https://github.com/meituan-project/project/blob/main/lib/agent/component-registry.ts): Structured UI schema · Maps model-emitted artifacts to deterministic UI components. · `lib/agent/component-registry.ts`
- [Agent cards](https://github.com/meituan-project/project/blob/main/components/agent/cards/AgentTraceTimeline.tsx): Structured renderers · 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](https://github.com/meituan-project/project/blob/main/lib/timebank/engine.ts): Domain engine · Central deterministic engine for local-life planning and execution logic. · `lib/timebank/engine.ts`
- [Plan & score](https://github.com/meituan-project/project/blob/main/lib/timebank/scoring-explain.ts): Planner/scorer · Generates candidate arrangements and evaluates business, time, and role tradeoffs. · `lib/timebank/scoring-explain.ts`
- [Consensus gate](https://github.com/meituan-project/project/blob/main/lib/timebank/consensus.ts): Consensus workflow · Collects feedback, tracks state, and finalizes multi-person agreement. · `lib/timebank/consensus.ts`
- [Confirm & execute](https://github.com/meituan-project/project/blob/main/lib/timebank/confirmation.ts): Safety gate · Signs executable arrangements and validates confirmation before controlled actions. · `lib/timebank/confirmation.ts`
- [Trace store](https://github.com/meituan-project/project/blob/main/lib/timebank/event-log.ts): Evidence/logging · Persists event logs, traces, replay data, and exported run artifacts. · `lib/timebank/event-log.ts`
- [Signals](https://github.com/meituan-project/project/blob/main/lib/timebank/adapters.ts): Adapters · Normalizes weather, map, Meituan, multimodal, and mock-tool inputs. · `lib/timebank/adapters.ts`
- [Readiness guard](https://github.com/meituan-project/project/blob/main/lib/timebank/workflow-guard.ts): Execution policy · 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](https://github.com/meituan-project/project/blob/main/workers/weekend-mcp/src/index.ts): Cloudflare worker · Portable MCP-facing tool surface for external host integrations. · `workers/weekend-mcp/src/index.ts`
- [Worker planner](https://github.com/meituan-project/project/blob/main/workers/weekend-mcp/src/tools/v2/plan.propose.ts): Tool pipeline · Worker-side planning, refinement, and receipt computation tools. · `workers/weekend-mcp/src/tools/v2/plan.propose.ts`
- [Worker adapters](https://github.com/meituan-project/project/blob/main/workers/weekend-mcp/src/adapters/weather.ts): External 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](https://github.com/meituan-project/project/blob/main/data/eval-cases.json): Data/schema · Canonical evaluation cases, multimodal samples, run-result schemas, and exported artifacts. · `data/eval-cases.json`
- [Verification](https://github.com/meituan-project/project/blob/main/scripts/precheck.mjs): Scripts · Precheck, eval, smoke, and integration scripts that gate repo quality. · `scripts/precheck.mjs`
- [Docs & evidence](https://github.com/meituan-project/project/blob/main/docs/api.md): Documentation · Architecture notes, API contracts, eval reports, and demo scripts. · `docs/api.md`

## Connections

- 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.
