How mrybs/slinn works
Project type and purpose
• Slinn is an open‑source Python HTTP/HTTPS server framework.
• It provides core classes to build simple web servers, handle requests, define filters/routers, and generate HTTP responses.
• It also includes a CLI entry point (slinn/__main__.py, manage.py in templates) and project/app scaffolding templates under slinn/templates.
File structure
• Top‑level:
• setup.py, README.md, LICENSE, CLI entry (slinn/__main__.py)
• slinn/ – framework package
• Inside slinn/:
• Core modules: server.py, dispatcher.py, request.py, http_response*.py, filter.py (+ specialized filters)
• Utility modules: address.py, file.py, utils.py
• Template scaffolds: templates/ (example, firstrun) and default/ (project bootstrap)
• Migration scripts: guides/migration1xx2xx.py
• Configuration:
• slinn/default/project.json – project‑level config
• slinn/templates/*/config.json – app‑level config
README for additional insights
• Describes the framework’s classes and functions (Server, Dispatcher, Address, Filter, HttpResponse variants).
• Shows how to bootstrap new projects or run standalone scripts.
• Explains CLI commands (slinn create, manage.py run, manage.py template).
Main components and their interactions
a. Components
1. CLI Interface
– slinn/__main__.py and manage.py scripts
– Commands: create project, run server, apply template
2. Server
– Server class listens on socket (uses Address)
– Accepts raw HTTP/HTTPS connections
3. Dispatcher
– Manages a registry of handlers annotated with filters
– Chooses the correct handler for each incoming Request
4. Request
– Parsed HTTP request object
– Contains headers, method, path, query args, cookies, files
5. Filters/Routing
– Filter, LinkFilter, AnyFilter define matching rules
– Applied in dispatcher to route to appropriate handler function
6. Response
– HttpResponse and subclasses (HttpRedirect, HttpJSONResponse, HttpJSONAPIResponse)
– Encapsulate payload, status, headers, cookies, produce raw HTTP response bytes
7. Utilities & Support
– Address for host/port resolution
– File wrapper for file uploads
– utils.py for shared helper functions
8. Templates & Scaffolding
– Provide default project/app structure (default/, templates/)
– JSON config files (project.json, config.json)
b. Relationships & data flows
1. Developer invokes CLI → scaffolds project or launches Server.
2. Server.listen(Address) opens socket and enters accept loop.
3. Incoming TCP connection → raw bytes passed to Server.
4. Server hands header/body to Request.parse_http_header / parse_http_body.
5. Completed Request object sent to Dispatcher.
6. Dispatcher iterates its registered handler list, using each Filter’s check() to match Request.
7. Matched handler function executes, returns an HttpResponse subclass.
8. Server calls response.make() to serialize to HTTP/2.0 (or HTTP/1.x) wire format.
9. Serialized response written back on the socket.
c. Architectural patterns & design principles
• Dispatcher + Filter pattern for routing.
• Modular separation: CLI, network I/O (Server), HTTP modeling (Request/Response), routing (Dispatcher/Filter), utilities.
• Template‑based scaffolding for project/app generation.
• Extensibility: add custom filters, middleware (could be introduced), response types.
d. Key technologies & libraries
• Python standard library: socket, json, re, ssl
• Packaging: setup.py for PyPI distribution
• No external dependencies
Detail without over‑engineering
• Core classes and their relationships.
• Where and how templates/config files plug into scaffolding.
• Avoid extraneous low‑level details (e.g., byte buffer sizes) unless relevant to the architecture.