A full-stack web application for storing and displaying turtle photos, built with Next.js frontend, Flask API backend, and PostgreSQL database.
- Photo Upload: Upload turtle photos with titles and descriptions
- Photo Gallery: View all uploaded photos in a responsive grid layout
- Photo Management: Delete photos with confirmation
- Image Processing: Automatic image resizing and optimization
- Responsive Design: Works on desktop and mobile devices
- File Validation: Supports JPEG, PNG, and GIF files up to 16MB
- Type Safety: Flask backend uses type hints, frontend uses JavaScript
- Flask - Python web framework
- PostgreSQL - Database
- SQLAlchemy - ORM
- Pillow - Image processing
- pytest - Testing framework
- Next.js - React framework
- React - UI library
- Jest - Testing framework
- React Testing Library - Component testing
- Docker & Docker Compose - Containerization
- CORS - Cross-origin resource sharing
turtle-app/
βββ backend/ # Flask API
β βββ app.py # Main Flask application
β βββ requirements.txt # Python dependencies
β βββ conftest.py # Test configuration
β βββ test_app.py # API tests
β βββ uploads/ # Uploaded photos storage
β βββ .env.example # Environment variables template
β βββ Dockerfile # Backend container config
βββ frontend/ # Next.js application
β βββ pages/ # Next.js pages
β βββ components/ # React components
β βββ utils/ # Utility functions
β βββ __tests__/ # Test files
β βββ styles/ # CSS styles
β βββ package.json # Node.js dependencies
β βββ Dockerfile # Frontend container config
βββ docker-compose.yml # Multi-container orchestration
- Python 3.11+
- Node.js 18+
- PostgreSQL 15+
- Docker & Docker Compose (optional)
-
Clone and navigate to the project:
cd turtle-app -
Start all services with Docker Compose:
docker-compose up --build
-
Access the application:
- Frontend: http://localhost:8089
- Backend API: http://localhost:8090
- Database: localhost:5432
-
Navigate to backend directory:
cd turtle-app/backend -
Create and activate virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\\Scripts\\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
cp .env.example .env # Edit .env with your database configuration -
Set up PostgreSQL database:
# Create database createdb turtle_db -
Run the Flask application:
python app.py
-
Navigate to frontend directory:
cd turtle-app/frontend -
Install dependencies:
npm install
-
Start the development server:
npm run dev
cd backend
python -m pytestcd frontend
npm testGET /api/photos- Get all photosGET /api/photos/{id}- Get specific photo detailsPOST /api/photos- Upload new photoDELETE /api/photos/{id}- Delete photoGET /api/photos/{id}/file- Get photo file
GET /api/health- API health status
DATABASE_URL=postgresql://postgres:password@localhost:5432/turtle_db
FLASK_ENV=development
UPLOAD_FOLDER=uploads
- Update
DATABASE_URLwith production database credentials - Set
FLASK_ENV=production - Configure proper CORS origins
- Set up file storage (AWS S3, etc.)
- Update frontend API base URL
docker-compose -f docker-compose.prod.yml up --build- Supported formats: JPEG, PNG, GIF
- Maximum file size: 16MB
- Image processing: Automatic resize to 800x600 max dimensions
- Storage: Local filesystem (uploads directory)
id(INTEGER, PRIMARY KEY)filename(VARCHAR(255)) - Generated unique filenameoriginal_filename(VARCHAR(255)) - Original uploaded filenametitle(VARCHAR(255)) - Photo titledescription(TEXT) - Photo descriptionupload_date(DATETIME) - Upload timestampfile_size(INTEGER) - File size in bytes
# Run tests
python -m pytest
# Run with auto-reload
python app.py
# Install new dependency
pip install package_name
pip freeze > requirements.txt# Development server
npm run dev
# Build for production
npm run build
# Run tests
npm test
# Lint code
npm run lint-
Database connection errors
- Ensure PostgreSQL is running
- Check DATABASE_URL in .env file
- Verify database exists
-
File upload errors
- Check uploads directory permissions
- Verify file size limits
- Check allowed file types
-
CORS errors
- Ensure CORS is properly configured
- Check frontend API URLs
-
Docker issues
- Run
docker-compose down -vto reset volumes - Check Docker logs:
docker-compose logs service_name
- Run
If ports 3000, 5000, or 5432 are in use:
- Update port mappings in docker-compose.yml
- Update API URLs in frontend configuration
- Fork the repository
- Create a feature branch
- Make changes with tests
- Ensure all tests pass
- Submit a pull request
This project is open source and available under the MIT License.