# dakshesh14/anukool architecture

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

- Interactive diagram: https://gitdiagram.com/dakshesh14/anukool
- Repository: https://github.com/dakshesh14/anukool

## Overview

##### Project Type and Purpose
- This is a single-page, AI-powered web application designed to help job seekers generate customized cover letters.
- The project leverages FastAPI as its backend framework and uses AI models (by default OpenAI’s or alternatively a local Llama-2 model) to craft cover letter content.
- The application includes components for PDF ingestion, template-based HTML rendering, and dynamic interactions via static assets (JS and CSS).

##### Analyzing the File Structure
- Top-level files like main.py and ingest.py indicate entry points for the web server and for preparing document data.
- The presence of a data_model folder (with query.py and an __init__.py) suggests a module responsible for managing data queries or interactions.
- Helper modules (helper.py, constants.py) indicate utility functions and constant definitions that support the application's core logic.
- The templates folder contains HTML files (including those for PDF output) that serve as the frontend’s view layer.
- The static folder houses CSS, JavaScript, and image resources which are critical for the client-side presentation.
- The .env.example file and requirements.txt indicate that environment configuration and dependency management are important parts of the deployment process.

##### Key Components to Highlight
a. Frontend:
- User Interface: Represented by the HTML templates (templates/index.html, templates/pdf/cover_letter.html) and static assets (CSS, JS, images). This component handles user interaction in the browser.

b. Backend:
- Ingest Module: ingest.py manages the ingestion of PDFs into the system. This should be depicted as a separate process/module that integrates with data sources.
- Data Model and Helper Layers: Group data_model (with its query capabilities) and helper.py (along with constants.py). This layer provides business logic, query processing, and abstraction over raw data.
- Environment Configuration: Show .env (populated from .env.example) to indicate that runtime configuration (like selecting the AI model or providing API tokens) influences backend behavior.

c. AI and Model Integration:
- External AI Service: Represent the integration with OpenAI’s API (by default) or a local Llama-2 model (when configured). Highlight that the choice is driven by the MODEL_NAME variable in the environment and model files downloaded into a “models” folder (note: although the file tree does not show a models folder, the README mentions that one should be created/populated as needed).
- LangChain Integration: Include this as part of the processing pipeline that might orchestrate interactions between the backend and the AI model.

##### Interactions and Data Flow
- The FastAPI backend processes the request (using main.py), possibly invoking functions in helper.py or modules in data_model.
- If the user triggers cover letter generation or PDF creation, the backend module assembles the content, calls the external AI service using either OpenAI or the locally served Llama-2 model (as determined by the environment configuration).
- Data returned from the AI service is passed back to the backend, which then renders HTML templates (located in the templates folder) or produces a generated PDF.
- Finally, the response (HTML page or downloadable PDF) is sent back to the client.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The system is modular, clearly separating the UI (templates/static), application logic (FastAPI and helper modules), and external integrations (AI model services).
- Configurability: With environment variables handling model selection and API tokens, the design allows dynamic behavior based on deployment (local model vs. external API).
- Extensibility: The clear structure (with distinct data_model and ingestion modules) suggests that future additions (like new data sources or functionalities) can be added without major refactoring.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        WC("Web Client (Browser)"):::frontend
        IT("HTML Template: Index"):::frontend
        PT("HTML Template: Cover Letter"):::frontend
        SA("Static Assets"):::frontend
    end

    subgraph "Server Layer"
        FAPI("FastAPI Backend"):::backend
        IM("Ingestion Module"):::backend
        subgraph "Business Logic"
            DM("Data Model"):::backend
            HM("Helper Module"):::backend
        end
        EC("Environment Config"):::config
    end

    subgraph "AI Integration Layer"
        ExtAI("External AI Service (OpenAI)"):::ai
        LocAI("Local Model (Llama-2)"):::ai
        LC("LangChain"):::ai
    end

    %% Flow from Client to Server
    WC -->|"HTTP_Request"| FAPI

    %% Server internal processing
    FAPI -->|"Call_Ingestion"| IM
    FAPI -->|"Process_Data"| DM
    FAPI -->|"Process_Data"| HM
    EC -- "config" --> FAPI

    %% AI Service Integration
    FAPI -->|"Model_Request"| ExtAI
    FAPI -->|"Model_Request"| LocAI
    FAPI -->|"Orchestrate"| LC
    ExtAI -->|"Model_Response"| FAPI
    LocAI -->|"Model_Response"| FAPI
    LC -->|"Processed_Response"| FAPI

    %% Rendering HTML for client
    FAPI -->|"Render_HTML"| IT
    FAPI -->|"Render_HTML"| PT
    IT -->|"Serve_Page"| WC
    PT -->|"Serve_Download"| WC

    %% Static Assets used by Web Client
    SA --> WC

    %% Click Events for Component Mapping
    click IT "https://github.com/dakshesh14/anukool/blob/main/templates/index.html"
    click PT "https://github.com/dakshesh14/anukool/blob/main/templates/pdf/cover_letter.html"
    click SA "https://github.com/dakshesh14/anukool/tree/main/static"
    click FAPI "https://github.com/dakshesh14/anukool/blob/main/main.py"
    click IM "https://github.com/dakshesh14/anukool/blob/main/ingest.py"
    click DM "https://github.com/dakshesh14/anukool/blob/main/data_model/__init__.py"
    click DM "https://github.com/dakshesh14/anukool/blob/main/data_model/query.py"
    click HM "https://github.com/dakshesh14/anukool/blob/main/helper.py"
    click HM "https://github.com/dakshesh14/anukool/blob/main/constants.py"
    click EC "https://github.com/dakshesh14/anukool/blob/main/.env.example"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#0056b3,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef config fill:#fff3cd,stroke:#ffecb5,stroke-width:2px;
    classDef ai fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
```
