A Python FastAPI backend for the Crittr application, containerized with Docker for easy deployment.
- 🚀 FastAPI - Modern, fast web framework for building APIs
- 🐘 PostgreSQL - Robust relational database
- 🔐 JWT Authentication - Secure token-based authentication
- 📧 Magic Link Auth - Passwordless email authentication
- 🤖 OpenAI Integration - AI-powered health insights
- 📊 Comprehensive API - Full CRUD operations for all entities
- 🐳 Docker Ready - Containerized for easy deployment
- 🔄 Redis Caching - Optional caching layer
- 📝 Structured Logging - Production-ready logging
- 🛡️ Security - CORS, rate limiting, and security headers
- Docker and Docker Compose
- Git
-
Start the database
docker-compose up postgres
-
Start the backend (in a new terminal)
source venv/bin/activate uvicorn main:app --reload --host 0.0.0.0 --port 8000
-
Clone and navigate to backend directory
git clone <repository-url> cd critter-app-BE
-
Start development environment
./manage.sh dev-start
-
Access the API
- API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- Database: localhost:5432
- Redis: localhost:6379
-
Set up environment variables
cp env.example .env # Edit .env with your actual values -
Start production environment
./manage.sh prod-start
# Development
./manage.sh dev-start # Start development environment
./manage.sh stop # Stop all services
./manage.sh logs # View logs
./manage.sh status # Show service status
./manage.sh clean # Clean up Docker resources
# Production
./manage.sh prod-start # Start production environment
./manage.sh logs prod # View production logs
./manage.sh restart prod # Restart production services# Development
docker-compose up --build -d
docker-compose logs -f
docker-compose down
# Production
docker-compose -f docker-compose.prod.yml up --build -d
docker-compose -f docker-compose.prod.yml logs -f
docker-compose -f docker-compose.prod.yml down# Database
DATABASE_URL=postgresql://crittr_user:crittr_password@localhost:5432/crittr
# JWT
SECRET_KEY=your-super-secret-key
# SMTP (for magic links)
SMTP_HOST=smtp.gmail.com
SMTP_USERNAME=your-email@gmail.com
SMTP_PASSWORD=your-app-password
SMTP_FROM_EMAIL=noreply@crittr.app
# OpenAI
OPENAI_API_KEY=your-openai-api-key
# Frontend
FRONTEND_URL=http://localhost:3000# JWT Configuration
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
# Environment
ENVIRONMENT=production
# Redis
REDIS_URL=redis://redis:6379
# Logging
LOG_LEVEL=INFO
LOG_FILE=/app/logs/app.logPOST /users/- Create userGET /users/me- Get current user
POST /pets/- Create petGET /pets/- Get user's petsGET /pets/{pet_id}- Get specific petPUT /pets/{pet_id}- Update petDELETE /pets/{pet_id}- Delete pet
POST /journal-entries/- Create journal entryGET /journal-entries/- Get journal entriesGET /journal-entries/{entry_id}- Get specific entry
POST /quick-logs/- Create quick logGET /quick-logs/- Get quick logs
GET /health- Health check endpoint
The application uses the following main entities:
- Users - User accounts and authentication
- Pets - Pet profiles and information
- Journal Entries - Detailed journal entries
- Quick Logs - Quick activity logging
- Reminders - Scheduled reminders
- User Connections - Social features
- Magic Links - Authentication tokens
-
Start the database
docker-compose up postgres
-
Start the backend (in a new terminal)
source venv/bin/activate uvicorn main:app --reload --host 0.0.0.0 --port 8000 -
The API will be available at http://localhost:8000
-
Set up environment variables
cp env.example .env # Update with production values -
Start production environment
./manage.sh prod-start
-
Configure reverse proxy (optional)
- Update
nginx.confwith your domain - Add SSL certificates to
./ssl/directory - Uncomment HTTPS configuration in nginx.conf
- Update
- Connect your GitHub repository
- Set environment variables in Railway dashboard
- Deploy automatically
- Create a new Heroku app
- Add PostgreSQL addon
- Set environment variables
- Deploy using Heroku CLI
- Create a new app
- Connect your repository
- Configure environment variables
- Deploy
- Application logs are stored in
./logs/directory - View logs:
./manage.sh logsordocker-compose logs -f
- Health endpoint:
GET /health - Docker health checks configured for all services
- Container resource usage:
./manage.sh status - Database performance monitoring via PostgreSQL logs
- CORS configuration
- Rate limiting (via Nginx)
- Security headers
- JWT token authentication
- Input validation with Pydantic
- SQL injection prevention with SQLAlchemy
- Use strong SECRET_KEY in production
- Enable HTTPS in production
- Regular security updates
- Monitor logs for suspicious activity
- Use environment variables for sensitive data
-
Database connection errors
# Check if PostgreSQL is running docker-compose ps # View database logs docker-compose logs postgres
-
Port conflicts
# Check what's using the port lsof -i :8000 # Stop conflicting services ./manage.sh stop
-
Permission issues
# Fix script permissions chmod +x manage.sh # Fix log directory permissions sudo chown -R $USER:$USER logs/
Enable debug mode by setting:
ENVIRONMENT=developmentThis will:
- Enable API documentation at
/docs - Show detailed error messages
- Enable SQL query logging
- Create database models in
main.py - Add Pydantic schemas for request/response validation
- Implement API endpoints with proper error handling
- Add tests for new functionality
- Update documentation
backend/
├── main.py # Main FastAPI application
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── docker-compose.yml # Development environment
├── docker-compose.prod.yml # Production environment
├── nginx.conf # Nginx configuration
├── manage.sh # Management script
├── init.sql # Database initialization
└── logs/ # Application logs
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License.