feat: implement MoloApp plans 01-15 with integration

Full C++23 framework tree: runtime, observability, security,
data, app, realtime, supervisor, clients, CLI, example plus
enterprise tenancy, audit, operability, governance,
supplychain. Postgres via docker compose for tests.
This commit is contained in:
2026-10-23 18:20:04 +02:00
parent 54068f1953
commit 3c4334cec9
1068 changed files with 100899 additions and 2 deletions
+215
View File
@@ -0,0 +1,215 @@
#pragma once
#include <span>
#include <string>
#include <vector>
#include "../caps.h"
#include "../versions/ApiVersion.h"
#include "SurfaceRules.h"
namespace molo::govern::surface {
// Lints route declarations against S1-S10. Reads route patterns, not views.
class RouteLinter {
public:
struct Route {
std::string method;
std::string path;
std::vector<int> statuses;
std::string auth; // none|key|key+scopes|session
std::vector<std::string> scopes;
bool paginated = false;
bool has_page_params = false;
bool has_envelope = false;
bool has_filters = false;
bool filter_in_query = true;
bool has_body = false;
bool idempotency_key = false;
bool has_problem_body = false;
bool has_summary = false;
bool has_example = false;
};
[[nodiscard]] static std::vector<SurfaceRules::Finding> Lint(std::span<const Route> routes) {
std::vector<SurfaceRules::Finding> out;
for (const auto& r : routes) {
const std::string target = r.method + " " + r.path;
CheckS1(r, target, out);
CheckS2(r, target, out);
CheckS3(r, target, out);
CheckS4(r, target, out);
CheckS5(r, target, out);
CheckS6(r, target, out);
CheckS7(r, target, out);
CheckS8(r, target, out);
CheckS9(r, target, out);
CheckS10(r, target, out);
if (out.size() >= Caps::kMaxFindings) break;
}
return out;
}
private:
using Findings = std::vector<SurfaceRules::Finding>;
static void Add(Findings& out, const std::string& rule, const std::string& target,
const std::string& msg) {
if (out.size() >= Caps::kMaxFindings) return;
SurfaceRules::Finding f;
f.rule = rule;
f.severity = std::string(SurfaceRules::SeverityOf(rule));
f.target = target;
f.message = msg;
out.push_back(std::move(f));
}
// S1: literal collection segments are plural nouns.
static void CheckS1(const Route& r, const std::string& target, Findings& out) {
for (const std::string& seg : Split(r.path)) {
if (seg.empty() || seg[0] == ':') continue;
if (seg[0] == 'v' && versions::ApiVersion::ParseMajor("/" + seg) != 0) continue;
if (seg == "status" || seg == "health" || seg == "version" || seg == "openapi" ||
seg == "auth" || seg == "metrics" || seg == "docs") {
continue;
}
if (seg.back() != 's') {
Add(out, "S1", target, "segment '" + seg + "' is not a plural noun");
}
}
}
// S2: known method; GET/HEAD/DELETE carry no body.
static void CheckS2(const Route& r, const std::string& target, Findings& out) {
const bool known = r.method == "GET" || r.method == "POST" || r.method == "PUT" ||
r.method == "PATCH" || r.method == "DELETE" || r.method == "HEAD" ||
r.method == "OPTIONS";
if (!known) {
Add(out, "S2", target, "unknown method '" + r.method + "'");
return;
}
if (r.has_body && (r.method == "GET" || r.method == "HEAD" || r.method == "DELETE")) {
Add(out, "S2", target, r.method + " must not carry a body");
}
}
// S3: at least one 2xx; only known status codes.
static void CheckS3(const Route& r, const std::string& target, Findings& out) {
if (r.statuses.empty()) {
Add(out, "S3", target, "no statuses declared");
return;
}
bool ok2xx = false;
for (int s : r.statuses) {
if (s >= 200 && s < 300) ok2xx = true;
if (!KnownStatus(s)) Add(out, "S3", target, "unknown status " + std::to_string(s));
}
if (!ok2xx) Add(out, "S3", target, "no 2xx status declared");
}
// S4: routes with 4xx/5xx declare a problem body.
static void CheckS4(const Route& r, const std::string& target, Findings& out) {
bool has_err = false;
for (int s : r.statuses) {
if (s >= 400) has_err = true;
}
if (has_err && !r.has_problem_body) {
Add(out, "S4", target, "error statuses without problem body");
}
}
// S5: paginated routes use page/per_page and the {data,meta,links} envelope.
static void CheckS5(const Route& r, const std::string& target, Findings& out) {
if (!r.paginated) return;
if (!r.has_page_params) Add(out, "S5", target, "paginated route without page/per_page");
if (!r.has_envelope) Add(out, "S5", target, "paginated route without {data,meta,links}");
}
// S6: filters travel in query params only.
static void CheckS6(const Route& r, const std::string& target, Findings& out) {
if (r.has_filters && !r.filter_in_query) {
Add(out, "S6", target, "filters must travel in query params");
}
}
// S7: auth declared.
static void CheckS7(const Route& r, const std::string& target, Findings& out) {
const bool known = r.auth == "none" || r.auth == "key" || r.auth == "key+scopes" ||
r.auth == "session";
if (!known) {
Add(out, "S7", target, "auth not declared");
return;
}
if (r.auth == "key+scopes" && r.scopes.empty()) {
Add(out, "S7", target, "key+scopes without scopes");
}
}
// S8: mutating methods accept Idempotency-Key.
static void CheckS8(const Route& r, const std::string& target, Findings& out) {
if ((r.method == "POST" || r.method == "PUT" || r.method == "PATCH") &&
!r.idempotency_key) {
Add(out, "S8", target, "missing Idempotency-Key support");
}
}
// S9: summary plus example.
static void CheckS9(const Route& r, const std::string& target, Findings& out) {
if (!r.has_summary) Add(out, "S9", target, "missing summary");
if (!r.has_example) Add(out, "S9", target, "missing example");
}
// S10: /v{n} prefix.
static void CheckS10(const Route& r, const std::string& target, Findings& out) {
if (versions::ApiVersion::ParseMajor(r.path) == 0) {
Add(out, "S10", target, "missing /v{n} prefix");
}
}
[[nodiscard]] static bool KnownStatus(int s) {
switch (s) {
case 200:
case 201:
case 202:
case 204:
case 206:
case 301:
case 302:
case 303:
case 307:
case 308:
case 400:
case 401:
case 403:
case 404:
case 405:
case 409:
case 410:
case 415:
case 422:
case 429:
case 500:
case 503:
return true;
default:
return false;
}
}
[[nodiscard]] static std::vector<std::string> Split(const std::string& path) {
std::vector<std::string> parts;
std::string cur;
for (char c : path) {
if (c == '/') {
parts.push_back(cur);
cur.clear();
} else {
cur += c;
}
}
parts.push_back(cur);
return parts;
}
};
} // namespace molo::govern::surface
+46
View File
@@ -0,0 +1,46 @@
#pragma once
#include <string>
#include <string_view>
#include <vector>
namespace molo::govern::surface {
// Route surface rules S1-S10. Metadata only; RouteLinter enforces them.
// S1 plural nouns, S2 method semantics, S3 status set, S4 problem body,
// S5 pagination envelope, S6 query-only filters, S7 auth declared,
// S8 Idempotency-Key, S9 summary plus example, S10 version prefix.
class SurfaceRules {
public:
struct Finding {
std::string rule;
std::string severity; // "ERR" or "WARN"
std::string target;
std::string message;
};
[[nodiscard]] static std::vector<std::string> RuleIds() {
return {"S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "S10"};
}
[[nodiscard]] static std::string_view Describe(std::string_view id) {
if (id == "S1") return "collection segments use plural nouns";
if (id == "S2") return "method semantics: known method, no body on GET/HEAD/DELETE";
if (id == "S3") return "status set: at least one 2xx, only known codes";
if (id == "S4") return "error statuses declare a problem body";
if (id == "S5") return "paginated routes use page/per_page plus {data,meta,links}";
if (id == "S6") return "filters travel in query params only";
if (id == "S7") return "auth declared: none|key|key+scopes|session";
if (id == "S8") return "POST/PUT/PATCH accept Idempotency-Key";
if (id == "S9") return "route has summary and example";
if (id == "S10") return "path carries a /v{n} prefix";
return "unknown rule";
}
[[nodiscard]] static std::string_view SeverityOf(std::string_view id) {
if (id == "S2" || id == "S3" || id == "S5" || id == "S7" || id == "S10") return "ERR";
return "WARN";
}
};
} // namespace molo::govern::surface