# marcoguzman211/eduhub architecture

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

- Interactive diagram: https://gitdiagram.com/marcoguzman211/eduhub
- Repository: https://github.com/marcoguzman211/eduhub

## Overview

##### Project Type and Purpose
- This is a full-stack web application built with the T3 Stack: Next.js for the front end (React/SSR/SSG), NextAuth.js for authentication, tRPC for type-safe RPC between client and server, and Drizzle (ORM) on top of a relational database.
- It’s scaffolded via create-t3-app to serve marketing pages, a dashboard section (with upload, profile, saved items), and a backend API exposing authentication and business logic.

##### File Structure
- Top-level config & scripts:
– next.config.js, tsconfig.json, drizzle.config.ts, start-database.sh
– package.json, eslint.config.js, prettier.config.js, .husky for Git hooks
- Public assets under `public/`
- Frontend “app router” pages under `src/app`:
– `(marketing)` catch-all for unauthenticated marketing site
– `(app)` for protected dashboard pages
– Shared components in `src/app/_components` and `src/lib/components`
- API layer under `src/app/api` (Next.js Route Handlers)
– `auth/[...nextauth]` for NextAuth.js
– `trpc/[trpc]` for tRPC HTTP handler
- Server logic in `src/server`:
– `auth/` (NextAuth config)
– `api/routers` (tRPC routers: post, session)
– `db/` (Drizzle schema & connection)
- tRPC client helpers under `src/trpc`
- Global CSS under `src/styles`

##### Key Architecture Insights from README
- Core technologies: Next.js (pages + API routes), NextAuth.js, Drizzle ORM, Tailwind CSS, tRPC.
- Designed for rapid bootstrapping with SSR/SSG, full-end-to-end typing, modular pages.

##### Main Components
- Browser / Client (React pages in Next.js)
- Next.js Server / Node.js Runtime
– SSR/SSG Rendering Engine
– API Routes:
- `/api/auth/[...nextauth]` (NextAuth)
- `/api/trpc/[trpc]` (tRPC entry point)
- tRPC Routers & Business Logic (session, post…)
- Auth Module (NextAuth config, providers, session callbacks)
- Database Layer (Drizzle ORM over PostgreSQL or MySQL)
- External Services (OAuth providers if any, e-mail, S3 for upload if integrated)

##### Relationships & Interactions
- The browser requests pages (marketing or dashboard).
- For SSR/SSG pages, Next.js server fetches data via:
– tRPC client calling `/api/trpc` → tRPC server routers → Drizzle queries → DB
– NextAuth session check via cookie + server session callback → DB
- Client-side React components use the tRPC React client for mutations & queries.
- Auth flows (login, callback) go through NextAuth’s API route, which reads/writes to the same database via Drizzle.

##### Architectural Patterns & Principles
- Monorepo-style single Next.js app combining frontend, API routes, server logic.
- “API-First” via tRPC: type-safe RPC calls instead of traditional REST.
- SSR/SSG mixing marketing (public) and protected (dashboard) routes.
- Modular CSS + Tailwind utility classes.
- Separation of concerns: `src/app` for UI, `src/server` for business logic, `src/lib` for shared components/utilities.

##### Step-by-Step
2. Two frontend areas: Marketing Pages vs. Dashboard Pages.
- SSR/SSG Engine
- `/api/auth/[...nextauth]` (NextAuth.js)
- `/api/trpc/[trpc]` (tRPC Handler)
6. External OAuth providers connecting to the Auth API route.

## Diagram (Mermaid)

```mermaid
graph TD
    Browser["Browser (React)"]:::frontend

    subgraph "Frontend UI"
        subgraph Marketing
            Marketing["Marketing Pages"]:::marketing
        end
        subgraph Dashboard
            Dashboard["Dashboard Pages"]:::dashboard
        end
        Shared1["App-wide Components"]:::shared
        Shared2["Library Components"]:::shared
        Layout["Root Layout"]:::shared
        Styles["Global CSS"]:::shared
        subgraph "tRPC Client Helpers"
            QueryClient["query-client.ts"]:::client
            ReactHooks["react.tsx"]:::client
            ServerHelpers["server.ts"]:::client
        end
    end

    subgraph "Next.js Server"
        SSR["SSR/SSG Engine"]:::server
        AuthAPI["NextAuth API Route"]:::api
        TRPCAPI["tRPC API Route"]:::api
    end

    subgraph "Business Logic"
        subgraph "tRPC Routers & Server"
            TRPCRoot["root.ts"]:::logic
            SessionRouter["session.ts"]:::logic
            PostRouter["post.ts"]:::logic
            TRPCServer["trpc.ts"]:::logic
        end
        subgraph "Auth Module"
            AuthConfig["config.ts"]:::logic
            AuthIndex["index.ts"]:::logic
        end
    end

    subgraph "Data Layer"
        Drizzle["Drizzle ORM"]:::db
        Migrations["0000_overjoyed_proteus.sql & meta"]:::db
        DBConn["db/index.ts"]:::db
        DBSchema["schema.ts"]:::db
        DB["Database (PostgreSQL)"]:::db
    end

    subgraph "External Services"
        OAuth["OAuth Providers"]:::ext
    end

    %% Relationships
    Browser --> Marketing
    Browser --> Dashboard
    Marketing --> NextJS
    Dashboard --> NextJS
    Browser --> QueryClient
    QueryClient --> TRPCAPI
    Browser -->|Auth Requests| AuthAPI
    NextJS --> SSR
    SSR -->|Server-side Data Fetch| TRPCAPI
    SSR -->|Session Check| AuthAPI
    NextJS --> AuthAPI
    NextJS --> TRPCAPI
    TRPCAPI --> TRPCRoot
    TRPCRoot --> SessionRouter
    TRPCRoot --> PostRouter
    TRPCRoot --> TRPCServer
    AuthAPI --> AuthConfig
    AuthAPI --> AuthIndex
    SessionRouter --> Drizzle
    PostRouter --> Drizzle
    AuthConfig --> Drizzle
    AuthIndex --> Drizzle
    Drizzle --> DBConn
    DBConn --> DBSchema
    DBConn --> Migrations
    DB --> DBConn
    OAuth --> AuthAPI

    %% Click Events
    click Marketing "https://github.com/marcoguzman211/eduhub/tree/dev/src/app/(marketing)"
    click Dashboard "https://github.com/marcoguzman211/eduhub/tree/dev/src/app/(app)/dashboard"
    click Shared1 "https://github.com/marcoguzman211/eduhub/tree/dev/src/app/_components"
    click Shared2 "https://github.com/marcoguzman211/eduhub/tree/dev/src/lib/components"
    click Layout "https://github.com/marcoguzman211/eduhub/blob/dev/src/app/layout.tsx"
    click Styles "https://github.com/marcoguzman211/eduhub/blob/dev/src/styles/globals.css"
    click AuthAPI "https://github.com/marcoguzman211/eduhub/blob/dev/src/app/api/auth/[...nextauth]/route.ts"
    click TRPCAPI "https://github.com/marcoguzman211/eduhub/blob/dev/src/app/api/trpc/[trpc]/route.ts"
    click QueryClient "https://github.com/marcoguzman211/eduhub/blob/dev/src/trpc/query-client.ts"
    click ReactHooks "https://github.com/marcoguzman211/eduhub/blob/dev/src/trpc/react.tsx"
    click ServerHelpers "https://github.com/marcoguzman211/eduhub/blob/dev/src/trpc/server.ts"
    click SessionRouter "https://github.com/marcoguzman211/eduhub/blob/dev/src/server/api/routers/session.ts"
    click PostRouter "https://github.com/marcoguzman211/eduhub/blob/dev/src/server/api/routers/post.ts"
    click TRPCRoot "https://github.com/marcoguzman211/eduhub/blob/dev/src/server/api/root.ts"
    click TRPCServer "https://github.com/marcoguzman211/eduhub/blob/dev/src/server/api/trpc.ts"
    click AuthConfig "https://github.com/marcoguzman211/eduhub/blob/dev/src/server/auth/config.ts"
    click AuthIndex "https://github.com/marcoguzman211/eduhub/blob/dev/src/server/auth/index.ts"
    click DBConn "https://github.com/marcoguzman211/eduhub/blob/dev/src/server/db/index.ts"
    click DBSchema "https://github.com/marcoguzman211/eduhub/blob/dev/src/server/db/schema.ts"
    click Migrations "https://github.com/marcoguzman211/eduhub/blob/dev/drizzle/0000_overjoyed_proteus.sql"

    %% Styles
    classDef frontend fill:#e3f2fd,stroke:#90caf9;
    classDef marketing fill:#bbdefb,stroke:#64b5f6;
    classDef dashboard fill:#90caf9,stroke:#42a5f5;
    classDef shared fill:#c8e6c9,stroke:#66bb6a;
    classDef client fill:#f8bbd0,stroke:#f06292;
    classDef server fill:#ffe082,stroke:#ffb300;
    classDef api fill:#ffcc80,stroke:#ffa726;
    classDef logic fill:#d1c4e9,stroke:#9575cd;
    classDef db fill:#b2dfdb,stroke:#26a69a;
    classDef ext fill:#ef9a9a,stroke:#e57373;
```
