Skip to main content

Getting Started with StateSet API

Welcome to StateSet API! This guide will help you get up and running with our comprehensive backend system for order management, inventory control, returns processing, and more.

Table of Contents

Prerequisites

Before you begin, ensure you have the following installed on your development machine:

Required Software

  • Rust (latest stable version)
  • Database (Choose one):
    • SQLite (default for development)
      • Automatically created when running the API
    • PostgreSQL 14+ (recommended for production)

Optional Tools

  • Redis (for caching, optional)
  • Protocol Buffer Compiler (for gRPC development)

Installation

  1. Clone the Repository
  2. Install Rust Dependencies

Configuration

StateSet API uses environment variables and configuration files for setup.

1. Environment Variables (.env)

Create a .env file in the project root:
Edit .env with your configuration:

2. Configuration File (config/default.toml)

The TOML configuration file provides additional settings:

Database Setup

SQLite (Default for Development)

SQLite requires no additional setup. The database file will be created automatically when you first run the application.

PostgreSQL (Production)

  1. Create Database
  2. Update DATABASE_URL in .env

Running Migrations

Migrations are handled automatically on startup if auto_migrate = true in your config. To run them manually:

Building the Project

StateSet API provides several build options:

Development Build

Release Build (Optimized)

Build Specific Components

Running the API

Main API Server

Alternative Servers

Verify the Server is Running

Development Workflow

1. Code Organization

2. Adding New Features

  1. Create Command/Query
  2. Implement Service
  3. Add Handler

3. Hot Reloading (Development)

Use cargo-watch for automatic recompilation:

4. Code Quality Tools

Testing

Running Tests

Writing Tests

Performance Testing

API Documentation

REST API Endpoints

The API provides comprehensive endpoints for all operations:

Authentication

  • POST /auth/register - Register new user
  • POST /auth/login - Login and receive JWT token
  • POST /auth/refresh - Refresh JWT token

Orders

  • GET /orders - List all orders
  • GET /orders/:id - Get order by ID
  • POST /orders - Create new order
  • PUT /orders/:id - Update order
  • DELETE /orders/:id - Delete order
  • POST /orders/:id/cancel - Cancel order
  • POST /orders/:id/hold - Put order on hold

Inventory

  • GET /inventory - Get inventory levels
  • POST /inventory/adjust - Adjust inventory
  • POST /inventory/allocate - Allocate inventory
  • POST /inventory/reserve - Reserve inventory

Returns

  • POST /returns - Create return
  • GET /returns/:id - Get return details
  • POST /returns/:id/approve - Approve return
  • POST /returns/:id/reject - Reject return

OpenAPI/Swagger Documentation

When running in development mode, interactive API documentation is available at:

gRPC API

For gRPC clients, proto files are located in proto/ directory. Generate client code:

Troubleshooting

Common Issues and Solutions

1. Build Errors

2. Database Connection Issues

3. Port Already in Use

4. Migration Failures

Debugging

Performance Issues

Next Steps

  1. Explore the Codebase
    • Review src/handlers/ for API endpoints
    • Check src/services/ for business logic
    • Look at tests/ for usage examples
  2. Customize Configuration
    • Modify config/default.toml for your needs
    • Set up proper JWT secrets for security
    • Configure database connections
  3. Set Up Development Environment
    • Install VS Code with rust-analyzer extension
    • Configure your IDE for Rust development
    • Set up pre-commit hooks for code quality
  4. Learn the Architecture
    • Read about CQRS pattern used in commands/queries
    • Understand the event-driven architecture
    • Review the domain models and entities
  5. Contribute
    • Check out open issues on GitHub
    • Read CONTRIBUTING.md for guidelines
    • Join our community discussions

Getting Help

License

StateSet API is licensed under the MIT License. See LICENSE for details.
Happy coding! Welcome to the StateSet community! 🚀