Files
liqa/docs/architecture.md
T
ars9 b0f2c72b5f docs: bring docs up to date and drop unused keys setting
- rewrite architecture, development, mcp and scenario docs to match the
  current code: single container, all mcp tools, runs, versioning,
  timeouts, settings, client routing and dev setup
- rewrite README as a general overview without liquio-specific wording
- remove the unused KEYS_DIR setting and ./keys compose mount
- remove the unused result parameter from step code execution
- complete .env.example with the file storage settings and fix the
  DB_PATH default
2026-09-30 21:18:41 +03:00

6.6 KiB

Architecture

 Browser (React SPA)              MCP client (AI agent, IDE)
        │  /  and  /api/v1                │  /mcp (Streamable HTTP)
        └──────────────┬──────────────────┘
                       ▼
┌─────────────────────────────────────────────────────────────┐
│ liqa container (:13000 → 3000)  NestJS app, server/src/     │
│                                                             │
│ Routes   /         built client (ServeStaticModule)         │
│          /api/v1   REST API        /docs    Swagger UI      │
│          /mcp      MCP tools       /health  health check    │
│                                                             │
│ McpService                MCP tools → services below        │
│ ScenarioService           scenarios, steps, versions, runs  │
│ ScenarioSchedulerService  @Interval(1 s) run worker         │
│ E2eExportService          standalone Playwright test zip    │
│ SnippetService            snippets + versions               │
│ EnvironmentService        environments                      │
│ CredentialService         credentials                       │
│ ImportService             central YAML import               │
│ FileStorageService        scenario files + run artifacts    │
│ SessionService            saved browser sessions            │
│ SessionContextService     live Playwright contexts          │
│ SessionSchedulerService   @Interval(60 s) session cleanup   │
│ BrowserService            ad-hoc open / exec                │
│ CodeExecutorService       runs step / snippet JS            │
└───────────────┬─────────────────────────────┬───────────────┘
                │ TypeORM (better-sqlite3)    │ Playwright
                ▼                             ▼
   data/liqa.db, data/files/        chromium-headless-shell

Everything runs in one container built from the root Dockerfile: the server serves the API, MCP and Swagger, and also the built client. See development.md for running it.

Server components (server/src/)

  • McpService (mcp/) registers the MCP tools and delegates to the services below. Each request gets a fresh MCP server over the Streamable HTTP transport.
  • ScenarioService (scenario/) manages scenarios, steps, credential aliases, versions, runs, run logs, scenario/run files, and scenario export/import.
  • ScenarioSchedulerService picks up pending runs every second (up to 10 in parallel) and executes their steps in order in one Playwright browser per run. It handles step and scenario timeouts, failure page dumps (screenshot + HTML), Playwright traces, and saving the browser as a session (saveSession).
  • E2eExportService builds a standalone Playwright test project (zip) from a scenario, bundling the snippets, credentials and files it uses.
  • SnippetService (snippet/), EnvironmentService (environment/) and CredentialService (credential/) provide CRUD plus export/import.
  • ImportService (import/) implements POST /import: validates a YAML stream of mixed items, then imports them in dependency order (environments, credentials, snippets, scenarios).
  • FileStorageService (file/) stores uploaded scenario files and run artifacts under FILES_DIR, and deletes expired files on a cron schedule (FILE_CLEANUP_CRON).
  • SessionService (session/) persists saved sessions (cookies, localStorage); SessionContextService keeps their live Playwright contexts; SessionSchedulerService closes idle sessions and deletes old closed ones every minute.
  • BrowserService (browser/) handles ad-hoc automation (POST /api/v1/open, POST /api/v1/exec, and the open_url / exec_code MCP tools), optionally in a saved session.
  • CodeExecutorService (code-executor/) checks step and snippet code with acorn, then runs it with the context API (page, environment values, credentials, snippets, files, assertions, logs). It is not a security sandbox: step code is trusted.

Cross-cutting pieces:

  • config/app.config.ts - all settings, validated at startup (see .env.example).
  • common/app-package.ts - app name and version, read from the workspace root package.json.
  • common/client-static.ts - serving the built client, with the index.html fallback for client-side routes.
  • common/body-parsers.ts - YAML request bodies (application/yaml) for the import endpoint.
  • interceptors/ - a trace id per request (kept in AsyncLocalStorage and added to log lines) and request/response logging; filters/ - consistent error responses.

Data

SQLite via TypeORM with synchronize: true: entity changes alter the schema on startup, and there are no migrations. The main tables:

  • scenarios / scenario_steps hold the latest version of each scenario; scenario_versions holds a snapshot of every version (content + steps).
  • snippets holds the latest version of each snippet; snippet_versions holds every version. Step code pins a version with runSnippet("alias@N").
  • scenario_runs record the scenario version, environment, trace mode and status; scenario_run_steps keep their own copy of each step's code, so a run always shows what it executed; scenario_run_logs hold ordered run logs.
  • files + scenario_files / scenario_run_files map stored files to scenarios and runs.
  • environments, credentials, scenario_credentials (alias → credential per scenario), sessions.

See scenario.md for versioning, runs and import/export rules.

Client (client/)

A React 19 + TypeScript SPA. During development it's served by the Vite dev server; in the Docker image the server serves the built client from the same origin as the API.

The client calls the server REST endpoints directly — there is no separate BFF layer. Routing uses BrowserRouter; the server answers any GET outside /api, /mcp, /docs and /health with the client's index.html, so client-side routes survive a page refresh.

Pages: scenarios (with steps, versions, credentials, used snippets and files), runs, snippets, credentials, environments, sessions, and the central import page. The sidebar footer contains the theme switcher and the app version (injected from the workspace root package.json at build time).

See development.md for the full client tech stack and directory layout.