System Architecture
An overview of HabitFlow's application architecture,, system layers, authentication flow and database communication.
Architecture Overview
HabitFlow uses a layered application structure built around Next.js, API routes, Prisma and PostgreSQL.
Presentation Layer
Next.js App Router + React
Renders the HabitFlow interface, dashboard, habit management, calendar, analytics and reminders.
Application Layer
Next.js API Routes
Handles application requests, validates incoming data, applies business logic and communicates with the database.
Authentication Layer
NextAuth.js
Manages authentication, OAuth accounts, sessions and access to user-specific application data.
Data Access Layer
Prisma ORM
Provides type-safe database queries and manages relationships between application models.
Database Layer
PostgreSQL
Stores users, habits, categories, completions, daily statistics, reminders and authentication records.
Conceptual application layers — not a deployment topology.
Authentication
NextAuth.js handles authentication and session management. The Prisma adapter connects authentication records to the database. Application endpoints use the authenticated user identity to protect personal habit data.
Data Flow
The interface sends requests to Next.js API routes. The application processes requests and uses Prisma to read or update PostgreSQL records. The resulting data is returned to the interface.
Database Components
The Prisma schema defines these main models.
Architecture Summary
HabitFlow separates its user interface, application endpoints, authentication, data access and persistent storage. This organization makes the application easier to maintain and extend as new features are introduced.