A scalable service-oriented architecture for building extension APIs for Tetsuo AI Core Services
This repository provides a modular FastAPI service framework with support for Redis, WebSockets, and more. The instructions below cover setup on Ubuntu and macOS environments, as well as using Docker.
Note: Use Python 3.11 (using pyenv on macOS is recommended) because Python 3.12 will fail.
External World
β
βββ FastAPI Service Layer βββ Central Source of Truth
β
βββ Services
β βββ Your Service
β
βββ Clients
βββ Your Service Clients
- FastAPI: Modern, fast web framework for building APIs
- Redis: In-memory data store for caching and real-time data
- WebSockets: Real-time bidirectional communication
- Pydantic: Data validation using Python type annotations
- Loguru: Python logging made simple
-
Python 3.11+
Important: Use Python 3.11; Python 3.12 will fail. (On macOS, consider using pyenv withpyenv local 3.11
.) -
Redis Server
- Ubuntu: Redis is installed via
apt-get
in the setup script. - macOS: Install via Homebrew:
brew install redis
- Ubuntu: Redis is installed via
These instructions are for Ubuntu 22.04 LTS (Jammy Jellyfish) (or a Ubuntu VM) or Ubuntu WSL.1
- Clone the repository:
sudo git clone https://github.com/tetsuo-ai/tetsuo-service-starter-kit /opt/tetsuo-service-starter-kit
- Run the provided Ubuntu setup script:
sudo su
cd tetsuo-service-starter-kit
chmod +x scripts/ubuntu-setup.sh
./scripts/ubuntu-setup.sh
This script will:
- Installs Python 3.11, Redis, and other required packages.
- Creates a project directory (default:
/opt/tetsuo-service-starter-kit
). - Sets up a virtual environment.
- Installs dependencies.
- Creates a default
.env
file (from.env.example
) β update this with your settings. - Creates a dedicated service user.
- Configures a systemd service for the FastAPI application.
- Generates convenience scripts:
./start.sh
β to start the service./stop.sh
β to stop the service./status.sh
β to check service status./test.sh
β to run tests
- Start Redis server:
sudo systemctl start redis-server
- Test Redis connection:
sudo su tetsuo-service # switch to the tetsuo-service user
source .venv/bin/activate # activate the virtual environment
python3.11 -m tests.redis_test # should return "β¨ All Redis tests passed" or
python3.11 tests/redis_test.py # should return "β¨ All Redis tests passed"
- Start the service:
./start.sh
- Check the status:
./status.sh
- Test the API:
curl -v http://127.0.0.1:6502/health
curl -X POST http://127.0.0.1:6502/api/v1/demo/demo -H "Authorization: Bearer your-super-secret-api-token-here" -H "Content-Type: application/json" -d '{"demo": "test"}'
- Stop the service:
./stop.sh
These instructions are for macOS.
- Clone the repository:
git clone https://github.com/tetsuo-ai/tetsuo-service-starter-kit
cd tetsuo-service-starter-kit
- Install Python 3.11 using pyenv:
brew install pyenv
pyenv install 3.11
pyenv local 3.11
- Create and activate virtual environment:
python --version # should return 3.11.x
python -m venv .venv
source .venv/bin/activate
- Install dependencies:
pip install --upgrade pip
pip install -r requirements.txt
- Copy example environment file and configure:
cp .env.example .env
# Edit .env with your settings
- Install and launch Redis:
brew install redis
brew services start redis
- Test Redis connection:
python -m tests.redis_test # should return "β¨ All Redis tests passed" or
python tests/redis_test.py # should return "β¨ All Redis tests passed"
- Start the service:
python -m app.main
- Test the API:
curl -v http://127.0.0.1:6502/health
curl -X POST http://127.0.0.1:6502/api/v1/demo/demo -H "Authorization: Bearer your-super-secret-api-token-here" -H "Content-Type: application/json" -d '{"demo": "test"}'
- Stop the service:
# Send an interrupt signal (SIGINT) by pressing **Ctrl+C** in the terminal running `python -m app.main`. This will gracefully shut down the FastAPI service.
# Stop the Redis service:
brew services stop redis
- Clone the repository:
git clone https://github.com/tetsuo-ai/tetsuo-service-starter-kit
cd tetsuo-service-starter-kit
- Copy the
.env.example
file to.env
and configure:
cp .env.example .env
# Edit .env with your settings
# For docker compose setup, be sure to change the REDIS_HOST from `localhost` to `redis`
- Start the docker compose services:
Important: If you are already running a Redis service on your host, you must stop it first to avoid port conflicts.
-
Ubuntu/WSL:
sudo systemctl stop redis
-
macOS:
brew services stop redis
Once the Redis service is stopped, you can build and start your application using Docker Compose.
docker compose up --build
This configuration is optimized for local developmentβthe app
directory is volume-mounted into the container, and Uvicorn's built-in file watcher (enabled via the --reload
flag) makes it easy to see code changes in real time.
Note: If you modify the dependencies in
requirements.txt
, you must stop and rebuild the docker container to incorporate the changes. If docker compose is running in detached mode, stop it usingdocker compose down
. If it's running in the foreground, press Ctrl+C to stop the process, then restart withdocker compose up --build
.
- Test the API:
curl -v http://127.0.0.1:6502/health
curl -X POST http://127.0.0.1:6502/api/v1/demo/demo -H "Authorization: Bearer your-super-secret-api-token-here" -H "Content-Type: application/json" -d '{"demo": "test"}'
- Stop the service:
docker compose down
Key environment variables in .env
:
# API Settings
API_V1_STR=/api/v1
PROJECT_NAME=Tetsuo AI Extension Service API
# Redis Settings
REDIS_HOST=localhost # or change to redis if using docker compose
REDIS_PORT=6379
REDIS_DB=0
REDIS_PASSWORD=
# Contract Addresses
TETSUO_POOL_ADDRESS=your_pool_address
TETSUO_TOKEN_ADDRESS=your_token_address
Once running, visit:
- OpenAPI docs:
http://localhost:6502/docs
- ReDoc:
http://localhost:6502/redoc
-
Whale Monitoring:
GET /api/v1/demo/demo
: Demo endpoint
-
WebSocket:
WSS /ws
: Real-time updates for all services
- Run tests:
./test.sh
- Check Redis:
python redis_test.py
- API tests:
python app/tests/test_api.py
- Fork the repository
- Create feature branch:
git checkout -b feature-name
- Commit changes:
git commit -am 'Add feature'
- Push to branch:
git push origin feature-name
- Submit a pull request
MIT License - see LICENSE file for details
- Create an issue for bug reports or feature requests
- For security issues, please email [email protected]
Current development status:
- β Foundation Layer (Redis, Config, Logging)
- β Data Models (Pydantic)
- β Redis Data Schemas
- β Core Services
- β API Layer
- β WebSocket Implementation
Made with β€οΈ by the Tetsuo Core Team
Footnotes
-
WSL Note: If you are using Ubuntu on Windows via WSL, please note that systemd is not enabled by default. As a result, service management commands using
systemctl
(e.g., starting Redis or the Tetsuo service) may not work until systemd is enabled in your WSL installation. For guidance on enabling systemd and other WSL-specific configurations, please consult the official WSL documentation. β©