- Introduced runtime bootstrap helpers in `mjr_am_backend.features.runtime` for dependency initialization. - Implemented `apply_startup_settings` to handle various startup configurations. - Added search request normalization helpers in `mjr_am_backend.features.search` including `SearchRequestContext` and `parse_search_request` for better query handling. - Created audit logging helpers in `mjr_am_backend.routes.core.audit_log` for state-changing route handlers. - Developed a quality gate script in `scripts/run_quality_gate.py` to enforce code quality checks. - Added comprehensive tests for audit routes, scan consistency, vendor routes, and code quality metrics.
2.3 KiB
2.3 KiB
Architecture Map
Version: 2.4.2
Last Updated: March 25, 2026
This map is the working reference for backend refactors. It is intentionally short and operational.
Package Responsibilities
mjr_am_backend/routes- HTTP surface only.
- Parse request data, apply auth/CSRF/rate-limit guards, call services, map
Resultpayloads.
mjr_am_backend/routes/core- Shared route helpers for security, path rules, JSON parsing, responses, and service resolution.
mjr_am_backend/features- Business logic and orchestration by domain: index, metadata, collections, browser, health, tags, viewer.
mjr_am_backend/adapters- Boundary code for SQLite, filesystem watchers, external tools, and other integration points.
mjr_am_shared- Shared result types, error definitions, logging, time helpers, and cross-cutting utilities.
Request Flow
UI action -> route handler -> route/core helper -> feature service -> adapter -> DB/filesystem/tool -> Result response -> UI mapping
Rules:
- Routes do not decide filesystem or security policy locally.
- Services own business rules and orchestration.
- Adapters isolate external side effects.
security.pyis the single policy entry point for auth, write access, safe mode, trusted proxies, and CSRF.
Watcher And Index Flow
Filesystem event -> watcher scope/runtime -> index orchestration -> DB update -> UI refresh event
Hot zones:
- watcher lifecycle and scope resolution
- reset/rebuild orchestration
- metadata probing and vector backfill
- live viewer synchronization
These zones should be refactored behind stable service facades before adding new behavior.
Security Rules
- Public API base stays
/mjr/am/*. - Backend returns structured
Resultpayloads for expected errors. - Safe mode is enabled by default.
- Remote write remains denied without a valid token.
- Loopback write is allowed by default in the current compatibility model unless
MAJOOR_REQUIRE_AUTH=1is set.
Naming And Internal API Conventions
- Public internal APIs should be thin, stable facades under
features/*orroutes/core/*. - Route modules may import facades and helpers, but should not directly orchestrate storage internals across multiple subsystems.
- New security-sensitive mutations must call shared security and path helpers instead of duplicating checks.