# phoenix-7theta-fi/tangerine-final architecture

> Architecture diagram of the GitHub repository phoenix-7theta-fi/tangerine-final, 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/phoenix-7theta-fi/tangerine-final
- Repository: https://github.com/phoenix-7theta-fi/tangerine-final

## Overview

##### Main System Components

A. Frontend Layer:
- Client-Side Pages (organized under /pages)
- Public Pages (home, practitioners listing, blog)
- Protected Dashboard Areas (user & practitioner)
- AI Chat Interface
- Components Library (/components)
- Styling System (Tailwind CSS)

B. Backend Layer:
- API Routes (/pages/api)
- Authentication System
- Practitioner Management
- Appointment Management
- Blog Management
- AI Chat Integration
- User Management

C. Data Layer:
- MongoDB Database (indicated by mongodb.js)
- Authentication Store
- Blog Posts Storage
- Embeddings System (for AI functionality)

D. External Services:
- NextAuth.js Authentication
- AI Service Integration
- Rate Limiting System

**┌─ Client Layer ─────────────────────┐**
- [Browser/User Interface]         │

- Next.js Frontend ────────────────┤
- Pages                         │
- Components                    │
- Client-side Navigation        │

- API Layer ──────────────────────┤
- Authentication               │
- Practitioners               │
- Appointments                │
- Blog                        │
- AI Chat                     │

- Service Layer ──────────────────┤
- MongoDB Operations           │
- Auth Services               │
- Rate Limiting               │
- AI Services                 │

- Data Layer ────────────────────┤
- MongoDB Database            │
- Authentication Store        │
- File Storage               │

##### Key Relationships to Highlight

- Authentication flow between frontend, API, and MongoDB
- Appointment booking flow from user to practitioner
- AI chat system integration
- Blog post management system
- Rate limiting protection for API routes

##### Implementation Details

- Notes for important architectural decisions

##### Additional Notes

- Next.js pages router architecture
- Separation between public and protected routes
- Integration points for AI features
- Error handling and fallback paths
- How the blog system integrates with the main application

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Browser/User Interface"]:::frontend
    end

    subgraph Frontend
        PublicPages["Public Pages"]:::frontend
        ProtectedPages["Protected Pages"]:::frontend
        Components["Components Library"]:::frontend
        AIChat["AI Chat Interface"]:::frontend
        Navigation["Navigation"]:::frontend

        click PublicPages "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/blob/main/pages/index.js"
        click Components "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/tree/main/components/"
        click Navigation "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/blob/main/components/Navigation.js"
        click AIChat "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/blob/main/pages/ai-chat/index.js"
    end

    subgraph APILayer
        AuthAPI["Authentication API"]:::api
        PractitionerAPI["Practitioner API"]:::api
        AppointmentAPI["Appointment API"]:::api
        BlogAPI["Blog API"]:::api
        AIChatAPI["AI Chat API"]:::api

        click AuthAPI "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/blob/main/pages/api/auth/[...nextauth].js"
        click PractitionerAPI "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/blob/main/pages/api/practitioners/index.js"
        click AppointmentAPI "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/blob/main/pages/api/appointments/create.js"
        click BlogAPI "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/blob/main/pages/api/blog/[id].js"
        click AIChatAPI "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/blob/main/pages/api/ai/chat.js"
    end

    subgraph ServiceLayer
        AuthService["Authentication Service"]:::service
        RateLimiting["Rate Limiting"]:::service
        MongoDBOps["MongoDB Operations"]:::service
        AIService["AI Service"]:::service

        click RateLimiting "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/blob/main/lib/rate-limit.js"
        click AuthService "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/blob/main/lib/auth-mongodb.js"
        click MongoDBOps "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/blob/main/lib/mongodb.js"
    end

    subgraph DataLayer
        MongoDB[(MongoDB Database)]:::database
        AuthStore[(Auth Store)]:::database
        BlogStore[(Blog Storage)]:::database
        Embeddings[(Embeddings System)]:::database

        click MongoDB "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/blob/main/lib/mongodb.js"
        click Embeddings "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/blob/main/lib/embeddings.js"
        click BlogStore "https://github.com/Phoenix-7Theta-Fi/Tangerine-Final/blob/main/data/blogPosts.js"
    end

    %% Connections
    Browser --> PublicPages
    Browser --> ProtectedPages
    Browser --> AIChat
    
    PublicPages --> Navigation
    ProtectedPages --> Navigation
    
    PublicPages --> AuthAPI
    ProtectedPages --> AuthAPI
    AIChat --> AIChatAPI
    
    AuthAPI --> AuthService
    AuthAPI --> RateLimiting
    PractitionerAPI --> RateLimiting
    AppointmentAPI --> RateLimiting
    BlogAPI --> RateLimiting
    AIChatAPI --> RateLimiting
    
    AuthService --> MongoDB
    MongoDBOps --> MongoDB
    AIService --> Embeddings
    BlogAPI --> BlogStore
    AuthService --> AuthStore
    
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:#fff
    classDef api fill:#2ecc71,stroke:#27ae60,color:#fff
    classDef service fill:#f1c40f,stroke:#f39c12,color:#000
    classDef database fill:#e74c3c,stroke:#c0392b,color:#fff
    
    %% Legend
    subgraph Legend
        Frontend_L["Frontend"]:::frontend
        API_L["API Layer"]:::api
        Service_L["Service Layer"]:::service
        Database_L[(Database Layer)]:::database
    end
```
