# nietocurcio/cs50-final-project architecture

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

- Interactive diagram: https://gitdiagram.com/nietocurcio/cs50-final-project
- Repository: https://github.com/nietocurcio/cs50-final-project

## Overview

##### Main Components
- Web Server / Application Layer:
- Files: application.py and login.py contain the core Flask routes and business logic.
- Frontend:
- Templates: HTML files (layout.html, index.html, adopt.html, login.html, recordsDonation.html, register.html) represent different web pages.
- Static Assets: stylesheets (static/styles.css) and static images (in static/images and static/images/users) are used to display the site’s visual content.
- Database Layer:
- The SQLite database (dogscats.db as described in the README) accessed via Flask-SQLAlchemy.
- Tables: users, cases, and selectedcases with defined relationships (e.g., foreign keys between users and cases).
- File Management:
- Handling of file uploads using Flask-WTF, ensuring image filenames are validated and stored safely (into static/images/users).

##### Relationships and Interactions
- The Frontend (client-side) sends HTTP requests to the backend.
- The Flask application receives these requests (from application.py and login.py), processes the business logic, and interacts with the database through SQLAlchemy.
- File uploads (e.g., pet images) are processed, validated, and saved to the filesystem (static/images/users), while their metadata (the filename) is stored in the database.
- After processing, Flask renders the appropriate HTML templates (from the templates folder) and sends an HTTP response back to the client.
- The database holds all user records, donation cases, and relationships (selectedcases) and is accessed for creating, reading, updating, and deleting records.

##### Architectural Patterns
- MVC (Model-View-Controller) Pattern:
- The ‘Model’ is represented by the SQLAlchemy models (even if not explicitly named as such, they are created via SQLAlchemy in the application).
- The ‘View’ is constructed via HTML templates.
- The ‘Controller’ aspect is handled in the Flask routes defined in application.py and login.py.
- Separation of Concerns:
- Frontend (templates, static resources) is cleanly separated from backend logic (Python scripts).
- Database interactions are centralized via Flask-SQLAlchemy.

##### Technologies and Frameworks
- Python, Flask, Flask-SQLAlchemy, Flask-WTF, and SQLite.
- HTML/CSS for client-side presentation.
- sqlite3 for database management.

##### Final Advice
- On potential extensions by including any external libraries (Flask-WTF for file handling, etc.) that add value to the architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        subgraph "Templates"
            T1["layout.html"]:::template
            T2["index.html"]:::template
            T3["adopt.html"]:::template
            T4["login.html"]:::template
            T5["recordsDonation.html"]:::template
            T6["register.html"]:::template
        end
        subgraph "Static Assets"
            SA1["CSS: styles.css"]:::static
            SA2["Images Directory"]:::static
        end
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B1["application.py"]:::backend
        B2["login.py"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["SQLite: dogscats.db<br/>(users, cases, selectedcases)"]:::database
    end

    %% File System for Uploaded Images
    subgraph "File System"
        FS["Uploaded Images Directory"]:::filesystem
    end

    %% Interactions
    %% Frontend to Backend (HTTP Requests)
    T1 -- "HTTPRequest" --> B1
    T2 -- "HTTPRequest" --> B1
    T3 -- "HTTPRequest" --> B1
    T4 -- "HTTPRequest" --> B1
    T5 -- "HTTPRequest" --> B1
    T6 -- "HTTPRequest" --> B1
    SA1 -- "AssetLoad" --> B1
    SA2 -- "AssetLoad" --> B1

    %% Backend to Database (CRUD operations)
    B1 -- "CRUDops" --> DB
    B2 -- "CRUDops" --> DB

    %% Backend to File System (File Upload Process)
    B1 -- "FileUpload" --> FS
    B2 -- "FileUpload" --> FS

    %% Click Events for Backend Components
    click B1 "https://github.com/nietocurcio/cs50-final-project/blob/master/application.py"
    click B2 "https://github.com/nietocurcio/cs50-final-project/blob/master/login.py"

    %% Click Events for Templates
    click T1 "https://github.com/nietocurcio/cs50-final-project/blob/master/templates/layout.html"
    click T2 "https://github.com/nietocurcio/cs50-final-project/blob/master/templates/index.html"
    click T3 "https://github.com/nietocurcio/cs50-final-project/blob/master/templates/adopt.html"
    click T4 "https://github.com/nietocurcio/cs50-final-project/blob/master/templates/login.html"
    click T5 "https://github.com/nietocurcio/cs50-final-project/blob/master/templates/recordsDonation.html"
    click T6 "https://github.com/nietocurcio/cs50-final-project/blob/master/templates/register.html"

    %% Click Events for Static Assets
    click SA1 "https://github.com/nietocurcio/cs50-final-project/blob/master/static/styles.css"
    click SA2 "https://github.com/nietocurcio/cs50-final-project/tree/master/static/images"

    %% Click Event for File System (Uploaded Images)
    click FS "https://github.com/nietocurcio/cs50-final-project/tree/master/static/images/users"

    %% Styles
    classDef frontend fill:#a2d2ff,stroke:#333,stroke-width:2px;
    classDef backend fill:#fcbf49,stroke:#333,stroke-width:2px;
    classDef database fill:#e0fbfc,stroke:#333,stroke-width:2px;
    classDef filesystem fill:#caffbf,stroke:#333,stroke-width:2px;
    classDef template fill:#bde0fe,stroke:#333,stroke-width:2px;
    classDef static fill:#ffc8dd,stroke:#333,stroke-width:2px;

    class T1,T2,T3,T4,T5,T6 template;
    class SA1,SA2 static;
    class B1,B2 backend;
    class DB database;
    class FS filesystem;
```
