# arthurluis/case-paggo architecture

> Architecture diagram of the GitHub repository arthurluis/case-paggo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arthurluis/case-paggo
- Repository: https://github.com/arthurluis/case-paggo

## Overview

##### Main Components
- Frontend: Represented as a Next.js application that includes various React components (AppButton, AppInput, Chat, DocumentCard, etc.) along with pages for dashboard, documents, login, etc. Note that it uses TailwindCSS for styling, Axios for HTTP requests, and TypeScript for type safety.
- Backend: A NestJS-based API organized into modules:
- Auth Module: Handles authentication (with JWT strategy).
- Document Module: Manages document operations, including OCR and PDF services.
- Gemini Module: Deals with Gemini API interactions that likely process AI responses.
- LLM-Response Module: Manages responses from a large language model.
- User Module: Manages user-related endpoints.
- Database Module: Provides access via Prisma, with migration support for a PostgreSQL database.
- Database: PostgreSQL (managed through Prisma migrations and connections).
- External Services:
- Tesseract OCR (includes trained data files in tessdata and backend assets for language models).
- Gemini AI service.
- (Possibly) Supabase – as per the README, indicating additional backend integrations.

##### Relationships and Data Flow
- The Frontend communicates with the Backend via HTTP APIs (typically Axios is used on the frontend).
- The Backend exposes REST (or possibly GraphQL, but more likely REST given the module structure) endpoints that cover authentication, document handling, and integrations with Gemini and LLM.
- Within the Backend, each module interacts with the database through the Database Module/Prisma service. For example, the document module fetches or stores document-related information.
- External service interactions (OCR service, Gemini API) occur in relevant modules (e.g., Document module calls OCR and PDF services; Gemini module processes API responses).

##### Architectural Patterns and Principles
- Modular Architecture: The backend’s folder structure shows clear module separation (auth, document, gemini, etc.) – indicative of a modular design.
- MVC-like Separation: Controllers, services, and entities are present in each module, following an MVC or similar layered pattern.
- Microservices Consideration: Although not fully distributed, the separation and potential external service integrations hint at a design that could be extended to microservices if needed.
- Clear Separation of Frontend and Backend concerns, with explicit API interaction.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Frontend Layer
    subgraph "Frontend Layer (Next.js/React, Vercel)"
        FE["Frontend App (Next.js/React)"]:::frontend
        FEComp["Components/Pages/Hooks (TailwindCSS, Axios, TS)"]:::frontend
        FE --> FEComp
    end

    %% Backend Layer
    subgraph "Backend Layer (NestJS, Railway)"
        Auth["Auth Module (JWT)"]:::backend
        Doc["Document Module (OCR,PDF)"]:::backend
        Gemini["Gemini Module (AI responses)"]:::backend
        LLM["LLM-Response Module"]:::backend
        User["User Module"]:::backend
        DBModule["Database Module (Prisma)"]:::backend
    end

    %% External Services
    subgraph "External Services"
        Tesseract["Tesseract OCR"]:::external
        GeminiAPI["Gemini API"]:::external
        Supabase["Supabase"]:::external
    end

    %% Database (PostgreSQL)
    DB["PostgreSQL Database (Prisma)"]:::database

    %% Deployment Infrastructure
    Vercel["Vercel (Frontend Deployment)"]:::deployment
    Railway["Railway (Backend Deployment)"]:::deployment

    %% Connections from Frontend to Backend APIs
    FEComp -->|"HTTP_API"| Auth
    FEComp -->|"HTTP_API"| Doc
    FEComp -->|"HTTP_API"| Gemini
    FEComp -->|"HTTP_API"| LLM
    FEComp -->|"HTTP_API"| User

    %% Backend Modules accessing the Database Module
    Auth -->|"Prisma_call"| DBModule
    Doc -->|"Prisma_call"| DBModule
    Gemini -->|"Prisma_call"| DBModule
    LLM -->|"Prisma_call"| DBModule
    User -->|"Prisma_call"| DBModule

    %% Database Module uses PostgreSQL via ORM
    DBModule -->|"ORM"| DB

    %% Backend External Integrations
    Doc -->|"OCR_call"| Tesseract
    Gemini -->|"Gemini_call"| GeminiAPI
    User -->|"Supabase_int"| Supabase

    %% Deployment links
    Vercel --- FE
    Railway --- DBModule

    %% Click Events
    click FE "https://github.com/arthurluis/case-paggo/tree/master/frontend"
    click Auth "https://github.com/arthurluis/case-paggo/tree/master/backend/src/auth"
    click Doc "https://github.com/arthurluis/case-paggo/tree/master/backend/src/document"
    click Gemini "https://github.com/arthurluis/case-paggo/tree/master/backend/src/gemini"
    click LLM "https://github.com/arthurluis/case-paggo/tree/master/backend/src/llm-response"
    click User "https://github.com/arthurluis/case-paggo/tree/master/backend/src/user"
    click DBModule "https://github.com/arthurluis/case-paggo/tree/master/backend/src/database"
    click DB "https://github.com/arthurluis/case-paggo/tree/master/backend/prisma"
    click Tesseract "https://github.com/arthurluis/case-paggo/tree/master/backend/tessdata"

    %% Styles
    classDef frontend fill:#8ec0ff,stroke:#2c3e50,stroke-width:2px,color:#2c3e50;
    classDef backend fill:#b2f7ef,stroke:#2c3e50,stroke-width:2px,color:#2c3e50;
    classDef database fill:#a3e635,stroke:#2c3e50,stroke-width:2px,color:#2c3e50;
    classDef external fill:#fcd34d,stroke:#2c3e50,stroke-width:2px,color:#2c3e50;
    classDef deployment fill:#e0aaff,stroke:#2c3e50,stroke-width:2px,color:#2c3e50;
```
