How chikashishirozu/django-kakeibo01 works
Project Type & Purpose
• This is a monolithic, full-stack Django web application named “Django-kakeibo01” (a home budgeting app).
• The “household_budget” folder is the Django project (settings, URL dispatch, ASGI/WSGI), and the “budget” folder is the core Django app (models, views, templates, forms, migrations, custom management commands).
File-Structure Analysis
Top-level
• manage.py – CLI entry-point for web server & custom commands
• db.sqlite3 – embedded SQLite database
• requirements.txt – Python dependencies
• urls.py – (likely included by household_budget/urls.py)
household_budget/
• settings.py – INSTALLED_APPS, database config, middleware, templates dirs
• urls.py – root URL dispatcher
• asgi.py / wsgi.py – ASGI/WSGI entrypoints for asynchronous/synchronous servers
budget/
• models.py – ORM definitions (BudgetEntry, Category, User relation)
• views.py – view functions rendering templates or returning JSON
• forms.py – Django form classes for input validation
• templates/budget/*.html – UI layer (dashboard, entry_form, graph, monthly_view)
• migrations/ – schema change history
• management/commands/setup_categories.py – custom CLI command to bootstrap categories
Key README Insights
• Emphasis on custom management commands (setup_categories, potential daily_report, cleanup_old_data)
• Instructions on packaging the commands directory with __init__.py
• Typical use cases: database initialization, periodic tasks via cron, maintenance tasks
a. Main Components
• Client (Web Browser / Mobile Browser)
• HTTP Server & ASGI/WSGI Layer (e.g., uvicorn/gunicorn behind Nginx)
• Django Core
– URL Dispatcher (household_budget/urls.py → budget/urls.py)
– Views & Forms (budget/views.py, forms.py)
– Templates (budget/templates)
– ORM & Models (budget/models.py)
• SQLite Database (db.sqlite3)
• Management Commands (manage.py → Django command registry → budget/management/commands)
• Cron / Scheduler (optional external service to run periodic commands)
b. Relationships & Interactions
1. Client sends HTTP request → Nginx/Apache (optional) → ASGI/WSGI server → Django’s URL dispatcher
2. Dispatcher routes to a view → view uses form validation → view queries/updates ORM → SQLite
3. ORM returns data → view renders template → HTTP response to client
4. CLI: sysadmin runs python manage.py setup_categories → Django loads settings & apps → executes command → writes to DB
5. Scheduler (cron) triggers manage.py daily_report/cleanup_old_data → same flow as CLI
c. Architectural Patterns & Principles
• Monolithic MVC (MVT in Django terms)
• Separation of concerns: URL routing, view logic, data models, templates
• Reusable management commands for one-off or scheduled tasks
• Single database for persistence
d. Key Technologies & Frameworks
• Python 3.x, Django framework
• SQLite (for development – can swap to PostgreSQL, MySQL)
• ASGI/WSGI servers (e.g., uvicorn, gunicorn)
• Cron or external scheduler for periodic tasks