# routinetinc/routinet-server architecture

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

- Interactive diagram: https://gitdiagram.com/routinetinc/routinet-server
- Repository: https://github.com/routinetinc/routinet-server

## Overview

##### Project type and purpose
- This is a monolithic Django-based backend service (no dedicated frontend in this repo).
- The README only covers coding/git conventions; architectural intent comes from the file tree.
- It exposes RESTful endpoints via multiple Django apps: feed, routine, run, supply_auth.

##### File structure
- Top-level Django project:
- KGAvengers/ – project settings, ASGI/WSGI entrypoints, middleware.
- manage.py – Django management utility.
- requirements.txt – Python dependencies.
- drop_and_create_db.py – DB setup script.
- Apps (each under root):
- feed/ – feed-related REST views, models, admin, migrations, caching, graph-DB utility code.
- routine/ – task scheduling endpoints, serializers, custom view packages.
- run/ – execution endpoints, management commands (graph_db), models, views.
- supply_auth/ – authentication/authorization, custom user models, views.
- Utilities:
- feed/utils/graph_db/* – abstractions and connections to a graph database.
- feed/cache.py – caching layer (likely Redis or similar).
- routine/utils and run/management/commands – helper scripts.

##### README for additional insights
- We infer use of Python 3.11, Django’s MVT, and a relational DB (via migrations) plus a graph DB.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Web Tier
    Client["Client"]:::ext
    Nginx["Nginx (Reverse Proxy)"]:::webTier
    ASGI["ASGI Server\n(KGAvengers/asgi.py)"]:::webTier
    WSGI["WSGI Server\n(KGAvengers/wsgi.py)"]:::webTier

    %% Django Service Boundary
    subgraph "Django Service" 
        direction TB
        Settings["Settings\n(KGAvengers/settings.py)"]:::appCode
        Middleware["Custom Middleware\n(KGAvengers/middleware_myself.py)"]:::appCode
        URLResolver["URL Resolver\n(KGAvengers/urls.py)"]:::appCode

        %% Feed App
        subgraph "Feed App" 
            direction TB
            FeedModels["feed/models.py"]:::appCode
            FeedViews["feed/views.py"]:::appCode
            FeedURLs["feed/urls.py"]:::appCode
            FeedAdmin["feed/admin.py"]:::appCode
            subgraph "Feed Utils"
                direction TB
                FeedCache["feed/cache.py"]:::appCode
                GraphAbstract["abstract_by_graph_db.py"]:::appCode
                GraphConn["connections.py"]:::appCode
                GraphInd["individual_edge_and_node.py"]:::appCode
                WorkerUtils["feed/utils/worker_utils.py"]:::appCode
            end
            FFRelated["feed/ff_related.py"]:::appCode
            UserActions["feed/user_actions.py"]:::appCode
        end

        %% Routine App
        subgraph "Routine App"
            direction TB
            RoutineModels["routine/models.py"]:::appCode
            RoutineSerializers["routine/serializers.py"]:::appCode
            RoutineViews["routine/views.py"]:::appCode
            RoutineURLs["routine/urls.py"]:::appCode
            subgraph "routine/utils"
                direction TB
                ConvTime["routine/utils/conv_time_fmt.py"]:::appCode
                HandleJSON["routine/utils/handle_json.py"]:::appCode
            end
            subgraph "views_package"
                direction TB
                MiniComment["mini_comment.py"]:::appCode
                NoAvailable["no_available_task.py"]:::appCode
                RoutineVP["routine.py"]:::appCode
                TaskVP["task.py"]:::appCode
                TimeTree["timetree.py"]:::appCode
            end
        end

        %% Run App
        subgraph "Run App"
            direction TB
            RunModels["run/models.py"]:::appCode
            RunViews["run/views.py"]:::appCode
            GraphCmd["graph_db command\n(run/management/commands/graph_db.py)"]:::appCode
        end

        %% Supply Auth App
        subgraph "Supply_Auth App"
            direction TB
            AuthModels["supply_auth/models.py"]:::appCode
            AuthViews["supply_auth/views.py"]:::appCode
            AuthURLs["supply_auth/urls.py"]:::appCode
            AuthAdmin["supply_auth/admin.py"]:::appCode
        end
    end

    %% Management & Utilities
    Manage["manage.py"]:::appCode
    DropDB["drop_and_create_db.py"]:::appCode
    Requirements["requirements.txt"]:::appCode

    %% Data Stores
    RelationalDB["Relational DB\n(Postgres)"]:::data
    GraphDB["Graph DB\n(Neo4j)"]:::data
    Redis["Redis Cache"]:::data

    %% External Services
    External["External Services\n(email, 3rd-party APIs)"]:::ext

    %% Background Workers
    Workers["Background Workers\n(management commands)"]:::ext

    %% Connections
    Client -->|HTTPS| Nginx
    Nginx --> ASGI
    Nginx --> WSGI
    ASGI --> Settings
    WSGI --> Settings
    Settings --> Middleware
    Middleware --> URLResolver
    URLResolver --> FeedURLs
    URLResolver --> RoutineURLs
    URLResolver --> RunViews
    URLResolver --> AuthURLs

    FeedViews -->|uses| FeedModels
    FeedViews -->|caches| Redis
    FeedViews -->|graph ops| GraphDB
    FeedViews -->|utils| FeedCache
    FeedViews -->|utils| WorkerUtils
    FeedViews -->|utils| FFRelated
    FeedViews -->|utils| UserActions

    RoutineViews -->|uses| RoutineModels
    RoutineViews -->|utils| ConvTime
    RoutineViews -->|utils| HandleJSON
    RoutineViews -->|views package| MiniComment
    RoutineViews -->|views package| NoAvailable
    RoutineViews -->|views package| RoutineVP
    RoutineViews -->|views package| TaskVP
    RoutineViews -->|views package| TimeTree

    RunViews -->|uses| RunModels
    RunViews -->|triggers| GraphCmd

    AuthViews -->|uses| AuthModels

    FeedModels --> RelationalDB
    RoutineModels --> RelationalDB
    RunModels --> RelationalDB
    AuthModels --> RelationalDB

    DropDB --> RelationalDB
    Manage --> URLResolver

    Workers -->|executes| GraphCmd

    External -->|called by| FeedViews
    External -->|called by| RoutineViews
    External -->|called by| RunViews

    %% Click Events
    click ASGI "https://github.com/routinetinc/routinet-server/blob/main/KGAvengers/asgi.py"
    click WSGI "https://github.com/routinetinc/routinet-server/blob/main/KGAvengers/wsgi.py"
    click Settings "https://github.com/routinetinc/routinet-server/blob/main/KGAvengers/settings.py"
    click Middleware "https://github.com/routinetinc/routinet-server/blob/main/KGAvengers/middleware_myself.py"
    click URLResolver "https://github.com/routinetinc/routinet-server/blob/main/KGAvengers/urls.py"
    click Manage "https://github.com/routinetinc/routinet-server/blob/main/manage.py"
    click DropDB "https://github.com/routinetinc/routinet-server/blob/main/drop_and_create_db.py"
    click Requirements "https://github.com/routinetinc/routinet-server/blob/main/requirements.txt"
    click FeedModels "https://github.com/routinetinc/routinet-server/blob/main/feed/models.py"
    click FeedViews "https://github.com/routinetinc/routinet-server/blob/main/feed/views.py"
    click FeedURLs "https://github.com/routinetinc/routinet-server/blob/main/feed/urls.py"
    click FeedAdmin "https://github.com/routinetinc/routinet-server/blob/main/feed/admin.py"
    click FeedCache "https://github.com/routinetinc/routinet-server/blob/main/feed/cache.py"
    click GraphAbstract "https://github.com/routinetinc/routinet-server/blob/main/feed/utils/graph_db/abstract_by_graph_db.py"
    click GraphConn "https://github.com/routinetinc/routinet-server/blob/main/feed/utils/graph_db/connections.py"
    click GraphInd "https://github.com/routinetinc/routinet-server/blob/main/feed/utils/graph_db/individual_edge_and_node.py"
    click WorkerUtils "https://github.com/routinetinc/routinet-server/blob/main/feed/utils/worker_utils.py"
    click FFRelated "https://github.com/routinetinc/routinet-server/blob/main/feed/ff_related.py"
    click UserActions "https://github.com/routinetinc/routinet-server/blob/main/feed/user_actions.py"
    click RoutineModels "https://github.com/routinetinc/routinet-server/blob/main/routine/models.py"
    click RoutineSerializers "https://github.com/routinetinc/routinet-server/blob/main/routine/serializers.py"
    click RoutineViews "https://github.com/routinetinc/routinet-server/blob/main/routine/views.py"
    click RoutineURLs "https://github.com/routinetinc/routinet-server/blob/main/routine/urls.py"
    click ConvTime "https://github.com/routinetinc/routinet-server/blob/main/routine/utils/conv_time_fmt.py"
    click HandleJSON "https://github.com/routinetinc/routinet-server/blob/main/routine/utils/handle_json.py"
    click MiniComment "https://github.com/routinetinc/routinet-server/blob/main/routine/views_package/mini_comment.py"
    click NoAvailable "https://github.com/routinetinc/routinet-server/blob/main/routine/views_package/no_available_task.py"
    click RoutineVP "https://github.com/routinetinc/routinet-server/blob/main/routine/views_package/routine.py"
    click TaskVP "https://github.com/routinetinc/routinet-server/blob/main/routine/views_package/task.py"
    click TimeTree "https://github.com/routinetinc/routinet-server/blob/main/routine/views_package/timetree.py"
    click RunModels "https://github.com/routinetinc/routinet-server/blob/main/run/models.py"
    click RunViews "https://github.com/routinetinc/routinet-server/blob/main/run/views.py"
    click GraphCmd "https://github.com/routinetinc/routinet-server/blob/main/run/management/commands/graph_db.py"
    click AuthModels "https://github.com/routinetinc/routinet-server/blob/main/supply_auth/models.py"
    click AuthViews "https://github.com/routinetinc/routinet-server/blob/main/supply_auth/views.py"
    click AuthURLs "https://github.com/routinetinc/routinet-server/blob/main/supply_auth/urls.py"
    click AuthAdmin "https://github.com/routinetinc/routinet-server/blob/main/supply_auth/admin.py"

    %% Styles
    classDef webTier fill:#CCEEFF,stroke:#333,stroke-width:1px
    classDef appCode fill:#CCFFCC,stroke:#333,stroke-width:1px
    classDef data fill:#FFDD99,stroke:#333,stroke-width:1px
    classDef ext fill:#DDDDDD,stroke:#333,stroke-width:1px
```
