Architecture Overview
Efision follows a 5-layer Clean Architecture pattern where business logic is completely separated from infrastructure concerns.
Layer Diagram
CLI (commands/) → Services → Domain (Entities + Repositories) ← Infrastructure (sqlserver/) → Database
| Layer | Location | Responsibility |
|---|---|---|
| CLI | crates/cli/ | Command parsing, user interaction, output formatting |
| Services | crates/core/src/services/ | Business logic, orchestration (database-agnostic) |
| Domain | crates/core/src/domain/ | Entities, DTOs, Repository trait definitions |
| Infrastructure | crates/core/src/infrastructure/ | SQL Server implementations of repository traits |
| Config | crates/core/src/infrastructure/config.rs | Database connection, region resolution |
Key Principle
Services are generic over repository traits:
#![allow(unused)]
fn main() {
struct WheelService<R: WheelRepository> {
repo: R,
}
}
This means the business logic never depends on SQL Server directly. To switch databases, only the infrastructure layer changes.
Cargo Workspace
The project is split into two crates:
| Crate | Package | Role |
|---|---|---|
crates/core/ | efision-core | Shared library: domain, services, infrastructure |
crates/cli/ | efision-cli | Binary: CLI commands, user interaction |
This separation allows future crates (e.g., crates/api/ for a REST API) to share the same business logic.
Business Domains
| Domain | Entities | Repository | Service |
|---|---|---|---|
| Products | domain/entities/products/ | infrastructure/sqlserver/products/ | services/products/ |
| Sales | domain/entities/sales/ | infrastructure/sqlserver/sales/ | services/sales/ |
| Warehouse | domain/entities/warehouse/ | infrastructure/sqlserver/warehouse/ | services/warehouse/ |
| Customers | domain/entities/customers/ | infrastructure/sqlserver/customers/ | services/customers/ |
Database Stats
| Stat | Value |
|---|---|
| Tables in schema | 305 |
| Entity files | 64 (across 4 business domains) |
| Repository traits | 5 |