A modern, full-stack web application that provides AI-powered answers to travel documentation questions. Built with FastAPI backend and Next.js frontend, featuring comprehensive testing, responsive design, and robust error handling.
- π€ AI-Powered Assistance - OpenAI GPT-3.5-turbo integration for intelligent responses
- π RESTful API - FastAPI with auto-generated documentation
- π CORS Support - Seamless frontend integration
- β Comprehensive Testing - Full test coverage with pytest
- π Auto Documentation - Swagger UI and ReDoc endpoints
- π Production Ready - Optimized for deployment
- π± Responsive Design - Beautiful, mobile-first UI with Tailwind CSS
- β‘ Fast Performance - Optimized Next.js with static generation
- π§ͺ Comprehensive Testing - Jest and React Testing Library
- π Error Handling - Robust error handling with user feedback
- βΏ Accessibility - Built with accessibility best practices
- π Real-time Communication - Seamless API integration
- Framework: FastAPI 0.104.1
- Language: Python 3.12+
- AI Integration: OpenAI GPT-3.5-turbo
- Testing: pytest + pytest-asyncio
- Server: Uvicorn
- Documentation: Swagger UI + ReDoc
- Framework: Next.js 14.2.32
- UI Library: React 18.2.0
- Styling: Tailwind CSS 3.3.5
- Testing: Jest + React Testing Library
- Build Tool: Next.js built-in bundler
- Package Manager: npm
fullstackapp/
βββ backend/ # FastAPI backend application
β βββ main.py # Main FastAPI application
β βββ test_main.py # Comprehensive test suite
β βββ start_server.py # Development server script
β βββ run_tests.py # Test runner script
β βββ requirements.txt # Python dependencies
β βββ pyproject.toml # Project configuration
β βββ pytest.ini # Pytest configuration
β βββ README.md # Backend documentation
βββ frontend/ # Next.js frontend application
β βββ components/
β β βββ TravelAssistant.js # Main application component
β βββ pages/
β β βββ index.js # Home page
β βββ __tests__/ # Test suites
β βββ jest.config.js # Jest configuration
β βββ jest.setup.js # Test setup and mocks
β βββ run_tests.js # Test runner script
β βββ TESTING.md # Detailed testing documentation
β βββ package.json # Node.js dependencies
β βββ tailwind.config.js # Tailwind CSS configuration
β βββ README.md # Frontend documentation
βββ README.md # This file
- Node.js 18+ (for frontend)
- Python 3.12+ (for backend)
- OpenAI API Key (for AI functionality)
git clone <repository-url>
cd fullstackappcd backendpip install -r requirements.txt# Create .env file
echo "OPENAI_API_KEY=your_openai_api_key_here" > .env# Option 1: Using the start script
python start_server.py
# Option 2: Using uvicorn directly
uvicorn main:app --reload --host 0.0.0.0 --port 8000Backend will be available at:
- API: http://localhost:8000
- Documentation: http://localhost:8000/docs
- Health Check: http://localhost:8000/health
cd frontendnpm installnpm run devFrontend will be available at: http://localhost:3000
- Visit OpenAI Platform
- Sign up for an account
- Generate an API key from your dashboard
- Add the API key to your backend
.envfile
# Development
python start_server.py # Start development server
uvicorn main:app --reload # Start with uvicorn directly
# Testing
python -m pytest test_main.py -v # Run all tests
python -m pytest test_main.py --cov=main # Run with coverage
python run_tests.py # Use test runner script
# Production
uvicorn main:app --host 0.0.0.0 --port 8000 # Production server# Development
npm run dev # Start development server with hot reload
npm run build # Build production-ready application
npm run start # Start production server
npm run lint # Run ESLint for code quality
# Testing
npm test # Run all tests
npm run test:watch # Run tests in watch mode
npm run test:coverage # Run tests with coverage report
node run_tests.js # Use custom test runnerThe backend includes comprehensive testing with 25+ passing tests:
# Run all backend tests
cd backend
python -m pytest test_main.py -v
# Run specific test categories
python -m pytest test_main.py::TestQueryRequest -v
python -m pytest test_main.py::TestAskEndpoint -vTest Categories:
- Model Validation - QueryRequest validation tests
- API Endpoints - All HTTP endpoint tests
- Error Handling - Various error scenario tests
- CORS Configuration - CORS middleware tests
- Integration Tests - End-to-end workflow tests
The frontend includes comprehensive testing with 7+ passing tests:
# Run all frontend tests
cd frontend
npm test
# Run specific test files
npm test TravelAssistant.simple.test.jsTest Categories:
- Component Rendering - UI elements render correctly
- User Interactions - Input changes, form submissions, button clicks
- API Integration - Successful requests, error handling, network failures
- State Management - Loading states, error states, response display
- Error Handling - Validation errors, API errors, network errors
- Response Management - Display responses, clear functionality
GET /- Root endpoint with server statusGET /health- Health check endpointPOST /api/ask- Ask travel documentation questions
GET /docs- Interactive API documentation (Swagger UI)GET /redoc- Alternative API documentation (ReDoc)GET /openapi.json- OpenAPI schema
curl -X POST "http://localhost:8000/api/ask" \
-H "Content-Type: application/json" \
-d '{"question": "What documents do I need to travel to Japan?"}'Response:
{
"answer": "For travel to Japan, you typically need:\n1. Valid passport (6+ months validity)\n2. Visa (depending on nationality)\n3. Return ticket\n4. Proof of accommodation",
"model": "gpt-3.5-turbo"
}curl http://localhost:8000/healthResponse:
{
"status": "healthy"
}| Variable | Description | Required |
|---|---|---|
OPENAI_API_KEY |
OpenAI API key for GPT-3.5-turbo | Yes |
- Origin:
http://localhost:3000(for frontend development) - Methods: All methods (
*) - Headers: All headers (
*) - Credentials: Enabled
Create a .env.local file:
NEXT_PUBLIC_API_URL=http://localhost:8000Configuration in tailwind.config.js:
module.exports = {
content: [
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
'./components/**/*.{js,ts,jsx,tsx,mdx}',
],
theme: {
extend: {},
},
plugins: [],
}- Environment Variables: Set
OPENAI_API_KEYin production - CORS: Update allowed origins for production domains
- Security: Consider adding authentication/rate limiting
- Monitoring: Add logging and health checks
- Scaling: Use a production ASGI server like Gunicorn
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]cd frontend
npm run build- Vercel (Recommended for Next.js)
- Netlify
- AWS Amplify
- Docker (with custom Dockerfile)
- "What documents do I need to travel from Kenya to Ireland?"
- "What's the visa requirement for US citizens visiting Brazil?"
- "Do I need vaccinations to travel to Thailand?"
- "What are the passport requirements for traveling to Japan?"
- "How long can I stay in the EU with a US passport?"
- Open your browser and navigate to http://localhost:3000
- Type your travel documentation question in the input field
- Click "Ask Question" to get an AI-generated response
- View the formatted response with model information
- Clear the response to ask another question
-
API Key Not Working
- Verify
OPENAI_API_KEYis set in.envfile - Check API key has sufficient credits
- Ensure API key is valid and active
- Verify
-
CORS Errors
- Verify CORS is configured for frontend URL
- Check that frontend is running on correct port
- Ensure backend allows the frontend origin
-
Tests Failing
- Run
pip install -r requirements.txtto ensure dependencies - Check Python version compatibility
- Verify test environment setup
- Run
-
API Connection Failed
- Ensure backend is running on
http://localhost:8000 - Check CORS configuration
- Verify API endpoint availability
- Ensure backend is running on
-
Tests Failing
- Run
npm installto ensure dependencies are installed - Check Jest configuration
- Verify test environment setup
- Run
-
Build Errors
- Clear
.nextdirectory:rm -rf .next - Reinstall dependencies:
rm -rf node_modules && npm install - Check for TypeScript errors (if using TS)
- Clear
# Backend debug
cd backend
uvicorn main:app --reload --log-level debug
# Frontend debug
cd frontend
DEBUG=* npm run dev- Backend README - Detailed backend documentation
- Frontend README - Detailed frontend documentation
- Frontend Testing Guide - Comprehensive testing documentation
- FastAPI Documentation
- Next.js Documentation
- React Testing Library
- Tailwind CSS
- OpenAI API Documentation
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Add tests for new functionality
- Run tests for both backend and frontend
- Commit changes:
git commit -m 'Add feature' - Push to branch:
git push origin feature-name - Submit a pull request
- Backend: All functions must be tested, use type hints, follow Python best practices
- Frontend: Write tests for new features, follow React best practices, ensure accessibility
- Documentation: Update relevant README files and add inline comments
- Testing: Ensure all tests pass before submitting PR
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Check the internal documentation in
backend/README.mdandfrontend/README.md - Review the troubleshooting section above
- Create an issue in the project repository
- Check the test suites for usage examples
Built with β€οΈ using FastAPI, Next.js, React, and Tailwind CSS