# owenhochwald/aftrbrnr architecture

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

- Interactive diagram: https://gitdiagram.com/owenhochwald/aftrbrnr
- Repository: https://github.com/owenhochwald/aftrbrnr

## Overview

##### Project Type and Purpose
- Aftrbrnr is a full-stack web application built with Next.js (App Router), React, and TypeScript.
- It provides a professional time-tracking platform: user authentication, project/client management, activity tracking, and dashboards.

##### High-Level Architecture Overview
Components:
- Browser (Client)
- Next.js Application Server
– UI Layer (React Components + App Router)
– API Layer (app/api/* routes, NextAuth endpoints)
– Middleware (authorization, session handling)
– Business Logic (lib/ folder: auth, authorization, session, utils)
- Database Layer (PostgreSQL via Prisma ORM)
- External Services (Google OAuth)

##### Relationships and Data Flow
1. User opens the browser → requests a page or API call.
2. Next.js App Router serves pages (SSR/SSG) or routes to client-side React components.
3. Client-side code calls internal API endpoints under /api (e.g., auth, track/actions).
4. API handlers invoke business logic in lib/, then use Prisma to query/update PostgreSQL.
5. NextAuth middleware intercepts auth-protected routes; delegates to OAuth provider (Google) and manages sessions.
6. Responses flow back to API → UI → browser.

##### Architectural Patterns & Design Principles
- Layered architecture: UI → API → Business Logic → Data Layer.
- Next.js App Router conventions: folder-based routing, server vs. client components.
- Reusable component library under components/ui for consistent styling.
- Prisma migrations manage database schema.
- Middleware enforces auth and role-based access control.

##### Relevant Technologies & Frameworks
- Next.js App Router (React + Server Components)
- NextAuth.js for authentication/authorization
- Prisma ORM + PostgreSQL for data persistence
- Tailwind CSS for styling
- TypeScript for static typing

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["Browser"]:::external

    subgraph "Next.js Server"
        subgraph "UI Layer"
            Public["Public Pages"]:::ui
            AuthPages["Authentication Pages"]:::ui
            AppPages["Authenticated App Pages"]:::ui
            UIlib["UI Components Library"]:::ui
            SharedComp["Shared React Components"]:::ui
            GlobalStyles["Global Styles"]:::ui
            Providers["Providers Wrapper"]:::ui
        end
        subgraph "API & Business Logic"
            Middleware["Middleware"]:::api
            subgraph "API Layer"
                NextAuthEP["NextAuth Endpoints"]:::api
                NextAuthOpt["NextAuth Options"]:::api
            end
            subgraph "Business Logic (lib)"
                AuthBL["Authentication Helpers"]:::api
                AuthZBL["Authorization/Role Checks"]:::api
                SessionBL["Session Management"]:::api
                UtilsBL["Utility Functions"]:::api
                TimeBL["Time Utilities"]:::api
                PrismaInit["Prisma Client Init"]:::data
            end
        end
    end

    Database["Prisma ORM → PostgreSQL"]:::data
    Schema["Database Schema Definition"]:::data
    Migrations["Database Migrations"]:::data
    External["Google OAuth"]:::external

    Browser -->|"renders pages"| Public
    Browser -->|"renders pages"| AuthPages
    Browser -->|"renders pages"| AppPages

    Public --> Providers
    AuthPages --> Providers
    AppPages --> Providers

    Providers -->|"API Call"| NextAuthEP
    Providers -->|"API Call"| NextAuthOpt

    Public -->|"API Call"| NextAuthEP
    AuthPages -->|"API Call"| NextAuthEP
    AppPages -->|"API Call"| NextAuthEP

    NextAuthEP -->|"authenticate"| External
    External -->|"callback"| NextAuthEP

    NextAuthEP --> AuthBL
    NextAuthOpt --> AuthBL

    AuthBL --> AuthZBL
    AuthBL --> SessionBL
    AuthZBL --> PrismaInit
    SessionBL --> PrismaInit
    UtilsBL --> PrismaInit
    TimeBL --> PrismaInit

    PrismaInit --> Database
    Migrations --> Schema
    Schema --> Database

    click Public "https://github.com/owenhochwald/aftrbrnr/tree/main/aftrbrnr/app/(public)"
    click AuthPages "https://github.com/owenhochwald/aftrbrnr/tree/main/aftrbrnr/app/(auth)"
    click AppPages "https://github.com/owenhochwald/aftrbrnr/tree/main/aftrbrnr/app/(app)"
    click UIlib "https://github.com/owenhochwald/aftrbrnr/tree/main/aftrbrnr/components/ui"
    click SharedComp "https://github.com/owenhochwald/aftrbrnr/tree/main/aftrbrnr/components"
    click GlobalStyles "https://github.com/owenhochwald/aftrbrnr/blob/main/aftrbrnr/app/globals.css"
    click Providers "https://github.com/owenhochwald/aftrbrnr/blob/main/aftrbrnr/app/providers.tsx"
    click NextAuthEP "https://github.com/owenhochwald/aftrbrnr/blob/main/aftrbrnr/app/api/auth/[...nextauth]/route.ts"
    click NextAuthOpt "https://github.com/owenhochwald/aftrbrnr/blob/main/aftrbrnr/app/api/auth/[...nextauth]/options.ts"
    click Middleware "https://github.com/owenhochwald/aftrbrnr/blob/main/aftrbrnr/middleware.ts"
    click AuthBL "https://github.com/owenhochwald/aftrbrnr/blob/main/aftrbrnr/lib/auth.ts"
    click AuthZBL "https://github.com/owenhochwald/aftrbrnr/blob/main/aftrbrnr/lib/authorization.ts"
    click SessionBL "https://github.com/owenhochwald/aftrbrnr/blob/main/aftrbrnr/lib/session.ts"
    click UtilsBL "https://github.com/owenhochwald/aftrbrnr/blob/main/aftrbrnr/lib/utils.ts"
    click TimeBL "https://github.com/owenhochwald/aftrbrnr/blob/main/aftrbrnr/lib/time.ts"
    click PrismaInit "https://github.com/owenhochwald/aftrbrnr/blob/main/aftrbrnr/lib/prisma.ts"
    click Schema "https://github.com/owenhochwald/aftrbrnr/blob/main/aftrbrnr/prisma/schema.prisma"
    click Migrations "https://github.com/owenhochwald/aftrbrnr/tree/main/aftrbrnr/prisma/migrations"

    classDef ui fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef api fill:#D0FFD0,stroke:#333,stroke-width:1px
    classDef data fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px
```
