8000 GitHub - gitEricsson/Enerdit-BE: Enerdit Backend is the server-side component of the Enerdit application, designed to handle user authentication, energy audit data management, and provide a RESTful API for the frontend. It is built using Django and Django REST Framework.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Enerdit Backend is the server-side component of the Enerdit application, designed to handle user authentication, energy audit data management, and provide a RESTful API for the frontend. It is built using Django and Django REST Framework.

Notifications You must be signed in to change notification settings

gitEricsson/Enerdit-BE

Repository files navigation

Enerdit Backend

Enerdit Backend is the server-side component of the Enerdit application, designed to handle user authentication, energy audit data management, and provide a RESTful API for the frontend. It is built using Django and Django REST Framework.

Table of Contents

Features

  • User authentication with JWT tokens
  • Management of energy audit data
  • RESTful API for frontend integration
  • Support for multiple building types and compartments
  • Energy consumption calculations and recommendations

Technologies Used

  • Django: A high-level Python web framework for rapid development.
  • Django REST Framework: A powerful toolkit for building Web APIs.
  • PostgreSQL: A powerful, open-source object-relational database system.
  • Django CORS Headers: For handling Cross-Origin Resource Sharing (CORS).
  • Django Environ: For managing environment variables.
  • Gunicorn: A Python WSGI HTTP Server for UNIX, used to serve the application.
  • Uvicorn: A lightning-fast ASGI server for Python, suitable for asynchronous applications.

Installation

To set up the Enerdit backend, follow these steps:

  1. Clone the repository:

    git clone https://github.com/yourusername/enerdit-backend.git
  2. Navigate to the project directory:

    cd enerdit-backend
  3. Create a virtual environment:

    python -m venv venv
  4. Activate the virtual environment:

    • On Windows:
      venv\Scripts\activate
    • On macOS/Linux:
      source venv/bin/activate
  5. Install the dependencies:

    pip install -r requirements.txt
  6. Create a .env file in the root directory and add the following environment variables:

    SECRET_KEY=your_secret_key
    DEBUG=True
    DATABASE_URL=postgres://user:password@localhost:5432/yourdbname
    
  7. Run database migrations:

    python manage.py migrate
  8. Create a superuser (optional):

    python manage.py createsuperuser

Usage

To run the application, use the following command:

python manage.py runserver

This will start the development server at http://127.0.0.1:8000/.

Running with Uvicorn

For production, you can run the application using Uvicorn. Use the following command:

python -m uvicorn Enerdit.asgi:application --host 0.0.0.0 --port 8000

Running with Gunicorn

Alternatively, you can use Gunicorn to serve your application with Uvicorn workers. This is recommended for production environments. Use the following command:

gunicorn -w 4 -k uvicorn.workers.UvicornWorker Enerdit.asgi:application --host 0.0.0.0 --port 8000
  • -w 4: This option specifies the number of worker processes. Adjust this based on your server's CPU cores.
  • -k uvicorn.workers.UvicornWorker: This option tells Gunicorn to use Uvicorn as the worker class.

API Endpoints

The following are the main API endpoints available:

  • Authentication

    • POST /auth/login/: Log in a user and receive a JWT token.
    • POST /auth/signup/: Register a new user.
  • Energy Audit

    • POST /energy-audit/: Create a new energy audit report.

Database Models

The backend includes the following key models:

  • User: Represents the user of the application.
  • Building: Represents a building with attributes like type, number of floors, and energy consumption.
  • Compartment: Represents a compartment within a building, containing appliances.
  • Appliance: Represents an appliance with attributes like power rating and usage time.

About

Enerdit Backend is the server-side component of the Enerdit application, designed to handle user authentication, energy audit data management, and provide a RESTful API for the frontend. It is built using Django and Django REST Framework.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0