Skip to content

Latest commit

 

History

History
194 lines (137 loc) · 6.82 KB

Project-Guide.md

File metadata and controls

194 lines (137 loc) · 6.82 KB

Project Setup Guide

Prerequisites

Clone the Repository

git clone https://github.com/kvcops/KV-Nexus.git
cd KV-Nexus

Create a Virtual Environment

It's recommended to use a virtual environment to manage dependencies.

python -m venv venv

Activate the virtual environment:

  • On Windows:
    venv\Scripts\activate
  • On macOS/Linux:
    source venv/bin/activate

Setup Firebase

Firebase

1. Create a Firebase Project

You will need to create a Firebase project to host your database. This project will be used to store your database and other resources. Make sure to select the region closest to you.

If you don't have a Firebase project:

  1. Go to the Firebase Console.

  2. Click on "Add project" and follow the prompts to create a new project.

Create Firebase Project
  1. Choosing the Google Analytics for this project is optional, but it is recommended.
Google Analytics
  1. Click on "Continue" to create your project. Wait for Firebase to finish creating your project.

2. Generate a Service Account Key

  1. In the Firebase Console, select your project.
  2. Click the gear icon (⚙️) next to "Project Overview" and select Project settings.
  3. Navigate to the Service accounts tab.
  4. Click on Generate new private key.
  5. A JSON file will be downloaded. Keep this file secure and do not commit it to version control.

3. Configure Environment Variables

Extract the necessary values from the downloaded JSON file and set them as environment variables.

Create a .env file in the root directory of your project:

FIREBASE_PROJECT_ID=your_project_id
FIREBASE_CLIENT_EMAIL=your_client_email
FIREBASE_PRIVATE_KEY=your_private_key
FIREBASE_CLIENT_ID=client_id
FIREBASE_AUTH_URI=auth_uri
FIREBASE_TOKEN_URI=token_uri
FIREBASE_AUTH_PROVIDER_X509_CERT_URL=auth_provider_x509_cert_url
FIREBASE_CLIENT_X509_CERT_URL=client_x509_cert_url
FIREBASE_UNIVERSE_DOMAIN=universe_domain

Replace your_project_id, your_client_email, and your_private_key with the corresponding values from the JSON file.

Note: Ensure that the serviceAccountKey.json file and .env file are added to your .gitignore to prevent them from being pushed to version control.

4. Storage Bucket

  1. In the Firebase Console, select your project.
  2. Click on Storage in the left sidebar.
  3. Scroll down and click on Firebase Storage in the center of the page.
  4. Choose the region closest to you. In my case, I chose Asia-east2 (hong kong).
  5. Always select the Start in production mode.
  6. Click on Next.
  1. STORAGE_BUCKET_URL: This is found in the Firebase console under Storage.Also make sure that the STORAGE_BUCKET_URL is correctly set like this.
STORAGE_BUCKET_URL=gs://<your-project-id>.appspot.com

5. Miscellaneous variables

authDomain=
projectId=
storageBucket=
messagingSenderId=
appId=

Install Dependencies

Ensure you have pip installed, then install the required packages:

pip install -r requirements.txt

Run the Application

With everything set up, you can now run the application:

flask run

NOTE: If you encounter an issue related to type "field" like one shown below:-

Field Error

Simply add a env var to specify the type of the firebase account.

FIREBASE_TYPE=service_account

Once all the above steps are done, you should be able to run the application without any issues. your .env file should look like this.

Final .env

Additional Notes

  • Database Setup: If your application uses a database, ensure it's properly configured and migrated.
  • Environment Variables: Consider using tools like python-dotenv to manage environment variables seamlessly.
  • Security: Always keep your service account keys and other sensitive information secure. Avoid hardcoding them in your codebase.

Also make sure to obtain these API keys from the respective websites. As they are also used in the application.

mailjet_api_key = os.environ.get("mail_API_KEY")  # Replace with your Mailjet API key
mailjet_api_secret = os.environ.get("mail_API_SECRET")  # Replace with your Mailjet API secret
mailjet = Client(auth=(mailjet_api_key, mailjet_api_secret), version='v3.1')
google_api_key = os.environ.get("API_KEY")
unsplash_api_key = os.getenv('UNSPLASH_API_KEY')
openweathermap_api_key = os.getenv('OPENWEATHERMAP_API_KEY')

Thank you for following this guide. I hope you found it helpful.