# antonymittul/momentum architecture

> Architecture diagram of the GitHub repository antonymittul/momentum, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/antonymittul/momentum
- Repository: https://github.com/antonymittul/momentum

## Overview

#### Purpose and Runtime Topology
Momentum is a local-first AI productivity companion for daily tasks, habits (“non-negotiables”), goals, notes, consistency metrics, and AI-generated coaching/reports. It runs as a Next.js 15 frontend and a FastAPI backend, with SQLite persistence. Primary startup points are `frontend/src/app/layout.tsx`, `frontend/src/app/page.tsx`, and `backend/main.py`.

#### Frontend Application Shell and Navigation
The frontend uses the Next.js App Router to provide feature pages and global presentation/theme behavior. The dashboard is rooted at `frontend/src/app/page.tsx`; dedicated routes cover tasks, habits, goals, calendar, insights, notes, assistant, and appearance settings under `frontend/src/app/`. Global styles and theme provisioning are defined in `frontend/src/app/globals.css` and `frontend/src/components/ThemeProvider.tsx`; responsive navigation includes `frontend/src/components/MobileNav.tsx`.

#### API Boundary
Browser-side feature pages call the FastAPI service through the centralized client in `frontend/src/lib/api.ts`. This is the main frontend/backend boundary: UI state and interactions are translated into HTTP requests, while backend routers expose domain-specific API surfaces. The frontend is a React/TypeScript runtime; the backend is Python/FastAPI, normally served via Uvicorn on port 8000.

#### Backend Composition and Persistence
`backend/main.py` constructs the FastAPI application and integrates route modules. `backend/database.py` owns SQLAlchemy/SQLite connectivity and session infrastructure. Persistent entities and their relationships are represented in `backend/models.py`, while API request/response contracts are separated into `backend/schemas.py`. This keeps HTTP payload validation distinct from database representation.

#### Productivity Domain APIs
Core CRUD and tracking capabilities are partitioned by resource:
- Tasks: `backend/routers/tasks.py`, surfaced through task UI and reusable task workflows in `frontend/src/app/tasks/page.tsx` and `frontend/src/components/TaskCard.tsx`.
- Habit adherence: `backend/routers/non_negotiables.py` and `frontend/src/app/non-negotiables/page.tsx`.
- Goals and notes: `backend/routers/goals.py`, `backend/routers/notes.py`, with corresponding pages.
- User-facing preferences: `backend/routers/settings.py` and `frontend/src/app/appearances/page.tsx`.

Task priority ordering and completion activity feed the dashboard and downstream analytics.

#### Metrics, Insights, and Calendar Flow
`backend/routers/metrics.py` aggregates persisted completion and habit data into consistency scores and streak-oriented outputs. The frontend renders these outputs in `frontend/src/app/insights/page.tsx` and `frontend/src/app/calendar/page.tsx`, using Recharts per the project stack. This is the reporting boundary between raw operational records and derived progress views.

#### AI Coaching and Weekly Reports
AI operations are isolated in `backend/routers/ai.py`, using Google Gemini 1.5 Flash through `google-generativeai` and a `GEMINI_API_KEY` environment variable. Dashboard/assistant experiences consume generated motivation or guidance through `frontend/src/app/assistant/page.tsx` and the main dashboard. `backend/routers/reports.py` generates weekly AI-authored PDF reports using FPDF2, drawing from task completion, streak, and habit-adherence data for download/review.

#### Infrastructure
Development is orchestrated as separate frontend and backend processes, with `docker-compose.yml` providing container-oriented deployment composition. SQLite avoids a separate database service; Google Gemini is the material external dependency and requires API-key configuration.

Main entry points: [`frontend/src/app/layout.tsx`](https://github.com/antonymittul/momentum/blob/main/frontend/src/app/layout.tsx) (App shell & theme), [`frontend/src/lib/api.ts`](https://github.com/antonymittul/momentum/blob/main/frontend/src/lib/api.ts) (API client), [`backend/main.py`](https://github.com/antonymittul/momentum/blob/main/backend/main.py) (FastAPI application), [`backend/models.py`](https://github.com/antonymittul/momentum/blob/main/backend/models.py) (Persistence models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Next.js frontend"]
  node_shell["App shell &amp; theme<br/>Next.js layout<br/>[layout.tsx]"]
  node_dashboard["Dashboard<br/>feature page<br/>[page.tsx]"]
  node_task_ui["Task workflows<br/>feature UI<br/>[page.tsx]"]
  node_habit_ui["Habits<br/>feature page<br/>[page.tsx]"]
  node_goals_notes_ui["Goals &amp; notes<br/>feature pages"]
  node_insights_calendar_ui["Insights &amp; calendar<br/>reporting UI<br/>[page.tsx]"]
  node_assistant_ui["Assistant<br/>feature page<br/>[page.tsx]"]
  node_appearance_ui["Appearance settings<br/>feature page<br/>[page.tsx]"]
  node_api_client{{"API client<br/>HTTP client<br/>[api.ts]"}}
end

subgraph group_backend["FastAPI backend"]
  node_fastapi_app["FastAPI application<br/>application entrypoint<br/>[main.py]"]
  node_domain_routers["Productivity APIs<br/>domain routers<br/>[tasks.py]"]
  node_metrics_api["Metrics API<br/>analytics router<br/>[metrics.py]"]
  node_ai_api["AI coaching API<br/>AI router<br/>[ai.py]"]
  node_reports_api["Weekly reports API<br/>report router<br/>[reports.py]"]
  node_schemas["API schemas<br/>request/response contracts<br/>[schemas.py]"]
  node_models["Persistence models<br/>SQLAlchemy models<br/>[models.py]"]
end

subgraph group_data["Data and external services"]
  node_database[("Database sessions<br/>SQLAlchemy infrastructure<br/>[database.py]")]
  node_sqlite[("SQLite store<br/>local database")]
  node_gemini{{"Google Gemini 1.5 Flash<br/>external AI service"}}
  node_compose["Container composition<br/>deployment orchestration<br/>[docker-compose.yml]"]
end

node_shell -->|"hosts"| node_dashboard
node_shell -->|"hosts"| node_task_ui
node_shell -->|"hosts"| node_habit_ui
node_shell -->|"hosts"| node_goals_notes_ui
node_shell -->|"hosts"| node_insights_calendar_ui
node_shell -->|"hosts"| node_assistant_ui
node_shell -->|"hosts"| node_appearance_ui
node_dashboard -->|"loads daily data"| node_api_client
node_task_ui -->|"CRUD requests"| node_api_client
node_habit_ui -->|"adherence requests"| node_api_client
node_goals_notes_ui -->|"CRUD requests"| node_api_client
node_insights_calendar_ui -->|"requests metrics"| node_api_client
node_assistant_ui -->|"coaching requests"| node_api_client
node_appearance_ui -->|"preference requests"| node_api_client
node_api_client -->|"HTTP"| node_fastapi_app
node_fastapi_app -->|"routes to"| node_domain_routers
node_fastapi_app -->|"routes to"| node_metrics_api
node_fastapi_app -->|"routes to"| node_ai_api
node_fastapi_app -->|"routes to"| node_reports_api
node_domain_routers -->|"validates payloads"| node_schemas
node_domain_routers -->|"reads and writes"| node_models
node_metrics_api -->|"aggregates activity"| node_models
node_reports_api -->|"uses completion data"| node_models
node_ai_api -->|"generates coaching"| node_gemini
node_reports_api -->|"authors report content"| node_gemini
node_models -->|"uses sessions"| node_database
node_database -->|"connects to"| node_sqlite
node_compose -.->|"deploys frontend"| node_shell
node_compose -.->|"deploys backend"| node_fastapi_app

click node_shell "https://github.com/antonymittul/momentum/blob/main/frontend/src/app/layout.tsx"
click node_dashboard "https://github.com/antonymittul/momentum/blob/main/frontend/src/app/page.tsx"
click node_task_ui "https://github.com/antonymittul/momentum/blob/main/frontend/src/app/tasks/page.tsx"
click node_habit_ui "https://github.com/antonymittul/momentum/blob/main/frontend/src/app/non-negotiables/page.tsx"
click node_insights_calendar_ui "https://github.com/antonymittul/momentum/blob/main/frontend/src/app/insights/page.tsx"
click node_assistant_ui "https://github.com/antonymittul/momentum/blob/main/frontend/src/app/assistant/page.tsx"
click node_appearance_ui "https://github.com/antonymittul/momentum/blob/main/frontend/src/app/appearances/page.tsx"
click node_api_client "https://github.com/antonymittul/momentum/blob/main/frontend/src/lib/api.ts"
click node_fastapi_app "https://github.com/antonymittul/momentum/blob/main/backend/main.py"
click node_domain_routers "https://github.com/antonymittul/momentum/blob/main/backend/routers/tasks.py"
click node_metrics_api "https://github.com/antonymittul/momentum/blob/main/backend/routers/metrics.py"
click node_ai_api "https://github.com/antonymittul/momentum/blob/main/backend/routers/ai.py"
click node_reports_api "https://github.com/antonymittul/momentum/blob/main/backend/routers/reports.py"
click node_schemas "https://github.com/antonymittul/momentum/blob/main/backend/schemas.py"
click node_models "https://github.com/antonymittul/momentum/blob/main/backend/models.py"
click node_database "https://github.com/antonymittul/momentum/blob/main/backend/database.py"
click node_compose "https://github.com/antonymittul/momentum/blob/main/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_shell,node_dashboard,node_task_ui,node_habit_ui,node_goals_notes_ui,node_insights_calendar_ui,node_assistant_ui,node_appearance_ui,node_api_client toneBlue
class node_fastapi_app,node_domain_routers,node_metrics_api,node_ai_api,node_reports_api,node_schemas,node_models toneAmber
class node_database,node_sqlite,node_gemini,node_compose toneMint
```

## Components

### Next.js frontend

React/TypeScript App Router UI.

- [App shell & theme](https://github.com/antonymittul/momentum/blob/main/frontend/src/app/layout.tsx): Next.js layout · Provides global styling, theme, and responsive navigation. · `frontend/src/app/layout.tsx`
- [Dashboard](https://github.com/antonymittul/momentum/blob/main/frontend/src/app/page.tsx): feature page · Primary daily productivity view. · `frontend/src/app/page.tsx`
- [Task workflows](https://github.com/antonymittul/momentum/blob/main/frontend/src/app/tasks/page.tsx): feature UI · Task page and reusable task cards. · `frontend/src/app/tasks/page.tsx`
- [Habits](https://github.com/antonymittul/momentum/blob/main/frontend/src/app/non-negotiables/page.tsx): feature page · `frontend/src/app/non-negotiables/page.tsx`
- **Goals & notes**: feature pages
- [Insights & calendar](https://github.com/antonymittul/momentum/blob/main/frontend/src/app/insights/page.tsx): reporting UI · Renders derived metrics and progress views. · `frontend/src/app/insights/page.tsx`
- [Assistant](https://github.com/antonymittul/momentum/blob/main/frontend/src/app/assistant/page.tsx): feature page · `frontend/src/app/assistant/page.tsx`
- [Appearance settings](https://github.com/antonymittul/momentum/blob/main/frontend/src/app/appearances/page.tsx): feature page · `frontend/src/app/appearances/page.tsx`
- [API client](https://github.com/antonymittul/momentum/blob/main/frontend/src/lib/api.ts): HTTP client · Centralized browser-to-backend boundary. · `frontend/src/lib/api.ts`

### FastAPI backend

Python API and domain processing.

- [FastAPI application](https://github.com/antonymittul/momentum/blob/main/backend/main.py): application entrypoint · Constructs the API and registers routers. · `backend/main.py`
- [Productivity APIs](https://github.com/antonymittul/momentum/blob/main/backend/routers/tasks.py): domain routers · Tasks, habits, goals, notes, and settings CRUD. · `backend/routers/tasks.py`
- [Metrics API](https://github.com/antonymittul/momentum/blob/main/backend/routers/metrics.py): analytics router · Calculates consistency scores and streak outputs. · `backend/routers/metrics.py`
- [AI coaching API](https://github.com/antonymittul/momentum/blob/main/backend/routers/ai.py): AI router · Generates motivation and guidance. · `backend/routers/ai.py`
- [Weekly reports API](https://github.com/antonymittul/momentum/blob/main/backend/routers/reports.py): report router · Builds AI-authored PDF weekly reports. · `backend/routers/reports.py`
- [API schemas](https://github.com/antonymittul/momentum/blob/main/backend/schemas.py): request/response contracts · Separates payload validation from persistence models. · `backend/schemas.py`
- [Persistence models](https://github.com/antonymittul/momentum/blob/main/backend/models.py): SQLAlchemy models · Defines persistent entities and relationships. · `backend/models.py`

### Data and external services

- [Database sessions](https://github.com/antonymittul/momentum/blob/main/backend/database.py): SQLAlchemy infrastructure · Owns SQLite connectivity and sessions. · `backend/database.py`
- **SQLite store**: local database
- **Google Gemini 1.5 Flash**: external AI service · Requires GEMINI_API_KEY.
- [Container composition](https://github.com/antonymittul/momentum/blob/main/docker-compose.yml): deployment orchestration · Runs frontend and backend processes for container deployment. · `docker-compose.yml`

## Connections

- App shell & theme → Dashboard: hosts
- App shell & theme → Task workflows: hosts
- App shell & theme → Habits: hosts
- App shell & theme → Goals & notes: hosts
- App shell & theme → Insights & calendar: hosts
- App shell & theme → Assistant: hosts
- App shell & theme → Appearance settings: hosts
- Dashboard → API client: loads daily data
- Task workflows → API client: CRUD requests
- Habits → API client: adherence requests
- Goals & notes → API client: CRUD requests
- Insights & calendar → API client: requests metrics
- Assistant → API client: coaching requests
- Appearance settings → API client: preference requests
- API client → FastAPI application: HTTP
- FastAPI application → Productivity APIs: routes to
- FastAPI application → Metrics API: routes to
- FastAPI application → AI coaching API: routes to
- FastAPI application → Weekly reports API: routes to
- Productivity APIs → API schemas: validates payloads
- Productivity APIs → Persistence models: reads and writes
- Metrics API → Persistence models: aggregates activity
- Weekly reports API → Persistence models: uses completion data
- AI coaching API → Google Gemini 1.5 Flash: generates coaching
- Weekly reports API → Google Gemini 1.5 Flash: authors report content
- Persistence models → Database sessions: uses sessions
- Database sessions → SQLite store: connects to
- Container composition → App shell & theme: deploys frontend
- Container composition → FastAPI application: deploys backend
