A FastAPI application with Domain Driven Design, AI integration, and database migrations.
tara/
├── app/ # FastAPI application
│ ├── main.py # FastAPI app creation
│ ├── config.py # Application settings
│ └── database/ # Database configuration
│ ├── connection.py # Database connection
│ └── models.py # SQLAlchemy models
├── internal/ # Internal business logic
│ ├── domain/ # Business domains
│ │ └── item/ # Item domain
│ │ ├── handler/ # API endpoints
│ │ ├── service/ # Business logic
│ │ ├── repository/ # Data access
│ │ └── model/ # Domain models
│ └── ai/ # AI module
│ ├── handler/ # AI API endpoints
│ ├── service/ # AI business logic
│ ├── repository/ # AI data access
│ └── model/ # AI models & DTOs
├── alembic/ # Database migrations
├── scripts/ # Utility scripts
├── tests/ # Test files
├── requirements/ # Dependencies
│ ├── base.txt
│ ├── dev.txt
│ └── prod.txt
├── run.py # Entry point
└── main.py # Legacy entry point
Copy the environment template and configure your settings:
cp .env.example .env
Edit .env
with your actual credentials:
# Database Configuration (REQUIRED)
DATABASE_URL=postgresql://your_username:your_password@localhost:5432/your_database
# For development
pip install -r requirements/dev.txt
# For production
pip install -r requirements/prod.txt
# Run migrations
alembic upgrade head
# Or initialize database manually
python scripts/init_db.py
# Using run.py
python run.py
# Using uvicorn directly
uvicorn app.main:app --reload
# Using legacy main.py
python main.py
- API:
http://localhost:8000
- Interactive Docs:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc
- Health Check:
http://localhost:8000/health
# Auto-generate migration from model changes
alembic revision --autogenerate -m "Description of changes"
# Create empty migration
alembic revision -m "Description of changes"
# Apply all pending migrations
alembic upgrade head
# Apply specific migration
alembic upgrade <revision_id>
# Rollback to previous migration
alembic downgrade -1
# Rollback to specific migration
alembic downgrade <revision_id>
# Show current revision
alembic current
# Show migration history
alembic history
# Show pending migrations
alembic show head
# Run tests
pytest
# Run tests with coverage
pytest --cov=app --cov=internal
GET /api/v1/items/
- Get all items with statisticsGET /api/v1/items/{item_id}
- Get item by IDPOST /api/v1/items/
- Create new itemPUT /api/v1/items/{item_id}
- Update itemDELETE /api/v1/items/{item_id}
- Delete itemGET /api/v1/items/expensive/?threshold=100.00
- Get expensive items
POST /api/v1/ai/chat
- Chat with AI assistantPOST /api/v1/ai/analyze
- Analyze items with AIPOST /api/v1/ai/recommendations
- Get AI recommendationsPOST /api/v1/ai/enhance-description/{item_id}
- Enhance descriptionsPOST /api/v1/ai/analyze-pricing/{item_id}
- Analyze pricingGET /api/v1/ai/conversations/{user_id}
- Get conversation historyGET /api/v1/ai/analyses/{item_id}
- Get item analysesGET /api/v1/ai/recommendations/{user_id}
- Get recommendation history
GET /
- Welcome messageGET /health
- Health check
Copy .env.example
to .env
and modify settings:
cp .env.example .env
# PostgreSQL (recommended)
DATABASE_URL=postgresql://user:password@localhost:5432/tara
# SQLite (for development)
DATABASE_URL=sqlite:///./tara.db
# MySQL
DATABASE_URL=mysql://user:password@localhost:3306/tara
This project follows a hybrid approach combining:
- Domain Driven Design principles
- FastAPI best practices
- Clean Architecture patterns
- Database migrations with Alembic
- AI integration with multiple providers
- Handler Layer - API endpoints and HTTP handling
- Service Layer - Business logic and use cases
- Repository Layer - Data access and persistence
- Model Layer - Domain entities and DTOs
- Database Layer - SQLAlchemy models and migrations
# Format code
black .
# Sort imports
isort .
# Lint code
flake8 .
# Type checking
mypy .
# Create new migration
alembic revision --autogenerate -m "Add new feature"
# Apply migrations
alembic upgrade head
# Rollback if needed
alembic downgrade -1
- Add domain models in
internal/domain/model/
orinternal/ai/model/
- Add database models in
app/database/models.py
- Create migration:
alembic revision --autogenerate -m "Description"
- Add business logic in
internal/*/service/
- Add data access in
internal/*/repository/
- Add API endpoints in
internal/*/handler/
- Add tests in
tests/