Skip to content
InternetSocietyPublic

About

APC Local Networks Supply and Demand Modeller Tool

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Community Network Builder

Overview

  • The Community Network Builder helps you estimate and understand the cost of building and operating a community network anywhere in the world.
  • Users can select the frequencies available in their context or proceed with the default ISM bands of 2.4GHz and 5.8GHz, which are widely available globally.
  • You can model mobile or Wi‑Fi networks, fixed wireless, fibre‑to‑the‑home, public access facilities, or any combination of these. Radio coverage accounts for terrain visibility and land cover around each configured location.
  • Users design the network by adding locations, radii, and technologies. Area is derived from location radii, while population can be modelled from coverage geometry or overridden with a household count for an individual location.

Background and credits

  • The Association for Progressive Communications (APC) commissioned Systems Knowledge Concepts (SKC) and Telco2 to develop a quantitative economic and financial model to enable the evaluation of the financial sustainability of different community‑based communications solutions in under‑serviced communities.
  • Systems Knowledge Concepts is an Australian economics consultancy specialising in telecommunications and economic development. Telco2 designs and builds innovative networks for broadband, public safety, utilities, and the Internet of Things.
  • Simon Molloy and Barry Burgan of SKC worked with Jonathan Brewer of Telco2 to develop and integrate the model into an Excel sheet. This team collaborated with Carlos Rey‑Moreno and Mike Jensen of APC on the work in 2024.
  • Telco2 ported the Excel model to Python and developed a prototype web user interface for it in 2025.
  • Matthew Holloway developed a single‑page architecture user interface for the application in 2026.
  • An advisory committee accompanied this process: Jane Coffin, Revi Sterling, Laina Green, Steve Song, Ben Matranga and representatives of Connect Humanity (initially Jochai Ben‑Avie, and later Erica Mesker, Brian Vo and Nathalia Foditsch).
  • The development of this application is part of the Local Networks initiative, a collective effort led by APC and Rhizomatica in partnership with grassroots communities and support organisations in Africa, Asia and Latin America and the Caribbean. Its production was supported by the "Meaningful community‑centred connectivity" project implemented with financial support from the Swedish International Development Cooperation Agency (Sida) and UK International Development from the UK Government through its Digital Access Programme. The views expressed here do not necessarily reflect the supporters' views.

Technologies in use

Backend

  • FastAPI (Python) for the web API and server-rendered endpoints
  • Pydantic v2 for request/response models and validation
  • Pandas for data handling and tabular computations
  • numpy‑financial for financial calculations
  • Requests for upstream HTTP calls
  • python‑dotenv for environment configuration
  • Jinja2 templates (via FastAPI) for server‑rendered pages

Frontend (SPA)

  • React + TypeScript (see spa/src/... with .tsx files)
  • Vite build pipeline producing static assets in spa/dist served by FastAPI at /assets

Data and integrations

  • Menu and lookup data come from the immutable SQLite seed at app/data/app.db.
  • Container startup copies the seed into the ignored runtime/ directory when no runtime database exists, then applies Alembic migrations to that copy.
  • Coverage and population modelling uses the GLO-30 viewshed, ESA WorldCover, and WorldPop services.
  • Documentation/QSG content is now in git and is rendered into /documentation and /qsg respectively.

Required external APIs

The application requires all three APIs below and valid bearer tokens for them. The network model does not function if an API is unavailable or incorrectly configured.

GLO-30

GLO-30 supplies viewsheds from the Copernicus GLO-30 digital elevation model. The application uses each viewshed to calculate the visible radio-coverage area from a tower.

ESA WorldCover

ESA WorldCover supplies land-cover fractions for a coverage area. The application uses its tree-cover and mangrove fractions to estimate vegetation loss and reduce the calculated radio range.

WorldPop

WorldPop estimates the population inside a coverage area for a selected country. The application uses this estimate when a user does not supply a household-count override for a location.

Architecture at a glance

  • Single repo with a Python FastAPI backend and a static SPA frontend.
  • Backend mounts static directories and serves:
    • / — public sign-in page
    • /app — SPA entry
    • /docs — authenticated API documentation for API-enabled users
    • /qsg — Quick Start Guide
    • /documentation — user documentation
    • /login — authentication page for administrators and API-enabled users
    • /api/* — lookup and modelling routes

Getting started

Prerequisites

  • Git
  • Docker Engine
  • Docker Compose

Environment and configuration

  • Copy .env.example to .env and provide the deployment values.
  • Set JWT_SECRET to a long random value before you start the application.
  • Set SESSION_COOKIE_SECURE=true for a production HTTPS deployment.
  • Coverage calculations require GLO30_API_URL, GLO30_API_TOKEN, ESAWC_API_URL, ESAWC_API_TOKEN, WPOP_API_URL, and WPOP_API_TOKEN.
  • Generated viewsheds are cached in cache/geojson by default; set GEOJSON_CACHE_DIRECTORY to a persistent volume path to override it. Entries expire after 30 days. When the cache exceeds 1 GB, least-recently-used entries are removed first.

Build and run through Docker Compose:

docker compose up --build

Run the backend suite in its dedicated Python 3.14 test image:

docker compose build test
docker compose run --rm test pytest

Open in your browser:

Create the first administrator after the application database starts:

docker compose run --rm web-locnet python -m app.admin create-admin admin@example.com

The command reads the password from the terminal. It does not print or store the plain password.

Remove a user with the administration command:

docker compose run --rm web-locnet python -m app.admin remove-user user@example.com

Production database operations

The production database is runtime/app.db. Docker Compose bind-mounts the host runtime/ directory into the application container. The same directory is mounted read/write by the internal sqlite-web service. It is available only through the Nginx-protected administrator editor at /admin/database/; sqlite-web has no published port or separate credentials.

A normal image rebuild does not replace this file. At container startup, the entry point completes these actions:

  1. It checks for the runtime database.
  2. If the runtime database is absent, it copies app/data/app.db to runtime/app.db.
  3. If the runtime database exists, it does not copy the seed database.
  4. It applies pending Alembic migrations to the runtime database.
  5. It starts the application with the existing data.

Thus, docker compose up --build keeps the production users, API tokens, caches, and other runtime data.

First deployment of the separate runtime database

The production docker-compose.yml file is not in Git. A Git pull does not update this file.

Complete these steps before the first deployment of this database layout:

  1. Stop the application.
  2. Back up the existing app/data/app.db file outside the repository.
  3. Pull the application changes.
  4. Copy the database backup to runtime/app.db.
  5. Update docker-compose.yml from docker-compose.yml.example.
  6. Make sure that DATABASE_URL points to /app/runtime/app.db.
  7. Make sure that Compose mounts ./runtime at /app/runtime.
  8. Build and start the application.
  9. Examine the application and the Alembic revision before you remove the backup.

Do not rely on the image build to transfer the old production database. Copy the stopped database explicitly.

Routine production update

Use this procedure for each production update:

  1. Stop web-locnet before you copy the SQLite file.
  2. Copy runtime/app.db to a backup location outside runtime/.
  3. Pull the application changes.
  4. Review changes in docker-compose.yml.example.
  5. Apply necessary changes to the production docker-compose.yml file.
  6. Run docker compose up --build -d.
  7. Examine the application logs for Alembic errors.
  8. Test the application before you remove the backup.

The entry point applies each pending migration once. A migration can change existing data, so keep a backup for each deployment.

Reference-data updates

The file app/data/app.db is an immutable seed database. A rebuild does not copy a changed seed over an existing runtime database.

Supply reference-data changes through an Alembic data migration or another explicit import process. Do not edit the production seed database.

Data-loss risks

Production data can be lost in these conditions:

  • An operator deletes or replaces runtime/app.db.
  • The Compose mount points to a different host directory.
  • A new server starts without a copy of the existing runtime/ directory.
  • A migration deletes or incorrectly changes data.
  • The SQLite file becomes corrupt and no usable backup exists.

To move the application to a new server, stop the old application and transfer runtime/app.db before startup.

Production docs and quick start

API usage

  • The public SPA uses the separate /web/api/* browser-service routes.
  • An administrator can enable persistent API access for a normal user.
  • Every /api/* request requires that token as Authorization: Bearer TOKEN.
  • The application stores only the token digest and shows the plain token once.
  • Signed-in normal users and administrators can open Swagger at /docs.

Playwright tests

Playwright is a browser automation and end-to-end testing framework for web applications. It is useful for checking that the app behaves correctly in real browsers, with real user actions such as clicking, typing, selecting options, and waiting for UI updates. The official documentation is here: Playwright docs.

This repository keeps its Playwright tests in the separate playwright/ package. The current tests are:

  • playwright/tests/locnet.spec.ts
    • Verifies that the app loads and the page title contains Community Network Builder.
    • Loads sample builder data into the browser, fills out a representative network configuration, clicks Calculate network, and checks that the report section appears.
  • playwright/tests/technologies.spec.ts
    • Opens the app, selects a country, and verifies that the Introduction section is visible after the page updates.

Install and run Playwright through Docker Compose:

docker compose run --rm --no-deps playwright npm ci
docker compose run --rm playwright npm test

The Playwright service starts an isolated application on port 8011. It uses disposable users, data, geospatial services, and map services.

Contributing

  • Issues and pull requests are welcome. Please discuss major changes via an issue before submitting a PR.

License

  • © 2024–2026 APC, SKC, Telco2, ISOC and contributors. See repository's LICENSE file for details.

Maintainer and support

About

APC Local Networks Supply and Demand Modeller Tool

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages