Skip to content

blandevv/aeromind-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

✈️ AeroMind API

Multi-agent AI backend for intelligent airport management

Python FastAPI PostgreSQL Gemini License


🌟 What is AeroMind?

AeroMind is a production-ready REST API that powers an intelligent airport assistant. Passengers and operators interact with it through a natural language chat interface. Behind the scenes, an orchestrator powered by Google Gemini classifies every message and routes it to the most suitable specialized AI agent.

Each agent can call real airport tools β€” searching flights, tracking baggage, filing incidents β€” via a Model Context Protocol (MCP) server. Agents that deal with policies and procedures also perform Retrieval-Augmented Generation (RAG) over an official document store backed by pgvector.


πŸ—οΈ Architecture Overview

graph TD
    Client["🌐 HTTP Client"] --> API

    subgraph API["⚑ FastAPI"]
        R["/auth Β· /flights Β· /bookings\n/baggage Β· /chat Β· /incidents Β· /documents"]
    end

    API --> Orch["🧠 Orchestrator\nGemini LLM · temperature=0\nIntent classification"]

    Orch -->|"✈️ flight queries"| FA["FlightAgent"]
    Orch -->|"🧳 baggage queries"| BA["BaggageAgent"]
    Orch -->|"πŸ’¬ support & policies"| SA["SupportAgent"]
    Orch -->|"πŸ”’ security & procedures"| SeA["SecurityAgent"]

    FA --> MCP
    BA --> MCP
    SA --> RAG
    SeA --> RAG

    subgraph MCP["πŸ”Œ MCP Server Β· FastMCP"]
        T["9 airport tools"]
    end

    subgraph RAG["πŸ“š RAG System"]
        E["Gemini Embeddings\n3072 dimensions"]
        V[("pgvector\ncosine similarity")]
        E --> V
    end

    MCP --> AppL
    RAG --> AppL

    subgraph AppL["πŸ“‹ Application Layer"]
        UC["Use Cases Β· DTOs Β· Ports"]
    end

    AppL --> DB[("🐘 PostgreSQL 17\n+ pgvector")]
Loading

Clean Architecture Layers

graph BT
    style Domain fill:#1e3a5f,stroke:#4a9eff,color:#e8f4ff
    style Application fill:#1a3a2a,stroke:#4aff8c,color:#e8fff0
    style Infra fill:#3a1e3a,stroke:#cc4aff,color:#f0e8ff
    style API fill:#3a2a1a,stroke:#ff8c4a,color:#fff0e8

    Domain["πŸ’Ž Domain\nEntities Β· Value Objects Β· Domain Exceptions"]
    Application["πŸ“‹ Application\nUse Cases Β· Ports Β· DTOs"]
    Infra["πŸ”§ Infrastructure\nSQLAlchemy Β· Gemini Β· JWT Β· bcrypt"]
    API["🌐 API\nRouters · Middleware · Dependencies"]

    Application --> Domain
    Infra --> Application
    API --> Application
Loading

πŸ› οΈ Tech Stack

Technology Purpose
⚑ FastAPI Async REST framework
πŸ—„οΈ SQLAlchemy 2 (async) ORM with async session support
🐘 PostgreSQL 17 + pgvector Relational DB + vector similarity search
πŸ”„ Alembic Database migrations
πŸ€– Google Gemini LLM (gemini-2.0-flash) + Embeddings (gemini-embedding-001)
πŸ”Œ FastMCP Model Context Protocol server for agent tools
βœ… Pydantic v2 Data validation and settings management
πŸ” bcrypt Password hashing
πŸͺ™ JWT (PyJWT) Stateless authentication
πŸ“¦ Poetry Dependency management
🐳 Docker / Docker Compose Containerization
πŸ§ͺ pytest + pytest-asyncio Testing
πŸ” ruff Linting
πŸ”¬ mypy Static type checking

πŸ“‹ Prerequisites

Before you start, make sure you have:

  • 🐳 Docker and Docker Compose v2 β€” verify with docker compose version
  • 🐍 Python 3.12+ β€” only needed for local development
  • πŸ“¦ Poetry β€” install with pip install poetry
  • πŸ”‘ Google AI Studio API key with Gemini access β€” get one here

πŸš€ Quick Start with Docker

The fastest way to run the full stack (database + API) is with Docker Compose.

β‘  Clone the repository

git clone https://github.com/blandev/aeromind-api.git
cd aeromind-api

β‘‘ Create your environment file

cp .env.example .env

Open .env and fill in your values:

# PostgreSQL (used by docker-compose)
POSTGRES_USER=aeromind
POSTGRES_PASSWORD=aeromind
POSTGRES_DB=aeromind
POSTGRES_PORT=5432

# Database URL β€” use this format when running inside Docker
DATABASE_URL=postgresql+asyncpg://aeromind:aeromind@db:5432/aeromind

# JWT β€” generate a secret with: openssl rand -hex 32
JWT_SECRET_KEY=replace-with-a-long-random-string
JWT_ALGORITHM=HS256
JWT_EXPIRATION_MINUTES=60

# Google Gemini
GOOGLE_API_KEY=your-google-api-key-here
GOOGLE_EMBEDDING_MODEL=models/gemini-embedding-001

β‘’ Start all services

docker compose up -d

This starts two containers:

Container Description Port
db PostgreSQL 17 with pgvector 5432
api AeroMind REST API 8000

β‘£ Apply database migrations

The API container starts but does not run migrations automatically. Run them once:

make migrate

β‘€ Open the interactive docs

Visit http://localhost:8000/docs β€” the full Swagger UI with all endpoints is ready.

β‘₯ Register your first admin user

curl -X POST http://localhost:8000/auth/register \
  -H "Content-Type: application/json" \
  -d '{"email": "admin@aeromind.com", "password": "secret123", "role": "ADMIN"}'

⑦ Log in and get your JWT token

curl -X POST http://localhost:8000/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email": "admin@aeromind.com", "password": "secret123"}'

Copy the access_token from the response and use it as a Bearer token in the Authorization header for all protected endpoints.


πŸ’» Local Development

For active development, run only the database in Docker and the API locally for hot-reload.

β‘  Start only the database

docker compose up -d db

β‘‘ Install dependencies

poetry install

β‘’ Switch the database URL in .env

# Comment out the Docker URL and use localhost instead:
DATABASE_URL=postgresql+asyncpg://aeromind:aeromind@localhost:5432/aeromind

β‘£ Apply migrations

make migrate

β‘€ Start the development server

make dev
# β†’ http://localhost:8000 with auto-reload

β‘₯ Run the test suite

make test          # run tests
make coverage      # run tests + coverage report

βš™οΈ Environment Variables

Variable Required Default Description
DATABASE_URL βœ… β€” AsyncPG connection string
POSTGRES_USER βœ… β€” PostgreSQL username (Docker only)
POSTGRES_PASSWORD βœ… β€” PostgreSQL password (Docker only)
POSTGRES_DB βœ… β€” PostgreSQL database name (Docker only)
POSTGRES_PORT ❌ 5432 Exposed PostgreSQL port
JWT_SECRET_KEY βœ… β€” Secret for signing JWT tokens
JWT_ALGORITHM ❌ HS256 JWT signing algorithm
JWT_EXPIRATION_MINUTES ❌ 60 Token validity in minutes
GOOGLE_API_KEY βœ… β€” Google AI Studio API key
GOOGLE_EMBEDDING_MODEL ❌ models/gemini-embedding-001 Gemini embedding model
GOOGLE_LLM_MODEL ❌ models/gemini-2.0-flash Gemini LLM model

πŸ”— API Endpoints

πŸ” Authentication

Method Path Auth Description
POST /auth/register Public Register a new user
POST /auth/login Public Log in and receive a JWT token

✈️ Flights

Method Path Auth Description
GET /flights Any Search flights (origin, destination, date)
GET /flights/{flight_id} Any Get a specific flight by ID

πŸ“‹ Bookings

Method Path Auth Description
GET /bookings/{booking_id} Passenger+ Get a booking by ID
GET /bookings/user/{user_id} Passenger+ Get all bookings for a user

🧳 Baggage

Method Path Auth Description
GET /baggage/{tag} Passenger+ Track baggage by tag number
POST /baggage/{tag}/report-lost Passenger+ Report lost baggage (auto-creates an incident)

⚠️ Incidents

Method Path Auth Description
POST /incidents Operator+ Create a new incident
GET /incidents Operator+ List all incidents

πŸ“š Documents (RAG)

Method Path Auth Description
POST /documents/ingest Admin Ingest a document into the vector store
POST /documents/search Any Semantic search over ingested documents

πŸ€– Chat (AI)

Method Path Auth Description
POST /chat Passenger+ Send a message to the multi-agent system

Example:

// Request
{ "message": "What is the status of flight AM-201?" }

// Response
{
  "response": "Flight AM-201 departs BOG at 08:30 and arrives MDE at 09:20. Status: ON TIME.",
  "agent": "flight_agent"
}

πŸ₯ Health

Method Path Auth Description
GET /health Public Service health check

πŸ‘€ User Roles

Role Access Level
πŸ§‘ PASSENGER Chat, baggage tracking, view bookings
πŸ›‚ OPERATOR Everything above + incident management
πŸ‘‘ ADMIN Full access including document ingestion

πŸ€– The AI System

Multi-Agent Flow

sequenceDiagram
    actor U as πŸ‘€ User
    participant O as 🧠 Orchestrator
    participant A as πŸ€– Specialized Agent
    participant G as ✨ Gemini LLM
    participant T as πŸ”§ Tools / RAG

    U->>O: POST /chat { message }
    O->>G: Classify intent (temperature=0)
    G-->>O: "flight_agent" | "baggage_agent" | "support_agent" | "security_agent"
    O->>A: run(message)

    loop Agentic Loop (up to 5 rounds)
        A->>G: message + tool declarations
        G-->>A: function_call(name, args)
        A->>T: execute tool
        T-->>A: tool result (JSON)
        A->>G: function_response
    end

    G-->>A: final text response
    A-->>U: { response, agent }
Loading

Specialized Agents

Agent Handles Tools
✈️ FlightAgent Flight searches and status queries search_flights, get_flight
🧳 BaggageAgent Baggage tracking and lost reports track_baggage, report_lost_baggage
πŸ’¬ SupportAgent Policies, FAQs, general assistance search_policies (RAG)
πŸ”’ SecurityAgent Security procedures and regulations search_policies (RAG)

πŸ“š RAG System

The SupportAgent and SecurityAgent ground their responses in official airport documents using RAG.

flowchart LR
    subgraph Ingestion["πŸ“₯ Ingestion (POST /documents/ingest)"]
        direction TB
        D["πŸ“„ Plain-text\nDocument"]
        C["Chunks\n500 chars Β· 50 overlap"]
        E["Embeddings\nGemini Β· 3072 dims"]
        D --> C --> E
    end

    DB[("🐘 pgvector")]
    E --> DB

    subgraph Retrieval["πŸ” Retrieval (at chat time)"]
        direction TB
        Q["❓ User Query"]
        QE["Query Embedding"]
        TOP["Top-5 chunks\ncosine similarity"]
        Q --> QE --> TOP
    end

    DB --> TOP
    TOP --> R["πŸ’¬ Grounded\nAgent Response"]
Loading

πŸ”Œ MCP Server

AeroMind exposes a Model Context Protocol (MCP) server via FastMCP, allowing any MCP-compatible client (such as Claude Desktop) to call airport tools directly.

Tool Description
search_flights Search for available flights
get_flight Get details of a specific flight
get_booking Get a booking by ID
get_user_bookings Get all bookings for a user
track_baggage Track baggage by tag
report_lost_baggage Report lost baggage
create_incident Create an airport incident
get_incidents List all incidents
search_documents Semantic search over airport documents

πŸ“ Project Structure

aeromind-api/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ agents/                  # πŸ€– Multi-agent system
β”‚   β”‚   β”œβ”€β”€ base_agent.py        #    Agentic loop base class
β”‚   β”‚   β”œβ”€β”€ rag_agent.py         #    Base for RAG-capable agents
β”‚   β”‚   β”œβ”€β”€ orchestrator.py      #    Intent classification + routing
β”‚   β”‚   β”œβ”€β”€ flight_agent.py
β”‚   β”‚   β”œβ”€β”€ baggage_agent.py
β”‚   β”‚   β”œβ”€β”€ support_agent.py
β”‚   β”‚   └── security_agent.py
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ routers/             # 🌐 FastAPI route handlers
β”‚   β”‚   β”œβ”€β”€ auth.py              #    JWT middleware
β”‚   β”‚   └── dependencies.py      #    Dependency injection
β”‚   β”œβ”€β”€ application/
β”‚   β”‚   β”œβ”€β”€ use_cases/           # πŸ“‹ Business logic (one file per use case)
β”‚   β”‚   β”œβ”€β”€ ports/               #    Repository & service interfaces
β”‚   β”‚   β”œβ”€β”€ dtos/                #    Data Transfer Objects
β”‚   β”‚   └── exceptions/          #    Application-level exceptions
β”‚   β”œβ”€β”€ domain/
β”‚   β”‚   β”œβ”€β”€ entities/            # πŸ’Ž Core business entities
β”‚   β”‚   └── exceptions/          #    Domain-level exceptions
β”‚   β”œβ”€β”€ infrastructure/
β”‚   β”‚   β”œβ”€β”€ config/              # βš™οΈ  Settings (pydantic-settings)
β”‚   β”‚   β”œβ”€β”€ database/            #    SQLAlchemy models, session, base
β”‚   β”‚   β”œβ”€β”€ repositories/        #    Concrete SQLAlchemy implementations
β”‚   β”‚   └── services/            #    Gemini, JWT, bcrypt implementations
β”‚   β”œβ”€β”€ mcp/
β”‚   β”‚   β”œβ”€β”€ server.py            # πŸ”Œ FastMCP server definition
β”‚   β”‚   └── tools/               #    One file per tool category
β”‚   └── main.py                  # πŸš€ FastAPI app + exception handlers
β”œβ”€β”€ migrations/                  # πŸ”„ Alembic migration files
β”œβ”€β”€ tests/                       # πŸ§ͺ pytest test suite
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ Makefile
β”œβ”€β”€ pyproject.toml
└── .env.example

🧰 Makefile Commands

Command Description
make dev Start dev server with hot-reload
make test Run the test suite
make coverage Run tests with coverage report
make lint Lint with ruff
make type-check Type check with mypy
make migrate Apply all pending migrations
make migrate-gen m="msg" Generate a new migration
make migrate-down Roll back the last migration
make docker-up Start all Docker services
make docker-down Stop all Docker services
make docker-logs Follow Docker logs
make docker-build Rebuild Docker images
make db-shell Open a psql shell in the container

⚑ CI/CD

GitHub Actions workflow (.github/workflows/ci.yml) runs on every push and pull request:

flowchart LR
    Push["πŸ“€ git push /\nPull Request"] --> Lint["πŸ” Lint\nruff check"]
    Lint --> Types["πŸ”¬ Type Check\nmypy"]
    Types --> Tests["πŸ§ͺ Tests\npytest --cov"]
    Tests --> Done["βœ… All checks\npassed"]
Loading

Required GitHub Secrets:

Secret Description
DATABASE_URL Test database connection string
JWT_SECRET_KEY Any random string for tests
GOOGLE_API_KEY Google AI Studio API key

πŸ“„ License

MIT

About

Multi-agent AI backend for smart airport management - RAG, vector search & MCP Server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages