.. | ||
config | ||
crates | ||
migrations | ||
Cargo.toml | ||
README.md |
Sharenet
A Rust backend for performing CRUD operations on various struct types (e.g., products, users) that uses a clean architecture with configurable storage and interface layers.
Features
- Clean architecture with separate domain, application, and infrastructure layers
- Support for both HTTP REST API and CLI interfaces
- Configurable storage backends (in-memory or PostgreSQL)
- Generic implementations for easy extension
- Static dispatch with generic traits
- Axum-based HTTP API
- Clap-based CLI
Project Structure
.
├── domain/ # Domain entities and traits
├── application/ # Application services and use cases
├── api/ # HTTP API implementation (Axum)
├── cli/ # CLI implementation (Clap)
├── memory/ # In-memory storage implementation
├── postgres/ # PostgreSQL storage implementation
└── src/ # Binary crate
Building
cargo build
Running
HTTP API with in-memory storage
cargo run -- --api --addr 127.0.0.1:3000
HTTP API with PostgreSQL
cargo run -- --api --postgres --database-url postgres://user:password@localhost/dbname --addr 127.0.0.1:3000
CLI with in-memory storage
cargo run -- user create --username john --email john@example.com
cargo run -- user list
cargo run -- product create --name "Product 1" --description "Description" --price 99.99
cargo run -- product list
CLI with PostgreSQL
cargo run -- --postgres --database-url postgres://user:password@localhost/dbname user create --username john --email john@example.com
API Endpoints
Users
POST /users
- Create a new userGET /users/:id
- Get a user by IDGET /users
- List all usersPUT /users/:id
- Update a userDELETE /users/:id
- Delete a user
Products
POST /products
- Create a new productGET /products/:id
- Get a product by IDGET /products
- List all productsPUT /products/:id
- Update a productDELETE /products/:id
- Delete a product
CLI Commands
Users
user create --username <username> --email <email>
- Create a new useruser get --id <id>
- Get a user by IDuser list
- List all usersuser update --id <id> [--username <username>] [--email <email>]
- Update a useruser delete --id <id>
- Delete a user
Products
product create --name <name> --description <description> --price <price>
- Create a new productproduct get --id <id>
- Get a product by IDproduct list
- List all productsproduct update --id <id> [--name <name>] [--description <description>] [--price <price>]
- Update a productproduct delete --id <id>
- Delete a product
License
MIT