Skip to content

richardkfm/neighbourgood

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

255 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

🏘️ NeighbourGood

v2.0.0 Β· A self-hostable web platform that helps communities share resources and coordinate during crises β€” including when the internet is gone.

Vision | Dual-State Architecture | Tech Stack | Quick Start | System Requirements | Project Structure | Offline-First Mesh | API | Roadmap | Telegram Bot | Contributing | License

πŸ’‘ Vision

Modern neighbourhoods have everything they need β€” the problem is that resources sit idle in individual households. NeighbourGood makes it easy to share tools, vehicles, equipment, food, and skills within a community, reducing waste and building real connections between neighbours.

But sharing goes beyond convenience. When a crisis hits β€” a flood, a power outage, a pandemic β€” the same network that shared a drill last Tuesday becomes a lifeline. NeighbourGood's dual-state architecture switches the platform from everyday comfort mode into emergency coordination mode with a single action.

πŸ”„ Dual-State Architecture

πŸ”΅ Blue Sky Mode (Normal Operation)

The default mode focuses on community building and resource sharing:

  • Resource Library – List and browse items available for borrowing (tools, vehicles, electronics, furniture)
  • Skill Exchange – Offer and request skills (tutoring, repairs, cooking, languages)
  • Calendar Booking – Reserve items with date/time slots
  • Community Events – Organise and RSVP to local events (repair cafΓ©s, workshops, seed swaps, meetups)
  • Trust & Reputation – Earn reputation points, collect trust badges (Reliable Borrower, Trusted Lender, Skilled Helper), review skills and lending experiences, public user profiles
  • Community Feed – Updates, requests, offers in a neighbourhood timeline

πŸ”΄ Red Sky Mode (Crisis Operation)

Activated by an admin or community vote when an emergency occurs:

  • Low-Bandwidth UI – Text-based, high-contrast, no heavy images
  • Essential Resources Focus – Food stocks, water filters, generators, medical supplies
  • Emergency Ticketing – Replace booking with Request / Offer / Emergency Ping
  • Neighbourhood Leaders – Pre-defined coordinators who can triage and assign
  • Offline-First – PWA with local caching, BLE mesh networking for internet-free crisis coordination

πŸ› οΈ Tech Stack

Layer Technology Why
Backend Python + FastAPI Lightweight, async, easy to extend with AI later
Frontend SvelteKit Fast, small bundles, good PWA/offline support
Database PostgreSQL (prod) / SQLite (dev) PostgreSQL in Docker for production, SQLite for quick local dev
Deployment Docker Compose Single docker-compose up to run everything

πŸš€ Quick Start

With Docker (recommended)

Docker Compose starts three containers: PostgreSQL database, Python/FastAPI backend, and SvelteKit frontend. Everything is wired together automatically.

Prerequisites: Docker 24+ and the Compose v2 plugin (docker compose β€” note: no hyphen).

# 1. Clone the repository
git clone https://github.com/neighbourgood/neighbourgood.git
cd neighbourgood

# 2. Create your config file from the template
cp .env.example .env

# 3. Generate a secret key β€” the app refuses to start without one
echo "NG_SECRET_KEY=$(openssl rand -hex 32)" >> .env

# 4. Build images and start all services (first run takes ~2–3 min)
docker compose up --build

Once you see Application startup complete in the backend logs, the stack is ready:

Service URL What it is
Web app http://localhost:3800 Main SvelteKit frontend β€” open this in your browser
API http://localhost:8300 FastAPI backend (JSON responses)
Interactive API docs http://localhost:8300/docs Swagger UI β€” explore and test every endpoint
Alternative API docs http://localhost:8300/redoc ReDoc-style reference

First time? Navigate to http://localhost:3800, click Sign Up, create an account, then go through the onboarding flow to create or join a community.

grafik Frontend User Onboarding

--

Useful Docker commands

# Start in the background (detached mode)
docker compose up --build -d

# Stream logs while running in the background
docker compose logs -f

### Local Development

# Stop everything (data is preserved in the postgres volume)
docker compose down

# Stop and wipe ALL data (fresh start)
docker compose down -v

# Rebuild a single service after a code change
docker compose up --build backend

Running database migrations inside Docker

# Apply Alembic migrations on a running stack
docker compose exec backend alembic upgrade head

Updating to a new version

git pull
docker compose up --build -d

Local Development (without Docker)

Use this when you want fast hot-reload and don't need a full Postgres instance. The backend defaults to SQLite.

Backend β€” runs on http://localhost:8300

cd backend
python -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate
pip install -r requirements.txt

# NG_DEBUG=true allows the default secret key and uses SQLite
NG_DEBUG=true uvicorn app.main:app --reload --port 8300

Frontend β€” runs on http://localhost:5173

cd frontend
npm install
npm run dev

The Vite dev server automatically proxies /api/* requests to the backend at :8300, so you only need to open http://localhost:5173 in your browser.

Service URL
Web app (dev) http://localhost:5173
Backend API http://localhost:8300
API docs http://localhost:8300/docs

πŸ–₯️ System Requirements

Minimum (VPS / Self-hosting)

Resource Minimum Recommended
CPU 1 vCPU 2 vCPU
RAM 512 MB 1 GB
Disk 5 GB 20 GB
OS Linux (any modern distro) Ubuntu 22.04 LTS
Docker 24+ latest
Docker Compose v2 plugin latest
Open ports 80, 443 (or 3800/8300 direct) + 22 for SSH

A $5–6/month VPS (e.g. Hetzner CX11, DigitalOcean Basic) is sufficient for a small community (< 200 users). PostgreSQL runs inside Docker β€” no separate DB server needed.

Advanced: Local AI features

The smart matching engine and Telegram AI assistant support an optional LLM backend (Ollama or any OpenAI-compatible API). If you want to run AI locally:

Resource Minimum Notes
CPU 4+ cores Inference is slow on < 4 cores
RAM 8 GB 16 GB recommended for 7B models
Disk 10 GB extra Per model (e.g. llama3.2:3b β‰ˆ 2 GB, mistral:7b β‰ˆ 4 GB)
GPU (optional) CUDA / ROCm / Apple Silicon Dramatically faster; not required

Recommended model for low-resource hosts: llama3.2:3b via Ollama. See TELEGRAM_SETUP.md for configuration. Without a local LLM configured, all features remain available β€” AI re-ranking simply falls back to rule-based matching.


πŸ“ Project Structure

neighbourgood/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ main.py            # FastAPI application entry point
β”‚   β”‚   β”œβ”€β”€ config.py           # Settings and environment config
β”‚   β”‚   β”œβ”€β”€ database.py         # SQLAlchemy database setup
β”‚   β”‚   β”œβ”€β”€ dependencies.py     # Auth dependencies (get_current_user)
β”‚   β”‚   β”œβ”€β”€ models/             # SQLAlchemy models (User, Resource, Booking, Message, Community)
β”‚   β”‚   β”œβ”€β”€ routers/            # API route handlers
β”‚   β”‚   β”œβ”€β”€ schemas/            # Pydantic request/response schemas
β”‚   β”‚   └── services/           # Business logic (auth, JWT, email notifications)
β”‚   β”œβ”€β”€ alembic/                # Database migrations
β”‚   β”œβ”€β”€ tests/                  # Backend tests
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── Dockerfile
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ routes/             # SvelteKit pages
β”‚   β”‚   β”œβ”€β”€ lib/                # Shared components, API client, stores
β”‚   β”‚   └── app.css             # Global styles (Blue/Red Sky themes)
β”‚   β”œβ”€β”€ static/                 # Static assets and PWA manifest
β”‚   β”œβ”€β”€ package.json
β”‚   └── Dockerfile
β”œβ”€β”€ docker-compose.yml          # One-command deployment
β”œβ”€β”€ .env.example                # Configuration template
β”œβ”€β”€ CHANGELOG.md
└── README.md

πŸ“‘ Offline-First Mesh Networking

When the internet goes down, NeighbourGood keeps working. In Red Sky mode the web app can connect to a nearby native BitChat node over Bluetooth Low Energy (BLE) and relay crisis data β€” emergency tickets, votes, pings β€” through the mesh without any internet connectivity at all.

How it works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         INTERNET DOWN                                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚   NeighbourGood         β”‚        β”‚   NeighbourGood                β”‚
  β”‚   Web App (Chrome)      β”‚        β”‚   Web App (Chrome)             β”‚
  β”‚                         β”‚        β”‚                                β”‚
  β”‚  [Connect to Mesh] btn  β”‚        β”‚  Receives mesh tickets         β”‚
  β”‚  Status: ● Connected    β”‚        β”‚  with "via BLE mesh" badge     β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚ Web Bluetooth (1 GATT connection)     β”‚ Web Bluetooth
             β”‚                                       β”‚
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚  BitChat Native Node    β”‚        β”‚  BitChat Native Node           β”‚
  β”‚  (iOS / Android)        β”‚        β”‚  (iOS / Android)               β”‚
  β”‚                         β”‚        β”‚                                β”‚
  β”‚  Acts as BLE relay      ◄────────►  Acts as BLE relay             β”‚
  β”‚  Handles mesh routing   β”‚  BLE   β”‚  Handles mesh routing          β”‚
  β”‚  Multi-hop, up to 7 hopsβ”‚  Mesh  β”‚  Store-and-forward             β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚                                       β”‚
             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
             β”‚  More BitChat nodes in the            β”‚
             β”‚  neighbourhood β€” no limit on count    β”‚
             β”‚  or distance (up to 7 hops / ~700m)   β”‚
             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚                    INTERNET RETURNS                              β”‚
  β”‚                                                                  β”‚
  β”‚  NeighbourGood shows "Sync N messages" button                    β”‚
  β”‚  POST /mesh/sync  β†’  server deduplicates by message UUID         β”‚
  β”‚  Emergency tickets and votes appear on the server                β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Message flow

Every NeighbourGood crisis action (create ticket, cast vote) is wrapped in a small JSON envelope and encoded as a standard BitChat broadcast message:

{
  "ng": 1,
  "type": "emergency_ticket",
  "community_id": 42,
  "sender_name": "Alice",
  "ts": 1741910400000,
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "data": {
    "title": "Need drinking water β€” north block",
    "ticket_type": "request",
    "urgency": "critical"
  }
}

Native BitChat apps relay this message through the mesh without needing to understand its contents. Other NeighbourGood web clients receive it and display it immediately with a "via BLE mesh" badge.

How to use it

Requirements: Chrome or Edge (desktop or Android). Web Bluetooth is not available in Firefox or Safari. A nearby device running the native BitChat app is required.

  1. Switch your community to Red Sky mode β€” the mesh panel only appears during crises.
  2. Open the Emergency (Triage) page in Chrome.
  3. Click "Connect to Mesh" β€” Chrome shows a device picker listing nearby BitChat nodes.
  4. Select a node β€” the status dot turns green and peer count appears.
  5. Create emergency tickets offline β€” the form button becomes "Broadcast via Mesh". Your ticket travels through the BLE mesh to other NeighbourGood users.
  6. When internet returns β€” click "Sync N messages" to push mesh-received data to the server. The server deduplicates by message UUID so re-syncing is safe.

Architecture decisions

Decision Rationale
Gateway model (1 BLE connection) Web Bluetooth supports only 1–2 simultaneous connections; native apps do the multi-hop routing
Native fork unmodified NG data is encoded as standard BitChat broadcast messages β€” no Swift/Kotlin changes needed
JSON in bitchat body Simple, debuggable, and relay-transparent β€” native nodes forward without parsing
UUID deduplication on server Safe to replay mesh sync multiple times; idempotent regardless of network partitions
Chrome/Edge only Web Bluetooth standard; Firefox/Safari do not support it as of 2026

πŸ“‘ API

See API_ENDPOINTS.md for the full endpoint reference. Interactive docs at /docs when the backend is running.

πŸ—ΊοΈ Roadmap

Phase 1 β€” Foundation (MVP)

  • Project scaffold (FastAPI + SvelteKit + Docker)
  • /status endpoint with dual-mode indicator
  • Blue Sky / Red Sky CSS theme system
  • User registration and authentication (JWT)
  • User profiles with neighbourhood assignment
  • Basic resource listing (CRUD for items)
  • Resource detail page
  • SQLite database with Alembic migrations

Phase 2 β€” Core Sharing

  • Resource categories (tools, vehicles, electronics, furniture, food, clothing)
  • Image upload for resources
  • Search and filter resources
  • Calendar-based booking system
  • Request/approve flow for borrowing
  • User messaging (in-app)
  • Email notifications

Phase 3 β€” Community & Trust

  • Skill exchange listings (offer/request with 10 categories)
  • Reputation/trust score system (computed from activity, 5 levels)
  • Community feed / activity timeline (auto-generated from events)
  • Community events β€” create, browse, RSVP; 9 categories, upcoming filter, max-attendee cap (v1.8.0)
  • Neighbourhood groups (Hybrid: PLZ-based with custom names)
  • Community merge function with auto-suggestions
  • Onboarding flow (search/join/create community)
  • Community-scoped resources (soft scoping with community_id)
  • Instance identity and /instance/info endpoint (federation prep)
  • PostgreSQL production default (Docker Compose)
  • Invite system for new members (code-based, with expiry/max uses)
  • Rating and review system for transactions (1-5 stars, per-booking)
  • Skill reviews & endorsements β€” community members can rate skill providers (v2.0.0)
  • Trust badges β€” Reliable Borrower, Trusted Lender, Skilled Helper (v2.0.0)
  • Public user profile page with trust summary, badges, and paginated reviews (v2.0.0)

Phase 3.5 β€” Federation Preparation

  • Instance metadata with admin accountability (name, region, contact)
  • /instance/info public endpoint for directory crawling
  • Instance directory (discover other NeighbourGood instances)
  • Cross-instance Red Sky alerts
  • User data export (portable backup)
  • Instance migration tooling

Phase 4 β€” Red Sky Mode 🚨

  • Admin toggle for crisis mode (per-community)
  • Community vote mechanism for mode activation (60% threshold)
  • Emergency ticketing system (Request / Offer / Emergency Ping)
  • Neighbourhood leader roles and assignment
  • Explore page with community map for unregistered users
  • Low-bandwidth UI variant (text-only, image-free mode)
  • Essential resource inventory tracking (quantity-based stock management)
  • Priority-based ticket triage (triage dashboard for leaders/admins)

Security Phase 4a β€” Hardening

  • Password strength validation (min 8 chars, uppercase + lowercase + digit)
  • Email format validation (EmailStr)
  • Security response headers (X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy, HSTS)
  • Secret key validation (reject default key in production, require 32+ chars)
  • File upload hardening (magic byte validation, extension sanitisation)
  • Input length limits on all user-facing schemas

Security Phase 4b β€” Access Control

  • Rate limiting on auth endpoints (login, register) β€” 5 req/min; general 60 req/min; uploads 10 req/min (v1.7.0)
  • Account lockout after repeated failed login attempts β€” 5 failures in 15 min β†’ 15-min lockout (v1.7.0)
  • CSRF protection for state-changing operations β€” Origin + X-CSRF-Token validation (v1.7.0)
  • Session invalidation on password change
  • Audit logging for admin actions

Security Phase 4c β€” Data Protection

  • Field-level encryption for sensitive data (email, messages)
  • Automated database backups with encryption at rest
  • PII anonymisation for deleted accounts
  • Content Security Policy tuning per route
  • Dependency vulnerability scanning (CI integration)

Phase 5 β€” Offline & Resilience

  • Full PWA with service worker caching (v0.9.9)
  • Offline item browsing and request queuing (v1.1.0)
  • Background sync when connectivity returns (v1.1.0)
  • Data export and backup tools (v1.1.0)
  • BLE mesh gateway for internet-free crisis coordination (v1.2.0)

Security Phase 5a β€” Infrastructure

  • TLS certificate automation (Let's Encrypt)
  • Container image scanning and hardening
  • Network segmentation (backend ↔ database)
  • Secrets management (Vault / sealed secrets)
  • Incident response runbook

Phase 6 β€” Advanced Features

  • Smart matching with AI enhancement (v1.5.0) β€” rule-based skill/resource matching + optional Ollama/OpenAI re-ranking
  • Mesh networking (BitChat BLE gateway) (v1.2.0) β€” offline crisis comms via Bluetooth mesh
  • Decentralized data sync between instances (v1.4.0) β€” pull-based federation sync with public snapshot endpoint, incremental cursors, and federated resource/skill browsing
  • Federation explorer UI (v1.9.0) β€” instance directory browser, federated resource/skill pages, cross-instance alert banners, enriched instance stats
  • Enhanced BLE mesh networking (v1.9.5) β€” 10-phase overhaul: mesh dashboard, auto-sync, resource sharing, check-ins, multi-hop relay, E2E encryption, analytics
  • Multi-language support (i18n) (v1.1.0) β€” 12 languages with RTL support
  • Community events (v1.8.0) β€” create, browse and RSVP to local events (repair cafΓ©s, workshops, seed swaps, meetups); 9 categories, max-attendee cap, upcoming filter, full-text search
  • Admin dashboard with analytics
  • Outbound webhook system with HMAC-SHA256 signing (generic integrations)
  • Telegram bot integration (personal notifications, community group alerts, bot commands) + AI natural language interface (v1.6.0)
  • Signal integration
  • Matrix integration

πŸ€– Telegram Bot & AI Assistant

NeighbourGood includes a Telegram bot with an AI-powered natural language interface β€” members can search resources, find skills, and coordinate during crises directly from Telegram without opening the app.

See TELEGRAM_SETUP.md for the full setup guide, including:

  • Creating and configuring your bot
  • Linking personal accounts and community groups
  • Setting up local AI with Ollama (model recommendations included)
  • What the agent can and cannot do
  • Slash command reference and notification event table

To customise the agent's behaviour, tone, or available intents, see TELEGRAM_AGENT.md.

🀝 Contributing

This project is in its early stages. Contributions, ideas, and feedback are welcome.

πŸ“„ License

See LICENSE for details.

About

πŸ™‹β€β™€οΈ a local network for neighbours to share stuff and skills. during good times and ready for crisis.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors