# 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 - Multiple interface options: - HTTP REST API - Command Line Interface (CLI) - Text User Interface (TUI) - Configurable storage backends: - In-memory storage - PostgreSQL database - Generic implementations for easy extension - Static dispatch with generic traits - Axum-based HTTP API - Clap-based CLI - Ratatui-based TUI ## Project Structure ``` . ├── crates/ │ ├── api/ # HTTP API implementation (Axum) │ ├── application/ # Application services and use cases │ ├── cli/ # CLI implementation (Clap) │ ├── domain/ # Domain entities and traits │ ├── memory/ # In-memory storage implementation │ ├── postgres/ # PostgreSQL storage implementation │ ├── tui/ # TUI implementation (Ratatui) │ ├── sharenet-api-memory/ # API binary with in-memory storage │ ├── sharenet-api-postgres/ # API binary with PostgreSQL storage │ ├── sharenet-cli-memory/ # CLI binary with in-memory storage │ ├── sharenet-cli-postgres/ # CLI binary with PostgreSQL storage │ ├── sharenet-tui-memory/ # TUI binary with in-memory storage │ └── sharenet-tui-postgres/ # TUI binary with PostgreSQL storage ├── migrations/ # Database migrations └── config/ # Configuration files for different environments ``` ## Building ```bash cargo build ``` ## Running ### HTTP API with in-memory storage ```bash cargo run --bin sharenet-api-memory ``` ### HTTP API with PostgreSQL ```bash cargo run --bin sharenet-api-postgres ``` ### CLI with in-memory storage ```bash cargo run --bin sharenet-cli-memory user create --username john --email john@example.com cargo run --bin sharenet-cli-memory user list cargo run --bin sharenet-cli-memory product create --name "Product 1" --description "Description" cargo run --bin sharenet-cli-memory product list ``` ### CLI with PostgreSQL ```bash cargo run --bin sharenet-cli-postgres user create --username john --email john@example.com ``` ### TUI with in-memory storage ```bash cargo run --bin sharenet-tui-memory ``` ### TUI with PostgreSQL ```bash cargo run --bin sharenet-tui-postgres ``` ## Database Setup ### Using SQLx CLI 1. Install SQLx CLI: ```bash cargo install sqlx-cli ``` 2. Create the database: ```bash sqlx database create ``` 3. Run migrations: ```bash sqlx migrate run ``` ## 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 --email ` - Create a new user - `user get --id ` - Get a user by ID - `user list` - List all users - `user update --id [--username ] [--email ]` - Update a user - `user delete --id ` - Delete a user ### Products - `product create --name --description ` - Create a new product - `product get --id ` - Get a product by ID - `product list` - List all products - `product update --id [--name ] [--description ]` - Update a product - `product delete --id ` - Delete a product ## Configuration Configuration files are located in the `config/` directory: - `api-memory.env` - API server with in-memory storage - `api-postgres.env` - API server with PostgreSQL storage - `cli-memory.env` - CLI with in-memory storage - `cli-postgres.env` - CLI with PostgreSQL storage - `tui-memory.env` - TUI with in-memory storage - `tui-postgres.env` - TUI with PostgreSQL storage ## License This project is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License - see the [LICENSE.md](../LICENSE.md) file for details.