How yeonnan/onedaychat works
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.