# olyaiy/resume-lm architecture

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

- Interactive diagram: https://gitdiagram.com/olyaiy/resume-lm
- Repository: https://github.com/olyaiy/resume-lm

## Overview

##### Main Components

- Frontend (UI Layer):
- Built with Next.js 15, React 19, and TypeScript.
- Contains split application directories (e.g., src/app, src/components, src/pages) that cover areas such as Landing, Dashboard (user profiles, resume management, subscription, and settings), Authentication, and Resume & Cover Letter editors.
- Utilizes Shadcn UI and Tailwind CSS for styling.

- Backend (Server/API Layer):
- Implemented with Next.js API routes under src/app/api.
- Includes endpoints for chat (for AI-powered resume assistant), authentication callbacks, webhooks (for Stripe integration), and potentially other services (e.g., subscription management).
- Middleware and Server Components (e.g., middleware.ts, server.ts in Supabase utilities) handle authentication and server-side operations.

- Database:
- PostgreSQL is used (with schema defined in schema.sql) and is configured to use Row Level Security (RLS).
- Integration with Supabase Auth for user management.
- Tables include profiles, resumes, jobs, and subscriptions.

- External Services & Integrations:
- Stripe for payment processing and subscription management (evident from the API endpoints and components like subscription/checkout, subscription/stripe-session, etc.).
- AI processing services (e.g., OpenAI, Claude, Gemini, etc.) are used for generating content suggestions, resume scoring, and job description analysis.
- PDF generation (via React PDF) for exporting resumes.

##### Out the Relationships and Flows

- Client Layer
- Users interact via web browsers accessing multiple pages such as the landing page, login/authentication pages, dashboard, resume editor, and profile management.
- Frontend components send requests to API endpoints when performing actions like login, resume saving/updating, or subscription modifications.

- Server/API Layer
- The API endpoints (organized under src/app/api) process requests, invoke business logic (such as AI suggestions or resume management actions), and then communicate either back to the UI or forward necessary commands.
- Middleware and server modules (found in src/utils/supabase and middleware.ts) provide authentication, authorization, and rate limiting before calls reach core API handlers.

- Database Communication
- Business logic and API endpoints interact with the PostgreSQL database via the Supabase client or ORM tools.

- External Integrations
- Stripe webhooks and checkout processes are managed by dedicated API endpoint routes (check src/app/api/webhooks/stripe and subscription folders) which interface with the subscription components on the frontend.
- AI integration services are part of the content generation pipelines evident in resume and cover letter components.

##### Architectural Patterns & Design Principles

- Modular, Component-Based Design:
- The structure of the src/components directory shows a clear separation of concerns (authentication, resume editor, dashboard, etc.).
- This encourages reusability and maintainability.

- Server-Side Rendering and API Layer Separation:
- Leveraging Next.js App Router allows clear separation between static/dynamic rendering and API handling.

- Secure and Scalable Data Handling:
- Using Supabase with Row Level Security and dedicated middleware assures security best practices.

- Integration of Third-Party Services:
- Dependencies on Stripe and various AI solutions are abstracted into specific API endpoints and utility functions (e.g., in src/lib and src/utils).

##### Final Checklist

- A component for the user interface with sub-sections (Dashboard, Resume Editor, Cover Letter Editor, Profile Management).
- Separation of API endpoints (e.g., /api/chat, /api/webhooks/stripe) and the associated business logic handled in middleware.
- A detailed section for the database showing key tables and emphasizing the use of Supabase Auth and Prisma ORM integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interaction"
        U["User (Browser)"]
    end

    subgraph "Frontend UI"
        FP1["Landing Page UI"]:::frontend
        FP2["Dashboard & User Management"]:::frontend
        FP3["Resume Editor"]:::frontend
        FP4["Cover Letter Editor"]:::frontend
        FP5["Authentication (Pages)"]:::frontend
        FP6["Authentication (Components)"]:::frontend
    end

    subgraph "Backend API"
        BA1["Chat API Endpoint (/api/chat)"]:::backend
        BA2["Stripe Webhook API (/api/webhooks/stripe)"]:::backend
    end

    subgraph "Middleware & Utilities"
        MU1["Global Middleware"]:::middleware
        MU2["Supabase Utilities"]:::middleware
    end

    subgraph "Database"
        DB1["PostgreSQL Database\n(RLS, Profiles, Resumes, Jobs, Subscriptions)"]:::database
    end

    subgraph "External Integrations"
        subgraph "Stripe Integration"
            SI1["Stripe Subscription Routes"]:::external
            SI2["Stripe Actions"]:::external
        end
        subgraph "AI Services"
            AI1["AI Prompts"]:::external
            AI2["Resume AI Actions"]:::external
            AI3["Jobs AI Actions"]:::external
        end
    end

    %% Connections from User to Frontend
    U --> FP1
    U --> FP2
    U --> FP3
    U --> FP4
    U --> FP5
    U --> FP6

    %% Frontend to Backend API calls
    FP2 -->|"apiRequest"| BA1
    FP3 -->|"apiRequest"| BA1
    FP4 -->|"apiRequest"| BA1
    FP5 -->|"apiRequest"| BA1
    FP6 -->|"apiRequest"| BA1
    FP2 -->|"subscriptionReq"| BA2

    %% Backend API to Middleware & Utilities and Database
    BA1 -->|"auth&DBQuery"| MU1
    MU1 -->|"DB Query"| DB1
    DB1 -->|"DB Response"| MU1
    MU1 -->|"Response"| BA1

    %% Chat API calling AI Services
    BA1 -->|"AIRequest"| AI1
    BA1 -->|"AIRequest"| AI2
    BA1 -->|"AIRequest"| AI3

    %% Stripe Webhook API interacting with Stripe Integration
    BA2 -->|"StripeEvent"| SI1
    BA2 -->|"StripeEvent"| SI2

    %% Click Events
    click FP1 "https://github.com/olyaiy/resume-lm/blob/main/src/app/page.tsx"
    click FP1 "https://github.com/olyaiy/resume-lm/tree/main/src/components/landing"
    click FP2 "https://github.com/olyaiy/resume-lm/tree/main/src/app/(dashboard)"
    click FP3 "https://github.com/olyaiy/resume-lm/tree/main/src/components/resume/editor"
    click FP4 "https://github.com/olyaiy/resume-lm/tree/main/src/components/cover-letter"
    click FP5 "https://github.com/olyaiy/resume-lm/tree/main/src/app/auth"
    click FP6 "https://github.com/olyaiy/resume-lm/tree/main/src/components/auth"
    click BA1 "https://github.com/olyaiy/resume-lm/blob/main/src/app/api/chat/route.ts"
    click BA2 "https://github.com/olyaiy/resume-lm/blob/main/src/app/api/webhooks/stripe/route.ts"
    click MU1 "https://github.com/olyaiy/resume-lm/blob/main/middleware.ts"
    click MU2 "https://github.com/olyaiy/resume-lm/tree/main/src/utils/supabase"
    click DB1 "https://github.com/olyaiy/resume-lm/blob/main/schema.sql"
    click SI1 "https://github.com/olyaiy/resume-lm/tree/main/src/app/(dashboard)/subscription"
    click SI2 "https://github.com/olyaiy/resume-lm/blob/main/src/utils/actions/stripe/actions.ts"
    click AI1 "https://github.com/olyaiy/resume-lm/blob/main/src/lib/prompts.ts"
    click AI2 "https://github.com/olyaiy/resume-lm/blob/main/src/utils/actions/resumes/ai.ts"
    click AI3 "https://github.com/olyaiy/resume-lm/blob/main/src/utils/actions/jobs/ai.ts"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef middleware fill:#DDA0DD,stroke:#000,stroke-width:1px;
    classDef database fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef external fill:#FFA500,stroke:#000,stroke-width:1px;
```
