The TraffiLearn Web API is the backbone of the TraffiLearn Web Application, dedicated for improving traffic rules education in Ukraine. This API serves as an intermediary between the client-side application and the underlying data sources. Note that the API is not directly accessible to users and is designed exclusively for frontend consumption.
This guide will help you set up and run the TraffiLearn Web API locally using Docker.
To run the API, ensure the following tools are installed on your local machine:
- Docker: Download and install Docker from the official Docker website.
- Stripe CLI: If using Stripe webhooks locally, download and install the Stripe CLI.
- API Keys and Environment Variables: Gather all required API keys and environment variables as outlined below.
To fully utilize the TraffiLearn Web API, the following API keys and connection strings are required:
- Groq API Key: Obtain from Groq API. (If not using Groq AI-specific endpoints, set a dummy value.)
- Azure Service Bus Connection String: Obtain from Azure Service Bus.
- Stripe Keys: If using payment-specific endpoints, obtain the following from Stripe:
- Publishable Key
- Secret Key
- Webhook Secret
- Google Client ID: Required for Google Authentication. Obtain from Google Developers Console.
Set the following environment variables before running the application:
GroqApiSettings__ApiKey(Groq API Key)MessageBrokerSettings__ConnectionString(Azure Service Bus Connection String)
For specific features, set these variables:
- Stripe Settings (For payment endpoints):
StripeSettings__PublishableKeyStripeSettings__SecretKeyStripeSettings__WebhookSecret
- Google Authentication:
GoogleAuthSettings__ClientId(Google Client ID)
You can also configure other settings specified in appsettings.json and appsettings.Development.json for advanced customization and environment-specific overrides.
Follow these steps to set up the TraffiLearn Web API:
Clone or download the TraffiLearn Web API source files to your local machine.
Open a terminal and navigate to the src folder of the downloaded project:
cd path/to/traffilearn/srcConfigure the necessary and additional environment variables in your terminal.
$env:GroqApiSettings__ApiKey="your-groq-api-key"
$env:MessageBrokerSettings__ConnectionString="your-connection-string"
$env:StripeSettings__PublishableKey="your-stripe-publishable-key"
$env:StripeSettings__SecretKey="your-stripe-secret-key"
$env:StripeSettings__WebhookSecret="your-stripe-webhook-secret"
$env:GoogleAuthSettings__ClientId="your-google-client-id"export GroqApiSettings__ApiKey="your-groq-api-key"
export MessageBrokerSettings__ConnectionString="your-connection-string"
export StripeSettings__PublishableKey="your-stripe-publishable-key"
export StripeSettings__SecretKey="your-stripe-secret-key"
export StripeSettings__WebhookSecret="your-stripe-webhook-secret"
export GoogleAuthSettings__ClientId="your-google-client-id"Ensure you are in the src directory, then run the following command:
docker-compose up -dIf using Stripe webhooks locally, start the Stripe CLI to listen for events and forward them to your application. Refer to the official guide for more details.
stripe listen --forward-to http://localhost:5000/api/webhooks/stripe --events checkout.session.completedEnsure the following ports are not occupied, as they will be used by the app:
- 5000 (API)
- 10000 (Azurite)
- 5432 (Postgres)
- 8025 (MailHog)
After some time, the application will be up and running. You can access the API documentation and test endpoints using Swagger:
To run the tests, you need to have .NET installed on your machine.
You can download .NET from the official .NET website.
After installing .NET, please follow the next steps:
-
Make sure you have repository files installed.
-
Navigate to the
srcfolder of the API in your terminal. -
Set the needed environment variables via CLI (see previous sections).
-
Run dotnet test:
dotnet test TraffiLearn.sln
If everything done right, you will see the test results.
- TraffiLearn Team Discord Server: Join Us
- Owner's Telegram: @masfrte
- GitHub Issues
We welcome contributions from the community! If you would like to contribute to this repository, please contact us.
For bugs, questions and discussions you can use the GitHub Issues.
This project is licensed under the MIT License. See the LICENSE file for details.
