codeBOKER commited on
Commit
9278db7
Β·
1 Parent(s): 2688cc5

add comprehensive README with project docs, image, and reorganize assets

Browse files
Files changed (1) hide show
  1. README.md +209 -14
README.md CHANGED
@@ -1,33 +1,228 @@
1
  # FALSA
2
 
3
- FALSA is an async FastAPI backend for WhatsApp-based AI travel customer service.
4
- It stores conversations in Supabase, retrieves short-term chat context, uses Groq
5
- with Hugging Face fallback, calls local tools for FALSA info/trip search/booking
6
- leads, stores vector embeddings in Supabase with Jina Embeddings, and sends replies
7
- through Meta WhatsApp Cloud API.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  ## Quick Start
10
 
 
 
 
 
 
 
 
 
11
  ```bash
 
 
 
 
12
  cp .env.example .env
 
 
 
13
  pip install -r requirements.txt
 
 
 
 
 
14
  uvicorn main:app --reload
15
  ```
16
 
17
- Run checks:
 
 
 
 
 
 
 
 
 
 
18
 
19
  ```bash
20
  pytest
21
  ruff check .
22
  ```
23
 
24
- ## Main Endpoints
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- - `GET /healthz`
27
- - `GET /webhooks/whatsapp`
28
- - `POST /webhooks/whatsapp`
29
- - `POST /admin/seed-info`
30
- - `POST /admin/sync-trips`
31
 
32
- Apply the SQL in `supabase/migrations` to create the Supabase schema, including the
33
- pgvector tables and RPC functions, before using the production services.
 
1
  # FALSA
2
 
3
+ > **AI-powered travel booking assistant β€” on WhatsApp.**
4
+
5
+ > **🚧 Work in progress β€” not yet published. Coming soon.**
6
+
7
+ <p align="center">
8
+ <img src="assets/Falsa.png" alt="FALSA logo" width="300">
9
+ </p>
10
+
11
+ FALSA lets passengers search trips and book seats, and lets drivers publish, update, and manage their trips β€” all through a natural conversation on WhatsApp. No app to install, no complex UI to learn. Just type what you want.
12
+
13
+ ---
14
+
15
+ ## Problem
16
+
17
+ Travel booking platforms in my country are poorly adopted. Not because people don't *want* a better way β€” but because:
18
+
19
+ - Users don't want to learn yet another app with a steep learning curve.
20
+ - People prefer something that works *inside* the tools they already use daily.
21
+ - Asking users to download a new app is a barrier. WhatsApp is already on their phone.
22
+ - Existing UIs are complicated and unintuitive.
23
+
24
+ ## Solution
25
+
26
+ FALSA removes all of that. The entire interface is a single chat conversation. **You say where you're going and when β€” FALSA handles the rest.**
27
+
28
+ - **Passengers** describe their trip in natural language; FALSA searches available trips, shows options, and helps book.
29
+ - **Drivers** publish trips, manage schedules, and receive booking leads β€” all by chatting.
30
+ - No app install, no account creation flow, no confusing dashboard.
31
+
32
+ ---
33
+
34
+ ## Features
35
+
36
+ - **Natural-language trip search** β€” "I want to go from Sana'a to Taiz tomorrow morning"
37
+ - **WhatsApp-native interaction** β€” interactive lists, text replies, no extra UI
38
+ - **Driver tools** β€” publish trips, add cars, modify/delete trips, receive booking notifications
39
+ - **Passenger tools** β€” search trips, create booking leads, get FALSA information
40
+ - **AI-powered orchestration** β€” tool-calling LLM (Groq primary, Hugging Face fallback) routes intent to the right action
41
+ - **RAG knowledge base** β€” company info, pricing, policies embedded via Jina AI and retrieved on demand
42
+ - **Trip vector search** β€” semantic search over driver trips for flexible departure matching
43
+ - **Multi-mode personas** β€” new-user onboarding, passenger mode, driver mode
44
+
45
+ ---
46
+
47
+ ## Why Vector Search?
48
+
49
+ Users describe trips in natural language: *"I want to go to Taiz tomorrow afternoon"*. Traditional SQL can't handle that. It would need exact dates, predefined routes, rigid filters.
50
+
51
+ **Semantic search** solves this. Trip departures ("tomorrow afternoon", "Friday morning") and routes are embedded into vectors using Jina AI. When a user says something, the query gets embedded the same way β€” and pgvector finds the closest matching trips by meaning, not by keyword.
52
+
53
+ This means:
54
+ - Users can phrase trips however they want β€” the system understands intent.
55
+ - Spelling mistakes or missing letters don't break the search β€” semantic similarity handles typos and partial input gracefully.
56
+ - No rigid dropdowns, no calendar pickers, no predefined route lists.
57
+ - The same vector index powers both trip search and RAG knowledge retrieval.
58
+ - It lives inside Postgres (pgvector) β€” no separate vector database to manage.
59
+
60
+ ---
61
+
62
+ ## Tech Stack
63
+
64
+ | Layer | Choice | Why |
65
+ |-------|--------|-----|
66
+ | **Language** | Python 3.12+ | Core comfort zone; best fit for the backend services, AI orchestration, and data work |
67
+ | **Framework** | FastAPI (async) | High performance, native async, great DX with Pydantic validation |
68
+ | **Primary LLM** | Groq (via OpenAI-compatible API) | Fast inference, generous free tier, tool-calling support |
69
+ | **Fallback LLM** | Hugging Face (OpenAI-compatible) | Backup provider for resilience when Groq is unavailable |
70
+ | **Embeddings** | Jina AI (`jina-embeddings-v5`) | Multilingual-capable, 1024-dim vectors, simple REST API |
71
+ | **Database** | Supabase (PostgreSQL + pgvector) | Managed Postgres with built-in vector search, real-time, and REST API |
72
+ | **WhatsApp** | Meta WhatsApp Cloud API | Official business API for reliable message delivery; webhook-based |
73
+ | **WhatsApp Bridge** | Baileys (Node.js) | Temporary bridge for WhatsApp Web protocol until Cloud API is fully onboarded; the system is designed to interact with Baileys identically to how it interacts with Cloud API, making the switch seamless |
74
+ | **Containerization** | Docker / Compose | Consistent dev environment, easy deployment |
75
+ | **Testing** | pytest + pytest-asyncio | Async-native testing with fully mocked external services |
76
+ | **Linting** | ruff | Fast, modern Python linter |
77
+
78
+ ---
79
+
80
+ ## Architecture
81
+
82
+ ```
83
+ WhatsApp User
84
+ β”‚
85
+ β–Ό (message)
86
+ Baileys Bridge ──► FALSA API ──► AI Orchestrator ──► Tools
87
+ (Node.js, (FastAPI) (Groq / HF) β”‚
88
+ separate repo) β”‚ β”‚
89
+ β–Ό β–Ό
90
+ Supabase (pgvector) WhatsApp Cloud API
91
+ (trips, customers, (outbound replies)
92
+ messages, embeddings)
93
+ ```
94
+
95
+ The system is designed so the WhatsApp integration layer is swappable. The Baileys bridge (Node.js) handles the Web protocol; the FALSA Python backend talks to it the same way it talks to the Cloud API. When Cloud API onboarding is complete, swapping the bridge requires zero changes to the core logic.
96
+
97
+ ---
98
 
99
  ## Quick Start
100
 
101
+ ### Prerequisites
102
+
103
+ - Python 3.12+
104
+ - A Supabase project (with pgvector enabled)
105
+ - API keys: Groq, Jina AI, Hugging Face, Meta WhatsApp Cloud
106
+
107
+ ### Setup
108
+
109
  ```bash
110
+ # 1. Clone and enter the repo
111
+ git clone <repo-url> && cd falsa
112
+
113
+ # 2. Configure environment
114
  cp .env.example .env
115
+ # Fill in your credentials (Supabase, Groq, Jina, WhatsApp, etc.)
116
+
117
+ # 3. Install dependencies
118
  pip install -r requirements.txt
119
+
120
+ # 4. Apply database migrations
121
+ # Run the SQL files in supabase/migrations/ in order via Supabase SQL editor or psql
122
+
123
+ # 5. Start the server
124
  uvicorn main:app --reload
125
  ```
126
 
127
+ The API is now running at `http://localhost:8000`.
128
+
129
+ ### Seed Knowledge Base
130
+
131
+ ```bash
132
+ ./scripts/setup_and_seed.sh
133
+ ```
134
+
135
+ This embeds the FALSA info document (`prompts/falsa_info.md`) and all active trips into Supabase pgvector for RAG retrieval.
136
+
137
+ ### Run Tests
138
 
139
  ```bash
140
  pytest
141
  ruff check .
142
  ```
143
 
144
+ > Note: I'm still learning testing best practices through this project. Tests exist and pass, but coverage and structure will improve over time.
145
+
146
+ ---
147
+
148
+ ## Docker
149
+
150
+ ```bash
151
+ docker compose up
152
+ ```
153
+
154
+ Mounts the current directory with hot-reload enabled.
155
+
156
+ ---
157
+
158
+ ## WhatsApp Baileys Bridge
159
+
160
+ FALSA uses the official Meta Cloud API for production messages. During early stages β€” while waiting for commercial approval β€” a **Baileys-based bridge** acts as the WhatsApp gateway.
161
+
162
+ The bridge is a separate Node.js project:
163
+
164
+ #### [https://github.com/codeBOKER/wh_baileys](https://github.com/codeBOKER/wh_baileys)
165
+
166
+ It connects to WhatsApp via the Web protocol, relays inbound messages to the FALSA API, and forwards responses back to the user. The FALSA API treats the bridge identically to the Cloud API, so switching later requires no backend changes.
167
+
168
+ ---
169
+
170
+ ## API Endpoints
171
+
172
+ | Method | Path | Description |
173
+ |--------|------|-------------|
174
+ | `GET` | `/healthz` | Health check |
175
+ | `GET` | `/webhooks/whatsapp` | Webhook verification (challenge) |
176
+ | `POST` | `/webhooks/whatsapp` | Receive WhatsApp messages |
177
+ | `POST` | `/admin/seed-info` | Seed FALSA RAG info |
178
+ | `POST` | `/admin/sync-trips` | Sync trip embeddings |
179
+ | `POST` | `/admin/jina-embed` | Test embedding |
180
+ | `POST` | `/admin/llm-tool-call` | Debug tool calling |
181
+
182
+ ---
183
+
184
+ ## Project Structure
185
+
186
+ ```
187
+ falsa/
188
+ β”œβ”€β”€ app/
189
+ β”‚ β”œβ”€β”€ ai/ # LLM orchestration, providers, tool schemas
190
+ β”‚ β”œβ”€β”€ api/ # FastAPI routes, dependency injection
191
+ β”‚ β”œβ”€β”€ database/ # Supabase repository (CRUD + vector search)
192
+ β”‚ β”œβ”€β”€ models/ # Pydantic request/response & domain models
193
+ β”‚ β”œβ”€β”€ services/ # Business logic (conversation, admin, embeddings)
194
+ β”‚ β”œβ”€β”€ tools/ # Tool handler implementations + registry
195
+ β”‚ β”œβ”€β”€ utils/ # Logging, time helpers, departure parsing
196
+ β”‚ └── whatsapp/ # WhatsApp client, parser, security, trip UI
197
+ β”œβ”€β”€ prompts/ # AI system prompts + RAG seed data
198
+ β”œβ”€β”€ scripts/ # Admin CLI scripts (seed, sync, test)
199
+ β”œβ”€β”€ supabase/migrations/ # SQL schema migrations (apply in order)
200
+ β”œβ”€β”€ tests/ # pytest suite with mocked externals
201
+ β”œβ”€β”€ docker-compose.yml
202
+ β”œβ”€β”€ Dockerfile
203
+ β”œβ”€β”€ pyproject.toml
204
+ β”œβ”€β”€ requirements.txt
205
+ └── .env.example
206
+ ```
207
+
208
+ ---
209
+
210
+ ## FAQ
211
+
212
+ **How do you find trips in the early stage with few users and drivers?**
213
+
214
+ We scrape public trip listings from WhatsApp groups and seed them into the database. This bootstraps the system with real trip data so passengers get results from day one. As adoption grows, drivers publish trips directly through the assistant.
215
+
216
+ **Why not use JavaScript across the entire project?**
217
+
218
+ Baileys (Node.js) is used only as a temporary WhatsApp bridge. My strongest area is Python β€” the core backend, AI orchestration, and data pipeline all benefit from Python's ecosystem, so the main service is built in Python. The bridge is minimal and swappable.
219
+
220
+ **How does the Baileys bridge differ from the Cloud API?**
221
+
222
+ It doesn't β€” that's the point. The FALSA backend speaks the same protocol to both. The Baileys bridge simply translates the WhatsApp Web protocol into the same format the Cloud API uses. When Cloud API approval comes through, we swap the bridge with zero backend changes.
223
+
224
+ ---
225
 
226
+ ## License
 
 
 
 
227
 
228
+ MIT