[新增] 同步更新英文版文档

This commit is contained in:
ryan
2026-05-28 23:00:48 +08:00
parent 95d58eb724
commit b0117b7c84
11 changed files with 870 additions and 121 deletions
+282 -18
View File
@@ -1,31 +1,295 @@
# Development Constraints
After `1.0.0`, OpenFlare development prioritizes stability, upgrade and rollback reliability, documentation accuracy, test coverage, and small iterations inside the existing boundary.
You will learn: The admission criteria for OpenFlare code modifications, backend/Agent/frontend tiered constraints, data model boundaries, API conventions, database migration requirements, and test delivery baselines.
This document integrates the original development specifications, frontend specifications, and development plans, and serves as the engineering constraints entry point for OpenFlare after `1.0.0`.
## Current Conclusions
* The mainline capabilities of the first to sixth versions have all been completed.
* `1.0.0` is the current official baseline.
* Procedural tasks of completed stages are subject to code, tests, and Git history.
* Priority for new work is given to bug fixes, maintainability improvements, and documentation and test reinforcement.
Current Development Priorities:
1. Stability.
2. Upgrade and rollback link reliability.
3. Document accuracy.
4. Test coverage reinforcement.
5. Small iterations within existing boundaries.
## Change Admission
Before implementing a requirement, check:
Before new requirements enter implementation, judge them in the following order:
1. Whether it fits the product boundary.
2. Whether it follows Server, Agent, and frontend development rules.
3. Whether it risks the publish, sync, rollback, or upgrade flow.
4. Whether deployment, configuration, or README docs need updates.
1. Whether it fits the [Product Boundary](./index.md).
2. Whether it follows the backend, Agent, and frontend constraints in this document.
3. Whether it risks breaking the existing publish, sync, rollback, or upgrade main links.
4. Whether it requires synchronized updates to deployment, configuration, README, or documentation site pages.
If a requirement expands the boundary or introduces new infrastructure, update design documentation first.
If a requirement expands the boundary or introduces new infrastructure, the design documentation must be updated first before starting implementation.
## Database Migrations
Any changes merged into the official baseline must at least meet:
Any table, index, column type, sharding, or internal persistence metadata change must bump the database version and include an explicit migration from the previous version.
* Does not break the Agent heartbeat, synchronization, publishing, and rollback main links.
* Does not break the existing OpenResty main configuration hosting model.
* Does not degrade the existing availability of the overview, node details, and access analysis.
* Has tests or joint debugging verification commensurate with the risks.
* Documentation remains consistent with the code.
Migrations must validate the upgraded schema. Startup must stop if migration or validation fails.
## Technical Baseline
## Frontend Rules
Server:
`openflare_server/web` is the frontend baseline:
* Go 1.25+
* Gin
* GORM
* SQLite / PostgreSQL
* Existing login system
* Routes and layouts live in `app/`.
* API calls are centralized under `lib/api/`.
* Business logic belongs in `features/`.
* Server state uses TanStack Query.
* Forms use React Hook Form and Zod.
* Theme supports `light`, `dark`, and `system`.
Agent:
* Single binary
* Node-local execution
* Control OpenResty binary via `openresty_path` or default `openresty`
* Docker deployment uses the Agent image with built-in OpenResty, and does not have the Agent control a separate OpenResty container
Frontend:
* Next.js 15 App Router
* React 19
* TypeScript 5
* Tailwind CSS 4
* TanStack Query
* React Hook Form + Zod
* Zustand only used for lightweight client status
* ESLint + Prettier
* Vitest + Testing Library + Playwright
* pnpm
## Server Layering
| Directory | Responsibility |
| --- | --- |
| `controller/` | Parameter parsing, calling services, returning responses |
| `service/` | Business logic, verification, transaction orchestration, rendering |
| `model/` | Model definition and persistence |
| `router/` | Route registration |
| `middleware/` | Auth, authorization, rate limiting, and other cross-cutting logic |
| `common/` | Configuration, global state, and initialization entry points |
| `utils/` | Pure utility functions and general helpers |
It is forbidden to accumulate business logic in `controller/`, forbidden to implement business flows in `middleware/`, and forbidden to add platform-level abstractions for simple requirements.
## Agent Layering
The Agent maintains its existing module boundaries:
* `config`
* `heartbeat`
* `sync`
* `openresty` / `nginx`
* `state`
* `httpclient`
* `protocol`
* `internal/updater`
Requirements:
* Each module has a single responsibility.
* External command calls are centrally encapsulated.
* State persistence and configuration persistence are separated.
## Frontend Layering
Recommended directories:
```text
app/
components/
features/
lib/
hooks/
store/
types/
styles/
tests/
```
Responsibility constraints:
* `app/`: Routes, layouts, page assembly.
* `features/`: Organize modules by business domains.
* `components/`: Reuse components across features.
* `lib/`: Request client, environment variables, utility functions, constants.
* `store/`: A small amount of cross-page UI state.
* `types/`: Shared type definitions.
Page files are only responsible for obtaining routing parameters, organizing page structures, and calling feature components; they should not handwrite complex API details, complex form verification logic, or maintain a large amount of mutually coupled local states.
## Data Model Specifications
Currently active entities:
* `proxy_routes`
* `origins`
* `config_versions`
* `nodes`
* `auth_sources`
* `external_accounts`
* `node_system_profiles`
* `apply_logs`
* `tls_certificates`
* `managed_domains`
* `node_request_reports`
* `node_access_logs`
* `node_metric_snapshots`
* `traffic_analytics_rollups`
* `node_health_events`
* `options`
General constraints:
* No new platform-oriented objects are added unless explicitly required by the design document.
* `origins` only serves as a reusable origin address directory, and the fields are kept lightweight.
* `proxy_routes` uses "site configuration" as the aggregation boundary and must contain a unique `site_name` and a non-empty `domains` list.
* Each domain in `proxy_routes.domains` must be globally unique, and the first item in the list is treated as the primary domain.
* `proxy_routes` continues to allow saving one or more upstream addresses for load balancing, but does not introduce an independent `origin_pool`.
* The legacy `domain` field can only be used as a compatible mirror of `domains[0]`; new code must not continue to use this field as the unique business input.
* If `proxy_routes` is associated with `origins`, it must also save the `origin_url` that can be directly rendered.
* Upstreams uniformly use named `upstream` + keepalive; for a single upstream carrying a base path or query, the original URI should be added back to `proxy_pass`. For multiple upstreams, only pure `scheme://host[:port]` is allowed.
* Rate limits, reverse proxy, and cache configurations currently belong to the site-level `proxy_routes`.
* HTTPS certificate binding must be saved on a per-domain basis through `domain_cert_ids` parallel to `domains`; domains not bound to a certificate must not participate in HTTPS rendering.
* `config_versions` must save complete snapshots and rendering results.
* There can only be one activated version globally at a time.
* Rollback is achieved by reactivating older versions.
* `nodes` only retains control plane status and low-frequency summaries.
* Observability data must be associated with nodes and time windows, and snapshots and aggregation results use an append-only model.
* Original access details must have a controlled retention policy.
* `auth_sources` only saves management console third-party login source configurations, currently supporting `github` and `oidc`.
* `external_accounts` is the unique source of binding between third-party accounts and local users; the old `users.github_id` is only used for compatible migration and must not be used as the business input for the new login flow.
## Database Migration
Any modification involving table structures, indexes, column types, sharding rules, or internal persistence metadata must upgrade the database version number in sync.
The database version number is defined in `openflare_server/model`, and it must not rely solely on `AutoMigrate` for implicit upgrades of existing databases.
Every time the database version number is upgraded, an explicit migration method from the previous version to the new version must be added. The migration method must contain validation logic after the upgrade; only when the validation passes can the new database version record be written.
After starting the new package, the database's current version must be checked first, and then upgraded step by step in order to the target version; skipping intermediate upgrade steps to directly write the target version is prohibited.
An empty database initialization can directly establish the current version structure, but the same-version validation must still be executed after the initialization is completed, and the current database version must be persisted.
If the migration or validation fails, the startup process must abort, and the database version record must not be upgraded. Submissions involving database version changes must add corresponding migration tests or equivalent regression tests.
## API and Authentication
The management console and Agent APIs uniformly use JSON. Both success and failure must return a clear `message`:
```json
{
"success": true,
"message": "",
"data": {}
}
```
Conventions:
* Agent APIs are uniformly placed under `/api/agent/*`.
* The overview and node details prioritize using dedicated aggregation interfaces.
* Management console mutation APIs uniformly use `POST`; read-only APIs use `GET`.
* The management console continues to reuse existing logins, roles, and Sessions.
* Third-party login uniformly enters through authentication source APIs; authentication source management interfaces must require Root Session.
* `/api/status` can only return the public fields of enabled authentication sources, and must not return the Client Secret.
* When a third-party account is not bound and registration is closed, a process to bind to an existing account should be provided, and users must not be automatically created.
* Official Agent requests uniformly use the node-exclusive `agent_token`.
* The first access can use the global `discovery_token`.
* Agent request headers uniformly use `X-Agent-Token`.
It is forbidden to expose remote shell or arbitrary command execution entries, forbidden to print full Tokens in logs, and forbidden to save main configuration templates that bypass placeholder constraints.
## Publishing and Runtime
The publishing logic must maintain:
* Read all enabled `proxy_routes` during publishing.
* Read OpenResty main configuration parameters, reverse proxy performance parameters, and cache parameters at the same time.
* Generate complete OpenResty configuration.
* Calculate `checksum`.
* Write to `config_versions`.
* Activate the version by switching `is_active`.
Version constraints:
* The version number format is fixed as `YYYYMMDD-NNN`.
* Do not modify historical versions online.
* Do not make differentiated versions grouped by nodes.
* Preview and diff are read-only capabilities and do not generate release records.
The Agent must satisfy:
* Read or generate local `node_id` after startup.
* Periodic heartbeat and synchronization.
* Conventional synchronization prioritizes judging based on the version summary returned by the heartbeat.
* Back up old files first when discovering a new version.
* Write main configurations, route configurations, and necessary certificate files.
* Execute `openresty -t -c <main_config_path>` after writing the new configuration, and then reload; direct startup of OpenResty is allowed when reload finds that it is not running.
* If the activation of the new configuration fails, the Agent must first try to restore execution with the target configuration, then roll back to the old configuration and pull up OpenResty again.
* Report warning when OpenResty recovers normally after rollback; report failure when it still cannot recover after rollback.
* Once a target `version + checksum` fails to apply and rolls back, the Agent must block repeated applications of this target in its local state.
## Frontend Requests, State, and Types
All API requests must be uniformly routed through `lib/api/`:
* Uniformly handle the `success/message/data` response structure.
* Uniformly handle authentication failure, network exceptions, and general error messages.
* Centralize maintenance of resource interfaces and request paths.
State Layering:
* Server state: TanStack Query.
* Page temporary state: Component-internal `useState`.
* Cross-page UI state: Zustand.
Strict TypeScript mode is required; abuse of `any` is prohibited. API responses, form inputs, and business entities must have explicit types.
## Forms, Interaction, Style, and Themes
Forms uniformly use React Hook Form and Zod.
High-risk operations must have double confirmation, show the name of the operation object, and clearly provide success and failure feedback.
Style principles:
* Uniformly use Tailwind CSS and the existing token system.
* Prioritize reusing existing basic components and layout components.
* Maintain consistent visual hierarchy, padding, and semantic colors.
Theme requirements:
* Support `light`, `dark`, and `system` simultaneously.
* User choices must be persisted.
* Try to avoid theme flickering on the first screen.
## Test and Delivery
* Key business logic must have unit tests or equivalent regression tests.
* Agent main link modifications must verify synchronization, application, and rollback.
* Frontend pages must cover at least loading states, empty states, error states, and success feedback.
* When the Go version is adjusted, check `go.mod`, Dockerfile, and CI workflows in sync.
## Subsequent Maintenance
Subsequent planning is no longer maintained in the form of "major version phase documents", but adopts the following methods:
* Product boundary changes: Update [Product Boundary](./index.md).
* Engineering constraint changes: Update this document.
* Deployment and configuration changes: Update [Deployment Guide](../guide/deployment.md), [Configuration Items](../reference/configuration.md), and README.
If explicit new stage goals appear in the future, add dedicated planning documents separately; do not pile completed historical plans back into this document.
The model boundary of the current special topic "Site-level Rules and Configuration Interface Reconstruction" has been integrated into the [Product Boundary](./index.md). When executing, still advance in the order of data models, interfaces, frontend pages, migration tests, and document linkage.
+142 -13
View File
@@ -1,21 +1,150 @@
# Product Boundary
OpenFlare is a self-hosted OpenResty control plane for single-team or single-organization operations. It unifies reverse proxy configuration, node synchronization, certificate management, and basic observability.
You will learn: What OpenFlare is, what problems it solves, who the target users are, what the current stable capabilities are, and which design boundaries cannot be bypassed during implementation.
Stable capabilities:
OpenFlare is a self-hosted OpenResty control plane oriented toward single-team or single-organization internal operation and maintenance (O&M) scenarios. It resolves the issues of scattered management in reverse proxy configuration, node synchronization, certificate hosting, configuration release/rollback, and basic observability.
## Project Positioning
OpenFlare is suitable for teams that need to centrally manage multiple OpenResty proxy nodes:
* Want to maintain reverse proxy site configurations using a management console.
* Want every configuration change to have a complete version, preview, activation, and rollback.
* Want nodes to actively sync configuration, rather than having the control plane SSH into nodes to execute commands.
* Want to manage TLS certificates, domain assets, node statuses, and basic access analytics within the same system.
OpenFlare is currently not positioned as a general-purpose log platform, service mesh, Kubernetes Ingress Controller, or multi-tenant cloud platform.
## Target Users
| User | Needs |
| --- | --- |
| Self-hosted users | Quickly deploy a visual OpenResty control plane |
| Internal O&M teams | Manage multiple reverse proxy nodes, certificates, and configuration versions |
| Development teams | Provide a unified entry point and basic access analytics for internal services |
| Contributors | Fix defects, strengthen tests, and improve documentation within clear boundaries |
## Current Stable Capabilities
| Capability | Description |
| --- | --- |
| Reverse proxy management | Site-level configuration with multiple domains and origins |
| Configuration versions | Preview, publish, activate, and rollback |
| Agent sync | Registration, heartbeat, sync, and apply result reporting |
| OpenResty management | Main template, performance options, cache options, and Lua assets |
| HTTPS/TLS | Certificate storage and per-domain binding |
| Basic observability | Request rollups, resource snapshots, health events, and access analytics |
| Node management | Node state, tokens, deployment, and update flow |
| Reverse Proxy Rule Management | Uses site configuration as the aggregation boundary, supporting multi-domain and origin configuration |
| Site-level Configuration | One rule corresponds to one site, which can bind one or more domains and share site-level configuration |
| Origin Management | Maintains a lightweight origin directory and allows sites to save renderable origin snapshots |
| Configuration Versioning | Supports preview, publishing, activation, immutable history, and rollback |
| Agent Synchronization | Supports registration, heartbeat, synchronization, application result reporting, and self-updating |
| OpenResty Hosting | Manages main configuration templates, performance parameters, cache parameters, and Lua resources |
| HTTPS/TLS | Hosts certificates and domain assets, and binds certificates on a per-domain basis |
| Basic Observability | Aggregates node requests, resource snapshots, health events, and access analytics |
| Node Management | Node status, token systems, deployment, and update links |
| Console Frontend | Next.js-based official management console |
| Auth Source Login | Supports configuring GitHub and standard OIDC login entries as authentication sources, allowing third-party accounts to bind to existing local users |
Default operating model:
Default working method:
* All nodes consume the same globally active version.
* Server stores configuration and state, but does not SSH into nodes.
* Agent is the only controlled entry point on each node.
* All nodes consume the same globally activated version.
* The Server saves configuration and status, and does not directly manage nodes via SSH.
* The Agent is the only controlled landing entry point on the node side.
## Typical Use Cases
| Scenario | Description |
| --- | --- |
| Unified Entry for Internal Services | Expose multiple internal HTTP services through a unified domain and certificate |
| Config Sync for Multi-node Reverse Proxy | Multiple OpenResty nodes consume the same activated configuration |
| Config Change Review | View preview or diff before publishing, and retain immutable history after publishing |
| Quick Rollback | Reactivate an older version, letting the Agent pull and apply it |
| Certificate Hosting | Bind TLS certificates for different domains |
| Basic Observability | View node status, request aggregation, access analytics, and health events |
## Core Objects
Currently active entities:
* `proxy_routes`
* `origins`
* `config_versions`
* `nodes`
* `auth_sources`
* `external_accounts`
* `node_system_profiles`
* `apply_logs`
* `tls_certificates`
* `managed_domains`
* `node_request_reports`
* `node_access_logs`
* `node_metric_snapshots`
* `traffic_analytics_rollups`
* `node_health_events`
## Site Configuration Constraints
`proxy_routes` is upgraded from a "single-domain rule" to a "site configuration" aggregate object. One record corresponds to one website, which can bind one or more domains and share a set of site-level configurations.
Constraints:
* `proxy_routes.site_name` is the unique business identifier of the website.
* `proxy_routes.domains` contains at least one domain, and `domains[0]` is used as the primary domain.
* Any domain can globally belong to only one `proxy_routes`.
* During the migration period, `proxy_routes.domain` can be kept as a mirror field of `domains[0]`, but business read/write and subsequent extensions must be based on `site_name` + `domains`.
* Site-level rate limits, reverse proxies, and cache configurations are currently shared by site and are not configured differently on a per-domain basis within the same website.
* HTTPS allows binding certificates per domain within the same site.
## Origin Constraints
`origins` only saves the origin address, display name, and remarks, and does not carry protocols, ports, paths, weights, or health check policies.
`proxy_routes` can optionally associate an `origins` record to reuse the origin address; the rule still saves a complete `origin_url` snapshot to participate in rendering and version snapshots.
Upstream constraints:
* `proxy_routes` must contain at least one upstream address.
* To maintain compatibility with historical data, the `origin_url` main upstream field is retained, and multiple upstreams are allowed to be added within the same rule for load balancing.
* Upstreams are rendered uniformly as a named `upstream` with keepalive.
* A single upstream can carry a base path or query and append it in `proxy_pass`.
* Multiple upstreams are restricted to pure `scheme://host[:port]`.
* `proxy_routes.origin_host` is an optional field, used to override the `Host` request header when back-origin.
* All upstream addresses must be legal `http://` or `https://`.
## HTTPS Constraints
`proxy_routes.domain_cert_ids` is used to record domain-certificate bindings parallel to `domains`; a value of `0` indicates that HTTPS is not enabled for the domain, retaining only HTTP.
During publishing rendering:
* Domains with certificates are output as separate `443 ssl` `server` blocks grouped by certificate.
* Domains not bound to a certificate must not be automatically brought into HTTPS.
* All domains in `proxy_routes.domains` must be included in the same site configuration to avoid the same site being split in version snapshots.
## Authentication Source Constraints
`auth_sources` is the configuration object for third-party login entries on the management console, currently supporting only two types: `github` and `oidc`. Enabled authentication sources will be displayed on the login page.
`external_accounts` saves the binding relationship between external accounts of authentication sources and local users. When a third-party account logs in for the first time:
* If it is bound to a local user, it logs in directly.
* If there is an existing local login session, it binds to the current user.
* If it is not bound and registration is allowed, a normal user is automatically created and bound.
* If it is not bound and registration is closed, the user is only allowed to enter an existing local account and password to complete the binding.
The old `users.github_id` only serves as a source for upgrade migration; new third-party account login and binding relationships must be based on `external_accounts`.
## Version and Observability Constraints
* `config_versions` must save complete snapshots, rendering results, and `checksum`.
* There can only be one activated version globally at a time.
* Rollback is achieved by reactivating older versions.
* `nodes` only carries control plane status and low-frequency summaries, not high-frequency observability facts.
* Metrics, trends, and access analytics prioritize server-side aggregation results, rather than temporary frontend statistics.
* Access details are only retained for controlled time windows, not evolving into a general-purpose log platform.
## Documentation Maintenance Principles
* Update this document when the product scope or system boundary changes.
* Update [System Architecture](./architecture.md) when the system structure or module responsibilities change.
* Update [Release Model](./release-model.md) when the release, synchronization, or rollback model changes.
* Update [Development Constraints](./development.md) when development constraints, code specifications, or interface conventions change.
* Update [Deployment Guide](../guide/deployment.md) and README when deployment methods change.
* Update [Configuration Reference](../reference/configuration.md) when configuration items change.
* Completed phases will no longer be backfilled in the form of "version plans".
* Before starting a new phase, complete the design first, then enter implementation.
+54 -16
View File
@@ -1,33 +1,71 @@
# Release Model
OpenFlare publishes complete configuration versions instead of modifying node configuration online.
You will learn: Why OpenFlare uses a complete configuration version as the release unit, and how publishing, activation, Agent application, and rollback work.
OpenFlare's release model is centered on complete configuration versions rather than modifying node configurations online.
Standard link:
```text
Edit rules -> Preview / diff -> Publish -> Create full version -> Activate -> Agent pulls -> Agent applies -> Agent reports
Modify rules -> Preview / View diff -> Publish -> Generate complete configuration version -> Activate version -> Agent pulls -> Local application -> Report result
```
## Publish Rules
## Publishing Rules
Server must:
When publishing, the Server must:
1. Read all enabled `proxy_routes`.
2. Read the OpenResty main template and structured options.
3. Render the full OpenResty configuration.
4. Compute `checksum`.
5. Write `config_versions`.
6. Switch the active version.
7. Let Agents discover and apply it in later heartbeats.
2. Read the OpenResty main configuration template, performance parameters, cache parameters, and necessary Lua resources on the Server side.
3. Read domain and certificate binding relationships.
4. Render the complete OpenResty configuration.
5. Calculate the `checksum`.
6. Write to `config_versions`.
7. Switch the activated version.
8. Let the Agent discover and apply it in subsequent heartbeats.
Version numbers use `YYYYMMDD-NNN`.
The version number format is fixed as `YYYYMMDD-NNN`.
## Preview and Publishing
Preview and diff are read-only capabilities and do not generate release records.
Publishing generates a new complete configuration version. The version must contain sufficient information so that future rollbacks can be re-applied based on historical snapshots, without relying on current mutable configurations.
## Activating Version
There can only be one activated version globally at a time.Differentiated versions grouped by nodes are currently not supported.
The Agent obtains the activated version summary through the heartbeat; only when the remote version or checksum is inconsistent with the local state does the Agent enter the synchronization flow.
## Immutable History
Historical versions are immutable. Rollback reactivates an old version.
Historical versions are immutable. Rollback is not achieved by modifying older versions, but by reactivating older versions.
Only one global active version exists at a time. Node-specific version groups are not part of the current model.
The result of doing this is:
## Agent Apply Strategy
* Every version can be traced back.
* The rollback link is consistent with the ordinary release application link.
* The Agent does not need to understand "reverse patch", but only needs to apply a target version.
Agent backs up old files, writes the new main config, route config, certificates, and Lua assets, then validates and reloads.
## Agent Application Policy
If activation fails, Agent attempts to recover. A failed `version + checksum` is blocked locally until the remote active version or checksum changes.
When discovering a new version, the Agent will:
1. Pull the details of the target version.
2. Back up old files.
3. Write the main configuration, route configurations, certificates, and necessary Lua resources.
4. Execute OpenResty configuration verification.
5. reload; if it is not started during runtime, try to start OpenResty with the current configuration.
6. Report success, warning, or failure.
If the activation of the new configuration fails, the Agent must try to restore execution; report a warning when the rollback succeeds, and report a failure when it still cannot recover after rollback.
Once a target `version + checksum` application fails and rolls back, the Agent will block repeated applications of this target in its local state. Only when the remote activated version or checksum changes is it allowed to try again.
## Design Constraints
* Publishing must read all enabled site configurations, rather than only rendering the modified object this time.
* Rollback is achieved by reactivating older versions, without modifying historical versions.
* The Agent API is fixed to use the node-exclusive `agent_token`; the first access can use the `discovery_token`.
* The Server does not provide remote shell or arbitrary command execution entries.
* The configuration version must save complete snapshots, rendering results, and `checksum`.