Skip to content

TharushaDinujaya/galanor-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

29 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌌 GalaNor Backend

Python Flask License API Docs

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.

✨ Features

  • πŸ›°οΈ 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

πŸš€ Quick Start

# 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

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   NASA NEO API  │────│  GalaNor Backend │────│   Client Apps   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚                   β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚ PostgreSQL  β”‚    β”‚  MongoDB    β”‚
              β”‚ (Relations) β”‚    β”‚ (Documents) β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“Š API Endpoints

Core Endpoints

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

Response Format

{
  "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
}

πŸ”§ Configuration

Required Environment Variables

# 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 Deployment

Simple Docker Run

docker build -t galanor-backend .
docker run -p 8080:8080 --env-file .env galanor-backend

Docker Compose (Recommended)

docker-compose up -d

Includes PostgreSQL and MongoDB containers with persistent volumes.

πŸ“š API Documentation

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

πŸ› οΈ Development

Prerequisites

  • Python 3.11+
  • PostgreSQL 12+
  • MongoDB 4.4+
  • NASA API Key

Development Setup

# 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.py

Project Structure

galanor-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

πŸš€ Deployment

Supported Platforms

  • 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

Production Checklist

  • βœ… Set FLASK_ENV=production
  • βœ… Use production database URLs
  • βœ… Configure SSL/TLS
  • βœ… Enable monitoring and logging
  • βœ… Set up backup strategies
  • βœ… Configure auto-scaling (if needed)

πŸ” Monitoring & Logging

Built-in Features

  • 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

Log Levels

  • DEBUG - Detailed debugging information
  • INFO - General operational messages
  • WARNING - Warning messages
  • ERROR - Error conditions
  • CRITICAL - Critical error conditions

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Style

  • Follow PEP 8 guidelines
  • Use Black for formatting
  • Use isort for import sorting
  • Add type hints where possible
  • Write docstrings for public functions

πŸ› Troubleshooting

Common Issues

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 minutes

Port Already in Use

# Change port in .env or kill existing process
PORT=5001

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • 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

About

This is repository for backend of NASA Space Apps challenge project by team galanor.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors