# yeonnan/onedaychat architecture

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

- Interactive diagram: https://gitdiagram.com/yeonnan/onedaychat
- Repository: https://github.com/yeonnan/onedaychat

## Overview

##### Project Type and Purpose
- One Day Chat is a full-stack Django web application (with Django REST Framework) that leverages OpenAI’s API to generate and manage daily diary entries via a chatbot interface. It also uses Celery for scheduled diary generation.

##### File Structure Analysis
- Top-level:
- manage.py, Dockerfile, docker-compose.yml, nginx.conf
- Requirements and settings under onedaychat/ (ASGI/WSGI, Celery config, Django settings)
- Three Django apps: accounts (authentication, user management), chatbot (chat UI, OpenAI integration), diary (diary CRUD)
- Static and templates directories for shared assets
- Deployment/config: docker-compose.yml defines service composition; nginx.conf for reverse proxy; .env for secrets.

##### README Highlights
- Tech stack: Python3.10, Django, DRF, PostgreSQL, Celery, AWS EC2/S3, Docker-compose, Nginx
- Task queue for midnight auto-creation of diary entries
- External service dependencies: OpenAI API, AWS S3 for media

##### Main Components
a. Clients (Web Browser / Mobile)
b. Nginx Reverse Proxy (serving static files, forwarding requests)
c. Django “web” Service (Docker container running Gunicorn/ASGI)
d. Celery Worker Service (for scheduled and async tasks)
e. Message Broker (Redis or RabbitMQ)
f. PostgreSQL Database
g. AWS S3 (media storage for diary assets)
h. External OpenAI API

##### Relationships & Data Flows
1. User → HTTP(S) → Nginx → Django Web
2. Django Web ↔ PostgreSQL (ORM reads/writes users, diaries)
3. Django Web ↔ AWS S3 (upload/retrieve media)
4. Django Web enqueues tasks → Broker → Celery Worker
5. Celery Worker → Broker for scheduling; Worker calls OpenAI API → processes response → saves diary to DB & S3
6. Django Web serves API endpoints (chatbot endpoints under /api/chatbot/, diary endpoints under /api/diary/, auth under /api/accounts/)

##### Architectural Patterns & Principles
- MVC (Django Views → Templates; Models → PostgreSQL; Controllers via URLs + Views)
- Service separation: Web vs. Worker
- Externalized configuration (env vars, Docker)
- Asynchronous processing for long-running tasks (Celery)
- REST API layer for frontend JavaScript to interact with backend

b. Next, show Nginx as the entry point; annotate “Docker: nginx container” with ports 80/443.
d. Under or beside it, show Celery worker container. Connect both to the message broker.
h. Surround the middle components with a “Docker-compose” boundary.
i. Optionally, surround the entire service cluster with an “AWS EC2” boundary.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    Client["Client Browser/Mobile"]:::frontend

    %% AWS EC2 Boundary
    subgraph "AWS EC2"
        %% Docker-compose Orchestration
        subgraph "Docker-compose"
            direction TB
            Compose["docker\-compose.yml"]:::infra

            %% Nginx Service
            Nginx["Nginx Reverse Proxy<br/>(80/443)"]:::frontend

            %% Django Web Service with Code Components
            subgraph "Django Web Service"
                direction TB
                Entry["manage.py"]:::code
                Settings["settings.py"]:::code
                URLs["urls.py"]:::code
                ASGI["asgi.py"]:::code
                WSGI["wsgi.py"]:::code
                Views["views.py"]:::code
            end

            %% Celery Worker Service with Code Components
            subgraph "Celery Worker"
                direction TB
                CeleryApp["celery.py"]:::code
                Tasks["tasks.py"]:::code
            end

            Broker["Message Broker<br/>(Redis/RabbitMQ)"]:::infra
            DB["PostgreSQL"]:::infra
        end

        S3["AWS S3<br/>(Media Storage)"]:::external
    end

    OpenAI["OpenAI API"]:::external

    %% Data Flows
    Client -->|"HTTPS Request"| Nginx
    Nginx -->|"Proxy to Web"| Entry
    Entry -->|"ORM Read/Write"| DB
    Entry -->|"Media Upload/Retrieve"| S3
    Entry -->|"Enqueue Task"| Broker
    Broker -->|"Deliver Task"| CeleryApp
    CeleryApp -->|"Scheduled/Async Task"| Tasks
    Tasks -->|"LLM Request"| OpenAI
    Tasks -->|"Save Entry"| DB
    Tasks -->|"Store Media"| S3

    %% Click Events
    click Compose "https://github.com/yeonnan/onedaychat/blob/main/docker-compose.yml"
    click Nginx "https://github.com/yeonnan/onedaychat/blob/main/nginx.conf"
    click Entry "https://github.com/yeonnan/onedaychat/blob/main/manage.py"
    click Settings "https://github.com/yeonnan/onedaychat/blob/main/onedaychat/settings.py"
    click URLs "https://github.com/yeonnan/onedaychat/blob/main/onedaychat/urls.py"
    click ASGI "https://github.com/yeonnan/onedaychat/blob/main/onedaychat/asgi.py"
    click WSGI "https://github.com/yeonnan/onedaychat/blob/main/onedaychat/wsgi.py"
    click Views "https://github.com/yeonnan/onedaychat/blob/main/onedaychat/views.py"
    click CeleryApp "https://github.com/yeonnan/onedaychat/blob/main/onedaychat/celery.py"
    click Tasks "https://github.com/yeonnan/onedaychat/blob/main/chatbot/tasks.py"
    click Broker "https://github.com/yeonnan/onedaychat/blob/main/docker-compose.yml"
    click DB "https://github.com/yeonnan/onedaychat/blob/main/docker-compose.yml"
    click S3 "https://github.com/yeonnan/onedaychat/blob/main/onedaychat/settings.py"
    click OpenAI "https://github.com/yeonnan/onedaychat/blob/main/chatbot/openai_service.py"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#0d47a1,color:#0d47a1
    classDef backend fill:#c8e6c9,stroke:#1b5e20,color:#1b5e20
    classDef infra fill:#ffecb3,stroke:#ff6f00,color:#e65100
    classDef external fill:#ffcdd2,stroke:#b71c1c,color:#b71c1c
    classDef code fill:#eef,stroke:#90a4ae,color:#37474f
```
