Skip to content

Project Structure and Boundaries

This page explains where code lives, which layer owns which responsibility, and where a change should land.

Root Layout

text
wg-free-mesh/
  src/       FastAPI backend, migrations, backend tests
  front/     Vue console
  client/    Go client and CLI
  docker/    Docker deployment, gateway, EMQX config
  docs/      VitePress documentation site
  docs-bak/  archived old docs, used only as migration reference

Business code should live only in src/, front/, client/, docker/, and docs/. Do not place new runtime modules, temporary caches, build outputs, or runtime data in the repository root.

If you have not read the system topology yet, start with Architecture. This page focuses on directories and change placement.

Backend

text
src/
  pyproject.toml
  alembic.ini
  migrations/
  app/
    main.py
    api/
      client/
      internal/
      v1/
    core/
    data/
    domain/
    events/
    infrastructure/
    mcp/
    projections/
    schemas/
    services/
  tests/
DirectoryBoundary
api/v1Admin REST API. Authentication dependencies, request parsing, response wrapping, and HTTP errors only.
api/clientClient bind entrypoint for wfmctl bind; not a console API.
api/internalInternal callbacks such as EMQX AuthZ. Protected by internal shared key.
coreConfig, auth, security, public host/origin checks, base errors.
dataSQLAlchemy engine, schema, repositories, transactions, and data access composition.
domainDomain enums, protocol parameter generation, and pure rules without IO.
eventsSSE event publishing and subscriber management.
infrastructureExternal adapters such as EMQX management API.
mcpMCP server, resources, tools, permissions, confirmation, and audit.
projectionsRead models for pages such as config overview, mesh workspace, and system status.
schemasPydantic request and response models.
servicesApplication use cases and business orchestration.
testsBackend tests. Temporary test data must use system temp paths or test-specific folders, not workspace root.

For backend layering, continue with Backend. For stable interface behavior, read API Contract and API Reference.

Backend Dependency Direction

Preferred direction:

text
api -> services -> data
api -> services -> infrastructure
api -> services -> events
mcp -> services
projections -> data
services -> projections

Avoid:

  • Routes writing SQL directly.
  • Frontend assembling cross-resource business rules from multiple APIs.
  • MCP tools bypassing services and mutating repositories directly.
  • Repositories calling HTTP, EMQX, SSE, or MCP.
  • Domain code reading environment variables, databases, or networks.

Frontend

text
front/
  src/
    api/
    assets/
    components/
    router/
    stores/
    types/
    views/
DirectoryBoundary
viewsPage-level components and page interactions.
componentsReusable UI components; no cross-resource business rules.
routerRoutes and navigation guards.
storesPinia state such as auth, layout, and preferences.
apiHTTP client wrappers and API functions.
typesFrontend type definitions aligned with backend responses.
assetsGlobal styles, theme variables, and asset references.

The frontend may handle layout, local interaction, lightweight input validation, REST calls, SSE subscriptions, and display of backend projections.

The frontend should not generate WG/AWG configs, decide final online state, validate mesh topology, compute quick-mesh output, compute default AllowedIPs, track backend build artifacts, or implement MCP/control business rules outside the backend.

For page organization, SSE usage, and i18n rules, continue with Frontend.

Client

text
client/
  cmd/
    agent/
    ctl/
  internal/
    agent/
    bind/
    config/
    control/
    mqtt/
    profile/
    service/

The client has two executables:

  • wfm-agent: system service for MQTT sessions, config push, control commands, status reports, and logs.
  • wfmctl: CLI for install, uninstall, bind, start/stop, status, and logs.

The client is not the business source of truth. It stores local profiles, local service state, and recent execution output. Tunnel protocol, AWG parameters, and control actions should come from the backend payload sent for the current operation.

For the client runtime model, continue with Client. For full MQTT topics and payloads, see MQTT Messages.

Docker

text
docker/
  app/
  emqx/
  gateway/
  sqlite/
  postgres/
DirectoryBoundary
sqliteSQLite deployment entrypoint for personal and small setups.
postgresPostgreSQL deployment entrypoint for long-running and higher-volume setups.
appApplication image build context.
gatewayNginx gateway template for Web/API/SSE/MCP and MQTT public ports.
emqxEMQX config templates, startup script, and certificate generation.

Docker is the recommended deployment path because WFM includes more than a Web app: backend, frontend, EMQX, gateway, certificates, database, and background reconciliation.

Deployment steps live in Docker Deploy. Environment fields live in Environment Reference.

Data Directory

Runtime data defaults to src/data. Docker deployments mount it into the app container. It may contain:

  • SQLite database or app data files.
  • WireGuard / AmneziaWG generated configs.
  • Snapshots.
  • Client build artifacts.
  • Bulk config download packages.

This is runtime data, not source code. Documentation, tests, and dev scripts must not depend on a specific local file existing there.

Source of Truth

The database is the source of truth:

  • Configs, nodes, mesh links, port forwards, system settings, MCP tokens, MCP audit, and client MQTT credentials are database data.
  • EMQX is a runtime projection of database state.
  • Client profiles are local copies of backend-dispatched state.
  • SSE is a refresh signal, not a source of truth.
  • Frontend stores are display caches, not business truth.

Where Changes Land

RequirementPreferred landing area
New business fielddata schema + Alembic + repository + schema + service + docs
New page display fieldPrefer projections; frontend consumes the projection
New console APIschemas + services + api/v1 + reference/api
New MCP capabilityReuse services + mcp/tools + mcp/resources + MCP docs
New client commandclient/cmd/ctl + client/internal + client docs
MQTT topic or payload changeBackend MQTT service + Go client + MQTT reference + client lifecycle docs
Database schema changeAlembic migration + SQLAlchemy schema + snapshot tests
Docker behavior changedocker/* + environment docs + deployment docs

Documentation Placement

  • User workflows: guide/ or usage/.
  • Stable fields, APIs, protocols, errors: reference/.
  • Code structure, architecture, implementation boundaries: developer/.

Do not turn temporary plans, development notes, or AI collaboration traces into user-facing documentation. User docs should describe the current system behavior.