# captainmccrank/instant_community_wifi_portal architecture

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

- Interactive diagram: https://gitdiagram.com/captainmccrank/instant_community_wifi_portal
- Repository: https://github.com/captainmccrank/instant_community_wifi_portal

## Overview

##### Project type and purpose
- This is an Ansible-driven firmware/configuration project for a Raspberry Pi that creates an offline Wi-Fi access point (“JoinMe”) with a captive portal image board (Werc-based) and a local media library.

##### File structure
- Top level: Ansible playbook (run.yml) + roles/system (tasks for hostapd, dnsmasq, nginx, nodogsplash, icecast2, firewall, etc.)
- /etc and /usr/local: configuration templates for network services (hostapd, dnsmasq, avahi, lighttpd, nginx, nodogsplash, Icecast2)
- /var/www/ansibledest.local: Werc-powered CGI image board source (apps, bin scripts, templates, lib, offgrid media)
- /var/www/html: static web assets (HTML5Up theme, CSS, JS)
- /usr/local/bin + /var/ices: custom scripts to launch ices/icecast streaming

##### README
- Describes purpose: turn Pi into isolated AP, captive-portal image board, off-grid neighbor network, optional static library & streaming.
- Mentions Ansible orchestration or Docker-based builder.

##### Main components & interactions
a. Hardware & OS
- Raspberry Pi running Raspbian (Linux)
b. Configuration Management
- Ansible playbook + roles pushes config files & systemd units
c. Network Stack
- hostapd: creates “JoinMe” SSID
- dnsmasq: DHCP + DNS, directs all HTTP to local portal
- firewall (nftables/iptables): blocks Internet, allows internal services
d. Captive Portal
- nodogsplash: intercepts HTTP, serves portal splash page
e. Web Servers & Apps
- lighttpd/nginx: serves the Werc CGI image board (dynamic) under /var/www/ansibledest.local
- static files served under /var/www/html (media library, theme assets)
f. Streaming Service (optional)
- icecast2 + ices-source: streams mp3 from /var/ices; controlled by LaunchIces.sh

##### Architectural patterns & design principles
- Infrastructure-as-Code (Ansible roles/modules)
- Layered separation:
- Infra layer (network services)
- App layer (web/Captive portal)
- Data layer (static content/media files)
- Systemd timers/services for periodic tasks (e.g., register-device, ices_source)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware & Controller
    AC["Ansible Controller"]:::config
    subgraph "Raspberry Pi (Raspbian Linux)" 
        direction TB
        ConfigMgmt["Ansible Roles & Playbook"]:::config
        subgraph "Network Services" 
            direction TB
            Hostapd["hostapd (Wi-Fi AP)"]:::infra
            Dnsmasq["dnsmasq (DHCP/DNS)"]:::infra
            Firewall["Firewall (nftables/iptables)"]:::infra
            Captive["NoDogSplash (Captive Portal)"]:::infra
        end
        subgraph "Application Layer"
            direction TB
            Nginx["nginx (Werc Imageboard)"]:::app
            Lighttpd["lighttpd (Static Assets)"]:::app
            WercApp["Werc CGI Imageboard"]:::app
            StaticContent["Static Library & Theme"]:::data
        end
        subgraph "Streaming Service"
            direction TB
            LaunchIces["LaunchIces.sh"]:::stream
            Icecast["Icecast2 & ices2"]:::stream
            StreamClients["Streaming Clients"]:::stream
        end
        RegistrationService["Device Registration Timer"]:::config
    end

    %% User Flow
    UserDevice["User Device"]:::hardware
    UserDevice -->|"JoinMe Wi-Fi"| Hostapd
    Hostapd -->|"DHCP/DNS"| Dnsmasq
    Dnsmasq -->|"HTTP Redirect"| Captive
    Captive -->|"Portal Splash"| Nginx
    Captive -->|"Static Media"| Lighttpd
    Nginx -->|"Serve Dynamic Images"| WercApp
    Lighttpd -->|"Serve CSS/JS/Media"| StaticContent

    %% Configuration Management Flow
    AC -->|"push configs & restart"| ConfigMgmt
    ConfigMgmt --> Hostapd
    ConfigMgmt --> Dnsmasq
    ConfigMgmt --> Firewall
    ConfigMgmt --> Captive
    ConfigMgmt --> Nginx
    ConfigMgmt --> Lighttpd
    ConfigMgmt --> LaunchIces
    ConfigMgmt --> RegistrationService

    %% Streaming Flow
    LaunchIces -->|"stream source"| Icecast
    Icecast -->|"MP3 Stream"| StreamClients

    %% Click Events
    click AC "https://github.com/captainmccrank/instant_community_wifi_portal/blob/main/run.yml"
    click ConfigMgmt "https://github.com/captainmccrank/instant_community_wifi_portal/tree/main/roles/system/"
    click Hostapd "https://github.com/captainmccrank/instant_community_wifi_portal/blob/main/roles/system/tasks/hostapd.yml"
    click Dnsmasq "https://github.com/captainmccrank/instant_community_wifi_portal/blob/main/roles/system/tasks/dnsmasq.yml"
    click Firewall "https://github.com/captainmccrank/instant_community_wifi_portal/blob/main/roles/system/tasks/firewall.yml"
    click Captive "https://github.com/captainmccrank/instant_community_wifi_portal/blob/main/roles/system/tasks/captivePortal.yml"
    click Nginx "https://github.com/captainmccrank/instant_community_wifi_portal/blob/main/roles/system/tasks/nginx.yml"
    click Lighttpd "https://github.com/captainmccrank/instant_community_wifi_portal/blob/main/etc/lighttpd/lighttpd.conf"
    click WercApp "https://github.com/captainmccrank/instant_community_wifi_portal/tree/main/var/www/ansibledest.local/"
    click StaticContent "https://github.com/captainmccrank/instant_community_wifi_portal/tree/main/var/www/html/"
    click LaunchIces "https://github.com/captainmccrank/instant_community_wifi_portal/blob/main/usr/local/bin/LaunchIces.sh"
    click RegistrationService "https://github.com/captainmccrank/instant_community_wifi_portal/blob/main/pi/config/systemd/user/register-device.service"

    %% Styles
    classDef hardware fill:#D0E6FF,stroke:#004A99,color:#004A99;
    classDef config fill:#DFFFE0,stroke:#239B00,color:#239B00;
    classDef infra fill:#FFE8CC,stroke:#CC7000,color:#CC7000;
    classDef app fill:#F3E0FF,stroke:#7A00A5,color:#7A00A5;
    classDef data fill:#F0F0F0,stroke:#888888,color:#555555;
    classDef stream fill:#FFCCCC,stroke:#CC0000,color:#CC0000;
```
