A simple AI-powered API for a soda vending machine that interprets natural language commands to sell products, track inventory, and manage transactions.
- Natural language processing for user interactions
- Product inventory management
- Transaction history tracking
- RESTful API with FastAPI
- SQLite database with SQLModel ORM
- Docker containerization with Nginx load balancer
The application is built with 3 core modules:
- Products Module: Handles product management operations including create, update, remove, and list products. Manages inventory and stock levels.
- Purchase Module: Processes natural language queries using AI, interprets user intent from text input, and calls the purchase service with parsed user intent.
- Transaction Module: Handles and stores transaction history, provides transaction records and analytics, and manages purchase logging.
- FastAPI - REST API framework
- SQLModel - Database ORM
- SQLite - Database
- Instructor - AI response parsing
- OpenAI GPT - Natural language processing
- Nginx - Load balancer and reverse proxy
- Docker - Containerization
- uv - Python package management
- Python 3.12+
- Docker and Docker Compose
- OpenAI API key
- Clone the repository:
git clone https://github.com/JulioPeixoto/happyloop-challenge.git
cd happyloop-challenge- Install dependencies:
uv sync- Set up environment variables:
cp .env.example .env
# Add your OPENAI_API_KEY to .env- Run database migrations:
uv run makemigrations "Initial migration"
uv run migrate- Start the application:
docker-compose up --buildThe API will be available at http://localhost/docs
POST /api/v1/chat- Natural language interaction
Example:
{
"message": "I want to buy 3 cokes"
}GET /api/v1/products- List all productsPOST /api/v1/products- Create a new productGET /api/v1/products/{id}- Get product by IDPUT /api/v1/products/{id}- Update productDELETE /api/v1/products/{id}- Delete product
GET /api/v1/transactions- Get transaction historyGET /api/v1/transactions/{id}- Get transaction by ID
curl -X POST "http://localhost/api/v1/chat" \
-H "Content-Type: application/json" \
-d '{"message": "I want to buy 2 sprites"}'curl -X POST "http://localhost/api/v1/chat" \
-H "Content-Type: application/json" \
-d '{"message": "What do you have in stock?"}'curl -X POST "http://localhost/api/v1/chat" \
-H "Content-Type: application/json" \
-d '{"message": "How many cokes are left?"}'# Create new migration
uv run makemigrations "Migration description"
# Apply migrations
uv run migrate
# Start development server
uv run dev