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
- Installation
- Configuration
- Database Setup
- Building the Project
- Running the API
- Development Workflow
- Testing
- API Documentation
- Troubleshooting
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)
- SQLite (default for development)
Optional Tools
-
Redis (for caching, optional)
-
Protocol Buffer Compiler (for gRPC development)
Installation
-
Clone the Repository
-
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:
.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)
-
Create Database
-
Update DATABASE_URL in .env
Running Migrations
Migrations are handled automatically on startup ifauto_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
-
Create Command/Query
-
Implement Service
-
Add Handler
3. Hot Reloading (Development)
Usecargo-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 userPOST /auth/login- Login and receive JWT tokenPOST /auth/refresh- Refresh JWT token
Orders
GET /orders- List all ordersGET /orders/:id- Get order by IDPOST /orders- Create new orderPUT /orders/:id- Update orderDELETE /orders/:id- Delete orderPOST /orders/:id/cancel- Cancel orderPOST /orders/:id/hold- Put order on hold
Inventory
GET /inventory- Get inventory levelsPOST /inventory/adjust- Adjust inventoryPOST /inventory/allocate- Allocate inventoryPOST /inventory/reserve- Reserve inventory
Returns
POST /returns- Create returnGET /returns/:id- Get return detailsPOST /returns/:id/approve- Approve returnPOST /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 inproto/ 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
-
Explore the Codebase
- Review
src/handlers/for API endpoints - Check
src/services/for business logic - Look at
tests/for usage examples
- Review
-
Customize Configuration
- Modify
config/default.tomlfor your needs - Set up proper JWT secrets for security
- Configure database connections
- Modify
-
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
-
Learn the Architecture
- Read about CQRS pattern used in commands/queries
- Understand the event-driven architecture
- Review the domain models and entities
-
Contribute
- Check out open issues on GitHub
- Read CONTRIBUTING.md for guidelines
- Join our community discussions
Getting Help
- Documentation: Full docs at docs.stateset.com
- GitHub Issues: github.com/stateset/stateset-api/issues
- Discord Community: Join our Discord for real-time help
- API Reference: Check
/swagger-uiwhen running locally
License
StateSet API is licensed under the MIT License. See LICENSE for details.Happy coding! Welcome to the StateSet community! 🚀