{"id":30430726,"url":"https://github.com/illusioxd/weatherfastapi","last_synced_at":"2025-08-22T18:33:49.652Z","repository":{"id":311176827,"uuid":"1039222128","full_name":"illusiOxd/WeatherFastAPI","owner":"illusiOxd","description":"RESTful FastAPI Weather API with JWT authentication, email OTP verification, and MongoDB integration.","archived":false,"fork":false,"pushed_at":"2025-08-22T14:49:12.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-22T16:48:34.107Z","etag":null,"topics":["api","authentication","backend","educational-project","email-verification","fastapi","jwt","microservices","mongodb","python","rest","security","weather","web-development"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/illusiOxd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-16T18:34:30.000Z","updated_at":"2025-08-22T14:53:17.000Z","dependencies_parsed_at":"2025-08-22T16:48:41.860Z","dependency_job_id":null,"html_url":"https://github.com/illusiOxd/WeatherFastAPI","commit_stats":null,"previous_names":["illusioxd/weatherfastapi"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/illusiOxd/WeatherFastAPI","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/illusiOxd%2FWeatherFastAPI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/illusiOxd%2FWeatherFastAPI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/illusiOxd%2FWeatherFastAPI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/illusiOxd%2FWeatherFastAPI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/illusiOxd","download_url":"https://codeload.github.com/illusiOxd/WeatherFastAPI/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/illusiOxd%2FWeatherFastAPI/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271681624,"owners_count":24802078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","authentication","backend","educational-project","email-verification","fastapi","jwt","microservices","mongodb","python","rest","security","weather","web-development"],"created_at":"2025-08-22T18:33:49.169Z","updated_at":"2025-08-22T18:33:49.644Z","avatar_url":"https://github.com/illusiOxd.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Weather Forecast API\n\nA RESTful API built with FastAPI that provides real-time weather forecasts and includes a secure user authentication system using JSON Web Tokens (JWT). The application connects to a MongoDB database to manage user data and store weather forecast records.\n\n## Table of Contents\n\n- [Features](#features)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [API Endpoints](#api-endpoints)\n- [Authentication](#authentication)\n- [Project Structure](#project-structure)\n- [Future Enhancements](#future-enhancements)\n- [License](#license)\n\n## Features\n\n- **🔐 Secure Authentication**: User authentication powered by JWT tokens, with bcrypt for password hashing\n- **📧 Email Verification**: A secure registration process that uses a one-time password (OTP) sent to the user's email\n- **🌤️ Weather Data**: Fetches real-time weather data from the OpenWeatherMap API\n- **💾 Data Persistence**: Stores user details and past weather queries in a MongoDB database\n- **⚡ Scalable Framework**: Built on FastAPI, known for its high performance and robust features\n\n## Requirements\n\nTo run this project, you need to have the following installed:\n\n- Python 3.7+\n- MongoDB\n\nThe Python dependencies can be installed using pip. It is highly recommended to use a virtual environment.\n\n```bash\npip install fastapi \"uvicorn[standard]\" pymongo python-jose[jwt] requests bcrypt\n```\n\n## Installation\n\nFollow these steps to get the project up and running on your local machine.\n\n### 1. Clone the repository\n\n```bash\ngit clone https://github.com/yourusername/your-repo-name.git\ncd your-repo-name\n```\n\n### 2. Create a virtual environment (optional but recommended)\n\n```bash\npython -m venv venv\nsource venv/bin/activate  # On Windows, use venv\\Scripts\\activate\n```\n\n### 3. Install dependencies\n\n```bash\npip install -r requirements.txt\n```\n\n\u003e **Note**: You may need to create a `requirements.txt` file from the list above.\n\n### 4. Set up environment variables\n\nYour code imports sensitive information (database URI, API keys, etc.) from `keys.gitignorfile.py`. For a public repository, a more secure and standard approach is to use a `.env` file.\n\nCreate a file named `.env` in the root of your project and populate it with your credentials:\n\n```env\n# Example .env file\nURI=\"mongodb+srv://\u003cusername\u003e:\u003cpassword\u003e@\u003ccluster\u003e.mongodb.net/?retryWrites=true\u0026w=majority\"\nAPI_KEY=\"your_openweathermap_api_key\"\nHOST=\"127.0.0.1\"\nPORT=\"8000\"\nSECRET_KEY=\"your_secret_key\"\nALGORITHM=\"HS256\"\nACCESS_TOKEN_EXPIRE_MINUTES=30\n```\n\n### 5. Run the application\n\n```bash\nuvicorn main:app --reload\n```\n\nThe API will be available at `http://127.0.0.1:8000`.\n\n## API Endpoints\n\nThe API is structured with the following endpoints.\n\n### Root\n\nA simple health check to ensure the server is running.\n\n- **Method**: `GET`\n- **Path**: `/`\n- **Description**: Returns the server status\n- **Response**:\n  ```json\n  {\n    \"server_status\": \"working\"\n  }\n  ```\n\n### Register\n\nInitiates the registration process by sending an OTP to the user's email.\n\n- **Method**: `POST`\n- **Path**: `/register`\n- **Description**: Sends a one-time password (OTP) to the provided email address\n- **Request Body**:\n  ```json\n  {\n    \"email\": \"user@example.com\"\n  }\n  ```\n- **Response**:\n  ```json\n  {\n    \"message\": \"OTP sent to your email\"\n  }\n  ```\n\n### Verify OTP and Complete Registration\n\nVerifies the OTP and, if valid, creates a new user and issues a JWT token.\n\n- **Method**: `POST`\n- **Path**: `/verify_otp`\n- **Description**: Verifies the OTP and completes the user registration\n- **Request Body**:\n  ```json\n  {\n    \"email\": \"user@example.com\",\n    \"password\": \"your_secure_password\",\n    \"otpcode\": \"123456\"\n  }\n  ```\n- **Response**:\n  ```json\n  {\n    \"access_token\": \"your_jwt_token_here\",\n    \"token_type\": \"bearer\"\n  }\n  ```\n\n### Get Weather Forecast\n\nA protected endpoint that requires a valid JWT token.\n\n- **Method**: `GET`\n- **Path**: `/forecast/{city}`\n- **Description**: Fetches weather data for a specified city\n- **Request Headers**:\n  ```\n  Authorization: Bearer \u003cyour_jwt_token\u003e\n  ```\n- **Response**:\n  ```json\n  {\n    \"city\": \"London\",\n    \"status\": \"sent to mongodb\",\n    \"temperature\": 15.5,\n    \"condition\": \"scattered clouds\"\n  }\n  ```\n\n## Authentication\n\nThis API uses a JWT-based authentication system. The current flow is a single-step registration and token issuance process.\n\n1. **Register**: A user sends a `POST` request to `/register` with their email\n2. **Verify \u0026 Get Token**: The user then sends a `POST` request to `/verify_otp` with their email, password, and the received OTP. If successful, the API returns a JWT token\n3. **Access Protected Endpoints**: This token can then be used in the Authorization header with the Bearer scheme to access protected endpoints like `/forecast/{city}`\n\n## Project Structure\n\n```\n.\n├── main.py                    # Main FastAPI application file\n├── pydantic_models/           # Pydantic models for data validation\n│   ├── auth_models.py\n│   └── __init__.py\n├── services/                  # Service functions like email sending\n│   ├── smtp_service.py\n│   └── __init__.py\n├── functions/                 # Helper functions, e.g., for JWT creation\n│   └── jwtfuncs.py\n├── keys/                      # Directory for configuration (best to use .env)\n│   └── gitignorfile.py        # Your private configuration file\n└── README.md\n```\n\n## Future Enhancements\n\n- **Add a `/login` endpoint**: Currently, there is no way for a user to get a new token after their initial registration without going through the registration process again. An endpoint for logging in with email and password would be a crucial improvement\n\n- **User Roles**: Expand the role field in the user document to support different user types with varying access levels\n\n- **Error Handling**: Implement more specific error handling for API failures (e.g., city not found, database connection errors)\n\n- **Token Refresh**: Add a token refresh mechanism to provide new tokens without requiring a full re-login\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fillusioxd%2Fweatherfastapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fillusioxd%2Fweatherfastapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fillusioxd%2Fweatherfastapi/lists"}