sharenet/backend/README.md

101 lines
No EOL
2.7 KiB
Markdown

# 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
```bash
cargo build
```
## Running
### HTTP API with in-memory storage
```bash
cargo run -- --api --addr 127.0.0.1:3000
```
### HTTP API with PostgreSQL
```bash
cargo run -- --api --postgres --database-url postgres://user:password@localhost/dbname --addr 127.0.0.1:3000
```
### CLI with in-memory storage
```bash
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
```bash
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 user
- `GET /users/:id` - Get a user by ID
- `GET /users` - List all users
- `PUT /users/:id` - Update a user
- `DELETE /users/:id` - Delete a user
### Products
- `POST /products` - Create a new product
- `GET /products/:id` - Get a product by ID
- `GET /products` - List all products
- `PUT /products/:id` - Update a product
- `DELETE /products/:id` - Delete a product
## CLI Commands
### Users
- `user create --username <username> --email <email>` - Create a new user
- `user get --id <id>` - Get a user by ID
- `user list` - List all users
- `user update --id <id> [--username <username>] [--email <email>]` - Update a user
- `user delete --id <id>` - Delete a user
### Products
- `product create --name <name> --description <description> --price <price>` - Create a new product
- `product get --id <id>` - Get a product by ID
- `product list` - List all products
- `product update --id <id> [--name <name>] [--description <description>] [--price <price>]` - Update a product
- `product delete --id <id>` - Delete a product
## License
MIT