# shahtiflain/the-last-minute-life-saver architecture

> Architecture diagram of the GitHub repository shahtiflain/the-last-minute-life-saver, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shahtiflain/the-last-minute-life-saver
- Repository: https://github.com/shahtiflain/the-last-minute-life-saver

## Overview

#### Purpose and system shape
Last-Minute Life Saver is an AI-assisted productivity and scheduling system. A React client manages tasks, goals, habits, focus blocks, analytics, and AI views; a Node/Express API owns application CRUD and authentication; a Python/FastAPI service executes a multi-agent planning pipeline. The system persists domain data in MongoDB Atlas and can schedule into Google Calendar and send Firebase notifications.

#### Entry points and deployment units
- Frontend Vite bootstrap and application shell: `frontend/src/main.tsx`, `frontend/src/App.tsx`.
- Backend Express application/server: `backend/src/app.ts`, `backend/src/server.ts`.
- AI FastAPI application: `ai-orchestrator/app/main.py`; an additional launcher exists at `ai-orchestrator/main.py`.
- Services are independently containerized and composed locally: `frontend/Dockerfile`, `backend/Dockerfile`, `ai-orchestrator/Dockerfile`, `docker-compose.yml`. Kubernetes manifests define corresponding deployable workloads under `k8s/`.

#### Frontend experience and client boundary
The React/TypeScript frontend presents routed productivity screens and dashboard widgets. `frontend/src/components/layout/MainLayout.tsx` supplies the authenticated application shell, while pages such as `frontend/src/pages/Dashboard.tsx`, `frontend/src/pages/Tasks.tsx`, and `frontend/src/pages/AiCoach.tsx` assemble feature views. Domain hooks (`frontend/src/hooks/useTasks.ts`, `frontend/src/hooks/useGoals.ts`) and the HTTP boundary in `frontend/src/services/api.ts` isolate UI components from backend REST APIs. Firebase client setup is at `frontend/src/config/firebase.ts`, including a messaging service worker at `frontend/public/firebase-messaging-sw.js`.

#### Application API, identity, and persistence
The Node/Express backend exposes separate route/controller layers for user productivity data and AI requests: `backend/src/routes/task.routes.ts`, `backend/src/routes/goal.routes.ts`, and `backend/src/routes/ai.routes.ts`, backed by their corresponding controllers. JWT/authentication enforcement is centralized in `backend/src/middlewares/auth.middleware.ts`. MongoDB models define the core durable domain—tasks, goals, habits, focus blocks, notifications, and users—e.g. `backend/src/models/Task.ts`, `backend/src/models/Goal.ts`, `backend/src/models/User.ts`; database connection is configured in `backend/src/config/database.ts`. The backend is the trust boundary between browser clients and internal AI orchestration, using an internal API key per the documented architecture.

#### AI orchestration pipeline
FastAPI routes in `ai-orchestrator/app/api/routes.py` accept AI-oriented requests and pass them to `ai-orchestrator/app/core/orchestrator.py`. The orchestrator coordinates registered specialist agents through `ai-orchestrator/app/agents/agent_registry.py`: the planner decomposes goals/tasks, risk analysis assesses deadline feasibility, and the scheduler constructs time blocks (`planner_agent.py`, `risk_analyzer_agent.py`, `scheduler_agent.py`). The watcher agent (`watcher_agent.py`) handles ongoing conflict/rescheduling intent. API schemas in `ai-orchestrator/app/api/agent_schemas.py` form the typed boundary for agent inputs and explainable outputs.

#### Agent state, model, and action boundaries
Agents derive common behavior from `ai-orchestrator/app/agents/base_agent.py`, use request-scoped/shared state in `ai-orchestrator/app/memory/request_context.py` and `ai-orchestrator/app/memory/shared_memory.py`, and load role-specific system prompts from `ai-orchestrator/prompts/system/`. Gemini is abstracted behind `ai-orchestrator/app/llm/base_llm.py` and implemented by `ai-orchestrator/app/llm/gemini_client.py`, keeping provider calls outside agent logic. External side effects are isolated as tools: Google Calendar interactions in `ai-orchestrator/app/tools/calendar_tool.py` and notification delivery in `ai-orchestrator/app/tools/notification_tool.py`.

#### Primary end-to-end flow
A user signs in through the frontend, then the frontend calls authenticated Express REST endpoints to create or retrieve productivity data. AI requests cross from the backend to FastAPI; the orchestrator invokes planner → risk analyzer → scheduler, sharing request context and using Gemini for reasoning. Results include explanations, confidence, and reasoning traces for UI presentation. The scheduler writes calendar blocks through Google Calendar; the watcher can detect/react to scheduling conflicts and trigger revised orchestration. MongoDB is the system-of-record boundary, while Firebase Cloud Messaging is the outbound notification channel.

Main entry points: [`ai-orchestrator/app/agents/agent_registry.py`](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/ai-orchestrator/app/agents/agent_registry.py) (Specialist agents), [`ai-orchestrator/app/core/orchestrator.py`](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/ai-orchestrator/app/core/orchestrator.py) (Planning orchestrator), [`backend/src/routes/ai.routes.ts`](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/backend/src/routes/ai.routes.ts) (AI request API), [`frontend/src/components/layout/MainLayout.tsx`](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/components/layout/MainLayout.tsx) (Authenticated workspace)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React client"]
  node_frontend["React application<br/>[main.tsx]"]
  node_layout["Authenticated workspace<br/>layout shell<br/>[MainLayout.tsx]"]
  node_productivity_views["Productivity views<br/>dashboard and task pages<br/>[Dashboard.tsx]"]
  node_ai_coach["AI Coach<br/>AI user interface<br/>[AiCoach.tsx]"]
  node_domain_hooks["Domain hooks<br/>task and goal state<br/>[useTasks.ts]"]
  node_client_api["HTTP client<br/>REST boundary<br/>[api.ts]"]
  node_firebase_client["Firebase messaging<br/>browser notification client<br/>[firebase.ts]"]
end

subgraph group_api["Application API"]
  node_express_server["Express server<br/>application entrypoint<br/>[server.ts]"]
  node_auth["JWT authentication<br/>auth middleware<br/>[auth.middleware.ts]"]
  node_productivity_routes["Productivity API<br/>task and goal routes<br/>[task.routes.ts]"]
  node_ai_routes["AI request API<br/>AI routes<br/>[ai.routes.ts]"]
  node_domain_models["Domain models<br/>MongoDB models<br/>[Task.ts]"]
end

subgraph group_ai["AI orchestration"]
  node_fastapi["FastAPI service<br/>AI API entrypoint<br/>[main.py]"]
  node_agent_routes["Agent API schemas<br/>typed AI boundary<br/>[routes.py]"]
  node_orchestrator["Planning orchestrator<br/>multi-agent coordinator<br/>[orchestrator.py]"]
  node_agent_registry["Specialist agents<br/>planner, risk, scheduler, watcher<br/>[agent_registry.py]"]
  node_agent_memory["Request state<br/>shared agent memory<br/>[request_context.py]"]
end

subgraph group_external["External services"]
  node_mongodb[("MongoDB Atlas<br/>system of record")]
  node_gemini{{"Gemini model<br/>LLM provider"}}
  node_calendar["Google Calendar<br/>calendar integration"]
  node_notifications["Firebase Cloud Messaging<br/>notification channel"]
end

node_frontend -->|"renders"| node_layout
node_layout -->|"hosts"| node_productivity_views
node_layout -->|"hosts"| node_ai_coach
node_productivity_views -->|"uses"| node_domain_hooks
node_domain_hooks -->|"calls"| node_client_api
node_ai_coach -->|"submits requests"| node_client_api
node_frontend -->|"initializes"| node_firebase_client
node_client_api -->|"authenticated REST"| node_express_server
node_express_server -->|"enforces"| node_auth
node_auth -->|"permits"| node_productivity_routes
node_auth -->|"permits"| node_ai_routes
node_productivity_routes -->|"reads and writes"| node_domain_models
node_domain_models -->|"persists to"| node_mongodb
node_ai_routes -->|"internal AI request"| node_fastapi
node_fastapi -->|"serves"| node_agent_routes
node_agent_routes -->|"dispatches"| node_orchestrator
node_orchestrator -->|"coordinates"| node_agent_registry
node_orchestrator -->|"shares context"| node_agent_memory
node_agent_registry -->|"reasons with"| node_gemini
node_agent_registry -->|"schedules blocks"| node_calendar
node_agent_registry -->|"sends alerts"| node_notifications
node_notifications -->|"delivers to"| node_firebase_client
node_orchestrator -.->|"explanations and plans"| node_ai_routes
node_ai_routes -.->|"AI result"| node_ai_coach
node_agent_registry -.->|"conflict revisions"| node_orchestrator

click node_frontend "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/main.tsx"
click node_layout "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/components/layout/MainLayout.tsx"
click node_productivity_views "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/pages/Dashboard.tsx"
click node_ai_coach "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/pages/AiCoach.tsx"
click node_domain_hooks "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/hooks/useTasks.ts"
click node_client_api "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/services/api.ts"
click node_firebase_client "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/config/firebase.ts"
click node_express_server "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/backend/src/server.ts"
click node_auth "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/backend/src/middlewares/auth.middleware.ts"
click node_productivity_routes "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/backend/src/routes/task.routes.ts"
click node_ai_routes "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/backend/src/routes/ai.routes.ts"
click node_domain_models "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/backend/src/models/Task.ts"
click node_fastapi "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/ai-orchestrator/app/main.py"
click node_agent_routes "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/ai-orchestrator/app/api/routes.py"
click node_orchestrator "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/ai-orchestrator/app/core/orchestrator.py"
click node_agent_registry "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/ai-orchestrator/app/agents/agent_registry.py"
click node_agent_memory "https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/ai-orchestrator/app/memory/request_context.py"

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_frontend,node_layout,node_productivity_views,node_ai_coach,node_domain_hooks,node_client_api,node_firebase_client toneBlue
class node_express_server,node_auth,node_productivity_routes,node_ai_routes,node_domain_models toneAmber
class node_fastapi,node_agent_routes,node_orchestrator,node_agent_registry,node_agent_memory toneMint
class node_mongodb,node_gemini,node_calendar,node_notifications toneRose
```

## Components

### React client

- [React application](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/main.tsx): Vite entry and app shell · `frontend/src/main.tsx`
- [Authenticated workspace](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/components/layout/MainLayout.tsx): layout shell · `frontend/src/components/layout/MainLayout.tsx`
- [Productivity views](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/pages/Dashboard.tsx): dashboard and task pages · `frontend/src/pages/Dashboard.tsx`
- [AI Coach](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/pages/AiCoach.tsx): AI user interface · `frontend/src/pages/AiCoach.tsx`
- [Domain hooks](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/hooks/useTasks.ts): task and goal state · `frontend/src/hooks/useTasks.ts`
- [HTTP client](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/services/api.ts): REST boundary · `frontend/src/services/api.ts`
- [Firebase messaging](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/frontend/src/config/firebase.ts): browser notification client · `frontend/src/config/firebase.ts`

### Application API

- [Express server](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/backend/src/server.ts): application entrypoint · `backend/src/server.ts`
- [JWT authentication](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/backend/src/middlewares/auth.middleware.ts): auth middleware · `backend/src/middlewares/auth.middleware.ts`
- [Productivity API](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/backend/src/routes/task.routes.ts): task and goal routes · `backend/src/routes/task.routes.ts`
- [AI request API](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/backend/src/routes/ai.routes.ts): AI routes · Internal-key boundary to orchestration. · `backend/src/routes/ai.routes.ts`
- [Domain models](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/backend/src/models/Task.ts): MongoDB models · Tasks, goals, habits, focus blocks, notifications, and users. · `backend/src/models/Task.ts`

### AI orchestration

- [FastAPI service](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/ai-orchestrator/app/main.py): AI API entrypoint · `ai-orchestrator/app/main.py`
- [Agent API schemas](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/ai-orchestrator/app/api/routes.py): typed AI boundary · `ai-orchestrator/app/api/routes.py`
- [Planning orchestrator](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/ai-orchestrator/app/core/orchestrator.py): multi-agent coordinator · `ai-orchestrator/app/core/orchestrator.py`
- [Specialist agents](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/ai-orchestrator/app/agents/agent_registry.py): planner, risk, scheduler, watcher · `ai-orchestrator/app/agents/agent_registry.py`
- [Request state](https://github.com/shahtiflain/the-last-minute-life-saver/blob/master/ai-orchestrator/app/memory/request_context.py): shared agent memory · `ai-orchestrator/app/memory/request_context.py`

### External services

- **MongoDB Atlas**: system of record
- **Gemini model**: LLM provider
- **Google Calendar**: calendar integration
- **Firebase Cloud Messaging**: notification channel

## Connections

- React application → Authenticated workspace: renders
- Authenticated workspace → Productivity views: hosts
- Authenticated workspace → AI Coach: hosts
- Productivity views → Domain hooks: uses
- Domain hooks → HTTP client: calls
- AI Coach → HTTP client: submits requests
- React application → Firebase messaging: initializes
- HTTP client → Express server: authenticated REST
- Express server → JWT authentication: enforces
- JWT authentication → Productivity API: permits
- JWT authentication → AI request API: permits
- Productivity API → Domain models: reads and writes
- Domain models → MongoDB Atlas: persists to
- AI request API → FastAPI service: internal AI request
- FastAPI service → Agent API schemas: serves
- Agent API schemas → Planning orchestrator: dispatches
- Planning orchestrator → Specialist agents: coordinates
- Planning orchestrator → Request state: shares context
- Specialist agents → Gemini model: reasons with
- Specialist agents → Google Calendar: schedules blocks
- Specialist agents → Firebase Cloud Messaging: sends alerts
- Firebase Cloud Messaging → Firebase messaging: delivers to
- Planning orchestrator → AI request API: explanations and plans
- AI request API → AI Coach: AI result
- Specialist agents → Planning orchestrator: conflict revisions
