# diegcard/arep_taller_1 architecture

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

- Interactive diagram: https://gitdiagram.com/diegcard/arep_taller_1
- Repository: https://github.com/diegcard/arep_taller_1

## Overview

##### Project Type and Purpose
- This is a lightweight full-stack HTTP server implemented from scratch in pure Java.
- It serves two main roles:
- Static web front-end (HTML/CSS/JS) for a demo interface
- REST API endpoints (/api/hello, /api/weather, /api/quote)

##### Top-Level Components
1. Client (Browser)
- Loads index.html, styles.css, app.js
- Makes HTTP requests to static assets and REST endpoints via JavaScript
2. HttpServer (Java Application on port 35000)
Internally subdivided into:
a. Connection Listener
- Accepts incoming TCP connections
b. Request Parser & Router
- Parses HTTP/1.1 requests
- Routes to either Static File Service or API Service
c. Static File Service
- MIME Type Detector (maps extensions to Content-Type)
- Cache Manager (in-memory file cache)
- File System Reader (serves files from src/main/resources/static/)
d. API Service
- Handles endpoints:
- GET /api/hello?name={name}
- GET /api/weather
- GET /api/quote
- Builds JSON responses
e. Response Writer
- Constructs HTTP responses with status, headers, body
3. File System / Resource Store
- src/main/resources/static (HTML, CSS, JS, images)
4. Tests
- HttpServerTest.java validating parser, mime detection, endpoints, error cases

##### Relationships & Data Flows
- Client → HttpServer (HTTP request)
- Branch in server:
– If request path begins “/api/” → API Service → Response Writer → Client
– Else → Static File Service (Cache → File System) → Response Writer → Client
- Static File Service ↔ Cache Manager ↔ File System
- Request Parser → Router → Appropriate handler

##### Architectural Patterns & Principles
- Single-process, single-port HTTP server
- Modular internal layering (Listener → Parser → Router → Handler → Writer)
- Separation of concerns: static vs. dynamic content
- In-memory caching to improve static file performance
- No external frameworks (zero dependencies)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Client (Browser)"]:::frontend
    click Client "https://github.com/diegcard/arep_taller_1/tree/main/src/main/resources/static"

    %% HttpServer Container
    subgraph "HttpServer (Java, port 35000)" 
        direction TB
        Listener["Connection Listener"]:::java
        ParserRouter["Request Parser & Router"]:::java
        subgraph "Static File Service" 
            direction TB
            MIME["MIME Type Detector"]:::java
            Cache["Cache Manager"]:::java
            FSReader["File System Reader"]:::java
        end
        subgraph "API Service" 
            direction TB
            APIHello["GET /api/hello"]:::api
            APIWeather["GET /api/weather"]:::api
            APIQuote["GET /api/quote"]:::api
        end
        Writer["Response Writer"]:::java
    end
    click Listener "https://github.com/diegcard/arep_taller_1/blob/main/src/main/java/com/escuelaing/arep/HttpServer.java"
    click ParserRouter "https://github.com/diegcard/arep_taller_1/blob/main/src/main/java/com/escuelaing/arep/HttpServer.java"
    click MIME "https://github.com/diegcard/arep_taller_1/blob/main/src/main/java/com/escuelaing/arep/HttpServer.java"
    click Cache "https://github.com/diegcard/arep_taller_1/blob/main/src/main/java/com/escuelaing/arep/HttpServer.java"
    click FSReader "https://github.com/diegcard/arep_taller_1/blob/main/src/main/java/com/escuelaing/arep/HttpServer.java"
    click APIHello "https://github.com/diegcard/arep_taller_1/blob/main/src/main/java/com/escuelaing/arep/HttpServer.java"
    click APIWeather "https://github.com/diegcard/arep_taller_1/blob/main/src/main/java/com/escuelaing/arep/HttpServer.java"
    click APIQuote "https://github.com/diegcard/arep_taller_1/blob/main/src/main/java/com/escuelaing/arep/HttpServer.java"
    click Writer "https://github.com/diegcard/arep_taller_1/blob/main/src/main/java/com/escuelaing/arep/HttpServer.java"

    %% File System
    FileSystem["Static Assets Folder"]:::storage
    click FileSystem "https://github.com/diegcard/arep_taller_1/tree/main/src/main/resources/static"
    Index["index.html"]:::asset
    Styles["styles.css"]:::asset
    AppJS["app.js"]:::asset
    click Index "https://github.com/diegcard/arep_taller_1/blob/main/src/main/resources/static/index.html"
    click Styles "https://github.com/diegcard/arep_taller_1/blob/main/src/main/resources/static/styles.css"
    click AppJS "https://github.com/diegcard/arep_taller_1/blob/main/src/main/resources/static/app.js"

    %% Test Suite
    Test["HttpServerTest.java"]:::test
    click Test "https://github.com/diegcard/arep_taller_1/blob/main/src/test/java/com/escuelaing/arep/HttpServerTest.java"

    %% Data Flows
    Client -->|"HTTP/1.1 request"| Listener
    Listener --> ParserRouter
    ParserRouter -->|"/api/*"| APIHello
    ParserRouter -->|"/api/*"| APIWeather
    ParserRouter -->|"/api/*"| APIQuote
    ParserRouter -->|"static request"| MIME
    MIME --> Cache
    Cache --> FSReader
    FSReader --> Writer
    APIHello --> Writer
    APIWeather --> Writer
    APIQuote --> Writer
    Writer -->|"HTTP response"| Client

    %% Static asset links
    Client -->|"loads HTML/CSS/JS"| Index
    Client --> Styles
    Client --> AppJS

    %% Styles
    classDef java fill:#D6EAF8,stroke:#21618C,color:#1B2631
    classDef api fill:#AED6F1,stroke:#1B4F72,color:#1B2631
    classDef storage fill:#D5F5E3,stroke:#1D8348,color:#1B2631
    classDef asset fill:#A9DFBF,stroke:#196F3D,color:#1B2631
    classDef frontend fill:#F9E79F,stroke:#B9770E,color:#1B2631
    classDef test fill:#FADBD8,stroke:#943126,color:#1B2631
```
