# davguifer/code-cook architecture

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

- Interactive diagram: https://gitdiagram.com/davguifer/code-cook
- Repository: https://github.com/davguifer/code-cook

## Overview

##### Main System Components
- Frontend: The user interface built with Bootstrap, driven by Django templates (the HTML files in the recipes/templates/ and recommendation/templates/ directories).
- Backend (Django Application): The central component including:
- Core Django configuration (settings.py, urls.py, wsgi.py, asgi.py) for the overall application routing and server configuration.
- The "recipes" app – responsible for handling recipe data, including models, views, URL routing, and template rendering.
- The "recommendation" app – which contains logic for calculating and serving recommendations (with utility functions using Scikit-learn to compute TF-IDF and cosine similarity).
- Data Extraction Component: A script/process using Beautiful Soup and Requests that crawls BBC Good Food to extract recipe data.
- Search Indexing Module: Integration of Whoosh via the recipes/whoosh_config module that provides fast search and filtering functionalities.
- Database: Likely SQLite (although configurable in settings.py), which stores recipes, recommendation data, and user-related information.

##### Relationships and Data Flows
- User Interaction: A web browser sends HTTP requests that hit Django’s URL routing.
- Request Handling: Django views handle requests for recipe searches, loading data, and showing recommendations.
- Data Management: Views interact with Django models stored in the database (including both recipe and recommendation models).
- External Data Flow: A background process or a management command triggers the Beautiful Soup scraping module, which populates the database with fresh recipes.
- Search Feature: Once data is loaded, Whoosh indexes the recipe data. When a user performs a search (e.g., by title or cooking time), the application interacts with the Whoosh index to quickly fetch results.
- Recommendation Flow: When a recipe detail is viewed, the application relies on the precomputed TF-IDF based recommendation engine (using Scikit-learn) to display similar recipes.

##### Architectural Patterns and Technologies
- External integration points are important:
- How Beautiful Soup functions as a scraping tool.
- The Whoosh search index acting as a dedicated search engine.
- Scikit-learn’s role in the recommendation engine.
- That the system precomputes recommendations, which are then saved in the database for efficient lookups.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        Browser["Web Browser"]:::browser
        RT["Recipes Templates"]:::frontend
        REC_T["Recommendation Templates"]:::frontend
    end

    subgraph "Application Layer"
        URL["Django URL Routing"]:::routing
        DP["Project Entry"]:::backend
        DCC["Django Core Configuration"]:::backend
        RA["Recipes App"]:::app
        RM["Recipes Migrations"]:::migrations
        REC["Recommendation App"]:::app
        REC_M["Recommendation Migrations"]:::migrations
        DES["Data Extraction Module (BeautifulSoup Scraping)"]:::scraper
    end

    subgraph "Data Layer"
        DB["Database (SQLite)"]:::database
        WI["Whoosh Index"]:::search
    end

    %% Data Flow Arrows
    Browser -->|"sendsHTTPRequest"| URL
    URL -->|"routesRequest"| DCC
    DP -->|"loads"| DCC
    DCC -->|"dispatches"| RA
    DCC -->|"dispatches"| REC
    RA -->|"rendersHTML"| RT
    REC -->|"rendersHTML"| REC_T
    RA -->|"reads/writes"| DB
    REC -->|"reads/writes"| DB
    RA -->|"indexesData"| WI
    WI -->|"fetchesResults"| RA
    DES -->|"scrapesAndPopulates"| DB
    REC -->|"calculatesRecommendations"| DB

    %% Click Events
    click RT "https://github.com/davguifer/code-cook/tree/main/code_cook_project/code_cook_project/recipes/templates/"
    click REC_T "https://github.com/davguifer/code-cook/tree/main/code_cook_project/code_cook_project/recommendation/templates/"
    click DCC "https://github.com/davguifer/code-cook/blob/main/code_cook_project/code_cook_project/code_cook_project/settings.py"
    click DP "https://github.com/davguifer/code-cook/blob/main/code_cook_project/code_cook_project/manage.py"
    click RA "https://github.com/davguifer/code-cook/tree/main/code_cook_project/code_cook_project/recipes/"
    click RM "https://github.com/davguifer/code-cook/tree/main/code_cook_project/code_cook_project/recipes/migrations/"
    click REC "https://github.com/davguifer/code-cook/tree/main/code_cook_project/code_cook_project/recommendation/"
    click REC_M "https://github.com/davguifer/code-cook/tree/main/code_cook_project/code_cook_project/recommendation/migrations/"
    click WI "https://github.com/davguifer/code-cook/tree/main/code_cook_project/code_cook_project/recipes/whoosh_config/"

    %% Styles
    classDef browser fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef frontend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef routing fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef backend fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef app fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef migrations fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef scraper fill:#ffeeba,stroke:#856404,stroke-width:2px;
    classDef database fill:#ffffff,stroke:#343a40,stroke-width:2px;
    classDef search fill:#d6d8d9,stroke:#1b1e21,stroke-width:2px;
```
