- Table of Contents
- Project Structure
- AI Agents Collaboration
- Preview
- Getting Started
- VSCode/Cursor Settings
- License
Dr. Koala is built with Next.js as the frontend and FastAPI as the backend. Both follow the principles of Clean Architecture. This project is using python-clean-arch as the template.
Based on the concept of clean architecture, the backend application contains the following major layers:
- Core layer (
/core): The entities layer, which contains the core business rules and logic - Service layer (
/service): The use cases layer, which contains the application of business rules and logic - Repository layer (
/repository): The infrastructure layer, which contains the data access logic - API layer (
/api): The presentation layer, which contains the HTTP API endpoints
The frontend application contains the following major folders:
- Components folder (
/components): The UI components folder, which contains the reusable UI components - Modules folder (
/modules): The module components folder, which contains the business logic for each page - Hooks folder (
/hooks): The hooks folder, which contains the custom hooks for the application, including the API integration logic - Routes(pages) folder (
/pages): The route components folder (in Next.js, it is the pages directory), which defines the routes for the application
Dr. Koala uses AutoGen as the multi-agent framework. The prompt templates for the agents are defined in the app/core/constant/agent_configs.toml file.
There are 3 main agents in Dr. Koala:
- Primary Agent: For understanding the user's intentions, questions, and requirements by analyzing the user's input then planning the search, generation, and review tasks. Adjust the processing plan if needed.
- Search Agent: For searching the web with the Brave Search MCP tool.
- Generation Agent: For generating the final answer based on the searched results in the markdown format.
demo.mov
Create a new .env file by running the following command:
cp .env.example .envRequired environment variables:
DB_HOST: PostgreSQL host (default:localhost)DB_PORT: PostgreSQL port (default:5432)DB_NAME: PostgreSQL database name (default:dr_koala)DB_USER: PostgreSQL user (default:postgres)DB_PASSWORD: PostgreSQL password (default:postgres)XAI_API_KEY: Your xAI API key for GrokBRAVE_SEARCH_API_KEY: Your Brave Search API key for web searching
Setup the frontend environment variables:
cd frontend
cp .env.example .envOptional environment variables:
NEXT_PUBLIC_API_URL: Backend API URL (default tohttp://localhost:7086, no need to change when running locally)
You can quickly start the server with docker compose:
# Development
docker compose up -dSetup the production environment variables:
cp .env.prod.example .envThen run the following command to start the server in production mode:
docker compose -f docker-compose.prod.yml up --remove-orphans -dIn this example, we use PostgreSQL as the database. If you have it installed locally, you can set the database connection parameters in the .env file:
DB_HOST=localhost
DB_PORT=5432
DB_NAME=dr_koala
DB_USER=postgres
DB_PASSWORD=postgresOr you can use docker compose file we provided to quickly setup one:
docker compose -f docker-compose.db.yml up -dYou can change the POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD in the .env file to change the database info of docker container.
Please remember to align the DB_NAME, DB_USER, DB_PASSWORD with the POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD in the .env file.
After the database is running, you can initialize the database by running the following commands:
make init-dbYou can start both the backend and frontend together, or run them separately.
To start both servers simultaneously:
make runThis will start:
- Backend API server at http://localhost:7086
- Frontend application at http://localhost:3076
Press Ctrl+C to stop both servers.
uv is used to manage the dependencies and virtual environment, make sure you have it installed before you start.
-
Install dependencies
uv sync
-
Run the backend server
make run-backend
The backend API will be available at http://localhost:7086.
Make sure you have installed the frontend dependencies first (see Start the Frontend section).
make run-frontendThe frontend will be available at http://localhost:3076.
VSCode is recommended for development, before you start, make sure you have installed the Python and Python Debugger extensions.
-
First, you need to install the dependencies (see Running Backend Only)
-
Then, select the correct python interpreter in VSCode by press
cmd + shift + pand searchPython: Select Interpreter. The python interpreter should be the one you installed in the first step, usually you can find the uv-managed virtual environment in the list. -
Then, you need to set up the debugger configuration for VSCode:
cp .vscode/launch.example.json .vscode/launch.json
-
Choose the "FastAPI" configuration from the VSCode and run it.
The frontend application is built with Next.js and requires Node.js to run.
-
Navigate to the frontend directory
cd frontend -
Setup frontend environment variables
cp .env.example .env
You can customize the API URL in
.env:NEXT_PUBLIC_API_URL: Backend API URL (default:http://localhost:7086)
-
Install dependencies
pnpm i
-
Run the development server
pnpm dev
The frontend application should be available at http://localhost:3076.
After installing dependencies, you can also use the make command from the project root:
make run-frontendMake sure you have installed the dependencies with uv:
uv syncThen, you can run the unit tests by the following command:
make run-unit-testsYou can also run the unit tests with docker:
docker build -f Dockerfile.dev -t app-test --build-arg RUN_MODE=test . && docker run app-testOnce the server is running, visit the Swagger UI at http://localhost:7086/docs
For VSCode/Cursor, run the following command to setup the editor config:
cp .vscode/settings.example.json .vscode/settings.json