# bunchhq/bunch architecture

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

- Interactive diagram: https://gitdiagram.com/bunchhq/bunch
- Repository: https://github.com/bunchhq/bunch

## Overview

##### Project type and purpose
- From the file tree and README, this is the server-side of “Bunch,” a cross-platform chat application. It’s a Django monolithic backend exposing REST endpoints (serializers, views, routers) and supporting real-time messaging (ASGI, Django Channels).

##### File structure
- Top-level “server/” directory holds the Django project named “orchard” (ASGI/WGSI settings, URLs) and three Django apps:
- users — user model, serializers, views, tests
- bunch — chat logic (channels, messages, permissions), serializers, views, tests
- core — any shared utilities or site-wide features
- Key config: pyproject.toml, requirements.txt for dependencies; manage.py entry point; .github/workflows/django.yml for CI.
- ASGI config suggests WebSocket support via Django Channels and a channel layer (likely Redis).

##### Elements
- Labels: “Web/Mobile Client,” “Django ASGI Server,” “Django REST API,” “Redis Channel Layer,” “PostgreSQL DB”

##### Detailed breakdown of components
- Client tier:
- Authentication UI → /users/login/
- Chat UI → WS://server/ws/chat/
- Application tier (Django project “orchard”):
- Users app: user registration, authentication, profile (models, serializers, viewsets)
- Bunch app: channel management, messaging, permissions (WebSocket consumers, REST endpoints)
- Core app: shared utilities, site-wide views
- Infrastructure tier:
- Redis channel layer (pub/sub for messages)
- PostgreSQL database (persistent storage)
- CI/CD pipeline (GitHub Actions)

##### Final advice
- Endpoints (e.g., /api/users/, /api/bunch/) and WebSocket routes.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    subgraph "Clients" 
        direction TB
        Web["Web Client"]:::frontend
        Mobile["Mobile Client"]:::frontend
        Desktop["Desktop Client"]:::frontend
    end

    %% Server
    subgraph "Django ASGI Server" 
        direction TB
        ASGI["ASGI Entry Point"]:::backend
        WSGI["WSGI Entry Point"]:::backend
        Settings["Settings & Routing"]:::backend
        manage["manage.py"]:::backend
    end

    %% Django Apps
    subgraph "Orchard Project Apps"
        direction TB
        subgraph "Users App"
            direction TB
            UDir["server/users/"]:::backend
            UModels["models.py"]:::backend
            USerializers["serializers.py"]:::backend
            UViews["views.py"]:::backend
            UUrls["urls.py"]:::backend
            UTests["test_models.py, test_serializers.py, test_users.py"]:::backend
        end
        subgraph "Bunch App"
            direction TB
            BDir["server/bunch/"]:::backend
            BModels["models.py"]:::backend
            BPerms["permissions.py"]:::backend
            BSerializers["serializers.py"]:::backend
            BViews["views.py"]:::backend
            BUrls["urls.py"]:::backend
            BTests["test_bunch.py, test_channels.py, test_members.py, test_messages.py, test_models.py"]:::backend
        end
        subgraph "Core App"
            direction TB
            CDir["server/core/"]:::backend
            CModels["models.py"]:::backend
            CViews["views.py"]:::backend
            CUrls["urls.py"]:::backend
            CAdmin["admin.py"]:::backend
            CTests["tests.py"]:::backend
        end
    end

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        Redis["Redis Channel Layer"]:::datastore
        Postgres["PostgreSQL Database"]:::datastore
        CI["GitHub Actions CI/CD"]:::ci
    end

    %% Clients to Server - REST
    Web -->|HTTP REST| WSGI
    Mobile -->|HTTP REST| WSGI
    Desktop -->|HTTP REST| WSGI

    %% Clients to Server - WebSocket
    Web -->|WebSocket| ASGI
    Mobile -->|WebSocket| ASGI
    Desktop -->|WebSocket| ASGI

    %% Server internals
    WSGI --> Settings
    ASGI --> Settings
    Settings --> UDir
    Settings --> BDir
    Settings --> CDir
    manage --> Settings

    %% App to DB
    UViews -->|ORM CRUD| Postgres
    BViews -->|ORM CRUD| Postgres
    CViews -->|ORM CRUD| Postgres

    %% Real-time flow
    ASGI -->|pub/sub| Redis
    Redis -->|broadcast| ASGI
    ASGI --> Web
    ASGI --> Mobile
    ASGI --> Desktop

    %% CI pipeline
    CI --> UTests
    CI --> BTests
    CI --> CTests

    %% Click Events
    click ASGI "https://github.com/bunchhq/bunch/blob/main/server/orchard/asgi.py"
    click WSGI "https://github.com/bunchhq/bunch/blob/main/server/orchard/wsgi.py"
    click Settings "https://github.com/bunchhq/bunch/blob/main/server/orchard/settings.py"
    click Settings "https://github.com/bunchhq/bunch/blob/main/server/orchard/urls.py"
    click manage "https://github.com/bunchhq/bunch/blob/main/server/manage.py"
    click UDir "https://github.com/bunchhq/bunch/tree/main/server/users/"
    click UModels "https://github.com/bunchhq/bunch/blob/main/server/users/models.py"
    click USerializers "https://github.com/bunchhq/bunch/blob/main/server/users/serializers.py"
    click UViews "https://github.com/bunchhq/bunch/blob/main/server/users/views.py"
    click UUrls "https://github.com/bunchhq/bunch/blob/main/server/users/urls.py"
    click UTests "https://github.com/bunchhq/bunch/blob/main/server/users/test_models.py"
    click BDir "https://github.com/bunchhq/bunch/tree/main/server/bunch/"
    click BModels "https://github.com/bunchhq/bunch/blob/main/server/bunch/models.py"
    click BPerms "https://github.com/bunchhq/bunch/blob/main/server/bunch/permissions.py"
    click BSerializers "https://github.com/bunchhq/bunch/blob/main/server/bunch/serializers.py"
    click BViews "https://github.com/bunchhq/bunch/blob/main/server/bunch/views.py"
    click BUrls "https://github.com/bunchhq/bunch/blob/main/server/bunch/urls.py"
    click BTests "https://github.com/bunchhq/bunch/blob/main/server/bunch/test_bunch.py"
    click CDir "https://github.com/bunchhq/bunch/tree/main/server/core/"
    click CModels "https://github.com/bunchhq/bunch/blob/main/server/core/models.py"
    click CViews "https://github.com/bunchhq/bunch/blob/main/server/core/views.py"
    click CUrls "https://github.com/bunchhq/bunch/blob/main/server/core/urls.py"
    click CAdmin "https://github.com/bunchhq/bunch/blob/main/server/core/admin.py"
    click CTests "https://github.com/bunchhq/bunch/blob/main/server/core/tests.py"
    click CI "https://github.com/bunchhq/bunch/blob/main/.github/workflows/django.yml"
    click Postgres "https://github.com/bunchhq/bunch/blob/main/server/orchard/settings.py"
    click Redis "https://github.com/bunchhq/bunch/blob/main/server/orchard/settings.py"

    %% Styles
    classDef frontend fill:#c8e6c9,stroke:#2e7d32,color:#1b5e20;
    classDef backend fill:#bbdefb,stroke:#1565c0,color:#0d47a1;
    classDef datastore fill:#ffe0b2,stroke:#ef6c00,color:#e65100;
    classDef ci fill:#e1bee7,stroke:#8e24aa,color:#4a148c;
```
