Accounting Module
A complete Domain-Driven Design (DDD) bounded context module built on the Backbone Framework. This module follows Clean Architecture principles with a schema-first approach where YAML schema files are the single source of truth.
๐ Full handbook:
docs/โ philosophy, architecture (C4), maintainer & developer guides, contribution guide, glossary, and ADRs. This README is the quickstart; the handbook is the depth.
Architecture Overview
accounting/
โโโ schema/ # SCHEMA DEFINITIONS (Single Source of Truth)
โ โโโ models/ # Entity schema definitions
โ โ โโโ index.model.yaml # Module configuration and shared types
โ โ โโโ {entity}.model.yaml # Entity definitions
โ โโโ hooks/ # Event hooks and triggers
โ โ โโโ index.hook.yaml # Events and scheduled jobs
โ โโโ workflows/ # Business workflows
โ โ โโโ README.md # Workflow documentation
โ โโโ openapi/ # OpenAPI specifications
โ โโโ index.openapi.yaml # API documentation
โ
โโโ src/ # SOURCE CODE (Generated + Custom)
โ โโโ domain/ # Domain Layer (generated)
โ โ โโโ entity/ # Entity implementations
โ โ โโโ value_object/ # Value objects
โ โ โโโ event/ # Domain events
โ โ โโโ mod.rs
โ โ
โ โโโ application/ # Application Layer (generated)
โ โ โโโ {entity}_services.rs # Application services
โ โ โโโ mod.rs
โ โ
โ โโโ infrastructure/ # Infrastructure Layer (generated)
โ โ โโโ persistence/ # Repository implementations
โ โ โ โโโ postgres/
โ โ โโโ mod.rs
โ โ
โ โโโ presentation/ # Presentation Layer (generated)
โ โ โโโ http/ # REST handlers
โ โ โโโ grpc/ # gRPC services
โ โ โโโ mod.rs
โ โ
โ โโโ lib.rs # Module entry point
โ
โโโ migrations/ # DATABASE MIGRATIONS
โ โโโ postgres/ # PostgreSQL migrations (generated)
โ
โโโ Cargo.toml # Dependencies
โโโ README.md # This file
Quick Start
1. Define Your Schema
Create entity schema files in schema/models/:
# schema/models/example.model.yaml
name: Example
table_name: examples
collection: examples
fields:
id:
type: uuid
attributes:
name:
type: string
attributes:
validation:
min_length: 1
max_length: 255
description:
type: text
attributes:
status:
type: enum
enum_values:
attributes:
created_at:
type: datetime
attributes:
updated_at:
type: datetime
attributes:
deleted_at:
type: datetime
attributes:
indexes:
- name: idx_examples_status
fields:
- name: idx_examples_created_at
fields:
permissions:
create:
read:
update:
delete:
2. Generate Code
Run the schema generator to create all code from your schema:
# Validate the schema first
# Generate everything
# Or generate specific targets
The canonical CLI is
metaphor(v0.2.0); schema codegen is the nested passthroughmetaphor schema schema <op>. Thebackbonename used elsewhere is a local dev alias for the framework CLI. Note: thegrpc,proto, andgraphqlgenerators are disabled inschema/models/index.model.yaml, so those targets currently produce nothing.
3. Run Migrations
# Run PostgreSQL migrations
4. Use the Module
use AccountingModule;
// Create module instance with builder pattern
let module = builder
.with_database
.build?;
// Get routes
let routes = module.routes;
Schema Generation Targets
| Target | Description | Generated Files |
|---|---|---|
proto |
Protocol Buffer definitions | *.proto files |
rust |
Rust entity structs | domain/entity/*.rs |
sql |
PostgreSQL migrations | migrations/postgres/*.sql |
repository |
Repository implementations | infrastructure/persistence/*.rs |
cqrs |
Commands and queries | application/commands/*.rs, application/queries/*.rs |
handler |
HTTP handlers | presentation/http/*.rs |
grpc |
gRPC services | presentation/grpc/*.rs |
events |
Domain events | domain/event/*.rs |
value-object |
Value objects | domain/value_object/*.rs |
validator |
Validation rules | domain/validator/*.rs |
state-machine |
State machines | domain/state_machine/*.rs |
permission |
Permission definitions | domain/permission/*.rs |
trigger |
Database triggers | infrastructure/trigger/*.rs |
openapi |
OpenAPI specifications | schema/openapi/*.yaml |
all |
All of the above | Everything |
Standard CRUD Endpoints
Each entity automatically gets the 12 standard BackboneCrudHandler endpoints:
| # | Endpoint | Description |
|---|---|---|
| 1 | list |
List with pagination, filtering, sorting |
| 2 | create |
Create |
| 3 | get / find_by_id |
Get by ID |
| 4 | update |
Full update (PUT) |
| 5 | patch |
Partial update (PATCH) |
| 6 | soft_delete |
Soft delete |
| 7 | restore |
Restore a soft-deleted record |
| 8 | empty_trash |
Permanently purge soft-deleted records |
| 9 | bulk_create |
Bulk create |
| 10 | upsert |
Upsert |
| 11 | list_deleted |
List soft-deleted records |
| 12 | find_by_id |
Fetch a single record by id |
Guarded in production. Posted GL entities (
Journal,JournalLine,Ledger,AccountingPost) are mounted read-only viacreate_guarded_accounting_routesโ the only sanctioned GL writer isPOST /accounting/posts(see ADR-002). Master/config entities keep full CRUD.JournalLineandReconciliationItemare cascade children with no@audit_metadata, so their soft-delete family (soft_delete/restore/empty_trash/list_deleted) is not generated.
Development Workflow
Adding a New Entity
- Create schema file:
schema/models/{entity}.model.yaml - Run generator:
metaphor schema schema generate accounting --target all - Create/run migrations:
metaphor migration create {entity} - Register the new service in the
AccountingModulebuilder (src/lib.rs) - Test endpoints
See the Maintainer Guide for the full add-a-feature walkthrough.
Modifying an Entity
- Update the schema file
- Generate a migration:
metaphor migration create {change} - Regenerate code:
metaphor schema schema generate accounting --target all - Run migrations
Custom Business Logic
Add custom logic in the generated service files. The generator preserves custom code in marked sections.
Testing
# Run all tests
# Run with database
DATABASE_URL=postgresql://...
Configuration
Environment variables:
DATABASE_URL- PostgreSQL connection stringRUST_LOG- Log level (trace, debug, info, warn, error)
Dependencies
This module depends on:
backbone-core- Core framework utilitiesbackbone-orm- ORM and database traitsbackbone-auth- Authentication and authorizationbackbone-messaging- Event messaging
Documentation
The full handbook lives in docs/:
- Philosophy & motivation ยท Background & prior art ยท Technology & the why
- Architecture (C4) ยท Maintainer Guide ยท Developer Guide
- Extension Guide ยท Contributing ยท Glossary ยท ADRs
- Specs: BRD ยท PRD ยท FSD
License
Part of the Backbone Framework.