# Red Head

A web application that displays Reddit posts from an archive.

## Project Structure

```
.
├── Dockerfile          # Docker configuration for the Python backend
├── docker-compose.yml  # Docker Compose configuration
├── .gitignore          # Git ignore rules
├── README.md           # This file
├── src/
│   ├── server/         # Python Flask backend
│   │   ├── app.py          # Main Flask application
│   │   ├── parse_archive.py # Archive parsing logic
│   │   ├── requirements.txt # Python dependencies
│   │   ├── sample_posts.json # Sample data
│   │   └── test_parse_archive.py # Tests
│   └── website/        # Frontend files
│       ├── app.js          # JavaScript logic
│       ├── index.html      # Main HTML file
│       ├── Reddit_Logo.webp # Logo image
│       └── styles.css      # CSS styling
└── website/            # Additional website files
    └── cache/          # Cache directory
```

## Docker Setup

### Prerequisites

- Docker Engine installed
- Docker Compose installed

### Running the Application

1. **Build and start the containers:**
   ```bash
   docker-compose up --build
   ```

2. **Run in detached mode:**
   ```bash
   docker-compose up -d
   ```

3. **Stop the containers:**
   ```bash
   docker-compose down
   ```

### Environment Variables

The application uses the following environment variables:

- `ARCHIVE_DIR`: Path to the archive directory (default: `/app/archive`)
- `FLASK_ENV`: Flask environment (default: `production`)

### Ports

- **6006**: Main application port (Flask server)

### Volumes

The following volumes are mounted for development:

- `./src/server` → `/app/src/server`
- `./src/website` → `/app/website`
- `./website/cache` → `/app/website/cache`

## Development

### Making Changes

1. **Modify source code** in the `src/` directory
2. **Docker will automatically reload** the application
3. **Access the application** at `http://localhost:6006`

### Testing

To test the Docker setup:

```bash
# Build the images
docker-compose build

# Start the containers
docker-compose up -d

# Check container status
docker-compose ps

# View logs
docker-compose logs app

# Stop containers
docker-compose down
```

## API Endpoints

- `GET /posts` - Get first 10 posts for initial load
- `GET /posts/more?count=N` - Get next 10 posts, starting from index N
- `GET /posts/total` - Get total number of posts available
- `GET /` - Server status endpoint

## Architecture

The application consists of:

1. **Python Flask Backend** (`src/server/`)
   - Serves API endpoints
   - Handles archive parsing
   - Serves static frontend files

2. **Frontend** (`src/website/`)
   - HTML, CSS, and JavaScript
   - Fetches data from the backend API
   - Implements infinite scrolling

## Dependencies

### Python Dependencies (from `src/server/requirements.txt`):
- Flask
- Flask-CORS
- Pillow
- beautifulsoup4
- requests

### Frontend Dependencies:
- None (pure HTML/CSS/JavaScript)

## License

This project is licensed under the MIT License.