LogoKalli
Get Started

Structure du projet

Structure détaillée du projet nAI'vi

Cette documentation présente l'architecture complète du projet nAI'vi.

.
├── .dockerignore
├── .env.example                               # Exemple de variables d'environnement
├── .gitignore
├── .gitlab-ci.yml                             # CI/CD GitLab
├── biome.json                                 # Linter/formateur Biome
├── bun.lock
├── docker-compose.yml                         # Dev local multi-services
├── Dockerfile                                 # Image Docker multi-étapes
├── package.json                               # Workspace Bun (scripts partagés)
├── README.md

├── apps/
│   │
│   ├── chatbot/                               # Moteur IA (Python)
│   │   ├── chainlit.md                        # Config UI Chainlit (titre, logo, couleurs)
│   │   ├── pyproject.toml                     # Dépendances Python (Poetry/pip)
│   │   │
│   │   └── src/
│   │       ├── chatbot/
│   │       │   ├── core/
│   │       │   │   ├── orchestration.py       # process_question() — point d'entrée principal
│   │       │   │   ├── intent_classifier.py   # classify_intent_and_answer() — NORMAL vs ALTER
│   │       │   │   └── external_agent.py      # forward_to_external_agent() — SSE vers agent externe
│   │       │   │
│   │       │   ├── rag/
│   │       │   │   ├── services.py            # prepare_rag_context(), answer_question(), run_query_mistral()
│   │       │   │   └── indexing.py            # get_text_embedding(), regenerate_index(), cache per-role
│   │       │   │
│   │       │   ├── finetuning/
│   │       │   │   ├── __main__.py            # CLI fine-tuning (JSONL → job Mistral)
│   │       │   │   └── utils.py
│   │       │   │
│   │       │   ├── copilot/
│   │       │   │   └── eYoma_mock/            # Prototype intégration Teams (expérimental)
│   │       │   │
│   │       │   └── interfaces/
│   │       │       ├── chainlit/
│   │       │       │   ├── app.py             # Hooks Chainlit: on_chat_start, on_message, audio, resume
│   │       │       │   └── utils.py           # transcribe_audio_with_voxtral(), generate_thread_title()
│   │       │       └── api/
│   │       │           └── index_api.py       # FastAPI: GET /, POST /regenerate-index
│   │       │
│   │       ├── common/
│   │       │   ├── db.py                      # Connexion DB, queries chunks/QA/rôles/embeddings/index
│   │       │   ├── mistral.py                 # initialize_mistral_client()
│   │       │   ├── logo_loader.py             # Chargement logos DB → /app/public/
│   │       │   └── logo_startup.py            # initialize_logo_system(), shutdown_logo_system()
│   │       │
│   │       └── config/
│   │           ├── config.py                  # get_mistral_api_key(), get_db_config()
│   │           ├── rag_config.py              # validate_rag_parameters(), constantes RAG
│   │           ├── orchestrator_config.py     # is_orchestrator_enabled(), get_external_agent_url()
│   │           ├── i18n.py                    # TranslationManager
│   │           └── i18n.json                  # Traductions (prompts, erreurs)
│   │
│   ├── document-processor/                    # Microservice de parsing (Python/FastAPI)
│   │   ├── pyproject.toml
│   │   └── src/
│   │       ├── main.py                        # FastAPI: GET /health, POST /process
│   │       ├── config.py                      # Settings (host, port, OCR, max_file_size)
│   │       ├── models.py                      # ProcessingRequest, ProcessingResult, HealthResponse
│   │       └── parsers/
│   │           ├── pdf_parser.py              # PDFParser (avec OCR Tesseract optionnel)
│   │           ├── office_parser.py           # OfficeParser (.docx, .pptx)
│   │           ├── csv_parser.py              # CSVParser (.csv, .xlsx)
│   │           ├── markdown_parser.py         # MarkdownParser (.md, .txt)
│   │           └── json_parser.py             # JSONParser (.json)
│   │
│   ├── server/                                # Backend API (Bun/TypeScript/Hono)
│   │   ├── drizzle.config.ts
│   │   ├── package.json
│   │   │
│   │   └── src/
│   │       ├── index.ts                       # Hono app: CORS, auth, ORPC, REST endpoints
│   │       │
│   │       ├── db/
│   │       │   ├── index.ts                   # Connexion Drizzle + DATABASE_URL
│   │       │   └── schema/
│   │       │       ├── auth.ts                # Tables: user, session, account, verification
│   │       │       └── naivi.ts               # Tables: files, chunks, qa_pair, file_assignments,
│   │       │                                  #         logo, tags, roles, role_tags, item_tags,
│   │       │                                  #         indexes, index_chunks
│   │       │
│   │       ├── lib/
│   │       │   ├── auth.ts                    # Better Auth config (Drizzle adapter, OAuth Microsoft)
│   │       │   ├── context.ts                 # createContext(): session + lastConnection update
│   │       │   ├── email.ts                   # Envoi d'emails
│   │       │   └── orpc.ts                    # publicProcedure, protectedProcedure, adminProcedure
│   │       │
│   │       ├── routers/
│   │       │   ├── index.ts                   # appRouter: healthCheck + i18n + auth + naivi + rolesTags
│   │       │   ├── auth.ts                    # getMe, getAllUsers, getUserById…
│   │       │   ├── naivi.ts                   # getFiles, processUploadedFile, chunks, QA, regenerateIndex…
│   │       │   └── roles-tags.ts              # Tags CRUD, Roles CRUD, role-tag, item-tag, user role
│   │       │
│   │       └── utils/
│   │           ├── regular-processing.ts      # Upload fichier → document-processor → DB chunks
│   │           ├── qa-processing.ts           # Parse CSV Q&A → DB qa_pair
│   │           ├── chunk-operations.ts        # CRUD chunks (catégorie, contenu, suppression)
│   │           ├── qa-operations.ts           # CRUD qa_pair
│   │           ├── file-operations.ts         # Renommage, statut, assignations
│   │           ├── manual-operations.ts       # Insertion manuelle chunks/QA sans fichier parent
│   │           ├── document-processor-client.ts  # Client HTTP vers document-processor
│   │           ├── roles-tags-operations.ts   # Logique métier tags/rôles/associations
│   │           ├── sanitize.ts                # Sanitisation texte pour PostgreSQL
│   │           └── user-operations.ts         # Mise à jour lastConnection
│   │
│   └── web/                                   # Frontend (React/TypeScript/Vite)
│       ├── components.json                    # Config Shadcn UI
│       ├── index.html
│       ├── package.json
│       ├── vite.config.ts
│       │
│       └── src/
│           ├── main.tsx
│           ├── index.css
│           │
│           ├── components/
│           │   ├── theme-provider.tsx         # Thème clair/sombre
│           │   └── ui/                        # Composants Shadcn UI
│           │
│           ├── features/
│           │   ├── auth/                      # sign-in, sign-up, forgot/reset-password
│           │   ├── protected/
│           │   │   ├── admin/                 # assignements, chunks manuels, fichiers admin,
│           │   │   │                          # tags, rôles, qa-visualisation
│           │   │   ├── common/                # dashboard, chunk-visualisation, fichiers communs
│           │   │   └── user/                  # vue utilisateur (fichiers assignés)
│           │   └── public/                    # home, faq, layout
│           │
│           ├── hooks/                         # Hooks React: useFiles, useChunks, useQA, useTags…
│           ├── lib/
│           │   ├── auth-client.ts             # Better Auth client
│           │   └── utils.ts
│           │
│           ├── routes/                        # TanStack Router (file-based routing)
│           └── utils/
│               ├── orpc.ts                    # Client ORPC typé (appRouter)
│               ├── read-file-content.ts       # Lecture fichier → base64/texte
│               ├── runtime-env.ts             # Variables runtime Kubernetes (window.__ENV__)
│               └── types.ts

├── docs/                                      # Documentation Fumadocs (ce site)

└── helm/                                      # Chart Helm Kubernetes
    ├── Chart.yaml
    ├── values.yaml                            # Valeurs par défaut (un bot)
    ├── values-*.yaml                          # Overrides par bot/environnement

    └── templates/
        ├── configmap.yaml                     # i18n, prompts, config bot
        ├── secrets.yaml                       # MISTRAL_API_KEY, DB password…
        ├── ingress.yaml
        ├── certificate.yaml                   # TLS cert-manager
        ├── db-statefulset.yaml
        ├── deployment/
        │   ├── chatbot-deployment.yaml
        │   ├── doc-processor-deployment.yaml  # document-processor microservice
        │   ├── server-deployment.yaml
        │   └── web-deployment.yaml
        └── service/
            ├── chatbot-service.yaml
            ├── doc-processor-service.yaml
            ├── db-service.yaml
            ├── server-service.yaml
            └── web-service.yaml

## Applications du monorepo

| App | Stack | Rôle |
|---|---|---|
| `apps/chatbot` | Python, Chainlit, FAISS, Mistral | Moteur RAG, interface de chat, index FAISS per-role |
| `apps/document-processor` | Python, FastAPI | Parsing et chunking de documents (PDF, DOCX, XLSX…) |
| `apps/server` | Bun, Hono, ORPC, Drizzle, Better Auth | API backend, authentification, gestion des données |
| `apps/web` | React, Vite, TanStack Router/Query, Shadcn UI | Interface utilisateur (administration et chat) |

## Responsabilités clés

- **Chatbot**: RAG per-role, orchestrateur optionnel, audio (Voxtral), logos dynamiques.
- **Document Processor**: microservice isolé, parseurs format-spécifiques, OCR optionnel.
- **Server**: ORPC type-safe, RBAC (Better Auth + rôles applicatifs), pipeline documents → DB.
- **Web**: routage type-safe, guards RBAC, annotation des chunks, visualisation des sources.
- **Helm**: déploiement multi-bot sur Kubernetes, ConfigMaps pour prompts/i18n/logos.

## Guide d'extension

- **Nouveau router ORPC** (Server): créez `routers/mon-router.ts`, utilisez `publicProcedure`/`protectedProcedure`/`adminProcedure`, spreader dans `routers/index.ts`.
- **Nouveau parser** (Document Processor): ajoutez un parser dans `apps/document-processor/src/parsers/`, enregistrez-le dans `_get_parser()` de `main.py`.
- **Nouvelle page** (Web): créez un fichier dans `apps/web/src/routes/`, consommez l'API via `utils/orpc.ts` + TanStack Query.
- **Nouveau rôle applicatif**: créez via l'interface admin (ou `createRole` ORPC), associez des tags, puis régénérez l'index FAISS.
- **Étendre le RAG**: ajustez `rag/services.py` (top-k, température) et `rag_config.py` (limites, defaults).