Production-oriented monorepo architecture for the Luna AI voice assistant and emotional counseling application.
.
βββ apps/
β βββ luna_mobile/ # Flutter mobile application (UI, Clean Architecture, Riverpod)
β β
β βββ backend/
β βββ api/ # FastAPI application server (REST, WebSocket, Auth, Sessions)
β β βββ app/
β β β βββ api/ # Routes & dependencies
β β β βββ core/ # Logging & config
β β β βββ models/ # SQLAlchemy 2.x models
β β β βββ schemas/ # Pydantic v2 schemas
β β β βββ services/ # Application domain services
β β β βββ main.py # FastAPI entry point
β β βββ migrations/ # Alembic database migrations
β β βββ tests/ # Pytest suite for API
β β βββ pyproject.toml
β β βββ Dockerfile
β β
β βββ mcp/ # FastMCP AI tool/context server (Model Context Protocol)
β β βββ app/
β β β βββ tools/ # MCP tools exposed to LLM
β β β βββ resources/ # MCP resources
β β β βββ services/ # Internal tool services
β β β βββ main.py # FastMCP entry point
β β βββ tests/ # Pytest suite for MCP
β β βββ pyproject.toml
β β βββ Dockerfile
β β
β βββ workers/ # ARQ async Redis background workers
β βββ app/
β β βββ tasks/ # Background task definitions (Summarization, Risk, Emotion)
β β βββ workers/ # ARQ WorkerSettings
β β βββ main.py # Worker entry point
β βββ tests/ # Pytest suite for workers
β βββ pyproject.toml
β βββ Dockerfile
β
βββ packages/
β βββ shared/ # Shared domain types, config, errors, DB connections
β β βββ config.py
β β βββ database.py
β β βββ errors.py
β β βββ types.py
β β βββ pyproject.toml
β β
β βββ ai/ # AI provider interfaces, RAG, emotion detection, orchestrator
β βββ interfaces/
β βββ orchestration/
β βββ services/
β βββ vector_store/
β βββ pyproject.toml
β
βββ scripts/ # Development & Docker automation scripts
β βββ docker-dev.sh / .ps1 # Automated Docker dev setup + auto-migration & seeding
β βββ dev.sh / .ps1 # Local Python services launcher
β βββ setup.sh / .ps1 # Virtual environment & package installation
β βββ seed.py # Initial database seeder script
β βββ DOCKER_SETUP.md # Detailed Docker documentation
β
βββ tests/ # Global & POC test suites
β βββ test_emotion/ # Speech Emotion Recognition (emotion2vec_plus_large) POC
β βββ test_ai_providers.py # Integration test for AI LLM providers
β
βββ docs/ # Architecture diagrams & business logic specs
βββ .env.example # Environment variables template
βββ docker-compose.yml # Local multi-service Docker setup
βββ ruff.toml # Root linting & formatting rules
βββ README.md # Project overview & documentation
| Component | Technology | Primary Role & Responsibilities |
|---|---|---|
| FastAPI Backend | Python 3.11 / FastAPI | Primary API server for mobile clients (REST & WebSocket). Manages auth, sessions, call routing, and enqueues jobs. |
| FastMCP Server | FastMCP | Exposes standard Model Context Protocol (MCP) tools and resources to LLMs safely. |
| ARQ Workers | ARQ / Redis | Executes async background tasks (e.g., emotion detection, diary synthesis, memory extraction). |
| PostgreSQL | PostgreSQL 16 | Relational store for users, conversation logs, call metadata, and application state. |
| Redis | Redis 7 | High-performance cache, pub/sub channel for audio streaming, and ARQ task queue storage. |
| Qdrant | Qdrant | Vector database for storing and querying long-term semantic memory embeddings. |
| Flutter Mobile | Flutter / Riverpod | Mobile application with Clean Architecture and mock/remote data source toggle. |
- Git
- Docker & Docker Compose (for Docker setup)
- Python 3.11+ (for local development)
- Flutter SDK (for running
luna_mobile)
Script otomatis docker-dev akan memeriksa berkas .env, menjalankan container, melakukan migrasi database (Alembic), dan mengisi data awal (seeding):
chmod +x scripts/docker-dev.sh
./scripts/docker-dev.sh.\scripts\docker-dev.ps1# Copas env jika belum ada
cp .env.example .env
# Jalankan semua service
docker compose up --build| Service | Host Port | Container Port | Endpoint / URL |
|---|---|---|---|
| FastAPI Backend | 8888 |
8888 |
http://localhost:8888 |
| FastMCP Server | 8889 |
8889 |
http://localhost:8889 |
| PostgreSQL | 5433 |
5432 |
localhost:5433 |
| Redis | 6380 |
6379 |
localhost:6380 |
| Qdrant Vector DB | 6333 |
6333 |
http://localhost:6333 |
βΉοΈ Detail panduan Docker dapat dibaca di scripts/DOCKER_SETUP.md.
Jika ingin menjalankan service secara langsung di lingkungan lokal Python:
-
Setup Environment & Virtualenv:
# Linux/macOS ./scripts/setup.sh # Windows .\scripts\setup.ps1
-
Jalankan Service Backend:
# Linux/macOS ./scripts/dev.sh # Windows .\scripts\dev.ps1
-
Atau Jalankan Service Secara Manual per Terminal:
source .venv/bin/activate # 1. FastAPI API cd apps/backend/api && uvicorn app.main:app --reload --port 8888 # 2. FastMCP Server cd apps/backend/mcp && python -m app.main # 3. ARQ Background Worker cd apps/backend/workers && arq app.workers.WorkerSettings
Aplikasi Flutter luna_mobile dapat dijalankan di Perangkat Fisik (HP Android via USB Debugging), Emulator, maupun Web/Desktop.
- Pastikan HP Android sudah dalam mode Developer Options dan USB Debugging telah diaktifkan.
- Hubungkan HP ke laptop/PC menggunakan kabel USB, lalu periksa koneksi perangkat:
(Pastikan perangkat muncul di daftar dengan status
adb devices
device)
Secara default, jika dijalankan dengan flutter run, aplikasi akan terhubung ke server production (172.93.219.133:8888). Untuk menghubungkannya ke server backend lokal laptop:
- Lakukan reverse port ADB agar port di dalam HP meneruskan request ke laptop via kabel USB:
adb reverse tcp:8888 tcp:8888
- Jalankan Flutter dengan flag
USE_LOCAL_API:cd apps/luna_mobile flutter run --dart-define=USE_LOCAL_API=trueβΉοΈ Host yang Digunakan:
http://127.0.0.1:8888/api/v1(terhubung langsung ke backend laptop via USB ADB reverse loopback).
Jika menggunakan Android Emulator standar (tanpa menjalankan adb reverse), tambahkan flag IS_EMULATOR=true:
cd apps/luna_mobile
flutter run --dart-define=USE_LOCAL_API=true --dart-define=IS_EMULATOR=trueβΉοΈ Host yang Digunakan:
http://10.0.2.2:8888/api/v1(karena10.0.2.2adalah gateway router virtual emulator untuk mengakses localhost host laptop).
Jika HP fisik dan laptop berada dalam satu jaringan Wi-Fi yang sama:
cd apps/luna_mobile
flutter run --dart-define=LOCAL_HOST=192.168.1.50:8888(Ganti 192.168.1.50 dengan IP lokal laptop Anda).
cd apps/luna_mobile
flutter runTambahkan konfigurasi berikut ke .vscode/launch.json di root workspace agar dapat langsung menekan F5 / Run:
{
"version": "0.2.0",
"configurations": [
{
"name": "Luna Mobile (HP Fisik USB - Local)",
"request": "launch",
"type": "dart",
"program": "apps/luna_mobile/lib/main.dart",
"args": [
"--dart-define=USE_LOCAL_API=true"
]
},
{
"name": "Luna Mobile (Android Emulator - Local)",
"request": "launch",
"type": "dart",
"program": "apps/luna_mobile/lib/main.dart",
"args": [
"--dart-define=USE_LOCAL_API=true",
"--dart-define=IS_EMULATOR=true"
]
},
{
"name": "Luna Mobile (Production Cloud)",
"request": "launch",
"type": "dart",
"program": "apps/luna_mobile/lib/main.dart"
}
]
}- Tekan
r: Hot Reload (Pembaruan UI secara instan tanpa mereset halaman) - Tekan
R: Hot Restart (Mereset ulang state aplikasi dari awal) - Tekan
c: Bersihkan layar terminal log - Tekan
q: Quit / Keluar dari aplikasi
Untuk keperluan pengujian dan demonstrasi aplikasi:
Saat menjalankan script docker-dev atau python scripts/seed.py, akun demo berikut otomatis tersedia di database:
- Email:
samsul@gmail.com - Password:
password123 - User Display Name: Samsul
- Data Pre-seeded:
- Kontak Darurat Utama: Ibu (Siti Rahma - 0812-3456-7890) & Dr. Handoko (Psikiater - 0811-9876-5432).
- Riwayat Jurnal Emosional: Termasuk entri jurnal refleksi krisis darurat (28 Agustus 2026) dan entri stabil (31 Agt & 1 Sep 2026).
- Rekomendasi Mental Health: Rekomendasi pernapasan 4-7-8, jurnal ekspresif, dan jeda digital.
Jika ingin menguji antarmuka aplikasi luna_mobile secara langsung tanpa menghubungkan ke server backend/database:
- Buka
apps/luna_mobile/lib/core/config/app_config.dart. - Set variabel
static const bool useMockData = true;.
| Komponen | Spesifikasi Direkomendasikan | Catatan Pengujian |
|---|---|---|
| Sistem Operasi | Linux (Ubuntu 22.04 LTS / WSL2), macOS 13+, Windows 11 | Lintas platform |
| Python Runtime | Python 3.11.x | Menggunakan pytest 8.x, pytest-asyncio |
| Mobile Runtime | Flutter SDK 3.22+, Dart 3.4+ | Tested di HP Android Fisik (API 34 / Android 14) & Emulator |
| Database & Cache | PostgreSQL 16, Redis 7, Qdrant Vector DB 1.9+ | Berjalan via Docker Compose |
| AI / Speech Model | FunASR (emotion2vec_plus_large) |
Test POC Speech Emotion Recognition |
# Test API
pytest apps/backend/api/tests
# Test MCP Tools
pytest apps/backend/mcp/tests
# Test Workers
pytest apps/backend/workers/tests
# Test AI Packages
pytest packages/ai/testspython3 tests/test_emotion/test_emotion.pyHasil pengujian emotion recognition akan otomatis ditulis ke tests/test_emotion/poc_result.md.
graph TD
Client["π± Luna Mobile (Flutter)"] -->|REST / WebSocket :8888| API["β‘ FastAPI Backend"]
LLM["π€ LLM Agent / Client"] -->|MCP Protocol :8889| MCP["π οΈ FastMCP Server"]
API -->|Read/Write| DB[(π PostgreSQL :5433)]
API -->|Cache / Queue| Redis[(π΄ Redis :6380)]
API -->|Vector Search| Qdrant[(π― Qdrant :6333)]
API -->|Enqueue Jobs| Redis
Redis -->|Dequeue Jobs| Worker["βοΈ ARQ Background Workers"]
Worker --> DB
Worker --> Qdrant
Worker -->|AI Services| AI["π§ packages/ai"]
MCP -->|Shared Models| Shared["π¦ packages/shared"]
- Python: Linter & formatter dikonfigurasi menggunakan Ruff (
ruff.toml). - Clean Architecture:
luna_mobilememisahkan lapisandomain,data, danpresentation. - Decoupled Packages: Module
packages/shareddanpackages/aidi-install sebagai paket editable (pip install -e) agar bisa digunakan bersama olehapi,mcp, danworkers.