+
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/app/main.py b/docs/app/main.py
new file mode 100644
index 0000000..c351bf6
--- /dev/null
+++ b/docs/app/main.py
@@ -0,0 +1,387 @@
+import os
+import sys
+import re
+import mimetypes
+import urllib.parse
+import posixpath
+from http.server import HTTPServer, BaseHTTPRequestHandler
+import markdown
+
+# Configurable paths
+DOCS_ROOT = os.path.realpath(os.environ.get("DOCS_ROOT", "/docs"))
+PORT = int(os.environ.get("PORT", "8000"))
+
+# Read layout template
+TEMPLATE_PATH = os.path.join(os.path.dirname(__file__), 'layout.html')
+try:
+ with open(TEMPLATE_PATH, 'r', encoding='utf-8') as f:
+ TEMPLATE = f.read()
+except OSError:
+ print(f"Error: Could not read template from {TEMPLATE_PATH}", file=sys.stderr)
+ TEMPLATE = "{{ content }}"
+
+
+def is_safe_path(path):
+ """Ensure the path is within the DOCS_ROOT directory to prevent traversal."""
+ real_path = os.path.realpath(path)
+ return real_path == DOCS_ROOT or real_path.startswith(DOCS_ROOT + os.sep)
+
+
+def get_breadcrumbs(url_path):
+ """Generate beautiful navigation breadcrumbs."""
+ parts = [p for p in url_path.split('/') if p]
+ breadcrumbs_html = 'Home'
+
+ current_acc = ""
+ for i, part in enumerate(parts):
+ current_acc += f"/{part}"
+ breadcrumbs_html += ' / '
+ if i == len(parts) - 1:
+ breadcrumbs_html += f'{part}'
+ else:
+ breadcrumbs_html += f'{part}'
+
+ return breadcrumbs_html
+
+
+def build_tree(path):
+ """Recursively build a tree of folders and markdown files."""
+ items = []
+ try:
+ names = os.listdir(path)
+ except OSError:
+ return []
+
+ for name in names:
+ if name.startswith('.'):
+ continue
+ if name in ('node_modules', 'venv', '.git', '__pycache__', 'data'):
+ continue
+
+ full_path = os.path.join(path, name)
+ rel_path = os.path.relpath(full_path, DOCS_ROOT)
+
+ if os.path.isdir(full_path):
+ children = build_tree(full_path)
+ # Only list directory if it contains markdown files or subdirs with markdown files
+ if children:
+ items.append({
+ 'name': name,
+ 'type': 'dir',
+ 'rel_path': rel_path.replace(os.sep, '/'),
+ 'children': children
+ })
+ elif name.endswith('.md'):
+ url_name = name[:-3]
+ # Handle root readme differently or filter it
+ if url_name.lower() in ('readme', 'index') and rel_path == name:
+ # We skip showing root readme directly in sidebar tree to prevent clutter,
+ # as it is already mapped to the Home button.
+ continue
+
+ # Form clean url
+ url_path = os.path.splitext(rel_path)[0]
+ url = '/' + url_path.replace(os.sep, '/')
+
+ # If it's a subdirectory README, we want to link it to the folder URL
+ if url_name.lower() in ('readme', 'index'):
+ parent_dir = os.path.dirname(rel_path)
+ url = '/' + parent_dir.replace(os.sep, '/') if parent_dir else '/'
+ display_name = os.path.basename(parent_dir) if parent_dir else 'Home'
+ else:
+ display_name = url_name
+
+ items.append({
+ 'name': display_name,
+ 'type': 'file',
+ 'url': url,
+ 'rel_path': rel_path.replace(os.sep, '/')
+ })
+
+ # Sort folders first, then files
+ items.sort(key=lambda x: (0 if x['type'] == 'dir' else 1, x['name'].lower()))
+ return items
+
+
+def render_tree(tree, active_url):
+ """Render the built tree into HTML nested ul/details list."""
+ if not tree:
+ return ""
+
+ html = '
'
+ for item in tree:
+ if item['type'] == 'dir':
+ # Check if active URL is nested inside this directory
+ active_clean = active_url.lstrip('/')
+ is_open = active_clean.startswith(item['rel_path'] + '/') or active_clean == item['rel_path']
+ open_attr = ' open' if is_open else ''
+
+ html += f'
đ {item["name"]}'
+ html += render_tree(item['children'], active_url)
+ html += '
'
+ else:
+ is_active = ' active' if active_url == item['url'] else ''
+ html += f'
"
+
+ for name in names:
+ if name.startswith('.') or name in ('node_modules', 'venv', '.git', '__pycache__', 'data'):
+ continue
+
+ full_p = os.path.join(folder_path, name)
+ is_dir = os.path.isdir(full_p)
+
+ if is_dir:
+ url = posixpath.join(rel_url_path, name)
+ html += f"
+ '''
+ sidebar_tree_data = build_tree(DOCS_ROOT)
+ sidebar_html = render_tree(sidebar_tree_data, active_url)
+ breadcrumbs = get_breadcrumbs(active_url)
+
+ page_html = TEMPLATE
+ page_html = page_html.replace('{{ title }}', f"Error {code}")
+ page_html = page_html.replace('{{ home_active }}', '')
+ page_html = page_html.replace('{{ sidebar_tree }}', sidebar_html)
+ page_html = page_html.replace('{{ breadcrumbs }}', breadcrumbs)
+ page_html = page_html.replace('{{ content }}', error_html)
+ page_html = page_html.replace('{{ toc }}', '')
+ page_html = page_html.replace('{{ grid_class }}', '')
+ page_html = re.sub(r'{% if has_toc %}.*?{% endif %}', '', page_html, flags=re.DOTALL)
+
+ self.send_response(code)
+ self.send_header('Content-Type', 'text/html; charset=utf-8')
+ self.end_headers()
+ self.wfile.write(page_html.encode('utf-8'))
+
+
+def run_server():
+ server_address = ('', PORT)
+ httpd = HTTPServer(server_address, DocsHTTPHandler)
+ print(f"Starting markdown docs server on port {PORT}...")
+ print(f"Serving files from {DOCS_ROOT}")
+ try:
+ httpd.serve_forever()
+ except KeyboardInterrupt:
+ pass
+ print("\nStopping server.")
+
+if __name__ == '__main__':
+ run_server()
diff --git a/docs/data/README.md b/docs/data/README.md
new file mode 100644
index 0000000..c77cb5e
--- /dev/null
+++ b/docs/data/README.md
@@ -0,0 +1,71 @@
+# đ Documentation Viewer
+
+Self-hosted local documentation viewer. This service serves markdown files from a designated directory as a lightweight, reactive HTML site with instant reloads.
+
+> [!NOTE]
+> Any changes you made to the markdown files in the documentation directory will show up here immediately upon refreshing the page. No rebuild steps, no compilation delay.
+
+---
+
+## đ Getting Started
+
+To mount your project documentation, configure the following environment variables in your deployment setup:
+
+1. **`DOCS_DOMAIN`**: The domain you want Traefik to route to this viewer (e.g. `docs.homelab.local`).
+2. **`DOCS_PROJECT_PATH`**: The absolute path on your host machine pointing to your markdown files (e.g. `/home/kiskaadee/Projects/my-app/docs`).
+
+For example, when using the repository's `appctl` CLI wrapper:
+```bash
+# Sourcing environment, appctl maps:
+# DOCS_PROJECT_PATH -> PROJECT_PATH
+./appctl up docs
+```
+
+---
+
+## đ ī¸ Features
+
+Here is a breakdown of what this documentation server provides out-of-the-box:
+
+### 1. Dynamic Routing
+- `GET /` resolves to `README.md` or `index.md` at your documentation root.
+- `GET /docs/infra` matches `docs/infra.md` or `docs/infra/README.md`.
+- Clicking directories with no `README.md` serves an automatic, styled list of that folder's contents.
+
+### 2. Search & Sidebar Navigation
+- The sidebar dynamically scans the directories of your project workspace for `.md` files.
+- You can filter documentation files instantly using the **Search** input at the top of the sidebar. It searches across names and URLs.
+
+### 3. Sleek Themes (Light & Dark)
+- Persisted theme settings using `localStorage`.
+- Click the toggle button in the bottom-left corner of the sidebar to switch between a gorgeous dark slate mode and a clean light mode.
+
+### 4. Code Highlight & Copy
+- Code blocks are automatically highlighted with Prism.js.
+- Hovering over a code block shows a **Copy** button to copy code instantly.
+
+```python
+# Test Python block
+def hello_world():
+ print("Welcome to your local docs!")
+ return True
+```
+
+### 5. Mermaid.js Support
+You can render flowcharts, sequence diagrams, and class diagrams directly inside your markdown pages using standard fenced code blocks labeled `mermaid`.
+
+```mermaid
+graph TD
+ A[Browse Docs] -->|GET /path| B(Safe Path Resolver)
+ B -->|Found .md| C{Render Markdown}
+ B -->|Found Folder| D[Generate Directory Listing]
+ C -->|Parse HTML| E[Inject layout.html Template]
+ D -->|Inject list| E
+ E -->|Serve Browser| F((Wow User!))
+```
+
+### 6. Alert Callouts
+Use standard GitHub alert formatting to highlight notices:
+
+> [!TIP]
+> Use callout boxes to highlight important tips, warnings, or caution sections. They render with custom icons and borders.
diff --git a/docs/docker-compose.yml b/docs/docker-compose.yml
new file mode 100644
index 0000000..55a6bba
--- /dev/null
+++ b/docs/docker-compose.yml
@@ -0,0 +1,31 @@
+services:
+ docs:
+ build: .
+ container_name: ${SERVICE_NAME}
+ restart: unless-stopped
+ volumes:
+ - ${PROJECT_PATH:-./data}:/docs:ro
+ environment:
+ - DOCS_ROOT=/docs
+ - PORT=8000
+ networks:
+ - proxy
+ labels:
+ - "traefik.enable=true"
+ - "traefik.http.routers.${SERVICE_NAME}.rule=Host(`${SERVICE_DOMAIN}`)"
+ - "traefik.http.routers.${SERVICE_NAME}.entrypoints=websecure"
+ - "traefik.http.routers.${SERVICE_NAME}.tls=true"
+ - "traefik.http.routers.${SERVICE_NAME}.service=${SERVICE_NAME}-svc"
+
+ # HTTP to HTTPS redirect
+ - "traefik.http.routers.${SERVICE_NAME}-red.rule=Host(`${SERVICE_DOMAIN}`)"
+ - "traefik.http.routers.${SERVICE_NAME}-red.entrypoints=web"
+ - "traefik.http.routers.${SERVICE_NAME}-red.middlewares=https-redirect@docker"
+
+ # Target Port
+ - "traefik.http.services.${SERVICE_NAME}-svc.loadbalancer.server.port=8000"
+
+networks:
+ proxy:
+ name: ${PROXY_NETWORK}
+ external: true