How mapswipe/mapswipe-backend works
Project type and purpose
• This is a monolithic Django-based backend service exposing a GraphQL API, used by the MapSwipe mobile/web clients.
• It also runs background jobs (via Celery) for tasks like data aggregation and tile generation, and serves a tile-map service.
File structure
• Top-level “main/” contains Django settings, ASGI/WSGI entrypoints, GraphQL schema bootstrap, middlewares, Celery setup.
• “apps/” holds Django apps organized by domain (common, user, project, mapping, contributor, community_dashboard, tutorial). Each app has models, serializers, GraphQL types/queries/mutations, Celery tasks, migrations, tests.
• “utils/” contains shared helper modules (geo/tile_server for tile generation, graphql helpers, common utilities).
• Docker/Helm manifests for containerized deployment; docker-compose.yaml for local development; helm/ for Kubernetes charts.
• Supporting files: .github workflows (CI, helm publish), pre-commit, pytest.ini.
README for additional insights
• The service boots via “docker compose up” exposing “web”, “worker” and “worker-beat” services.
• It uses environment variables (via .env) to configure Django, the database, Redis, and third-party integrations.
• Provides GraphQL schema generation, Django migrations, and pytest integration.
a. Main components
• API Layer: Django web service (Gunicorn/Uvicorn) hosting GraphQL endpoint and Django Admin.
• Background Workers: Celery worker & Celery-beat processes.
• Message Broker & Cache: Redis (broker for Celery, also used for caching or rate-limiting).
• Primary Database: PostgreSQL (persistent storage for all Django models).
• Tile Server Module: internal Python service (utils/geo/tile_server) invoked by API or tasks to serve map tiles or group them.
• External Clients: MapSwipe mobile & web apps, third-party integrations (e.g. Sentry for error logging).
• DevOps/CI: Docker Registry, GitHub Actions, Helm/Kubernetes.
b. Relationships & interactions
• Clients → HTTP/GraphQL → Web container → Reads/writes → Postgres.
• Web container → enqueues tasks → Redis broker → Celery worker → processes task → writes back to DB or publishes tile data to tile service.
• Celery-beat (scheduler) → enqueues periodic tasks (e.g. aggregated data updates).
• Web container & Celery workers → publish errors/logs → Sentry.
• Web container → cache lookups → Redis (optional).
• DevOps pipeline → builds Docker images → pushes → Helm chart deploys to k8s.
c. Architectural patterns & design principles
• Monolithic Django with clearly separated domain apps.
• GraphQL façade with DataLoader pattern to batch & cache DB calls.
• Asynchronous task queue for long-running or scheduled jobs.
• Utility libraries extracted under “utils/” to avoid duplication.
• Containerized micro-services pattern for web & worker processes.
• Infrastructure-as-code via Helm charts for reproducible deployments.
d. Technologies & frameworks
• Python 3.x, Django, Graphene-Django (GraphQL), Celery, Redis, PostgreSQL.
• Docker, Docker Compose, Kubernetes (Helm), GitHub Actions.
• Sentry for error tracking, pytest for testing.