Layer Overview
The Golden Rule: a layer may only depend on layers closer to the center.
TursoDatabase.ts implements ITenderRepository; the Domain interface never imports from Infrastructure.
Directory Structure
Request Flow
The following steps trace a complete tender analysis request from the browser to the database and back.1
Upload
The React frontend POSTs a multipart form (PDF file) to
POST /api/tenders/analyze. The request includes either an HttpOnly cookie (token) or an Authorization: Bearer <jwt> header.2
Authentication
authMiddleware intercepts the request. It first reads the JWT from the cookie; if absent, it falls back to the Authorization header. The JWT is verified with jsonwebtoken. Invalid or missing tokens return 401.3
Controller dispatch
TenderController receives the validated request, extracts the file buffer and user identity from req.user, and delegates to the CreateTender use case.4
Use case orchestration
CreateTender calls the injected dependencies in sequence:PdfParserAdapter.parsePages()extracts page-delimited text from the PDF buffer usingpdf-parse.GeminiGenkitService.analyze()(oranalyzeChunks()for large PDFs) sends the text to Gemini 2.5 Flash and receives a structured list ofRequirementobjects.VectorSearchService.generateEmbedding()produces aFloat32Arrayfor each requirement and serialises it to aBufferfor storage.
5
Persistence
TursoTenderRepository.save() writes the TenderAnalysis record — including all requirements and their embedding BLOBs — to the Turso (LibSQL) database.6
Response
A
TenderAnalysis JSON object is returned to the frontend with status: "COMPLETED", a summary, and the full requirements array including pageNumber and sourceText for clickable citations.Frontend Architecture
The frontend is a React + Vite + Tailwind CSS single-page application. Key dashboard components are:Dashboard— root layout that composes all other dashboard components.TenderUpload— drag-and-drop file input that triggers the analysis API call.AnalysisResults— renders the extracted requirements list with confidence badges.ValidationSummary— aggregated compliance scores after proposal validation.HistorySidebar— browsable list of past analyses fetched from the API.CitationPreview— modal that shows the full page text with the AI-identified source fragment highlighted.
AuthContext— holds the authenticated user, JWT, and login/logout actions.ThemeContext— drives the dual light (Beige/Gold) and dark (Charcoal/Emerald) theme toggle applied across the entire application.
Deployment Architecture
AI Pipeline
How Gemini 2.5 Flash, Google Genkit flows, and
gemini-embedding-001 vector embeddings work together to extract requirements and validate proposals.Database
The full Turso (LibSQL) schema, repository pattern, and how vector embeddings are stored and queried in SQLite.