README.md
md
# Seq Demo
A simple HTTP server written in [Seq](https://github.com/navicore/patch-seq), a concatenative stack-based programming language.
## What is Seq?
Seq is a stack-based language with:
- Static typing with row polymorphic stack effects
- LLVM compilation to native binaries
- CSP-style concurrency via green threads ("strands") and channels
- Built-in TCP networking primitives
## Quick Start
```bash
make run
```
Then visit http://localhost:5000
## Endpoints
| Route | Description |
|-------|-------------|
| `GET /` | Home page (static HTML) |
| `GET /health` | Health check |
| `GET /api/status` | JSON status |
| `GET /echo/:msg` | Echo message back |
## Commands
```bash
make build    # Build Docker image
make run      # Run in background
make run-fg   # Run in foreground
make stop     # Stop container
make logs     # View logs
make restart  # Rebuild and restart
make test     # Test endpoints
make clean    # Remove image
```
## Project Structure
```
seq-demo/
├── main.seq          # Seq HTTP server source
├── static/
│   ├── index.html    # Home page
│   └── 404.html      # Not found page
├── Dockerfile        # Multi-stage build
└── Makefile          # Build commands
```
## How It Works
The server uses Seq's native TCP primitives:
```seq
: main ( -- )
  8080 tcp-listen      # Listen on port
  accept-loop          # Accept connections
;
: accept-loop ( Int -- )
  dup tcp-accept       # Accept connection
  make-channel         # Create channel for worker
  dup [ worker ] spawn # Spawn green thread
  drop drop send       # Send connection to worker
  accept-loop          # Tail-recursive loop
;
```
Static files are loaded with `file-slurp`:
```seq
: serve-index ( -- String )
  "static/index.html" file-slurp http-html
;
```
## Architecture
```
┌─────────────────────────────────────┐
│           Docker Container          │
│                                     │
│  ┌─────────┐       ┌─────────────┐  │
│  │  socat  │──────▶│  seq-demo   │  │
│  │  :5000  │       │    :8080    │  │
│  └─────────┘       └─────────────┘  │
│       ▲                             │
└───────│─────────────────────────────┘
   External traffic
socat forwards external port 5000 to internal port 8080
(seq tcp-listen binds to localhost only)
```
## Requirements
- Docker
## License
MIT
No comments yet.