A robust, scalable REST API service that transforms NASA's Near-Earth Object (NEO) data into developer-friendly endpoints. Built for asteroid intelligence and analytics applications.
- π°οΈ Real-time NASA Data Integration - Automated fetching from NASA NEO API
- ποΈ Dual Database Architecture - PostgreSQL for relational integrity + MongoDB for flexible querying
- π Interactive API Documentation - Auto-generated Swagger/OpenAPI docs
- β‘ High Performance - Caching, connection pooling, and optimized queries
- π Background Scheduling - Configurable data sync intervals with APScheduler
- π³ Production Ready - Docker support, logging, error handling, and monitoring
- π Secure & Configurable - Environment-based config with validation
# Clone the repository
git clone https://github.com/TharushaDinujaya/galanor-backend.git
cd galanor-backend
# Set up virtual environment
python -m venv .venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # macOS/Linux
# Install dependencies
pip install -r requirements.txt
# Configure environment (see Configuration section)
cp .env.example .env # Edit with your credentials
# Run the application
python run.pyπ That's it! Your API will be running at http://localhost:5000
π Need detailed setup instructions? β RUNNING_INSTRUCTIONS.md
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β NASA NEO API ββββββ GalaNor Backend ββββββ Client Apps β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββΌββββββββββ
β β
βββββββββββββββ βββββββββββββββ
β PostgreSQL β β MongoDB β
β (Relations) β β (Documents) β
βββββββββββββββ βββββββββββββββ
| Endpoint | Method | Description | Example |
|---|---|---|---|
/api/one |
GET | Get single asteroid by ID | /api/one?id=2000433 |
/api/asteroids |
GET | List asteroids (paginated) | /api/asteroids?page=1&size=20 |
/api/asteroids/names |
GET | Get all asteroid names | /api/asteroids/names |
/api/asteroids/diameter |
GET | Filter by diameter range | /api/asteroids/diameter?min=0.1&max=1.0 |
{
"data": {
"id": "2000433",
"name": "433 Eros (A898 PA)",
"absolute_magnitude_h": 10.4,
"estimated_diameter_min": 16.84,
"estimated_diameter_max": 37.68,
"is_potentially_hazardous_asteroid": false,
"orbital_data": {
"semi_major_axis": "1.458045729",
"eccentricity": "0.2226769",
"inclination": "10.8276",
"orbital_period": "643.219"
}
},
"success": true
}# Database Configuration
POSTGRES_URL=postgresql://username:password@host:port/database
MONGO_URL=mongodb+srv://username:password@cluster.mongodb.net/
MONGO_DB_NAME=galanor
# NASA API
NASA_API_KEY=your_nasa_api_key_here
NASA_FETCH_INTERVAL=10 # minutes
# Application
FLASK_ENV=development
PORT=5000
LOG_LEVEL=INFOπ Get NASA API Key: NASA API Portal (free registration)
docker build -t galanor-backend .
docker run -p 8080:8080 --env-file .env galanor-backenddocker-compose up -dIncludes PostgreSQL and MongoDB containers with persistent volumes.
Interactive documentation available at:
- Development:
http://localhost:5000/apidocs/ - Production:
https://your-domain.com/apidocs/
Features:
- π Complete endpoint documentation
- π§ͺ Interactive request testing
- π Schema definitions
- π‘ Example requests/responses
- Python 3.11+
- PostgreSQL 12+
- MongoDB 4.4+
- NASA API Key
# Install development dependencies
pip install -r requirements.txt
# Install pre-commit hooks
pre-commit install
# Run code formatting
black .
isort .
# Run the application in debug mode
python run.pygalanor-backend/
βββ app/
β βββ models/ # Database models
β βββ routes/ # API endpoints
β βββ services/ # Business logic
β βββ schemas/ # Marshmallow schemas
β βββ schedulers/ # Background tasks
β βββ config.py # Configuration
βββ requirements.txt # Python dependencies
βββ Dockerfile # Container configuration
βββ run.py # Application entry point
βββ README.md # This file
- Render - Zero-config deployment with Dockerfile
- Heroku - Add
Procfile: web: gunicorn run:app - AWS/GCP/Azure - Docker or serverless options
- DigitalOcean - App Platform or Droplets
- β
Set
FLASK_ENV=production - β Use production database URLs
- β Configure SSL/TLS
- β Enable monitoring and logging
- β Set up backup strategies
- β Configure auto-scaling (if needed)
- Structured Logging - JSON format with configurable levels
- Error Tracking - Comprehensive exception handling
- Performance Metrics - Request timing and database query stats
- Health Checks - Ready for load balancer integration
DEBUG- Detailed debugging informationINFO- General operational messagesWARNING- Warning messagesERROR- Error conditionsCRITICAL- Critical error conditions
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow PEP 8 guidelines
- Use Black for formatting
- Use isort for import sorting
- Add type hints where possible
- Write docstrings for public functions
Database Connection Failed
# Check database status and credentials
python -c "from app.config import Config; print(Config.POSTGRES_URL)"NASA API Rate Limited
# Increase fetch interval in .env
NASA_FETCH_INTERVAL=30 # 30 minutesPort Already in Use
# Change port in .env or kill existing process
PORT=5001This project is licensed under the MIT License - see the LICENSE file for details.
- NASA for providing the amazing NEO API
- Flask community for the robust web framework
- MongoDB and PostgreSQL for reliable data storage
- All the open-source contributors who made this possible
π Star this repo if you find it useful!
π Report Bug Β· β¨ Request Feature Β· π Documentation
Made with β€οΈ by TharushaDinujaya