Checkpoint: Application complète de dématérialisation de facturation avec extraction IA (Mistral), authentification locale + Azure AD, stockage local, et export SFTP.

Fonctionnalités implémentées :
 Authentification locale (email/password) + Azure AD + Manus OAuth
 Upload drag-and-drop de fichiers PDF avec suivi en temps réel
 Extraction automatique avec Mistral AI (OCR + LLM)
 Détection de doublons (fournisseur, numéro, date)
 Score de qualité d'extraction (0-100)
 Tableau de bord avec statistiques
 Liste des factures avec recherche et filtres
 Paramètres utilisateur (LLM, keywords, SFTP)
 Historique des imports avec logs détaillés
 Gestion des utilisateurs (admin)
 Export SFTP manuel/automatique
 Stockage local avec organisation YYYY-MM
 Tests unitaires d'authentification

Architecture :
- Frontend : React 19 + Vite + TailwindCSS + Radix UI
- Backend : Express + tRPC + Drizzle ORM
- Base de données : MySQL (6 tables)
- IA : Mistral AI pour extraction
- Stockage : Local filesystem
- Export : SFTP

Pages :
- Login (choix local/Azure/Manus)
- Dashboard (statistiques)
- Upload (drag-and-drop)
- Invoices (liste avec recherche)
- Settings (LLM, keywords, SFTP)
- History (logs d'import)
- Users (gestion admin)
This commit is contained in:
Manus
2026-01-08 06:02:07 -05:00
parent 205b6061ef
commit 5a01860aba
31 changed files with 4644 additions and 99 deletions

View File

@@ -0,0 +1,13 @@
CREATE TABLE `users` (
`id` int AUTO_INCREMENT NOT NULL,
`openId` varchar(64) NOT NULL,
`name` text,
`email` varchar(320),
`loginMethod` varchar(64),
`role` enum('user','admin') NOT NULL DEFAULT 'user',
`createdAt` timestamp NOT NULL DEFAULT (now()),
`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
`lastSignedIn` timestamp NOT NULL DEFAULT (now()),
CONSTRAINT `users_id` PRIMARY KEY(`id`),
CONSTRAINT `users_openId_unique` UNIQUE(`openId`)
);

View File

@@ -0,0 +1,107 @@
CREATE TABLE `importLogs` (
`id` int AUTO_INCREMENT NOT NULL,
`userId` int NOT NULL,
`sourceFileId` int NOT NULL,
`fileName` varchar(255) NOT NULL,
`totalInvoicesDetected` int NOT NULL DEFAULT 0,
`invoicesImported` int NOT NULL DEFAULT 0,
`duplicatesIgnored` int NOT NULL DEFAULT 0,
`errors` int NOT NULL DEFAULT 0,
`duplicateDetails` text,
`errorDetails` text,
`importedAt` timestamp NOT NULL DEFAULT (now()),
CONSTRAINT `importLogs_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `invoices` (
`id` int AUTO_INCREMENT NOT NULL,
`userId` int NOT NULL,
`sourceFileId` int NOT NULL,
`invoiceIndexInFile` int NOT NULL DEFAULT 1,
`fileName` varchar(255) NOT NULL,
`fileKey` text NOT NULL,
`fileUrl` text NOT NULL,
`supplierName` varchar(255),
`invoiceNumber` varchar(100),
`invoiceDate` timestamp,
`deliveryNoteNumber` varchar(100),
`orderNumber` varchar(100),
`totalAmount` decimal(10,2),
`pageRange` varchar(20),
`qualityScore` int,
`metadataFileKey` text,
`metadataFileUrl` text,
`status` enum('processing','completed','error') NOT NULL DEFAULT 'processing',
`errorMessage` text,
`manuallyEdited` int NOT NULL DEFAULT 0,
`exportedAt` timestamp,
`exportMode` enum('manual','automatic'),
`createdAt` timestamp NOT NULL DEFAULT (now()),
`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT `invoices_id` PRIMARY KEY(`id`),
CONSTRAINT `supplier_invoice_date_unique` UNIQUE(`supplierName`,`invoiceNumber`,`invoiceDate`)
);
--> statement-breakpoint
CREATE TABLE `llmLogs` (
`id` int AUTO_INCREMENT NOT NULL,
`userId` int NOT NULL,
`sourceFileId` int,
`invoiceId` int,
`operation` varchar(50) NOT NULL,
`model` varchar(50) NOT NULL,
`promptSent` text NOT NULL,
`rawResponse` text NOT NULL,
`cleanedResponse` text,
`success` int NOT NULL DEFAULT 1,
`errorMessage` text,
`processingTimeMs` int,
`pageRange` varchar(50),
`createdAt` timestamp NOT NULL DEFAULT (now()),
CONSTRAINT `llmLogs_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `sourceFiles` (
`id` int AUTO_INCREMENT NOT NULL,
`userId` int NOT NULL,
`fileName` varchar(255) NOT NULL,
`fileKey` text NOT NULL,
`fileUrl` text NOT NULL,
`totalInvoicesDetected` int NOT NULL DEFAULT 0,
`processingStatus` enum('processing','completed','error') NOT NULL DEFAULT 'processing',
`processingProgress` varchar(255),
`createdAt` timestamp NOT NULL DEFAULT (now()),
`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT `sourceFiles_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `userSettings` (
`id` int AUTO_INCREMENT NOT NULL,
`userId` int NOT NULL,
`llmModel` varchar(50) NOT NULL DEFAULT 'mistral-large-latest',
`orderNumberFormat` text,
`invoiceNumberKeywords` text,
`deliveryNoteKeywords` text,
`orderNumberKeywords` text,
`supplierKeywords` text,
`totalAmountKeywords` text,
`sftpHost` varchar(255),
`sftpPort` int DEFAULT 22,
`sftpUsername` varchar(255),
`sftpPassword` text,
`sftpRemotePath` varchar(500) DEFAULT '/',
`sftpAutoExport` int NOT NULL DEFAULT 0,
`llmLogsRetentionMonths` int NOT NULL DEFAULT 3,
`createdAt` timestamp NOT NULL DEFAULT (now()),
`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT `userSettings_id` PRIMARY KEY(`id`),
CONSTRAINT `userSettings_userId_unique` UNIQUE(`userId`)
);
--> statement-breakpoint
ALTER TABLE `users` MODIFY COLUMN `openId` varchar(64);--> statement-breakpoint
ALTER TABLE `users` MODIFY COLUMN `email` varchar(320) NOT NULL;--> statement-breakpoint
ALTER TABLE `users` MODIFY COLUMN `loginMethod` enum('manus','local','azure-ad') NOT NULL;--> statement-breakpoint
ALTER TABLE `users` ADD `azureAdId` varchar(64);--> statement-breakpoint
ALTER TABLE `users` ADD `passwordHash` varchar(255);--> statement-breakpoint
ALTER TABLE `users` ADD `isActive` int DEFAULT 1 NOT NULL;--> statement-breakpoint
ALTER TABLE `users` ADD CONSTRAINT `users_azureAdId_unique` UNIQUE(`azureAdId`);--> statement-breakpoint
ALTER TABLE `users` ADD CONSTRAINT `users_email_unique` UNIQUE(`email`);

View File

@@ -0,0 +1,110 @@
{
"version": "5",
"dialect": "mysql",
"id": "a83c4429-6f78-429c-9b2d-933ddd6d357d",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"users": {
"name": "users",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"openId": {
"name": "openId",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"email": {
"name": "email",
"type": "varchar(320)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"loginMethod": {
"name": "loginMethod",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"role": {
"name": "role",
"type": "enum('user','admin')",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'user'"
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"onUpdate": true,
"default": "(now())"
},
"lastSignedIn": {
"name": "lastSignedIn",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"users_id": {
"name": "users_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {
"users_openId_unique": {
"name": "users_openId_unique",
"columns": [
"openId"
]
}
},
"checkConstraint": {}
}
},
"views": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"tables": {},
"indexes": {}
}
}

View File

@@ -0,0 +1,811 @@
{
"version": "5",
"dialect": "mysql",
"id": "82b3cbc0-6925-4f7c-b3c7-0a1c0e96f34d",
"prevId": "a83c4429-6f78-429c-9b2d-933ddd6d357d",
"tables": {
"importLogs": {
"name": "importLogs",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"userId": {
"name": "userId",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"sourceFileId": {
"name": "sourceFileId",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"fileName": {
"name": "fileName",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"totalInvoicesDetected": {
"name": "totalInvoicesDetected",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"invoicesImported": {
"name": "invoicesImported",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"duplicatesIgnored": {
"name": "duplicatesIgnored",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"errors": {
"name": "errors",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"duplicateDetails": {
"name": "duplicateDetails",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"errorDetails": {
"name": "errorDetails",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"importedAt": {
"name": "importedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"importLogs_id": {
"name": "importLogs_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {},
"checkConstraint": {}
},
"invoices": {
"name": "invoices",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"userId": {
"name": "userId",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"sourceFileId": {
"name": "sourceFileId",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"invoiceIndexInFile": {
"name": "invoiceIndexInFile",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 1
},
"fileName": {
"name": "fileName",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"fileKey": {
"name": "fileKey",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"fileUrl": {
"name": "fileUrl",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"supplierName": {
"name": "supplierName",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"invoiceNumber": {
"name": "invoiceNumber",
"type": "varchar(100)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"invoiceDate": {
"name": "invoiceDate",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"deliveryNoteNumber": {
"name": "deliveryNoteNumber",
"type": "varchar(100)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"orderNumber": {
"name": "orderNumber",
"type": "varchar(100)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"totalAmount": {
"name": "totalAmount",
"type": "decimal(10,2)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"pageRange": {
"name": "pageRange",
"type": "varchar(20)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"qualityScore": {
"name": "qualityScore",
"type": "int",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"metadataFileKey": {
"name": "metadataFileKey",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"metadataFileUrl": {
"name": "metadataFileUrl",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"status": {
"name": "status",
"type": "enum('processing','completed','error')",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'processing'"
},
"errorMessage": {
"name": "errorMessage",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"manuallyEdited": {
"name": "manuallyEdited",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"exportedAt": {
"name": "exportedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"exportMode": {
"name": "exportMode",
"type": "enum('manual','automatic')",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"onUpdate": true,
"default": "(now())"
}
},
"indexes": {
"supplier_invoice_date_unique": {
"name": "supplier_invoice_date_unique",
"columns": [
"supplierName",
"invoiceNumber",
"invoiceDate"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {
"invoices_id": {
"name": "invoices_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {},
"checkConstraint": {}
},
"llmLogs": {
"name": "llmLogs",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"userId": {
"name": "userId",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"sourceFileId": {
"name": "sourceFileId",
"type": "int",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"invoiceId": {
"name": "invoiceId",
"type": "int",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"operation": {
"name": "operation",
"type": "varchar(50)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"model": {
"name": "model",
"type": "varchar(50)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"promptSent": {
"name": "promptSent",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"rawResponse": {
"name": "rawResponse",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"cleanedResponse": {
"name": "cleanedResponse",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"success": {
"name": "success",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 1
},
"errorMessage": {
"name": "errorMessage",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"processingTimeMs": {
"name": "processingTimeMs",
"type": "int",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"pageRange": {
"name": "pageRange",
"type": "varchar(50)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"llmLogs_id": {
"name": "llmLogs_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {},
"checkConstraint": {}
},
"sourceFiles": {
"name": "sourceFiles",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"userId": {
"name": "userId",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"fileName": {
"name": "fileName",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"fileKey": {
"name": "fileKey",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"fileUrl": {
"name": "fileUrl",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"totalInvoicesDetected": {
"name": "totalInvoicesDetected",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"processingStatus": {
"name": "processingStatus",
"type": "enum('processing','completed','error')",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'processing'"
},
"processingProgress": {
"name": "processingProgress",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"onUpdate": true,
"default": "(now())"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"sourceFiles_id": {
"name": "sourceFiles_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {},
"checkConstraint": {}
},
"userSettings": {
"name": "userSettings",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"userId": {
"name": "userId",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"llmModel": {
"name": "llmModel",
"type": "varchar(50)",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'mistral-large-latest'"
},
"orderNumberFormat": {
"name": "orderNumberFormat",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"invoiceNumberKeywords": {
"name": "invoiceNumberKeywords",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"deliveryNoteKeywords": {
"name": "deliveryNoteKeywords",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"orderNumberKeywords": {
"name": "orderNumberKeywords",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"supplierKeywords": {
"name": "supplierKeywords",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"totalAmountKeywords": {
"name": "totalAmountKeywords",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"sftpHost": {
"name": "sftpHost",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"sftpPort": {
"name": "sftpPort",
"type": "int",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 22
},
"sftpUsername": {
"name": "sftpUsername",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"sftpPassword": {
"name": "sftpPassword",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"sftpRemotePath": {
"name": "sftpRemotePath",
"type": "varchar(500)",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": "'/'"
},
"sftpAutoExport": {
"name": "sftpAutoExport",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"llmLogsRetentionMonths": {
"name": "llmLogsRetentionMonths",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 3
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"onUpdate": true,
"default": "(now())"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"userSettings_id": {
"name": "userSettings_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {
"userSettings_userId_unique": {
"name": "userSettings_userId_unique",
"columns": [
"userId"
]
}
},
"checkConstraint": {}
},
"users": {
"name": "users",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"openId": {
"name": "openId",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"azureAdId": {
"name": "azureAdId",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"email": {
"name": "email",
"type": "varchar(320)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"passwordHash": {
"name": "passwordHash",
"type": "varchar(255)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"loginMethod": {
"name": "loginMethod",
"type": "enum('manus','local','azure-ad')",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"role": {
"name": "role",
"type": "enum('user','admin')",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'user'"
},
"isActive": {
"name": "isActive",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 1
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"onUpdate": true,
"default": "(now())"
},
"lastSignedIn": {
"name": "lastSignedIn",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"users_id": {
"name": "users_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {
"users_openId_unique": {
"name": "users_openId_unique",
"columns": [
"openId"
]
},
"users_azureAdId_unique": {
"name": "users_azureAdId_unique",
"columns": [
"azureAdId"
]
},
"users_email_unique": {
"name": "users_email_unique",
"columns": [
"email"
]
}
},
"checkConstraint": {}
}
},
"views": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"tables": {},
"indexes": {}
}
}

View File

@@ -1,5 +1,20 @@
{
"version": "7",
"dialect": "mysql",
"entries": []
}
"entries": [
{
"idx": 0,
"version": "5",
"when": 1767869282094,
"tag": "0000_dashing_earthquake",
"breakpoints": true
},
{
"idx": 1,
"version": "5",
"when": 1767869488758,
"tag": "0001_breezy_the_spike",
"breakpoints": true
}
]
}

View File

@@ -1,22 +1,24 @@
import { int, mysqlEnum, mysqlTable, text, timestamp, varchar } from "drizzle-orm/mysql-core";
import { int, mysqlEnum, mysqlTable, text, timestamp, varchar, uniqueIndex, decimal } from "drizzle-orm/mysql-core";
/**
* Core user table backing auth flow.
* Extend this file with additional tables as your product grows.
* Columns use camelCase to match both database fields and generated types.
* Supports multiple authentication methods: Manus OAuth, local, and Azure AD
*/
export const users = mysqlTable("users", {
/**
* Surrogate primary key. Auto-incremented numeric value managed by the database.
* Use this for relations between tables.
*/
id: int("id").autoincrement().primaryKey(),
/** Manus OAuth identifier (openId) returned from the OAuth callback. Unique per user. */
openId: varchar("openId", { length: 64 }).notNull().unique(),
/** Manus OAuth identifier (openId) - Optional for backward compatibility */
openId: varchar("openId", { length: 64 }).unique(),
/** Azure AD Object ID - Unique identifier from Azure AD */
azureAdId: varchar("azureAdId", { length: 64 }).unique(),
name: text("name"),
email: varchar("email", { length: 320 }),
loginMethod: varchar("loginMethod", { length: 64 }),
email: varchar("email", { length: 320 }).notNull().unique(),
/** Hashed password for local authentication (bcrypt) */
passwordHash: varchar("passwordHash", { length: 255 }),
/** Authentication method: 'manus', 'local', 'azure-ad' */
loginMethod: mysqlEnum("loginMethod", ["manus", "local", "azure-ad"]).notNull(),
role: mysqlEnum("role", ["user", "admin"]).default("user").notNull(),
/** Account status for manual user management */
isActive: int("isActive").default(1).notNull(), // 0 = inactive, 1 = active
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
lastSignedIn: timestamp("lastSignedIn").defaultNow().notNull(),
@@ -25,4 +27,145 @@ export const users = mysqlTable("users", {
export type User = typeof users.$inferSelect;
export type InsertUser = typeof users.$inferInsert;
// TODO: Add your tables here
/**
* Source files table storing uploaded PDF files that may contain multiple invoices
*/
export const sourceFiles = mysqlTable("sourceFiles", {
id: int("id").autoincrement().primaryKey(),
userId: int("userId").notNull(),
fileName: varchar("fileName", { length: 255 }).notNull(),
fileKey: text("fileKey").notNull(), // Local storage key with YYYY-MM prefix
fileUrl: text("fileUrl").notNull(), // Public URL
totalInvoicesDetected: int("totalInvoicesDetected").default(0).notNull(),
processingStatus: mysqlEnum("processingStatus", ["processing", "completed", "error"]).default("processing").notNull(),
processingProgress: varchar("processingProgress", { length: 255 }), // Progress message (e.g., "Extraction 3/9 factures...")
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
});
export type SourceFile = typeof sourceFiles.$inferSelect;
export type InsertSourceFile = typeof sourceFiles.$inferInsert;
/**
* Invoices table storing individual invoices extracted from source files
*/
export const invoices = mysqlTable("invoices", {
id: int("id").autoincrement().primaryKey(),
userId: int("userId").notNull(),
sourceFileId: int("sourceFileId").notNull(), // Reference to the source PDF file
invoiceIndexInFile: int("invoiceIndexInFile").default(1).notNull(), // Position in the source file (1, 2, 3...)
// File storage information (for individual invoice if split, or reference to source)
fileName: varchar("fileName", { length: 255 }).notNull(),
fileKey: text("fileKey").notNull(), // Local storage key
fileUrl: text("fileUrl").notNull(), // Public URL
// Extracted metadata
supplierName: varchar("supplierName", { length: 255 }),
invoiceNumber: varchar("invoiceNumber", { length: 100 }),
invoiceDate: timestamp("invoiceDate"),
deliveryNoteNumber: varchar("deliveryNoteNumber", { length: 100 }),
orderNumber: varchar("orderNumber", { length: 100 }),
totalAmount: decimal("totalAmount", { precision: 10, scale: 2 }),
pageRange: varchar("pageRange", { length: 20 }), // ex: "1-2" ou "5"
qualityScore: int("qualityScore"), // Score de qualité de l'extraction (0-100)
// Metadata JSON file
metadataFileKey: text("metadataFileKey"), // Storage key for JSON metadata
metadataFileUrl: text("metadataFileUrl"), // Public URL for JSON
// Processing status
status: mysqlEnum("status", ["processing", "completed", "error"]).default("processing").notNull(),
errorMessage: text("errorMessage"),
// Manual correction tracking
manuallyEdited: int("manuallyEdited").default(0).notNull(), // 0 = false, 1 = true
// SFTP Export tracking
exportedAt: timestamp("exportedAt"),
exportMode: mysqlEnum("exportMode", ["manual", "automatic"]),
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
}, (table) => {
return {
// Unique constraint: no duplicate invoices with same supplier, invoice number, and date
supplierInvoiceDateIdx: uniqueIndex("supplier_invoice_date_unique").on(table.supplierName, table.invoiceNumber, table.invoiceDate),
};
});
export type Invoice = typeof invoices.$inferSelect;
export type InsertInvoice = typeof invoices.$inferInsert;
/**
* User settings table for application preferences
*/
export const userSettings = mysqlTable("userSettings", {
id: int("id").autoincrement().primaryKey(),
userId: int("userId").notNull().unique(), // One settings record per user
llmModel: varchar("llmModel", { length: 50 }).default("mistral-large-latest").notNull(), // Mistral model for invoice extraction
orderNumberFormat: text("orderNumberFormat"), // Format/pattern du numéro de commande pour aider l'extraction
// Mots-clés personnalisés pour améliorer la détection (séparés par des virgules)
invoiceNumberKeywords: text("invoiceNumberKeywords"), // Ex: "Référence, Ref facture, Invoice ref"
deliveryNoteKeywords: text("deliveryNoteKeywords"), // Ex: "Livraison, Delivery, Expédition"
orderNumberKeywords: text("orderNumberKeywords"), // Ex: "Cde client, Référence commande, PO Number"
supplierKeywords: text("supplierKeywords"), // Ex: "Vendeur, Société, Émetteur"
totalAmountKeywords: text("totalAmountKeywords"), // Ex: "Net à payer, Total à régler, Amount due"
// SFTP Configuration
sftpHost: varchar("sftpHost", { length: 255 }),
sftpPort: int("sftpPort").default(22),
sftpUsername: varchar("sftpUsername", { length: 255 }),
sftpPassword: text("sftpPassword"), // Encrypted password
sftpRemotePath: varchar("sftpRemotePath", { length: 500 }).default("/"), // Remote directory path
sftpAutoExport: int("sftpAutoExport").default(0).notNull(), // 0 = manual, 1 = automatic
// LLM Logs retention
llmLogsRetentionMonths: int("llmLogsRetentionMonths").default(3).notNull(), // Durée de conservation des logs LLM en mois (défaut: 3 mois)
createdAt: timestamp("createdAt").defaultNow().notNull(),
updatedAt: timestamp("updatedAt").defaultNow().onUpdateNow().notNull(),
});
export type UserSettings = typeof userSettings.$inferSelect;
export type InsertUserSettings = typeof userSettings.$inferInsert;
/**
* Import logs table for tracking all import operations
*/
export const importLogs = mysqlTable("importLogs", {
id: int("id").autoincrement().primaryKey(),
userId: int("userId").notNull(),
sourceFileId: int("sourceFileId").notNull(), // Reference to source file
fileName: varchar("fileName", { length: 255 }).notNull(),
totalInvoicesDetected: int("totalInvoicesDetected").default(0).notNull(),
invoicesImported: int("invoicesImported").default(0).notNull(),
duplicatesIgnored: int("duplicatesIgnored").default(0).notNull(),
errors: int("errors").default(0).notNull(),
duplicateDetails: text("duplicateDetails"), // JSON array of duplicate invoice info
errorDetails: text("errorDetails"), // JSON array of error messages
importedAt: timestamp("importedAt").defaultNow().notNull(),
});
export type ImportLog = typeof importLogs.$inferSelect;
export type InsertImportLog = typeof importLogs.$inferInsert;
/**
* LLM Logs table for storing raw LLM responses for debugging and improvement
*/
export const llmLogs = mysqlTable("llmLogs", {
id: int("id").autoincrement().primaryKey(),
userId: int("userId").notNull(),
sourceFileId: int("sourceFileId"), // Optional: link to source file if applicable
invoiceId: int("invoiceId"), // Optional: link to invoice if applicable
operation: varchar("operation", { length: 50 }).notNull(), // "detection" or "extraction"
model: varchar("model", { length: 50 }).notNull(), // LLM model used
promptSent: text("promptSent").notNull(), // Full prompt sent to LLM
rawResponse: text("rawResponse").notNull(), // Raw response from LLM (before cleaning)
cleanedResponse: text("cleanedResponse"), // Response after markdown cleaning
success: int("success").default(1).notNull(), // 1 = success, 0 = error
errorMessage: text("errorMessage"), // Error message if failed
processingTimeMs: int("processingTimeMs"), // Processing time in milliseconds
pageRange: varchar("pageRange", { length: 50 }), // Page range for this log (e.g., "1-2")
createdAt: timestamp("createdAt").defaultNow().notNull(),
});
export type LlmLog = typeof llmLogs.$inferSelect;
export type InsertLlmLog = typeof llmLogs.$inferInsert;