Wattio-Backend is an efficient FastAPI application designed to manage various functionalities like rides, recommendations, redeemables, and more.
The project structure is organized as follows:
.
├── app
│ ├── main.py # Main application runner
│ └── server
│ ├── app.py
│ ├── config.py # General Configuration
│ ├── database # Database CRUD operations
│ │ ├── ...
│ ├── dependencies.py # API Dependencies
│ ├── models # Pydantic Models for API
│ │ ├── ...
│ ├── routes # API Endpoints/Routes
│ │ ├── ...
│ └── utils.py # Utilities
├── requirements.txt # Python dependencies
├── static # Static assets
│ ├── icons
│ ├── recommendations
│ └── redeemables
├── tests
│ └── api_auth_test.py # Authentication Tests
└── triggers
├── recommendations.json # Recommendation triggers
├── recommendations.py
├── redeemable.json # Redeemable triggers
├── redeemable.py
├── vehicles.json # Vehicle triggers
└── vehicles.py
To set up and run the project locally, use the following steps:
- Set up a virtual environment:
python3 -m venv venv
- Activate the virtual environment:
source ./venv/bin/activate
- Install the required dependencies:
pip install -r requirements.txt
- Run the application:
python app/main.py
You can also run the service with this command:
cp .env.example .env
# Make sure to edit the .env file properly
docker-compose up -d
This will start the FastAPI application and it should be accessible on http://localhost:8000/
.
The application uses environment variables for configuration. An example .env
file is provided as .env.example
in the root directory. Before running the application, make a copy of this file, rename it to .env
, and fill in the appropriate values.
MONGO_URL="mongodb://<USER>:<PASSWORD>@<HOST>:<PORT>/?authMechanism=DEFAULT" # MongoDB Connection URL
SECRET_KEY="<YOUR_SECRET_KEY>" # Secret key for encoding and decoding JWT tokens
PORT=8000 # The port on which the FastAPI application will run
ACCESS_TOKEN_EXPIRE_MINUTES=30 # Token expiration time in minutes
PROJECT_ENVIRONMENT="DEVELOPMENT" # Use "DEVELOPMENT" for development mode or "RELEASE" for release mode
The application's functionalities are divided into different modules such as rides, recommendations, redeemables, and more. Each module has its own set of routes. Here are some examples:
- Rides: Manage and log rides. Users earn points based on their rides.
- Routes can be found in
app/server/routes/ride.py
.
- Routes can be found in
- Recommendations: Provide eco-friendly recommendations to users.
- Routes can be found in
app/server/routes/recommendation.py
.
- Routes can be found in
- Redeemables: Items or services that users can redeem using their earned points.
- Routes can be found in
app/server/routes/redeemable.py
.
- Routes can be found in
The application uses database models defined using Pydantic. These models can be found under the app/server/models
directory. Each module (rides, recommendations, redeemables, etc.) has its own model.
For example, the Ride model is defined in app/server/models/ride.py
and it contains attributes like user_id, distance, points_obtained, etc.