# varuno8/eigen_login architecture

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

- Interactive diagram: https://gitdiagram.com/varuno8/eigen_login
- Repository: https://github.com/varuno8/eigen_login

## Overview

##### Project type and purpose
- This is a full-stack Next.js (React) web application with built-in API routes (app/api), server-side rendering (SSR), authentication (NextAuth), database access (Prisma ORM), and separate UI flows for admin, auth, and user dashboards.
- Its purpose is to present an authenticated user experience (sign-in/sign-up), expose a user dashboard with search and subscription management features, and provide an admin interface for analytics, feature requests, user/subscription management, and service creation.

##### File structure
- Top-level “app” directory is the Next.js App Router:
- /(auth) contains sign-in and sign-up pages
- /(dashboard) contains user-facing dashboard pages (homepage, account, search, subscriptions, service detail)
- /(admin) contains admin UI subpaths (analytics, feature-requests, settings, subscriptions, users, new-service)
- app/api holds serverless API endpoints for auth (NextAuth), user data, Streamlit token, etc.
- “components” and “components/ui” hold shared React components and design-system primitives.
- “lib” holds shared utilities: auth helpers, constants, database client (Prisma), and utils.
- “prisma” directory holds DB schema and migration history.
- Configuration files: next.config.ts, postcss.config, tailwind.config, tsconfig.

##### README for additional insights
- Confirms Next.js app created with create-next-app, uses next/font for custom fonts, deployable on Vercel.
- Mentions standard dev server and deployment instructions.

##### Main components of the system
a. Client Browser (React SSR/CSR)
b. Next.js Server (Node.js on Vercel/Node runtime)
c. API layer (app/api routes)
d. Authentication subsystem (NextAuth integration, Google OAuth)
e. Database (PostgreSQL or other, accessed via Prisma ORM)
f. External services: Google OAuth Provider, Streamlit token service
g. Shared UI Component Library (components/ui)
h. Prisma Migrations subsystem

##### Relationships and interactions
- Client Browser sends HTTP requests to Next.js Server (page navigation and API calls).
- Next.js Server renders pages (SSR) or serves static assets; routes API calls under /api/*.
- The API layer interacts with Prisma to read/write the database.
- NextAuth middleware in the API layer and pages manages session tokens, refreshes, and integrates with Google OAuth.
- Prisma Client communicates with the Database.
- The Streamlit-token API route calls an external Streamlit authentication service.
- The database migrations are managed offline by Prisma Migrate, not part of runtime flow but crucial for schema versioning.

##### Architectural patterns and design principles
- Separation of Concerns:
- UI components vs. page-level layouts vs. business logic (app/actions, lib) vs. persistence (Prisma)
- Auth flow isolated to its own route group (app/api/auth & NextAuth config in lib/auth.ts)
- Modular Code Organization: components/ui for design primitives, components/form for forms, hooks for custom React logic.
- Serverless Micro-endpoints: each API route is its own function/handler.
- Convention-over-configuration via Next.js app directory routing.

##### Relevant technologies, frameworks, and libraries
- Next.js (App Router) for server-side rendering and routing
- React for UI
- Tailwind CSS for styling
- Prisma ORM & Migrate for DB access and schema evolution
- NextAuth.js for authentication and session management
- Vercel (implied) or Node.js serverless runtime for deployment
- External OAuth (Google) and Streamlit token service

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    subgraph "Client Browser" 
        direction TB
        Browser["User Browser"]:::client
    end

    %% Server Boundary
    subgraph "Next.js Server (Runtime)" 
        direction TB

        %% Page Rendering
        subgraph "App Router (Page Rendering)" 
            direction TB
            Layout["app/layout.tsx"]:::pages
            RootPage["app/page.tsx"]:::pages

            subgraph "(auth) Routes" 
                direction TB
                SignIn["Sign-In Page"]:::pages
                SignUp["Sign-Up Page"]:::pages
            end

            subgraph "(dashboard) Routes" 
                direction TB
                DashboardHome["Homepage"]:::pages
                DashboardMain["Dashboard Main"]:::pages
                Account["Account Page"]:::pages
                Search["Search Page"]:::pages
                Subs["Subscriptions Page"]:::pages
                ServiceDetail["Service Detail"]:::pages
            end

            subgraph "(admin) Routes" 
                direction TB
                AdminMain["Admin Dashboard"]:::pages
                Analytics["Analytics Page"]:::pages
                FeatureReq["Feature Requests"]:::pages
                NewService["New Service"]:::pages
                Settings["Settings Page"]:::pages
                AdminSubs["Subscriptions"]:::pages
                Users["Users Page"]:::pages
            end
        end

        %% API Layer
        subgraph "API Layer (Serverless Functions)" 
            direction TB
            NextAuthAPI["/[...nextauth] API"]:::api
            StreamlitAPI["/get-streamlit-token"]:::api
            UserAPI["/user API"]:::api
        end

        %% Auth Middleware
        AuthMux{"Auth Middleware"}:::auth

        %% Business Logic
        subgraph "Server Actions" 
            direction TB
            ServicesAction["app/actions/services.ts"]:::logic
            SubsAction["app/actions/subscriptions.ts"]:::logic
            UserAction["app/actions/user.ts"]:::logic
        end

        %% Database Access
        subgraph "Prisma ORM" 
            direction TB
            DBClient["lib/db.ts"]:::db
            Schema["prisma/schema.prisma"]:::db
        end

        %% Migrations (Offline)
        subgraph "Prisma Migrations" 
            direction TB
            MigrationsDir["prisma/migrations/"]:::db
        end

    end

    %% External Services
    subgraph "External Services" 
        direction TB
        GoogleOAuth["Google OAuth Provider"]:::external
        StreamlitService["Streamlit Auth Service"]:::external
    end

    %% Shared Libraries and Utils
    subgraph "Shared UI Component Library" 
        direction TB
        ComponentsDir["components/ui/"]:::ui
    end

    subgraph "Utilities & Config" 
        direction TB
        Constants["lib/constants.ts"]:::util
        Utils["lib/utils.ts"]:::util
        Hooks["hooks/use-toast.ts"]:::util
        Configs["next.config.ts\ntailwind.config.ts\npostcss.config.mjs\ntsconfig.json\napp/globals.css"]:::config
    end

    %% Data Flows
    Browser -->|GET/POST| Layout
    Layout --> RootPage
    Layout --> SignIn
    Layout --> SignUp
    Layout --> DashboardHome
    Layout --> AdminMain

    SignIn --> AuthMux
    SignUp --> AuthMux
    DashboardHome --> AuthMux
    AdminMain --> AuthMux

    AuthMux --> NextAuthAPI
    Browser -->|API Call| NextAuthAPI
    Browser -->|API Call| StreamlitAPI
    Browser -->|API Call| UserAPI

    NextAuthAPI -->|OAuth Exchange| GoogleOAuth
    StreamlitAPI -->|Fetch Token| StreamlitService

    NextAuthAPI --> DBClient
    UserAPI --> DBClient

    DBClient --> Schema
    DBClient -->|SQL| Database[(Database)]:::db

    MigrationsDir -.-> Schema

    %% Shared library usage
    SignIn --> ComponentsDir
    SignUp --> ComponentsDir
    DashboardHome --> ComponentsDir
    AdminMain --> ComponentsDir

    ServicesAction --> DBClient
    SubsAction --> DBClient
    UserAction --> DBClient

    %% Click events
    click Layout "https://github.com/varuno8/eigen_login/blob/main/app/layout.tsx"
    click RootPage "https://github.com/varuno8/eigen_login/blob/main/app/page.tsx"
    click SignIn "https://github.com/varuno8/eigen_login/blob/main/app/(auth)/sign-in/page.tsx"
    click SignUp "https://github.com/varuno8/eigen_login/blob/main/app/(auth)/sign-up/page.tsx"
    click DashboardHome "https://github.com/varuno8/eigen_login/blob/main/app/(dashboard)/homepage/page.tsx"
    click DashboardMain "https://github.com/varuno8/eigen_login/blob/main/app/(dashboard)/dashboard/page.tsx"
    click Account "https://github.com/varuno8/eigen_login/blob/main/app/(dashboard)/dashboard/account/page.tsx"
    click Search "https://github.com/varuno8/eigen_login/blob/main/app/(dashboard)/dashboard/search/page.tsx"
    click Subs "https://github.com/varuno8/eigen_login/blob/main/app/(dashboard)/dashboard/subscriptions/page.tsx"
    click ServiceDetail "https://github.com/varuno8/eigen_login/blob/main/app/(dashboard)/services/[id]/page.tsx"
    click AdminMain "https://github.com/varuno8/eigen_login/blob/main/app/(admin)/admin/page.tsx"
    click Analytics "https://github.com/varuno8/eigen_login/blob/main/app/(admin)/admin/analytics/page.tsx"
    click FeatureReq "https://github.com/varuno8/eigen_login/blob/main/app/(admin)/admin/feature-requests/page.tsx"
    click NewService "https://github.com/varuno8/eigen_login/blob/main/app/(admin)/admin/new-service/page.tsx"
    click Settings "https://github.com/varuno8/eigen_login/blob/main/app/(admin)/admin/settings/page.tsx"
    click AdminSubs "https://github.com/varuno8/eigen_login/blob/main/app/(admin)/admin/subscriptions/page.tsx"
    click Users "https://github.com/varuno8/eigen_login/blob/main/app/(admin)/admin/users/page.tsx"
    click NextAuthAPI "https://github.com/varuno8/eigen_login/blob/main/app/api/auth/[...nextauth]/route.ts"
    click StreamlitAPI "https://github.com/varuno8/eigen_login/blob/main/app/api/get-streamlit-token/route.ts"
    click UserAPI "https://github.com/varuno8/eigen_login/blob/main/app/api/user/route.ts"
    click DBClient "https://github.com/varuno8/eigen_login/blob/main/lib/db.ts"
    click Schema "https://github.com/varuno8/eigen_login/blob/main/prisma/schema.prisma"
    click MigrationsDir "https://github.com/varuno8/eigen_login/tree/main/prisma/migrations/"
    click ComponentsDir "https://github.com/varuno8/eigen_login/tree/main/components/ui/"
    click ServicesAction "https://github.com/varuno8/eigen_login/blob/main/app/actions/services.ts"
    click SubsAction "https://github.com/varuno8/eigen_login/blob/main/app/actions/subscriptions.ts"
    click UserAction "https://github.com/varuno8/eigen_login/blob/main/app/actions/user.ts"
    click Constants "https://github.com/varuno8/eigen_login/blob/main/lib/constants.ts"
    click Utils "https://github.com/varuno8/eigen_login/blob/main/lib/utils.ts"
    click Hooks "https://github.com/varuno8/eigen_login/blob/main/hooks/use-toast.ts"

    %% Styles
    classDef client fill:#E8F0FE,stroke:#4285F4,color:#000
    classDef pages fill:#FFEEDB,stroke:#FF9100,color:#000
    classDef api fill:#E0F7FA,stroke:#00ACC1,color:#000
    classDef auth fill:#FFF3E0,stroke:#FB8C00,color:#000
    classDef logic fill:#F3E5F5,stroke:#8E24AA,color:#000
    classDef db fill:#E8F5E9,stroke:#43A047,color:#000
    classDef external fill:#EFEBE9,stroke:#6D4C41,color:#000
    classDef ui fill:#FFFDE7,stroke:#FBC02D,color:#000
    classDef util fill:#ECEFF1,stroke:#546E7A,color:#000
    classDef config fill:#F1F8E9,stroke:#7CB342,color:#000
```
