# pedrinvits/codehub architecture

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

- Interactive diagram: https://gitdiagram.com/pedrinvits/codehub
- Repository: https://github.com/pedrinvits/codehub

## Overview

##### Main System Components

A. Frontend Layer:
- Next.js Application (src/app directory structure)
- Component Library (src/components)
- Client-side State Management (src/hooks)
- Theme System (components/theme-provider)

B. Authentication Layer:
- NextAuth.js Integration (src/app/api/auth)
- Authentication Forms (src/components/auth)
- Session Management (src/app/auth/session-provider.tsx)

C. Backend Layer:
- API Routes (src/app/api)
- Data Access Layer (data/ directory)
- Database Operations (prisma/schema.prisma)

D. Storage Layer:
- Firebase Integration (firebase/firebase.tsx)
- Database (PostgreSQL via Prisma)

##### Component Relationships

**[Client Browser] ←→ [Next.js Frontend]**
- ↓
**[Authentication Layer (NextAuth.js)]**
- ↓
**[API Layer]**
- ↙     ↘
**[Prisma ORM]  [Firebase]**
- ↓
**[Database]**

##### Detailed Component Breakdown

Frontend Layer:
- Main application routes (/app, /auth, /admin)
- Components (posts, comments, profile)
- Theme system and UI components

Authentication Flow:
- Login/Register paths
- Session management
- Protected routes

Data Management:
- CRUD operations for:
- Posts
- Comments
- User profiles
- Following system
- Save posts feature

##### Technical Stack Indicators

- Next.js
- Prisma
- Docker
- Firebase
- PostgreSQL
- TypeScript

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph FrontendLayer["Frontend Layer"]
        NextApp["Next.js Application"]:::frontend
        Components["Component Library"]:::frontend
        StateManagement["Client-side State"]:::frontend
        ThemeSystem["Theme System"]:::frontend
        UIComponents["UI Components"]:::frontend
        NavComponents["Navigation"]:::frontend
        ProfileUI["Profile Components"]:::frontend
    end

    subgraph AuthLayer["Authentication Layer"]
        NextAuth["NextAuth.js"]:::auth
        AuthForms["Auth Forms"]:::auth
        SessionMgmt["Session Management"]:::auth
        AuthActions["Auth Actions"]:::auth
    end

    subgraph BackendLayer["Backend Layer"]
        APIRoutes["API Routes"]:::backend
        DataAccess["Data Access Layer"]:::backend
        DBOps["Database Operations"]:::backend
        DBConn["Database Connection"]:::backend
    end

    subgraph Features["Feature Components"]
        PostMgmt["Post Management"]:::feature
        CommentSys["Comment System"]:::feature
        FollowSys["Following System"]:::feature
        GitHubInt["GitHub Star Integration"]:::feature
        UserMgmt["User Management"]:::feature
    end

    subgraph AdminSection["Admin Features"]
        AdminDash["Admin Dashboard"]:::admin
        AdminUsers["User Management"]:::admin
    end

    subgraph Storage["Storage Layer"]
        Firebase["Firebase"]:::storage
        PostgreSQL["PostgreSQL"]:::storage
        PrismaMigrations["Database Migrations"]:::storage
    end

    Browser --> NextApp
    NextApp --> Components
    NextApp --> StateManagement
    NextApp --> ThemeSystem
    Components --> UIComponents
    Components --> NavComponents
    Components --> ProfileUI

    Browser --> NextAuth
    NextAuth --> AuthForms
    NextAuth --> SessionMgmt
    NextAuth --> AuthActions

    NextApp --> APIRoutes
    APIRoutes --> DataAccess
    DataAccess --> DBOps
    DBOps --> DBConn
    DBConn --> PostgreSQL

    APIRoutes --> Features
    Features --> DataAccess
    Features --> Firebase

    APIRoutes --> AdminSection
    AdminSection --> DataAccess

    %% Click events
    click NextApp "https://github.com/Pedrinvits/CodeHub/tree/master/src/app/"
    click Components "https://github.com/Pedrinvits/CodeHub/tree/master/src/components/"
    click StateManagement "https://github.com/Pedrinvits/CodeHub/tree/master/src/hooks/"
    click ThemeSystem "https://github.com/Pedrinvits/CodeHub/blob/master/src/components/theme-provider/theme-provider.tsx"
    click NextAuth "https://github.com/Pedrinvits/CodeHub/tree/master/src/app/api/auth/[...nextauth]/"
    click AuthForms "https://github.com/Pedrinvits/CodeHub/tree/master/src/components/auth/"
    click SessionMgmt "https://github.com/Pedrinvits/CodeHub/blob/master/src/app/auth/session-provider.tsx"
    click AuthActions "https://github.com/Pedrinvits/CodeHub/blob/master/src/action/login.ts"
    click APIRoutes "https://github.com/Pedrinvits/CodeHub/tree/master/src/app/api/"
    click DataAccess "https://github.com/Pedrinvits/CodeHub/tree/master/data/"
    click DBOps "https://github.com/Pedrinvits/CodeHub/blob/master/prisma/schema.prisma"
    click DBConn "https://github.com/Pedrinvits/CodeHub/blob/master/src/lib/db.ts"
    click Firebase "https://github.com/Pedrinvits/CodeHub/blob/master/firebase/firebase.tsx"
    click PrismaMigrations "https://github.com/Pedrinvits/CodeHub/tree/master/prisma/migrations/"
    click PostMgmt "https://github.com/Pedrinvits/CodeHub/tree/master/data/post/"
    click CommentSys "https://github.com/Pedrinvits/CodeHub/tree/master/data/comments/"
    click FollowSys "https://github.com/Pedrinvits/CodeHub/tree/master/data/following/"
    click GitHubInt "https://github.com/Pedrinvits/CodeHub/tree/master/data/github-star/"
    click UserMgmt "https://github.com/Pedrinvits/CodeHub/blob/master/data/user.ts"
    click AdminDash "https://github.com/Pedrinvits/CodeHub/tree/master/src/app/admin/dashboard/"
    click AdminUsers "https://github.com/Pedrinvits/CodeHub/tree/master/src/app/admin/manage-users/"
    click UIComponents "https://github.com/Pedrinvits/CodeHub/tree/master/src/components/ui/"
    click NavComponents "https://github.com/Pedrinvits/CodeHub/tree/master/src/components/navbar/"
    click ProfileUI "https://github.com/Pedrinvits/CodeHub/tree/master/src/components/profile-infos/"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef auth fill:#2ecc71,stroke:#27ae60,color:white
    classDef backend fill:#f1c40f,stroke:#f39c12,color:black
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white
    classDef feature fill:#e67e22,stroke:#d35400,color:white
    classDef admin fill:#e74c3c,stroke:#c0392b,color:white
```
