agentleFS
matrixoriginmatrixorigin/Memoria/skills/architecture/SKILL.md

architecture

Skill624 starsChanged 6 months agoApache-2.0View on GitHub

Memoria codebase structure, workspace layout, key traits, database tables, config patterns, and testing conventions. Use when navigating or modifying Memoria code.

136 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use intelligent-routing, bash-linux and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • SKB3002Skill

    intelligent-routing

    Automatic agent selection and intelligent task routing. Analyzes user requests and automatically selects the best specialist agent(s) without requiring explicit user mentions.

    Also in 6 projects that use this

  • xenitV1Skill

    bash-linux

    Bash/Linux terminal patterns. Critical commands, piping, error handling, scripting. Use when working on macOS or Linux systems.

    Also in 8 projects that use this

  • xenitV1Skill

    red-team-tactics

    Red team tactics principles based on MITRE ATT&CK. Attack phases, detection evasion, reporting.

    Also in 8 projects that use this

  • SKB3002Skill

    nextjs-react-expert

    React and Next.js performance optimization from Vercel Engineering. Use when building React components, optimizing performance, eliminating waterfalls, reducing bundle size, reviewing code for performance issues, or implementing server/client-side optimizations.

    Also in 3 projects that use this

  • +8 more from xenitV1

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 118 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When adding a Config field: update ALL test Config { ..

    line 89
  2. Very specific:

    Add handler in memoria-api/src/routes/

    line 106
  3. Very specific:

    Add e2e test in memoria-api/tests/api_e2e.rs using spawn_server()

    line 108

“Common” is measured: kept by at least 6 in 10 of the 118 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Workspace Layout

memoria/                          # Cargo workspace root
├── crates/
│   ├── memoria-core/             # Shared types: MemoriaError, Memory, MemoryType
│   ├── memoria-storage/          # SqlMemoryStore — all SQL queries, migrations
│   ├── memoria-service/          # Business logic
│   │   └── src/
│   │       ├── service.rs        # MemoryService — main entry point
│   │       ├── scheduler.rs      # GovernanceScheduler — periodic tasks + leader election
│   │       ├── config.rs         # Config struct (reads env vars)
│   │       ├── distributed.rs    # DistributedLock, AsyncTaskStore traits + SQL impls
│   │       ├── governance/       # GovernanceStrategy trait, DefaultGovernanceStrategy
│   │       └── plugin/           # Plugin system (manifest, repository, rhai, grpc)
│   ├── memoria-api/              # REST API (axum)
│   │   └── src/
│   │       ├── lib.rs            # build_router(), route registration
│   │       ├── state.rs          # AppState (service, task_store, instance_id)
│   │       └── routes/           # memory, admin, governance, plugins, sessions
│   ├── memoria-mcp/              # MCP server (stdio/SSE transport)
│   ├── memoria-cli/              # CLI binary: init, mcp, serve, plugin, benchmark
│   ├── memoria-embedding/        # Embedding + LLM client
│   └── memoria-git/              # Git-for-Data: snapshots, branches, merge
├── Cargo.toml                    # Workspace deps
└── build.rs                      # Proto compilation (tonic)

Key Traits

trait GovernanceStrategy: Send + Sync {
    fn strategy_key(&self) -> &str;
    async fn plan(&self, store, task) -> Result<GovernancePlan>;
    async fn execute(&self, store, task, plan) -> Result<GovernanceExecution>;
}

trait GovernanceStore: Send + Sync {
    async fn list_active_users(&self) -> Result<Vec<String>>;
    async fn quarantine_low_confidence(&self, user) -> Result<i64>;
    // ... cleanup/maintenance methods
}

trait DistributedLock: Send + Sync {
    async fn try_acquire(&self, key, holder, ttl) -> Result<bool>;
    async fn renew(&self, key, holder, ttl) -> Result<bool>;
    async fn release(&self, key, holder) -> Result<()>;
}

trait AsyncTaskStore: Send + Sync {
    async fn create_task(&self, task) -> Result<()>;
    async fn complete_task(&self, task_id, result) -> Result<()>;
    async fn fail_task(&self, task_id, error) -> Result<()>;
    async fn get_task(&self, task_id) -> Result<Option<AsyncTask>>;
}

Database Tables

GroupTables
Coremem_memories, mem_user_state, mem_branches, mem_snapshots
Graphmemory_graph_nodes, memory_graph_edges, mem_entities, mem_memory_entity_links, mem_entity_links
Auditmem_edit_log, mem_retrieval_feedback, mem_memories_stats
Governancemem_governance_cooldown, mem_governance_runtime_state, mem_user_retrieval_params
Authmem_api_keys
Pluginmem_plugin_packages, mem_plugin_signers, mem_plugin_bindings, mem_plugin_binding_rules, mem_plugin_reviews, mem_plugin_audit_events
Distributedmem_distributed_locks, mem_async_tasks

Config

Config struct in config.rs reads from env vars:

FieldEnv VarDefault
db_urlDATABASE_URLmysql://root:111@localhost:6001/memoria
embedding_providerEMBEDDING_PROVIDERlocal
instance_idMEMORIA_INSTANCE_IDRandom UUID
lock_ttl_secsMEMORIA_LOCK_TTL_SECS120
governance_plugin_dirMEMORIA_GOVERNANCE_PLUGIN_DIRNone
governance_plugin_bindingMEMORIA_GOVERNANCE_PLUGIN_BINDINGdefault
governance_plugin_subjectMEMORIA_GOVERNANCE_PLUGIN_SUBJECTsystem

When adding a Config field: update ALL test Config { .. } constructors — check scheduler.rs tests AND tests/plugin_repository.rs.

REST API Structure

PrefixModuleAuthPurpose
/v1/memoriesroutes/memory.rsBearerCRUD, search, retrieve
/v1/snapshots, /v1/branchesroutes/memory.rsBearerGit-for-Data
/v1/sessionsroutes/sessions.rsBearerEpisodic memory, async tasks
/v1/governanceroutes/governance.rsBearerTrigger governance
/admin/*routes/admin.rsMasterAdmin ops
/admin/plugins/*routes/plugins.rsMasterPlugin repository
/healthroutes/admin.rsNoneLiveness probe
/health/instanceroutes/memory.rsNoneReadiness probe (returns instance_id)

Adding a New REST Endpoint

  1. Add handler in memoria-api/src/routes/
  2. Register route in memoria-api/src/lib.rs build_router()
  3. Add e2e test in memoria-api/tests/api_e2e.rs using spawn_server()

Plugin System Files

plugin/
├── mod.rs              # Re-exports
├── manifest.rs         # PluginManifest, PluginPackage, signing verification
├── repository.rs       # Publish, review, score, binding rules, audit
├── rhai_runtime.rs     # RhaiGovernanceStrategy (sandboxed Rhai)
├── grpc_runtime.rs     # GrpcGovernanceStrategy (remote gRPC)
├── governance_hook.rs  # Contract testing harness
└── templates/          # Rhai governance template

Distributed Components

ComponentFilePurpose
DistributedLock traitdistributed.rsLock abstraction
NoopDistributedLockdistributed.rsSingle-instance no-op
SqlMemoryStore lock impldistributed.rsINSERT-based DB lock with TTL
AsyncTaskStore traitdistributed.rsCross-instance task visibility
GovernanceSchedulerscheduler.rsLeader election + heartbeat
AppStatestate.rsHolds instance_id + DB task store

Testing

make check          # cargo check + clippy -D warnings (MUST pass)
make test-unit      # Unit tests (no DB): memoria-core, memoria-service, memoria-mcp
make test           # All tests (needs MatrixOne, --test-threads=1)
make test-e2e       # API e2e tests only

Patterns:

  • E2e: spawn_server() → random port, shared DB, reqwest client
  • Distributed e2e: spawn_server_with_instance() → custom instance ID
  • Plugin: build_signed_plugin_files() helper for base64 file maps
  • Unique names: uuid::Uuid::new_v4().simple() for test isolation
  • DB tests need DATABASE_URL env var

Common Pitfalls

  1. Adding Config fields → must update ALL test constructors
  2. Clippy -D warnings → any warning = build failure
  3. PathBuf::from("x") in comparisons → use Path::new("x")
  4. format!() inside println!() → inline args directly
  5. Plugin exports → re-export chain: repository.rs → plugin/mod.rs → lib.rs
  6. Shared DB in tests → use unique names for isolation
  7. GovernanceScheduler constructors → #[allow(clippy::too_many_arguments)]
  8. MatrixOne DATETIME columns → use chrono::NaiveDateTime, not String

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.