# omiras/fototeca-uf1844-ironhack-2025 architecture

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

- Interactive diagram: https://gitdiagram.com/omiras/fototeca-uf1844-ironhack-2025
- Repository: https://github.com/omiras/fototeca-uf1844-ironhack-2025

## Overview

##### Project Type and Purpose
- Fototeca UF1844 is a small server-rendered full-stack web application built with Node.js, Express and EJS.
- It serves HTML views, supports an AJAX URL-check endpoint, and uses an in‐memory array as its “database.”

##### File Structure
- index.js – the Express server entrypoint, defines routes, middleware (morgan) and holds the in-memory image array.
- views/ – EJS templates (home, add-image form, 404) plus a shared navbar partial.
- No external “public” folder is shown, so static assets (PicoCSS) likely come from a CDN.

##### Key Architectural Patterns
- MVC-style separation:
– Model: in-memory JavaScript array
– View: EJS templates in views/
– Controller: route handlers in index.js
- Middleware pipeline (Express + morgan + body-parser + static assets from CDN)
- RESTful/ AJAX endpoint for URL uniqueness check

##### Main Components
1. Client Browser
– Requests HTML from endpoints `/`, `/new-image`.
– Sends AJAX GET to `/check-url`.
– Submits POST form to `/new-image`.
2. Express Application (Node.js)
– HTTP Server
– Middleware stack (morgan logger, express.json/urlencoded, static‐asset loader if any)
– Router with three main routes:
- GET `/` → renders home.ejs (gallery)
- GET `/new-image` → renders add-image.ejs
- POST `/new-image` → appends to in-memory array
- GET `/check-url` → searches array, returns JSON
– EJS View Engine (renders templates + partials)
3. In-Memory Data Store
– A simple JavaScript array of image objects { title, description, url } (resets on restart)
4. External Services
– PicoCSS CDN (delivers CSS)
– Optional: Browser’s DevTools/Network for AJAX logging

##### Relationships and Data Flows
- Express → EJS Engine → HTML → back to Client.

##### Essential Elements
- Component labels (Client, Express Server, EJS Engine, In-Memory Store, CDN)
- Middleware flow (morgan, body-parser)
- Routes and their responsibilities

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client Browser"]:::client

    %% External Services
    PicoCSS["PicoCSS CDN"]:::external

    %% Server Components
    subgraph "Express Server"
        direction TB
        Morgan["morgan Logger"]:::server
        BodyParser["body-parser & express.json/urlencoded"]:::server
        Router["Router (index.js)"]:::server
        EjsEngine["EJS View Engine"]:::server
    end

    %% In-Memory Store
    Store["In-Memory Store\n(JavaScript Array)"]:::store

    %% View Layer
    subgraph "View Layer"
        direction TB
        ViewsDir["views/"]:::view
        Home["home.ejs"]:::view
        AddForm["add-image.ejs"]:::view
        Error404["404.ejs"]:::view
        Navbar["partials/navbar.ejs"]:::view
    end

    %% Documentation & Config
    Docs["README.md"]:::external
    PackageJSON["package.json"]:::external
    PackageLock["package-lock.json"]:::external
    GitIgnore[".gitignore"]:::external

    %% Flows
    Client -->|"GET / or /new-image\nPOST /new-image"| Morgan
    Morgan --> BodyParser
    BodyParser --> Router
    Router -->|"Render View"| EjsEngine
    EjsEngine --> Client
    Router -->|"Read/Write Images"| Store
    Client -->|"AJAX GET /check-url"| Morgan
    Morgan --> Router
    Router -->|"Return JSON"| Client
    Client -->|"GET CSS"| PicoCSS

    %% View Rendering Links
    EjsEngine --> ViewsDir
    ViewsDir --> Home
    ViewsDir --> AddForm
    ViewsDir --> Error404
    ViewsDir --> Navbar

    %% Click Events
    click Router "https://github.com/omiras/fototeca-uf1844-ironhack-2025/blob/main/index.js"
    click ViewsDir "https://github.com/omiras/fototeca-uf1844-ironhack-2025/tree/main/views/"
    click Home "https://github.com/omiras/fototeca-uf1844-ironhack-2025/blob/main/views/home.ejs"
    click AddForm "https://github.com/omiras/fototeca-uf1844-ironhack-2025/blob/main/views/add-image.ejs"
    click Error404 "https://github.com/omiras/fototeca-uf1844-ironhack-2025/blob/main/views/404.ejs"
    click Navbar "https://github.com/omiras/fototeca-uf1844-ironhack-2025/blob/main/views/partials/navbar.ejs"
    click PackageJSON "https://github.com/omiras/fototeca-uf1844-ironhack-2025/blob/main/package.json"
    click PackageLock "https://github.com/omiras/fototeca-uf1844-ironhack-2025/blob/main/package-lock.json"
    click Docs "https://github.com/omiras/fototeca-uf1844-ironhack-2025/blob/main/README.md"
    click GitIgnore "https://github.com/omiras/fototeca-uf1844-ironhack-2025/blob/main/.gitignore"

    %% Styles
    classDef server fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef store fill:#d4edda,stroke:#333,stroke-width:1px
    classDef external fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef view fill:#e2e3e5,stroke:#333,stroke-width:1px
    classDef client fill:#f0f0f0,stroke:#333,stroke-width:1px
```
