# jacekong/borderless-api architecture

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

- Interactive diagram: https://gitdiagram.com/jacekong/borderless-api
- Repository: https://github.com/jacekong/borderless-api

## Overview

##### Project Type & Purpose
- This is a full-stack, monolithic Django web application (with Django REST Framework) that serves:
–  Blog posting (CRUD via REST endpoints)
–  Real-time messaging (WebSockets via Django Channels)
–  Friend management (REST endpoints)
–  User authentication/registration (including OAuth and email)
–  Static HTML/JS/CSS frontend plus optional Flutter mobile client
- It also includes a “Spatialite Tools” folder containing geospatial utilities (EXIF loader, raster tools, etc.).

##### File Structure
Top level:
- Spatialite Tools (GPL/MPL-licensed geospatial command-line tools)
- borderlessApi/ (Django project directory with settings.py, asgi.py, celery.py, wsgi.py)
- api/, chat/, friend/, notification/, tracking/, users/ (six Django “apps” each encapsulating one domain)
- static/ & templates/ (server-rendered assets, CSS/JS pipelines, Tailwind config)
- manage.py, package.json (front-end build), requirements.txt, Redis config hint

##### Key Runtime Components
- ASGI Server (e.g., Daphne or Uvicorn)
- Django Apps
–  api (blog endpoints + optional feed templates)
–  chat (WebSocket consumers for realtime messaging)
–  friend (REST for friend requests)
–  notification (REST + WebSocket consumer for push notifications)
–  users (user profile + serializers)
–  tracking (middleware for analytics, optional background tasks)
- Django REST Framework (serializers + viewsets)
- Django Channels
–  Channel Layer backed by Redis
–  WebSocket routing in chat/routing.py & api/routing.py
- Celery Worker (background task queue, broker = Redis)
- Relational Database (SQLite for dev, PostgreSQL in prod)
- Redis (channel layer & Celery broker)
- Static/File Server (WhiteNoise or Nginx) serving CSS/JS/images
- External Services
–  OAuth Provider (Google login via allauth)
–  SMTP Email Service (password reset)

A. Components
1. Clients (Web Browser & Flutter Mobile App)
- Them issuing both HTTP(S) and WebSocket requests
2. Reverse Proxy / Load Balancer
- (Optional) Nginx or Cloud Load Balancer in front of ASGI
3. ASGI Application Server
- Single rectangle labeled “Django ASGI Server (borderlessApi)”
- Inside, group six app-modules: api, chat, friend, notification, users, tracking
- Django Channels consumers next to chat & notification modules
4. REST API Layer
- As a boundary around DRF viewsets/serializers in each app
5. WebSocket Layer
- Ws/chat/<user_id>/ and ws/notifications/ endpoints
6. Channel Layer (Redis)
7. Celery Worker
- Separate rectangle connected to Redis broker for background jobs (e.g., email notifications)
8. Database
9. Static Asset Server
10. External OAuth & Email Services

B. Data Flows & Relationships
–  Celery: ASGI or apps enqueue tasks → Redis broker → Celery worker → (optional) DB or external services
–  OAuth flow: ASGI → Google OAuth → callback → ASGI
–  Email flow: Celery worker → SMTP → user inbox

C. Architectural Patterns & Principles
–  Modular “Django app” decomposition by domain
–  RESTful endpoints for CRUD on posts, friends, users, notifications
–  Event-driven, real-time messaging via Channels (pub/sub pattern)
–  Asynchronous background processing (Celery)
–  Static asset pipeline (Tailwind, Webpack) for efficient client payloads

##### Don’t Overthink—Be Detailed
- Both REST & WebSocket layers
- Runtime dependencies (DB, Redis, Celery, external OAuth/email)

## Diagram (Mermaid)

```mermaid
graph TD
    %% Clients
    subgraph "Clients"
        Browser["Web Browser"]:::frontend
        Mobile["Flutter Mobile App"]:::frontend
    end

    %% Reverse Proxy
    Proxy["Nginx / Load Balancer"]:::frontend

    %% ASGI Server and Django
    subgraph "Django ASGI Server (borderlessApi)"
        ASGI["ASGI Entry"]:::backend
        WSGI["WSGI Entry"]:::backend
        Settings["Settings"]:::backend
        Utils["Utils"]:::backend
        CeleryConf["Celery Config"]:::backend

        subgraph "Django Apps"
            API["api"]:::backend
            Chat["chat"]:::backend
            Friend["friend"]:::backend
            Notification["notification"]:::backend
            Users["users"]:::backend
            Tracking["tracking"]:::backend
        end
    end

    %% Databases and Brokers
    Postgres["Postgres / SQLite"]:::db
    Redis["Redis (Channel Layer & Broker)"]:::queue
    CeleryWorker["Celery Worker"]:::queue

    %% Static & Templates
    Static["Static Asset Server\n(WhiteNoise / Nginx)"]:::asset
    Templates["Server-rendered Templates"]:::asset

    %% Spatialite Tools
    Spatialite["Spatialite Tools (Geospatial CLI)"]:::external

    %% External Services
    OAuth["Google OAuth Provider"]:::external
    SMTP["SMTP Email Service"]:::external

    %% Connections: Clients to Proxy
    Browser -->|HTTPS / HTTP| Proxy
    Mobile -->|HTTPS / HTTP| Proxy
    Browser -->|WSS| Proxy
    Mobile -->|WSS| Proxy

    %% Proxy to ASGI
    Proxy -->|HTTPS| ASGI
    Proxy -->|WSS| ASGI

    %% ASGI internals
    ASGI --> Settings
    ASGI --> Utils
    ASGI --> API
    ASGI --> Chat
    ASGI --> Friend
    ASGI --> Notification
    ASGI --> Users
    ASGI --> Tracking
    ASGI --> WSGI

    %% Data flows
    API -->|ORM| Postgres
    Friend -->|ORM| Postgres
    Users -->|ORM| Postgres
    Notification -->|ORM| Postgres
    Tracking -->|ORM| Postgres
    Chat -->|ORM| Postgres

    %% WebSocket flows
    Browser -->|WSS ws/chat/<user_id>/| Chat
    Browser -->|WSS ws/notifications/| Notification
    Mobile -->|WSS ws/chat/<user_id>/| Chat
    Mobile -->|WSS ws/notifications/| Notification
    Chat -->|pub/sub| Redis
    Notification -->|pub/sub| Redis

    %% Celery flows
    ASGI -->|enqueue AMQP| Redis
    API -->|tasks| Redis
    Notification -->|tasks| Redis
    Tracking -->|tasks| Redis
    CeleryWorker -->|consume AMQP| Redis
    CeleryWorker -->|ORM / side effects| Postgres
    CeleryWorker -->|SMTP| SMTP

    %% Static & Templates
    Proxy -->|serves| Static
    ASGI -->|renders| Templates

    %% External OAuth
    ASGI -->|OAuth flow| OAuth
    OAuth --> ASGI

    %% Spatialite Tools
    Spatialite

    %% Click events
    click Spatialite "https://github.com/jacekong/borderless-api/tree/master/Spatialite Tools/"
    click ASGI "https://github.com/jacekong/borderless-api/blob/master/borderlessApi/asgi.py"
    click WSGI "https://github.com/jacekong/borderless-api/blob/master/borderlessApi/wsgi.py"
    click CeleryConf "https://github.com/jacekong/borderless-api/blob/master/borderlessApi/celery.py"
    click Settings "https://github.com/jacekong/borderless-api/blob/master/borderlessApi/settings.py"
    click Utils "https://github.com/jacekong/borderless-api/blob/master/borderlessApi/utils.py"
    click API "https://github.com/jacekong/borderless-api/tree/master/api/"
    click API "https://github.com/jacekong/borderless-api/blob/master/api/serializers.py"
    click API "https://github.com/jacekong/borderless-api/blob/master/api/views.py"
    click API "https://github.com/jacekong/borderless-api/blob/master/api/urls.py"
    click API "https://github.com/jacekong/borderless-api/blob/master/api/consumers.py"
    click API "https://github.com/jacekong/borderless-api/blob/master/api/routing.py"
    click API "https://github.com/jacekong/borderless-api/blob/master/api/tasks.py"
    click API "https://github.com/jacekong/borderless-api/tree/master/api/templates/posts/"
    click Chat "https://github.com/jacekong/borderless-api/tree/master/chat/"
    click Chat "https://github.com/jacekong/borderless-api/blob/master/chat/models.py"
    click Chat "https://github.com/jacekong/borderless-api/blob/master/chat/serializers.py"
    click Chat "https://github.com/jacekong/borderless-api/blob/master/chat/views.py"
    click Chat "https://github.com/jacekong/borderless-api/blob/master/chat/urls.py"
    click Chat "https://github.com/jacekong/borderless-api/blob/master/chat/consumers.py"
    click Chat "https://github.com/jacekong/borderless-api/blob/master/chat/routing.py"
    click Chat "https://github.com/jacekong/borderless-api/blob/master/chat/channel_middlware.py"
    click Chat "https://github.com/jacekong/borderless-api/blob/master/chat/token_authentication.py"
    click Chat "https://github.com/jacekong/borderless-api/tree/master/chat/templates/chat/"
    click Friend "https://github.com/jacekong/borderless-api/tree/master/friend/"
    click Friend "https://github.com/jacekong/borderless-api/blob/master/friend/models.py"
    click Friend "https://github.com/jacekong/borderless-api/blob/master/friend/serializers.py"
    click Friend "https://github.com/jacekong/borderless-api/blob/master/friend/views.py"
    click Friend "https://github.com/jacekong/borderless-api/blob/master/friend/urls.py"
    click Friend "https://github.com/jacekong/borderless-api/tree/master/friend/templates/partials/"
    click Notification "https://github.com/jacekong/borderless-api/tree/master/notification/"
    click Notification "https://github.com/jacekong/borderless-api/blob/master/notification/models.py"
    click Notification "https://github.com/jacekong/borderless-api/blob/master/notification/views.py"
    click Notification "https://github.com/jacekong/borderless-api/blob/master/notification/urls.py"
    click Notification "https://github.com/jacekong/borderless-api/tree/master/notification/templates/"
    click Tracking "https://github.com/jacekong/borderless-api/tree/master/tracking/"
    click Tracking "https://github.com/jacekong/borderless-api/blob/master/tracking/middleware.py"
    click Tracking "https://github.com/jacekong/borderless-api/blob/master/tracking/models.py"
    click Tracking "https://github.com/jacekong/borderless-api/blob/master/tracking/views.py"
    click Users "https://github.com/jacekong/borderless-api/tree/master/users/"
    click Users "https://github.com/jacekong/borderless-api/blob/master/users/models.py"
    click Users "https://github.com/jacekong/borderless-api/blob/master/users/serializers.py"
    click Users "https://github.com/jacekong/borderless-api/blob/master/users/views.py"
    click Users "https://github.com/jacekong/borderless-api/blob/master/users/urls.py"
    click Users "https://github.com/jacekong/borderless-api/blob/master/users/signals.py"
    click Users "https://github.com/jacekong/borderless-api/tree/master/users/templates/users/"
    click Static "https://github.com/jacekong/borderless-api/tree/master/static/"
    click Static "https://github.com/jacekong/borderless-api/blob/master/tailwind.config.js"
    click Static "https://github.com/jacekong/borderless-api/blob/master/package.json"
    click Templates "https://github.com/jacekong/borderless-api/tree/master/templates/"
    click Templates "https://github.com/jacekong/borderless-api/tree/master/templates/account/"
    click Templates "https://github.com/jacekong/borderless-api/tree/master/templates/components/"
    click Templates "https://github.com/jacekong/borderless-api/tree/master/templates/home/"
    click Templates "https://github.com/jacekong/borderless-api/tree/master/templates/registration/"
    click Templates "https://github.com/jacekong/borderless-api/tree/master/templates/socialaccount/"
    click Postgres "https://github.com/jacekong/borderless-api/blob/master/requirements.txt"
    click Postgres "https://github.com/jacekong/borderless-api/blob/master/manage.py"

    %% Styles
    classDef frontend fill:#D6E9FF,stroke:#3178C6
    classDef backend fill:#DFF2BF,stroke:#4F8A10
    classDef db fill:#FEEFB3,stroke:#9C5700
    classDef queue fill:#F2DEDE,stroke:#A94442
    classDef asset fill:#E0F7FA,stroke:#00796B
    classDef external fill:#EEEEEE,stroke:#AAAAAA
```
