A FastAPI-based backend for managing chatbots, users, and API keys.
- User Management: Create and manage users
- Chatbot Management: Create and manage chatbots for users
- API Key Management: Generate and manage API keys for chatbots
- Database: PostgreSQL with async SQLAlchemy
- Migrations: Alembic for database schema management
Project/
├── app/
│ ├── main.py # FastAPI app entry point
│ ├── seed_data.py # Database seeding script
│ ├── api/
│ │ ├── routes.py # API routes
│ │ └── schemas.py # Pydantic models
│ ├── db/
│ │ ├── db_config.py # Database configuration
│ │ └── models.py # SQLAlchemy models
│ └── services/ # Business logic services
├── migrations/ # Alembic migrations
├── alembic.ini # Alembic configuration
├── requirements.txt # Python dependencies
├── .env # Environment variables
└── README.md # This file
- Python 3.8+
- PostgreSQL
- pip
Create a .env file in the root directory:
DATABASE_URL=postgresql+asyncpg://username:password@localhost:5432/database_name
SECRET_KEY=your_secret_key_here# Create virtual environment
python -m venv myvenv
source myvenv/bin/activate # On Windows: myvenv\Scripts\activate
# Install dependencies
pip install -r requirements.txt# Run migrations
alembic upgrade head
# Seed the database with initial data
python -m app.seed_datauvicorn app.main:app --reload --host 0.0.0.0 --port 8000The API will be available at http://localhost:8000
Once the server is running, you can access:
- Interactive API Docs: http://localhost:8000/docs
- ReDoc Documentation: http://localhost:8000/redoc
GET /health- Check API health
GET /db-status- Get database connection status and record counts
GET /users- Get all usersGET /users/{user_id}- Get specific user
GET /chatbots- Get all chatbotsGET /chatbots/{chatbot_id}- Get specific chatbotGET /users/{user_id}/chatbots- Get chatbots for specific user
GET /chatbots/{chatbot_id}/api-keys- Get API keys for specific chatbot
id: Unique identifieremail: User email (unique)hashed_password: Hashed passwordcreated_at: Creation timestamp
id: Unique identifiername: Chatbot nameowner_id: Reference to userllm_endpoint_url: LLM endpoint URLcreated_at: Creation timestamp
id: Auto-incrementing IDchatbot_id: Reference to chatbotkey_hash: Hashed API keyrevoked: Whether key is revokedcreated_at: Creation timestamp
# Create a new migration
alembic revision --autogenerate -m "Description of changes"
# Apply migrations
alembic upgrade head
# Rollback migration
alembic downgrade -1python -m app.seed_data# Test health endpoint
curl http://localhost:8000/health
# Test database status
curl http://localhost:8000/db-status
# Get all users
curl http://localhost:8000/users
# Get all chatbots
curl http://localhost:8000/chatbots- Authentication: Add JWT-based authentication
- Password Hashing: Implement proper password hashing with bcrypt
- CRUD Operations: Add POST, PUT, DELETE endpoints
- Validation: Add input validation and error handling
- Testing: Add unit and integration tests
- Logging: Add proper logging configuration
- Rate Limiting: Implement API rate limiting
- Documentation: Add more detailed API documentation # chatbot_generator