# jnikolo/aspire architecture

> Architecture diagram of the GitHub repository jnikolo/aspire, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jnikolo/aspire
- Repository: https://github.com/jnikolo/aspire

## Overview

##### Project Type and Purpose
- Aspire is a full-stack habit-tracking application with a strong focus on personalized coaching, community engagement, and data visualization.
- The README emphasizes key features like intelligent habit tracking (with dynamic heatmaps), community support, and AI-driven personalized guidance.
- The tech stack includes React with Tailwind CSS on the frontend, and Node.js, Supabase, Prisma, OpenAI, and Clerk on the backend.

##### File Structure
- The project is separated into two main parts: the client (frontend) and the server (backend).
- In the client directory:
- Components, pages, services, and routing indicate a React-based SPA (Single Page Application) structure.
- The use of Tailwind CSS and Daisy UI for styling is evident.
- The presence of supabase integration in client/src/supabase signifies frontend data communication with the backend/data layer.
- In the server directory:
- The structure includes controllers, routes, and middleware, suggesting a RESTful API design.
- Prisma migrations indicate a relational database managed with Prisma.
- Middleware for Clerk and a service for OpenAI integration show how authentication and AI-powered features are implemented.
- Configuration files in both directories (like vercel.json, vite.config.js, and package.json) suggest readiness for cloud deployment and continuous integration.

a. Frontend (Client):
- React SPA with its components, pages, and services.
- Modules: Navigation, Dashboard, Survey, Authentication pages (Login, Sign Up, Profile).
- That the client interacts with Supabase for some data operations.

b. Backend (Server):
- Node.js server with its controllers, routes, and middlewares.
- REST API endpoints (e.g., habitRoutes, chatRoutes, profileRoutes, completionRoutes, registerRoutes).
- Business logic managed via controllers and services (e.g., OpenAI service for personalized coaching).
- Prisma layer which connects to the database and handles migrations.

c. Database Layer:
- Denote the relational database system managed through Prisma.
- Detail the migration process (with the migrations directory) and how schema changes are tracked.
- This to the backend services.

d. External Services & Integrations:
- Clerk for authentication: show how authentication middleware is integrated into the server.
- OpenAI for AI-driven insights: note the specific service module that handles calls to OpenAI.
- Supabase: highlight that both the frontend (for cross-device syncing) and possibly backend use Supabase for secure data management.

##### Relationships and Data Flow
- From the client, illustrate API calls (HTTP requests) to the server endpoints.
- From the server, show the flow of requests through middlewares (like Clerk for authentication checks) and into the controllers.
- How controllers interact with the database through Prisma.
- Outbound calls from the server to external services (e.g., OpenAI API calls for generating personalized messages).
- Additionally, if applicable, display how Supabase is used for real-time data syncing between devices.

##### Architectural Patterns and Design Principles
- The separation of concerns is maintained via clear division between the frontend and backend.
- The RESTful API design in the backend suggests modularity in handling different aspects (habit tracking, chat, registration, profile management).
- Middleware components (authentication and database connection management) emphasize security and maintainability.
- The integration of external services (Clerk and OpenAI) is clearly encapsulated, allowing the core logic to remain focused on habit tracking and user engagement.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Frontend"
        Client["Client (React App)"]:::frontend
        A1["Navigation (NavBar)"]:::frontend
        A2["Dashboard Page"]:::frontend
        A3["Dashboard Components"]:::frontend
        A4["Survey Page"]:::frontend
        A5["Survey Components"]:::frontend
        A6["Login Page"]:::frontend
        A7["Sign Up Page"]:::frontend
        A8["Profile Page"]:::frontend
        A9["Supabase Integration"]:::frontend
    end

    %% Backend Modules Subgraph
    subgraph "Backend Modules"
        B1["Controllers"]:::backend
        B2["Habit Routes"]:::backend
        B3["Chat Routes"]:::backend
        B4["Profile Routes"]:::backend
        B5["Completion Routes"]:::backend
        B6["Register Routes"]:::backend
        B7["Clerk Middleware"]:::backend
        B8["Prisma Middleware"]:::backend
        B9["OpenAI Service"]:::backend
    end

    %% Database Subgraph
    subgraph "Database Layer"
        D1["Prisma Schema"]:::database
        D2["Migrations"]:::database
    end

    %% Backend Server Node (outside modules for clarity)
    B["Backend Server (Node.js API)"]:::backend

    %% Connections between Frontend and Backend
    Client -->|"HTTP_Request"| B
    Client -->|"Data_Sync"| A9

    %% Backend processing flow
    B -->|"AuthCheck"| B7
    B7 -->|"DB_Connection"| B8
    B8 -->|"Dispatch_Request"| B1
    B1 -->|"handles"| B2
    B1 -->|"handles"| B3
    B1 -->|"handles"| B4
    B1 -->|"handles"| B5
    B1 -->|"handles"| B6
    B1 -->|"AI_Call"| B9
    B1 -->|"ORM_Query"| D1

    %% Optional internal database connection annotation
    D1 -->|"Schema_Migration"| D2

    %% Styling
    classDef frontend fill:#a2d2ff,stroke:#000,stroke-width:2px,color:#000;
    classDef backend fill:#ffafcc,stroke:#000,stroke-width:2px,color:#000;
    classDef database fill:#caffbf,stroke:#000,stroke-width:2px,color:#000;
    classDef external fill:#ffd6a5,stroke:#000,stroke-width:2px,color:#000;

    %% Click Events for Frontend
    click Client "https://github.com/jnikolo/aspire/tree/main/client/src"
    click A1 "https://github.com/jnikolo/aspire/blob/main/client/src/components/NavBar.jsx"
    click A2 "https://github.com/jnikolo/aspire/blob/main/client/src/pages/DashboardPage.jsx"
    click A3 "https://github.com/jnikolo/aspire/tree/main/client/src/components/Dashboard"
    click A4 "https://github.com/jnikolo/aspire/blob/main/client/src/pages/SurveyPage.jsx"
    click A5 "https://github.com/jnikolo/aspire/tree/main/client/src/components/Survey"
    click A6 "https://github.com/jnikolo/aspire/blob/main/client/src/pages/LoginPage.jsx"
    click A7 "https://github.com/jnikolo/aspire/blob/main/client/src/pages/SignUpPage.jsx"
    click A8 "https://github.com/jnikolo/aspire/blob/main/client/src/pages/ProfilePage.jsx"
    click A9 "https://github.com/jnikolo/aspire/blob/main/client/src/supabase/supabase.jsx"

    %% Click Events for Backend
    click B "https://github.com/jnikolo/aspire/blob/main/server/src/index.js"
    click B1 "https://github.com/jnikolo/aspire/tree/main/server/src/controllers"
    click B2 "https://github.com/jnikolo/aspire/blob/main/server/src/routes/habitRoutes.js"
    click B3 "https://github.com/jnikolo/aspire/blob/main/server/src/routes/chatRoutes.js"
    click B4 "https://github.com/jnikolo/aspire/blob/main/server/src/routes/profileRoutes.js"
    click B5 "https://github.com/jnikolo/aspire/blob/main/server/src/routes/completionRoutes.js"
    click B6 "https://github.com/jnikolo/aspire/blob/main/server/src/routes/registerRoutes.js"
    click B7 "https://github.com/jnikolo/aspire/blob/main/server/src/middlewares/clerk.js"
    click B8 "https://github.com/jnikolo/aspire/blob/main/server/src/middlewares/prisma.js"
    click B9 "https://github.com/jnikolo/aspire/blob/main/server/src/services/openai.js"

    %% Click Events for Database
    click D1 "https://github.com/jnikolo/aspire/blob/main/server/prisma/schema.prisma"
    click D2 "https://github.com/jnikolo/aspire/tree/main/server/prisma/migrations"
```
