How rangonroyutsab/ledgerly works
Purpose and Runtime
Ledgerly is a personal expense tracker with conventional CRUD workflows and an AI chat interface for recording and querying expenses. The backend is Django/Django REST Framework; the client is a React/Vite single-page application. Backend startup is through manage.py, core/asgi.py, or core/wsgi.py; frontend startup begins at frontend/src/main.jsx.
HTTP and Application Composition
Django settings and top-level route composition are centralized in core/settings.py and core/urls.py. Domain apps expose their own route/view boundaries:
• apps/users/urls.py, apps/users/views.py
• apps/expenses/urls.py, apps/expenses/views.py
• apps/categories/urls.py, apps/categories/views.py
• apps/presets/urls.py, apps/presets/views.py
• apps/assistant/urls.py, apps/assistant/views.py
Views/serializers form the REST boundary; services and selectors keep domain operations and read access out of transport handlers.
Identity and Data Isolation
The users domain owns the custom user model and authentication-facing API contracts in apps/users/models.py, apps/users/serializers.py, and apps/users/views.py. JWT-protected frontend routing is represented by frontend/src/contexts/AuthContext.jsx and frontend/src/components/ProtectedRoute.jsx. Expense, category, preset, and assistant operations are intended to be scoped to the authenticated user rather than globally shared.
Expense and Category Domain
Expenses are the core ledger records, modeled and operated through apps/expenses/models.py, apps/expenses/services/expenses.py, and apps/expenses/selectors/expenses.py. Categories have independent persistence and business operations in apps/categories/models.py, apps/categories/services/categories.py, and apps/categories/selectors/. Category signals (apps/categories/signals.py) imply lifecycle coupling, likely for maintaining defaults or related state. Presets provide reusable expense-oriented data/templates through apps/presets/models.py, apps/presets/serializers.py, and apps/presets/views.py.
Assistant Processing Pipeline
The assistant API delegates natural-language handling into a staged service layer:
1. Request/chat transport: apps/assistant/views.py
2. Provider-neutral AI interface and selection: apps/assistant/providers/base.py, apps/assistant/providers/factory.py
3. Provider invocation: apps/assistant/providers/gemini.py or apps/assistant/providers/ollama.py
4. AI-output parsing and intent orchestration: apps/assistant/services/parser.py, apps/assistant/services/intent_handler.py
5. Domain resolution and mutation/query messaging: apps/assistant/services/resolvers.py, apps/assistant/services/category_resolution.py, apps/assistant/services/messaging.py
This separates nondeterministic LLM interpretation from deterministic resolution against user, category, and expense data.
Frontend Control Flow
frontend/src/App.jsx composes page-level routes for login, dashboard, expenses, categories, presets, settings, and assistant. API communication is centralized through frontend/src/api/axios.js; auth state and assistant conversation state are held in frontend/src/contexts/AuthContext.jsx and frontend/src/contexts/AssistantChatContext.jsx. Primary interaction surfaces include frontend/src/pages/Expenses.jsx, frontend/src/pages/Categories.jsx, and frontend/src/pages/Assistant.jsx.
Infrastructure and External Boundaries
PostgreSQL is the persistent store, configured through DATABASE_URL; schema evolution lives in per-app migrations such as apps/expenses/migrations/0001_initial.py. Docker deployment is defined by Dockerfile and docker-compose.yml. AI is pluggable via AI_PROVIDER: Gemini requires an external API key, while Ollama targets a configurable local/network inference endpoint. Backend API and database run in Compose; the Vite frontend is run separately in development.
Main entry points: urls.py API composition · App.jsx App routes · axios.js API client · resolvers.py Domain resolution
Components 18
React SPA
- App routes · Composes login, ledger, settings, and assistant pages.
frontend/src/App.jsx - Auth state · Maintains authenticated client state.
frontend/src/contexts/AuthContext.jsx - Protected routes
frontend/src/components/ProtectedRoute.jsx - Ledger pages
frontend/src/pages/Expenses.jsx - Assistant UI
frontend/src/pages/Assistant.jsx - API client
frontend/src/api/axios.js
Django API
- API composition · Central settings and top-level URL composition.
core/urls.py - Users & auth API · Owns the custom user and authentication contracts.
apps/users/views.py - Expense domain · User-scoped ledger writes and reads.
apps/expenses/services/expenses.py - Category domain · Independent categories with lifecycle signals.
apps/categories/services/categories.py - Preset API · Reusable expense-oriented templates.
apps/presets/views.py
Assistant pipeline
- Assistant API
apps/assistant/views.py - AI provider selection · Selects a provider-neutral AI implementation.
apps/assistant/providers/factory.py - Gemini or Ollama · External Gemini API or configurable Ollama endpoint.
apps/assistant/providers/gemini.py - Parse & intent handling · Turns model output into deterministic intents.
apps/assistant/services/intent_handler.py - Domain resolution · Resolves users and categories, mutates or queries ledger data, and formats replies.
apps/assistant/services/resolvers.py
Infrastructure
- PostgreSQL · Schema is evolved through per-app migrations.
- Docker Compose · Runs backend API and database.
docker-compose.yml
Connections 25
- App routes → Auth state: uses
- App routes → Protected routes: guards
- App routes → Ledger pages: routes to
- App routes → Assistant UI: routes to
- Auth state → API client: supplies JWT
- Ledger pages → API client: CRUD requests
- Assistant UI → API client: chat requests
- API client → API composition: HTTP API
- API composition → Users & auth API: routes
- API composition → Expense domain: routes
- API composition → Category domain: routes
- API composition → Preset API: routes
- API composition → Assistant API: routes
- Users & auth API → PostgreSQL: users
- Expense domain → PostgreSQL: expenses
- Category domain → PostgreSQL: categories
- Preset API → PostgreSQL: presets
- Assistant API → AI provider selection: delegates
- AI provider selection → Gemini or Ollama: invokes
- Gemini or Ollama → Parse & intent handling: model output
- Parse & intent handling → Domain resolution: intent
- Domain resolution → Expense domain: queries or mutates
- Domain resolution → Category domain: resolves categories
- Docker Compose → API composition: runs API
- Docker Compose → PostgreSQL: runs database