feat: add smart-app-city sub-project architecture

- Architecture globale (React Native + NestJS + FastAPI)
- Beckn Protocol (OTN-DPI) integration docs
- AI layer: RAG pipeline + AI Agents (LocalAI + Qdrant)
- i18n: FR/EN/ES/DE support
- Docker Compose for backend services
- Project structure with frontend, backend, ai, beckn directories
This commit is contained in:
Eric FELIXINE
2026-05-26 18:47:02 -04:00
parent f1e1b98519
commit 94f74f2dfc
20 changed files with 1013 additions and 0 deletions

0
smart-app-city/.gitignore vendored Normal file
View File

61
smart-app-city/README.md Normal file
View File

@@ -0,0 +1,61 @@
# Smart App City — Mobile Application
> Multi-platform mobile application for Smart City Digital Twin Martinique
## Quick Start
### Prerequisites
- Node.js 20+
- Expo CLI: `npm install -g expo-cli`
- Docker & Docker Compose
### Development
```bash
# Install dependencies
cd frontend
npm install
# Start development server
npx expo start
# Run on device
# Scan QR code with Expo Go app
```
### Backend
```bash
# Start all services
cd ..
docker-compose up -d
# Start individual service
cd backend/auth-service
npm run start:dev
```
### AI Services
```bash
# Start RAG service
cd ai/rag-service
pip install -r requirements.txt
uvicorn main:app --reload --port 8001
# Start Agent service
cd ai/agent-service
pip install -r requirements.txt
uvicorn main:app --reload --port 8002
```
## Documentation
- [Architecture](docs/ARCHITECTURE.md)
- [Beckn Integration](docs/BECKN_INTEGRATION.md)
- [AI Architecture](docs/AI_ARCHITECTURE.md)
- [Internationalization](docs/I18N.md)
## License
Smart City Digital Twin Martinique — Projet public

View File

View File

View File

View File

View File

@@ -0,0 +1,82 @@
# Smart App City — Docker Compose
version: "3.8"
services:
# API Gateway
api-gateway:
build: ./backend/api-gateway
container_name: smartapp-gateway
ports:
- "8000:8000"
environment:
- KEYCLOAK_URL=http://openremote-keycloak:8080/auth
- LOCALAI_URL=http://localai-api:8080
- QDRANT_URL=http://qdrant:***
- REDIS_URL=redis://redis:6379
networks:
- smartcity-shared
restart: always
# RAG Service
rag-service:
build: ./ai/rag-service
container_name: smartapp-rag
ports:
- "8001:8001"
environment:
- LOCALAI_URL=http://localai-api:8080
- QDRANT_URL=http://qdrant:***
- EMBEDDING_MODEL=intfloat/multilingual-e5-large
networks:
- smartcity-shared
depends_on:
- api-gateway
restart: always
# Agent Service
agent-service:
build: ./ai/agent-service
container_name: smartapp-agent
ports:
- "8002:8002"
environment:
- LOCALAI_URL=http://localai-api:8080
- RAG_URL=http://rag-service:8001
networks:
- smartcity-shared
depends_on:
- rag-service
restart: always
# Qdrant (if not existing)
qdrant:
image: qdrant/qdrant:v1.9.0
container_name: smartapp-qdrant
ports:
- "6333:6333"
volumes:
- qdrant_data:/qdrant/storage
networks:
- smartcity-shared
restart: always
# Meilisearch (if not existing)
meilisearch:
image: getmeili/meilisearch:v1.7
container_name: smartapp-search
ports:
- "7700:7700"
volumes:
- meilisearch_data:/meili_data
networks:
- smartcity-shared
restart: always
networks:
smartcity-shared:
external: true
volumes:
qdrant_data:
meilisearch_data:

View File

@@ -0,0 +1,221 @@
# Smart App City — AI Architecture
## Overview
AI-powered features for the Smart App City mobile application, leveraging RAG, LLM, and AI Agents.
## AI Architecture
```
┌─────────────────────────────────────────────────────────────────┐
│ AI Pipeline │
│ │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ User Query │ │
│ │ "Quel est le bus pour Fort-de-France à 14h?" │ │
│ └───────────────────────┬───────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ NLP / Intent Classifier │ │
│ │ - Intent: transport.search │ │
│ │ - Entities: {time: "14h", destination: "Fort-de-France"}│ │
│ │ - Language: fr │ │
│ └───────────────────────┬───────────────────────────────────┘ │
│ │ │
│ ┌───────────┼───────────┐ │
│ ▼ ▼ ▼ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Transport │ │ Tourisme │ │ Services │ │
│ │ Agent │ │ Agent │ │ Agent │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │ │
│ └────────────────┴────────────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ RAG Pipeline │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Query │ │ Embed │ │ Vector │ │ Rerank │ │ │
│ │ │ Rewrite │ │ (E5) │ │ Search │ │ (BM25+) │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │
│ └───────────────────────┬───────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ LLM Generation │ │
│ │ - Context: Retrieved documents + real-time data │ │
│ │ - Model: Llama 3.1 70B (LocalAI) │ │
│ │ - Output: Natural language response │ │
│ └───────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
```
## Components
### 1. LocalAI (LLM Server)
- **Container**: `localai-api` (existing)
- **Model**: Llama 3.1 70B quantized or Mistral 7B
- **API**: OpenAI-compatible (`/v1/completions`, `/v1/chat/completions`)
- **Endpoint**: `http://localai-api:8080`
### 2. RAG Pipeline
#### Embedding
- **Model**: `intfloat/multilingual-e5-large` (multilingual)
- **Dimensions**: 1024
- **Input**: Documents, FAQ, municipal data, tourist guides
#### Vector Database
- **Engine**: Qdrant (existing)
- **Collection**: `smart-city-docs`
- **Payload**: `{doc_type, language, timestamp, source}`
#### Documents to Index
| Source | Type | Language |
|--------|------|----------|
| Municipal regulations | PDF/HTML | FR, EN |
| Tourist guides | Markdown | FR, EN, ES, DE |
| Transport schedules | JSON/API | FR |
| FAQ | Markdown | FR, EN, ES, DE |
| Event calendar | API | FR |
| Sensor data descriptions | JSON | FR, EN |
### 3. AI Agents
#### Transport Agent
- **Tools**: Bus API, Parking API, Traffic API
- **Capabilities**: Schedule lookup, route planning, real-time delays
- **Data Sources**: FROST-Server, Orion-LD
#### Tourism Agent
- **Tools**: POI database, Weather API, Event API
- **Capabilities**: Recommendations, itineraries, booking suggestions
- **Data Sources**: PostGIS (POI), OpenWeatherMap
#### Services Agent
- **Tools**: Forms API, Appointment API, Document API
- **Capabilities**: Procedure guidance, appointment scheduling
- **Data Sources**: City ERP
#### Environment Agent
- **Tools**: Sensor API, Air Quality API, Weather API
- **Capabilities**: Real-time monitoring, health recommendations
- **Data Sources**: InfluxDB (IoT sensors)
## Implementation
### RAG Service (Python/FastAPI)
```python
# ai/rag-service/main.py
from fastapi import FastAPI
from langchain import hub
from langchain_community.embeddings import HuggingFaceEmbeddings
from langchain_community.vectorstores import Qdrant
from langchain_community.llms import OpenAI
app = FastAPI()
# Connect to LocalAI
llm = OpenAI(
base_url="http://localai-api:8080/v1",
api_key="dummy",
model="llama-3.1-70b"
)
# Connect to Qdrant
embeddings = HuggingFaceEmbeddings(
model_name="intfloat/multilingual-e5-large"
)
vectorstore = Qdrant.from_existing_collection(
collection_name="smart-city-docs",
embedding=embeddings,
url="http://qdrant:6333"
)
@app.post("/query")
async def query(request: QueryRequest):
# Vector search
docs = vectorstore.similarity_search(request.query, k=5)
# RAG prompt
prompt = hub.pull("rlm/rag-prompt")
chain = prompt | llm | StrParser()
response = chain.invoke({
"question": request.query,
"context": format_docs(docs)
})
return {"response": response, "sources": [d.metadata for d in docs]}
```
### Agent Service (Python/LangChain)
```python
# ai/agent-service/agents/transport.py
from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain_community.tools import Tool
tools = [
Tool(
name="bus_schedule",
func=bus_schedule_lookup,
description="Lookup bus schedules. Input: route_id, time"
),
Tool(
name="parking_availability",
func=parking_lookup,
description="Check parking availability. Input: location, time"
),
Tool(
name="traffic_conditions",
func=traffic_lookup,
description="Get traffic conditions. Input: route, time"
)
]
agent = create_openai_functions_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools)
```
## Multilingual Support
### LLM Prompts per Language
```yaml
# ai/agent-service/prompts/fr.yml
transport_agent: |
Tu es un assistant transport pour la Martinique.
Réponds en français de manière concise et utile.
Donne les horaires de bus, places de parking, et conditions de circulation.
# ai/agent-service/prompts/en.yml
transport_agent: |
You are a transport assistant for Martinique.
Respond in English concisely and helpfully.
Provide bus schedules, parking availability, and traffic conditions.
```
### Translation Fallback
For languages without specific prompts, use automatic translation:
1. Detect language → translate query to FR/EN
2. Process in FR/EN
3. Translate response back to original language
## Roadmap
### Phase 1: RAG Setup
- [ ] Deploy Qdrant collection
- [ ] Index municipal documents
- [ ] Connect LocalAI
- [ ] Basic Q&A endpoint
### Phase 2: AI Agents
- [ ] Transport agent
- [ ] Tourism agent
- [ ] Services agent
- [ ] Environment agent
### Phase 3: Advanced Features
- [ ] Multi-turn conversations
- [ ] Personalization
- [ ] Predictive recommendations
- [ ] Voice interface (STT/TTS)

View File

@@ -0,0 +1,326 @@
# Smart App City — Architecture & Propositions
> Sous-projet Smart City Digital Twin Martinique
> Créé le : 2026-05-28
## 1. Vision
Application mobile multi-plateforme (Android/iOS) pour les citoyens de Martinique, couvrant :
- **Transport** : Info trafic, bus, parking
- **Environnement** : Qualité de l'air, météo, pollution sonore
- **Services municipaux** : Démarches, alertes, événements
- **Tourisme** : Points d'intérêt, itinéraires, réalité augmentée
- **Citoyen** : Signalements, participations, notifications
**Inspiration** : [SmartAppCity](https://smartappcity.com/en/) — plateforme smart city multi-services.
## 2. Architecture Globale
```
┌─────────────────────────────────────────────────────────────────────┐
│ MOBILE APP (React Native) │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Transport│ │ Environ. │ │ Services │ │ Tourisme │ │ Citoyen │ │
│ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ │
│ └────────────┴────────────┴────────────┴────────────┘ │
│ │ │
│ ┌─────────┴─────────┐ │
│ │ API Gateway │ │
│ │ (Kong / Traefik)│ │
│ └─────────┬─────────┘ │
└──────────────────────────────┼──────────────────────────────────────┘
┌──────────────────────────────┼──────────────────────────────────────┐
│ BACKEND │
│ │ │
│ ┌───────────────────────────┴───────────────────────────────────┐ │
│ │ Beckn Protocol (OTN-DPI) │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ BAP │ │ BPP │ │ Beckn │ │ ONDC │ │ │
│ │ │ (Buyer) │ │ (Seller) │ │ Gateway │ │ Adapter │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │
│ └───────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌───────────────────────────┴───────────────────────────────────┐ │
│ │ AI / LLM Layer │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ RAG │ │ Agents │ │ LLM │ │ NLP │ │ │
│ │ │ (Retriev)│ │(Actions) │ │(Generate)│ │(Intent) │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │
│ └───────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌───────────────────────────┴───────────────────────────────────┐ │
│ │ Microservices Backend │ │
│ │ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ │ │
│ │ │Auth │ │Notif. │ │GIS │ │IoT │ │Analytics│ │ │
│ │ │Service │ │Service │ │Service │ │Service │ │Service │ │ │
│ │ └────────┘ └────────┘ └────────┘ └────────┘ └────────┘ │ │
│ └───────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌───────────────────────────┴───────────────────────────────────┐ │
│ │ Data Layer │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │PostgreSQL│ │ InfluxDB │ │ Redis │ │ MinIO │ │ │
│ │ │ (Users) │ │ (IoT) │ │ (Cache) │ │ (Files) │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │
│ └───────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
```
## 3. Frontend — React Native
### Stack Technique
| Composant | Technologie | Justification |
|-----------|-------------|---------------|
| **Framework** | React Native + Expo | Cross-platform, hot reload, large communauté |
| **State Management** | Zustand + React Query | Léger, performant, cache intelligent |
| **Navigation** | React Navigation v6 | Standard React Native |
| **UI Kit** | React Native Paper + Tamagui | Material Design + performance |
| **Maps** | react-native-maps + MapBox | Cartographie interactive |
| **i18n** | i18next + react-i18next | Multi-langue (FR, EN, ES, DE) |
| **Notifications** | Firebase Cloud Messaging | Push notifications cross-platform |
| **Offline** | WatermelonDB + SQLite | Mode hors-ligne essentiel |
| **Auth** | OAuth2 + Keychain | Sécurité des credentials |
### Écrans Principaux
1. **Dashboard** — Vue d'ensemble temps réel (météo, trafic, alertes)
2. **Carte interactive** — Points d'intérêt, capteurs, événements
3. **Transport** — Itinéraires, horaires bus, disponibilité parking
4. **Signalement** — Photo + géolocalisation + catégorisation
5. **Services** — Démarches administratives, RDV, formulaires
6. **Profil** — Paramètres, langue, notifications
## 4. Backend — Microservices
### Stack Technique
| Composant | Technologie | Justification |
|-----------|-------------|---------------|
| **Runtime** | Node.js (NestJS) + Python (FastAPI) | NestJS pour l'API, FastAPI pour l'IA |
| **API Gateway** | Kong ou Traefik | Routage, rate limiting, auth |
| **Auth** | Keycloak (existant) | SSO, OAuth2, multi-tenant |
| **Message Queue** | RabbitMQ (existant) | Async communication |
| **Cache** | Redis (existant) | Sessions, rate limiting |
| **Search** | Meilisearch | Recherche full-text rapide |
| **Storage** | MinIO (S3-compatible) | Fichiers, images, documents |
### Microservices
1. **Auth Service** — Authentification, rôles, permissions (Keycloak)
2. **User Service** — Profils, préférences, historique
3. **Notification Service** — Push, SMS, email (multi-canal)
4. **GIS Service** — Données géospatiales, itinéraires (PostGIS)
5. **IoT Service** — Ingestion données capteurs (InfluxDB)
6. **Reporting Service** — Signalements, suivi, analytics
7. **Translation Service** — i18n côté serveur
## 5. Beckn Protocol (OTN-DPI)
### Intégration
Le Beckn Protocol permet l'interopérabilité avec les services externes (transport, commerce, administration).
```
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Mobile App │────▶│ Beckn BAP │────▶│ Beckn GW │
│ (Buyer) │◀────│ (Backend) │◀────│ (OTN) │
└─────────────┘ └─────────────┘ └──────┬──────┘
┌──────┴──────┐
│ Beckn BPP │
│ (Sellers) │
│ - Transport│
│ - Commerce │
│ - Admin │
└─────────────┘
```
### Cas d'usage Beckn
- **Transport** : Recherche/réservation de trajets (bus, covoiturage)
- **Commerce local** : Découverte de commerces, commandes
- **Services publics** : RDV mairie, demandes de documents
- **Tourisme** : Réservation d'activités, guides
## 6. AI / LLM Layer
### Architecture AI
```
┌─────────────────────────────────────────────────────────────┐
│ AI Layer │
│ │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ LLM (LocalAI / Ollama) │ │
│ │ - Modèle : Llama 3.1 70B ou Mistral 7B │ │
│ │ - API : OpenAI-compatible │ │
│ │ - Hébergement : LocalAI container (existant) │ │
│ └──────────────────────────────────────────────────────┘ │
│ │ │
│ ┌───────────────────────┴───────────────────────────────┐ │
│ │ RAG Pipeline │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Embedding│ │ Vector │ │ Retriever│ │ │
│ │ │ (E5) │ │ (Qdrant) │ │ (Hybrid) │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ │ │
│ └───────────────────────────────────────────────────────┘ │
│ │ │
│ ┌───────────────────────┴───────────────────────────────┐ │
│ │ AI Agents │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Transport│ │ Tourisme │ │ Services │ │ │
│ │ │ Agent │ │ Agent │ │ Agent │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ │ │
│ └───────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
```
### Cas d'usage AI
1. **Chatbot citoyen** — Réponses aux questions (RAG sur documents municipaux)
2. **Recommandations** — Activités, restaurants, événements personnalisés
3. **Prédictions** — Trafic, qualité de l'air, affluence
4. **Analyse signalements** — Classification automatique, priorisation
5. **Traduction temps réel** — Conversations multilingues
## 7. Multi-Langue (i18n)
### Langues supportées
| Langue | Code | Priorité |
|--------|------|----------|
| Français | fr | 1 (principal) |
| English | en | 2 |
| Español | es | 3 |
| Deutsch | de | 4 |
### Architecture i18n
```
┌─────────────────────────────────────────────────────────────┐
│ i18n Pipeline │
│ │
│ Frontend (React Native) Backend (NestJS) │
│ ┌─────────────────────┐ ┌─────────────────────┐ │
│ │ i18next + ICU │ │ nestjs-i18n │ │
│ │ Format.js │ │ Accept-Language │ │
│ │ Pluralization │ │ Content negotiation │ │
│ └─────────────────────┘ └─────────────────────┘ │
│ │ │
│ ┌───────────────────────┴───────────────────────────────┐ │
│ │ Translation Management │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Crowdin │ │ LLM │ │ Manual │ │ │
│ │ │ (Sync) │ │ (Auto) │ │ (Review) │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ │ │
│ └───────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
```
## 8. Infrastructure & Déploiement
### Conteneurs Docker
```yaml
# docker-compose.smart-app.yml
services:
# Frontend (dev server)
mobile-web:
build: ./frontend
ports: ["8081:8081"]
# Backend API
api-gateway:
image: kong:3.5
ports: ["8000:8000"]
auth-service:
build: ./backend/auth
depends_on: [keycloak]
gis-service:
build: ./backend/gis
depends_on: [postgis]
iot-service:
build: ./backend/iot
depends_on: [influxdb]
notification-service:
build: ./backend/notification
depends_on: [rabbitmq]
# AI Services
rag-service:
build: ./ai/rag
depends_on: [localai, qdrant]
agent-service:
build: ./ai/agents
depends_on: [localai]
# Data
qdrant:
image: qdrant/qdrant:latest
ports: ["6333:6333"]
meilisearch:
image: getmeili/meilisearch:v1.7
ports: ["7700:7700"]
```
### CI/CD
- **GitHub Actions** → Build → Test → Deploy
- **EAS Build** (Expo) → Builds iOS/Android
- **CodePush** → OTA updates
## 9. Roadmap
### Phase 1 — MVP (2-3 mois)
- [ ] Setup React Native + Expo
- [ ] Auth Keycloak + profil utilisateur
- [ ] Dashboard temps réel (météo, qualité air)
- [ ] Carte interactive (capteurs, POI)
- [ ] i18n FR/EN
- [ ] Notifications push
### Phase 2 — Services (3-4 mois)
- [ ] Signalements citoyens
- [ ] Transport (info trafic, bus)
- [ ] Beckn BAP/BPP integration
- [ ] Chatbot RAG (documents municipaux)
- [ ] i18n ES/DE
### Phase 3 — AI & Avancé (4-6 mois)
- [ ] AI Agents (transport, tourisme, services)
- [ ] Recommandations personnalisées
- [ ] Prédictions (trafic, environnement)
- [ ] Réalité augmentée (tourisme)
- [ ] Mode offline complet
## 10. Répertoires
```
smart-app-city/
├── docs/
│ ├── ARCHITECTURE.md (ce fichier)
│ ├── BECKN_INTEGRATION.md
│ ├── AI_ARCHITECTURE.md
│ └── I18N.md
├── frontend/
│ ├── src/
│ │ ├── screens/
│ │ ├── components/
│ │ ├── services/
│ │ ├── i18n/
│ │ └── store/
│ ├── app.json
│ └── package.json
├── backend/
│ ├── api-gateway/
│ ├── auth-service/
│ ├── gis-service/
│ ├── iot-service/
│ ├── notification-service/
│ └── reporting-service/
├── ai/
│ ├── rag-service/
│ ├── agent-service/
│ └── models/
├── beckn/
│ ├── bap/
│ └── bpp-adapter/
├── docker-compose.yml
└── README.md
```

View File

@@ -0,0 +1,113 @@
# Smart App City — Beckn Protocol (OTN-DPI) Integration
## Overview
Integration with the Beckn Protocol for interoperability with external services (transport, commerce, public services).
## Beckn Architecture
```
┌─────────────────────────────────────────────────────────────────┐
│ Beckn Protocol Stack │
│ │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ Mobile App (BAP - Buyer) │ │
│ │ - Search for services │ │
│ │ - Initiate orders │ │
│ │ - Track fulfillments │ │
│ └───────────────────────┬───────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────────────────────────────────────────┐ │
│ │ Beckn Gateway (OTN) │ │
│ │ - Routes requests to appropriate BPPs │ │
│ │ - Handles subscription management │ │
│ │ - Protocol validation │ │
│ └───────────────────────┬───────────────────────────────────┘ │
│ │ │
│ ┌───────────────┼───────────────┐ │
│ ▼ ▼ ▼ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Transport BPP│ │ Commerce BPP │ │ Admin BPP │ │
│ │ (Bus, Taxi) │ │ (Shops) │ │ (City Hall) │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────────┘
```
## Use Cases
### 1. Transport
```json
{
"context": {
"action": "search",
"domain": "mobility:transport:0.8"
},
"message": {
"intent": {
"fulfillment": {
"stops": [
{ "location": { "gps": "14.6415,-61.0242" } },
{ "location": { "gps": "14.5900,-60.9800" } }
]
}
}
}
}
```
### 2. Commerce Local
```json
{
"context": {
"action": "search",
"domain": "retail:commerce:0.8"
},
"message": {
"intent": {
"item": { "descriptor": { "name": "Hébergement" } },
"location": { "city": "Martinique" }
}
}
}
```
### 3. Services Publics
```json
{
"context": {
"action": "search",
"domain": "services:govt:0.8"
},
"message": {
"intent": {
"item": { "descriptor": { "name": "Carte d'identité" } }
}
}
}
```
## Integration Points with Smart City
| Beckn Domain | Smart City Component | Data Source |
|--------------|---------------------|-------------|
| mobility:transport | Orion-LD + FROST | Bus GPS, parking sensors |
| retail:commerce | ONDC Adapter | Local business catalog |
| services:govt | City Services API | ERP municipal |
| tourism:experiences | Tourism API | POI database |
## Implementation Plan
### Phase 1: BAP Client
- [ ] Implement Beckn client library in mobile app
- [ ] Connect to OTN Gateway (existing)
- [ ] Basic search functionality
### Phase 2: BPP Adapter
- [ ] Build BPP adapter for city services
- [ ] Connect to transport data (Orion-LD)
- [ ] Connect to commerce directory
### Phase 3: Full Integration
- [ ] Order management
- [ ] Fulfillment tracking
- [ ] Payment integration

167
smart-app-city/docs/I18N.md Normal file
View File

@@ -0,0 +1,167 @@
# Smart App City — Internationalization (i18n) Guide
## Supported Languages
| Language | Code | Status | Coverage |
|----------|------|--------|----------|
| Français | fr | ✅ Primary | 100% |
| English | en | 🔄 Phase 1 | 100% |
| Español | es | 📋 Phase 2 | 80% |
| Deutsch | de | 📋 Phase 2 | 80% |
## Architecture
### Frontend (React Native)
```typescript
// frontend/src/i18n/index.ts
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import fr from './locales/fr.json';
import en from './locales/en.json';
import es from './locales/es.json';
import de from './locales/de.json';
i18n.use(initReactI18next).init({
resources: { fr, en, es, de },
lng: 'fr',
fallbackLng: 'en',
interpolation: { escapeValue: false },
});
```
### Translation Files Structure
```
frontend/src/i18n/locales/
├── fr.json (source of truth)
├── en.json
├── es.json
└── de.json
```
### Example Translation File
```json
{
"common": {
"welcome": "Bienvenue",
"loading": "Chargement...",
"error": "Erreur",
"retry": "Réessayer",
"cancel": "Annuler"
},
"dashboard": {
"title": "Tableau de bord",
"weather": "Météo",
"airQuality": "Qualité de l'air",
"traffic": "Trafic",
"notifications": "Notifications"
},
"transport": {
"title": "Transport",
"bus": "Bus",
"parking": "Parking",
"taxi": "Taxi",
"bike": "Vélo",
"searchPlaceholder": "Où allez-vous?"
},
"report": {
"title": "Signalement",
"category": "Catégorie",
"description": "Description",
"photo": "Photo",
"location": "Position",
"submit": "Envoyer",
"success": "Signalement envoyé!"
}
}
```
### ICU MessageFormat for Pluralization
```json
{
"notifications": {
"count": "{count, plural, =0 {Aucune notification} =1 {1 notification} other {{count} notifications}}"
},
"sensors": {
"active": "{count, plural, =0 {Aucun capteur actif} =1 {1 capteur actif} other {{count} capteurs actifs}}"
}
}
```
## Backend (NestJS)
### Language Detection优先级
1. User preference (stored in profile)
2. `Accept-Language` header
3. Device locale
4. Default: French
### Response Headers
```typescript
// backend/common/interceptors/i18n.interceptor.ts
@Injectable()
export class I18nInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler) {
const request = context.switchToHttp().getRequest();
const lang = request.headers['accept-language']?.split(',')[0] || 'fr';
return next.handle().pipe(
map(data => ({
...data,
_meta: { language: lang, timestamp: new Date().toISOString() }
}))
);
}
}
```
## Content Translation Strategy
### Static Content (UI Strings)
- ✅ Manual translation (high quality)
- ✅ i18n JSON files in repo
- ✅ LLM-assist for initial translation (Phase 2: ES, DE)
### Dynamic Content (Database)
- ✅ PostgreSQL `jsonb` multilingual fields
- ✅ Example: `{ "fr": "Parc de stationnement", "en": "Parking lot", "es": "Aparcamiento" }`
```sql
-- Database schema for multilingual content
CREATE TABLE poi (
id UUID PRIMARY KEY,
name JSONB NOT NULL, -- {"fr": "...", "en": "...", "es": "..."}
description JSONB,
location GEOGRAPHY(POINT),
category VARCHAR(50),
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Query with language fallback
SELECT
COALESCE(name->>'fr', name->>'en') as name,
COALESCE(description->>'fr', description->>'en') as description
FROM poi
WHERE id = $1;
```
### API Content (Real-time data)
- ⚠️ English (data source language)
- ✅ LLM translation for user-facing text
- ⚠️ No translation for sensor values (numbers are universal)
## Quality Assurance
### Automated Checks
```bash
# Check for missing translations
npm run i18n:check
# Output:
# ❌ Missing ES translation: "report.success"
# ❌ Missing DE translation: "transport.searchPlaceholder"
```
### Community Translation
- Crowdin integration for community contributions
- GitHub Actions sync PO files
- Monthly translation sprints

View File

View File

@@ -0,0 +1,43 @@
{
"name": "smart-app-city",
"version": "0.1.0",
"main": "src/App.tsx",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"i18n:check": "node scripts/check-translations.js",
"test": "jest",
"lint": "eslint src/"
},
"dependencies": {
"expo": "~51.0.0",
"react": "18.2.0",
"react-native": "0.74.0",
"@react-navigation/native": "^6.1.0",
"@react-navigation/bottom-tabs": "^6.5.0",
"react-native-maps": "^1.14.0",
"react-native-paper": "^5.12.0",
"zustand": "^4.5.0",
"@tanstack/react-query": "^5.32.0",
"i18next": "^23.11.0",
"react-i18next": "^14.1.0",
"watermelondb": "^0.27.0",
"@nozbe/watermelondb": "^0.27.0",
"expo-notifications": "~0.28.0",
"expo-location": "~17.0.0",
"expo-camera": "~15.0.0",
"expo-image-picker": "~15.0.0",
"react-native-gesture-handler": "~2.16.0",
"react-native-reanimated": "~3.10.0",
"expo-secure-store": "~13.0.0",
"expo-localization": "~15.0.0"
},
"devDependencies": {
"@types/react": "~18.2.0",
"typescript": "~5.3.0",
"jest": "~29.7.0",
"eslint": "~8.57.0"
}
}

View File