# kaushikjaincodes/hackathon-backend architecture

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

- Interactive diagram: https://gitdiagram.com/kaushikjaincodes/hackathon-backend
- Repository: https://github.com/kaushikjaincodes/hackathon-backend

## Overview

##### Main components
- API Layer (Frontend Gateway): Represented by the FastAPI server. Here, the “routers” directory contains modules for endpoints (chat, loan, request, users) which act as entry points for client requests.
- Business Logic Layer: This includes:
- The “services” directory, which contains distinct services such as:
▪ Bureau Service – for credit score normalization.
▪ LLM Service – which integrates with the Llama 8B model for AI-based report generation.
▪ Supabase Service – for interacting with your PostgreSQL/Supabase database.
- The “prompts” directory, where various AI prompt templates are maintained (e.g., ais_prompt, bank_statement, chat_prompt, credit_score_prompt) to tailor input to the AI model.
- Configuration and Utility Components:
- “app/config/settings.py” for configuration settings.
- “app/utils/pdf_reader.py” for reading PDF files, likely used for processing documents.
- Data Persistence: While not shown as explicit directories, your README specifies integration with PostgreSQL and Supabase, indicating a database layer that supports data storage.

##### Relationships and interactions
- Each endpoint then interacts with the corresponding service components. For example, the “loan” router would call the Bureau and LLM services to process and generate loan assessment reports.
- The prompt templates feed into the LLM service for generating AI-powered recommendations. Indicate this connection by linking the prompts component to the LLM service.
- The Supabase service is responsible for database interactions (e.g., storing normalized credit scores, conversation logs, etc.).
- The configuration component (settings.py) essentially underpins the initialization of these services, so a connection from “config” to each major component should be visible.
- Any file utilities (like the PDF reader) should be shown as support services that process input documents which might eventually feed into the overall workflow.

##### Architectural patterns and design principles
- The application follows a layered architecture – clearly separating the API (routers), business logic (services, prompts), and configuration/utilities.
- There is a modular design where each functional concern (credit score normalization, AI-based loan assessment, chat functionality) is encapsulated within its own module.
- Integration points with external services such as external credit bureaus and the database (Supabase/PostgreSQL).

##### Relevant technologies
- FastAPI as the backend framework managing the HTTP layer.
- Llama 8B AI model integrated via the LLM service.
- Supabase/PostgreSQL for persistent data storage.
- Python and PDM for dependency management & application setup.

##### Final checklist for the principal software engineer
- As many details as possible to reflect the real interactions and modular structure of the project – do not hesitate to break down high-level components further (for example, separate out individual routers or services if needed).

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client
    Client["Client Request"]

    %% API Layer: Routers
    subgraph "API Endpoints"
        Chat["Chat Router"]:::api
        Loan["Loan Router"]:::api
        Request["Request Router"]:::api
        Users["Users Router"]:::api
    end

    %% Business Logic Layer: Services
    subgraph "Business Logic: Services"
        Bureau["Bureau Service"]:::services
        LLM["LLM Service"]:::services
        Supabase["Supabase Service"]:::services
    end

    %% Business Logic Layer: Prompts Templates
    subgraph "Prompts Templates"
        Ais["ais_prompt"]:::prompts
        Bank["bank_statement"]:::prompts
        ChatPrompt["chat_prompt"]:::prompts
        CreditPrompt["credit_score_prompt"]:::prompts
    end

    %% Configuration & Utilities
    subgraph "Configuration & Utilities"
        Config["Configuration (settings.py)"]:::config
        PDF["PDF Utility (pdf_reader.py)"]:::config
    end

    %% External Systems
    subgraph "External Systems"
        ExternalCredit["External Credit Bureaus"]:::external
        ExternalAI["Llama 8B AI Model"]:::external
        DB["Database (PostgreSQL/Supabase)"]:::external
    end

    %% Connections from Client to Routers
    Client -->|"request"| Chat
    Client -->|"request"| Loan
    Client -->|"request"| Request
    Client -->|"request"| Users

    %% Routers to Services interactions
    Chat -->|"calls_LLM"| LLM
    Loan -->|"calls_Bureau"| Bureau
    Loan -->|"calls_LLM"| LLM
    Request -->|"calls_DB"| Supabase
    Users -->|"calls_DB"| Supabase

    %% Services interactions with External Systems
    Bureau -->|"normalizes"| ExternalCredit
    LLM -->|"generates_report"| ExternalAI
    Supabase -->|"interacts_with"| DB

    %% Prompts to LLM Service
    Ais -->|"supplies_prompt"| LLM
    Bank -->|"supplies_prompt"| LLM
    ChatPrompt -->|"supplies_prompt"| LLM
    CreditPrompt -->|"supplies_prompt"| LLM

    %% Configuration supports Services and Prompts
    Config -->|"configures"| Bureau
    Config -->|"configures"| LLM
    Config -->|"configures"| Supabase
    Config -->|"configures"| Ais
    Config -->|"configures"| Bank
    Config -->|"configures"| ChatPrompt
    Config -->|"configures"| CreditPrompt

    %% PDF Utility supports document processing
    PDF -->|"processes_docs"| Bureau

    %% Click Events for Routers
    click Chat "https://github.com/kaushikjaincodes/hackathon-backend/blob/main/app/routers/chat.py"
    click Loan "https://github.com/kaushikjaincodes/hackathon-backend/blob/main/app/routers/loan.py"
    click Request "https://github.com/kaushikjaincodes/hackathon-backend/blob/main/app/routers/request.py"
    click Users "https://github.com/kaushikjaincodes/hackathon-backend/blob/main/app/routers/users.py"

    %% Click Events for Services
    click Bureau "https://github.com/kaushikjaincodes/hackathon-backend/blob/main/app/services/bureau.py"
    click LLM "https://github.com/kaushikjaincodes/hackathon-backend/blob/main/app/services/llm.py"
    click Supabase "https://github.com/kaushikjaincodes/hackathon-backend/blob/main/app/services/supabase.py"

    %% Click Events for Prompts Templates
    click Ais "https://github.com/kaushikjaincodes/hackathon-backend/blob/main/app/prompts/ais_prompt.py"
    click Bank "https://github.com/kaushikjaincodes/hackathon-backend/blob/main/app/prompts/bank_statement.py"
    click ChatPrompt "https://github.com/kaushikjaincodes/hackathon-backend/blob/main/app/prompts/chat_prompt.py"
    click CreditPrompt "https://github.com/kaushikjaincodes/hackathon-backend/blob/main/app/prompts/credit_score_prompt.py"

    %% Click Events for Config & Utilities
    click Config "https://github.com/kaushikjaincodes/hackathon-backend/blob/main/app/config/settings.py"
    click PDF "https://github.com/kaushikjaincodes/hackathon-backend/blob/main/app/utils/pdf_reader.py"

    %% Styles
    classDef api fill:#f9c,stroke:#333,stroke-width:2px;
    classDef services fill:#bbf,stroke:#333,stroke-width:2px;
    classDef prompts fill:#cfc,stroke:#333,stroke-width:2px;
    classDef config fill:#fcf,stroke:#333,stroke-width:2px;
    classDef external fill:#eee,stroke:#333,stroke-width:2px;
```
