Update table migration and update readmes

This commit is contained in:
continuist 2025-06-16 01:09:45 -04:00
parent bcd54103e3
commit 74fc473cbe
4 changed files with 334 additions and 36 deletions

147
README.md Normal file
View file

@ -0,0 +1,147 @@
# Sharenet
A full-stack application for managing users and products, built with Rust and Next.js.
## Project Overview
Sharenet is a modern web application that demonstrates clean architecture principles and provides multiple interfaces for data management:
- **Web Interface**: Modern React-based UI with Next.js
- **API**: RESTful HTTP API built with Rust and Axum
- **CLI**: Command-line interface for automation
- **TUI**: Text-based user interface for terminal users
## Tech Stack
### Backend
- **Language**: Rust
- **Framework**: Axum (HTTP), Clap (CLI), Ratatui (TUI)
- **Database**: PostgreSQL (with in-memory option)
- **Architecture**: Clean Architecture with domain-driven design
### Frontend
- **Framework**: Next.js 15.3.3
- **Language**: TypeScript
- **UI Library**: React 19
- **Styling**: Tailwind CSS with shadcn/ui components
- **Form Handling**: React Hook Form with Zod validation
## Quick Start
### Prerequisites
- Rust (latest stable)
- Node.js (latest LTS)
- PostgreSQL (optional, in-memory storage available)
- SQLx CLI (for database migrations)
### Installation
1. Clone the repository:
```bash
git clone git@git.gcdo.org:devteam/sharenet.git
cd sharenet
```
2. Set up the backend:
```bash
# Install SQLx CLI
cargo install sqlx-cli
# Create and set up the database (if using PostgreSQL)
sqlx database create
sqlx migrate run
# Build the backend
cd backend
cargo build
```
3. Set up the frontend:
```bash
cd frontend
npm install
```
### Running the Application
1. Start the backend (choose one):
```bash
# API with in-memory storage
cargo run --bin sharenet-api-memory
# API with PostgreSQL
cargo run --bin sharenet-api-postgres
# CLI with in-memory storage
cargo run --bin sharenet-cli-memory
# TUI with in-memory storage
cargo run --bin sharenet-tui-memory
```
2. Start the frontend:
```bash
cd frontend
npm run dev
```
The web interface will be available at `http://localhost:3000`.
## Project Structure
```
sharenet/
├── backend/ # Rust backend
│ ├── crates/ # Backend modules
│ ├── migrations/ # Database migrations
│ └── config/ # Configuration files
├── frontend/ # Next.js frontend
│ ├── src/ # Source code
│ └── public/ # Static assets
└── LICENSE.md # Project license
```
## Features
### User Management
- Create, read, update, and delete users
- User authentication (coming soon)
- Role-based access control (coming soon)
### Product Management
- Create, read, update, and delete products
- Product categorization (coming soon)
- Inventory tracking (coming soon)
### Multiple Interfaces
- Web UI for general users
- REST API for integration
- CLI for automation
- TUI for terminal users
## Development
### Backend Development
See [backend/README.md](backend/README.md) for detailed backend development instructions.
### Frontend Development
See [frontend/README.md](frontend/README.md) for detailed frontend development instructions.
## Configuration
### Backend Configuration
Configuration files are located in `backend/config/`:
- `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
### Frontend Configuration
The frontend is configured to connect to the backend at `http://127.0.0.1:3000` by default. Update `frontend/src/lib/api.ts` if your backend is running on a different address.
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.

View file

@ -5,24 +5,39 @@ A Rust backend for performing CRUD operations on various struct types (e.g., pro
## 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)
- 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
```
.
├── 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
├── 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
@ -36,28 +51,59 @@ cargo build
### HTTP API with in-memory storage
```bash
cargo run -- --api --addr 127.0.0.1:3000
cargo run --bin sharenet-api-memory
```
### HTTP API with PostgreSQL
```bash
cargo run -- --api --postgres --database-url postgres://user:password@localhost/dbname --addr 127.0.0.1:3000
cargo run --bin sharenet-api-postgres
```
### 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
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 -- --postgres --database-url postgres://user:password@localhost/dbname user create --username john --email john@example.com
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
@ -90,12 +136,22 @@ cargo run -- --postgres --database-url postgres://user:password@localhost/dbname
### Products
- `product create --name <name> --description <description> --price <price>` - Create a new product
- `product create --name <name> --description <description>` - 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 update --id <id> [--name <name>] [--description <description>]` - Update a product
- `product delete --id <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
MIT

View file

@ -10,7 +10,6 @@ CREATE TABLE products (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
description TEXT NOT NULL,
price DOUBLE PRECISION NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);

View file

@ -1,36 +1,132 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
# Sharenet Frontend
A modern web application built with Next.js, React, and TypeScript for managing users and products.
## Features
- Modern UI with Tailwind CSS and shadcn/ui components
- Type-safe development with TypeScript
- Form handling with React Hook Form and Zod validation
- Responsive design
- Real-time data updates
- Clean and intuitive user interface
## Tech Stack
- **Framework**: Next.js 15.3.3
- **Language**: TypeScript
- **UI Library**: React 19
- **Styling**: Tailwind CSS
- **Components**: shadcn/ui
- **Form Handling**: React Hook Form with Zod validation
- **HTTP Client**: Axios
- **Icons**: Lucide React
## Project Structure
```
frontend/
├── src/
│ ├── app/ # Next.js app directory (pages and layouts)
│ ├── components/ # Reusable UI components
│ │ └── ui/ # shadcn/ui components
│ └── lib/ # Utility functions and API client
├── public/ # Static assets
├── components.json # shadcn/ui configuration
├── next.config.ts # Next.js configuration
├── postcss.config.mjs # PostCSS configuration
├── tailwind.config.js # Tailwind CSS configuration
└── tsconfig.json # TypeScript configuration
```
## Getting Started
First, run the development server:
### Prerequisites
- Node.js (latest LTS version recommended)
- npm or yarn
### Installation
1. Install dependencies:
```bash
npm install
# or
yarn install
```
2. Start the development server:
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
The application will be available at `http://localhost:3000`.
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
### Building for Production
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
```bash
npm run build
# or
yarn build
```
## Learn More
### Running in Production
To learn more about Next.js, take a look at the following resources:
```bash
npm run start
# or
yarn start
```
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
## Available Scripts
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
- `dev`: Start the development server with Turbopack
- `build`: Build the application for production
- `start`: Start the production server
- `lint`: Run ESLint to check code quality
## Deploy on Vercel
## API Integration
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
The frontend communicates with the Sharenet backend API. Make sure the backend server is running at `http://127.0.0.1:3000` or update the `API_BASE_URL` in `src/lib/api.ts` to match your backend configuration.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
## Features
### Users Management
- View all users
- Create new users
- Edit existing users
- Delete users
### Products Management
- View all products
- Create new products
- Edit existing products
- Delete products
## Development
### Code Style
The project uses ESLint for code linting. Run the linter with:
```bash
npm run lint
# or
yarn lint
```
### TypeScript
The project is written in TypeScript. Type definitions are available for all components and utilities.
### Styling
- Tailwind CSS is used for styling
- shadcn/ui components are used for the UI
- Custom styles can be added in the respective component files
## License
MIT