# denuoweb/questbycycle architecture

> Architecture diagram of the GitHub repository denuoweb/questbycycle, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/denuoweb/questbycycle
- Repository: https://github.com/denuoweb/questbycycle

## Overview

##### Main Components

a) Frontend Layer:
- Static assets (/app/static/)
- CSS styles
- JavaScript modules
- Images and media
- Templates (/app/templates/)
- Core pages
- Modal components
- Email templates

b) Backend Layer:
- Core Application Modules:
- Authentication (auth.py)
- Game Management (games.py)
- Quest System (quests.py)
- Badge System (badges.py)
- AI Integration (ai.py)
- Social Features (social.py)
- Admin Interface (admin.py)
- User Profiles (profile.py)

c) Database Layer:
- PostgreSQL Database
- Models (models.py)

d) External Services:
- Social Media Integration
- Twitter/X
- Facebook
- Instagram
- OpenAI API
- Email Service (SMTP)

**[Client Browsers/Devices]**
- ↕
**[NGINX Web Server]**
- ↕
**[Gunicorn WSGI Server]**
- ↕
**[Flask Application]**
- ↙   ↓   ↘
**[Database] [External APIs] [File System]**

##### Component Relationships

Following interactions:
- Client-Server communication through NGINX
- WebSocket connections for real-time features
- Database interactions for user data, quests, and badges
- External API calls to social media platforms and OpenAI
- File system interactions for static assets

##### Technical Details

- Python/Flask backend
- PostgreSQL database
- Gunicorn with GeventWebSocket workers
- NGINX reverse proxy
- Poetry for dependency management
- External API connections

##### Deployment Architecture

Production setup:
- NGINX configuration
- Gunicorn service
- Database connection
- File system structure

## Diagram (Mermaid)

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

    subgraph Infrastructure
        NGINX["NGINX Web Server"]:::server
        Gunicorn["Gunicorn WSGI Server"]:::server
    end

    subgraph "Flask Application"
        Main["Main Application"]:::app
        click Main "https://github.com/denuoweb/questbycycle/blob/main/app/main.py"
        
        subgraph "Frontend Layer"
            Static["Static Assets"]:::frontend
            click Static "https://github.com/denuoweb/questbycycle/tree/main/app/static/"
            Templates["Templates"]:::frontend
            click Templates "https://github.com/denuoweb/questbycycle/tree/main/app/static/templates/"
            Forms["Forms Handler"]:::frontend
            click Forms "https://github.com/denuoweb/questbycycle/blob/main/app/forms.py"
        end

        subgraph "Core Modules"
            Auth["Authentication"]:::module
            click Auth "https://github.com/denuoweb/questbycycle/blob/main/app/auth.py"
            Games["Game Management"]:::module
            click Games "https://github.com/denuoweb/questbycycle/blob/main/app/games.py"
            Quests["Quest System"]:::module
            click Quests "https://github.com/denuoweb/questbycycle/blob/main/app/quests.py"
            Badges["Badge System"]:::module
            click Badges "https://github.com/denuoweb/questbycycle/blob/main/app/badges.py"
            AI["AI Integration"]:::module
            click AI "https://github.com/denuoweb/questbycycle/blob/main/app/ai.py"
            Social["Social Features"]:::module
            click Social "https://github.com/denuoweb/questbycycle/blob/main/app/social.py"
            Admin["Admin Interface"]:::module
            click Admin "https://github.com/denuoweb/questbycycle/blob/main/app/admin.py"
            Profile["User Profiles"]:::module
            click Profile "https://github.com/denuoweb/questbycycle/blob/main/app/profile.py"
        end

        subgraph "Utility Layer"
            Utils["Utility Functions"]:::util
            click Utils "https://github.com/denuoweb/questbycycle/blob/main/app/utils.py"
            Config["Configuration"]:::util
            click Config "https://github.com/denuoweb/questbycycle/blob/main/app/config.py"
        end
    end

    subgraph "External Services"
        OpenAI["OpenAI API"]:::external
        click OpenAI "https://github.com/denuoweb/questbycycle/blob/main/docs/OPENAI.md"
        EmailService["Email Service"]:::external
        click EmailService "https://github.com/denuoweb/questbycycle/blob/main/docs/EMAIL.md"
        Twitter["Twitter/X"]:::external
        click Twitter "https://github.com/denuoweb/questbycycle/blob/main/docs/TWITTER.md"
        Facebook["Facebook"]:::external
        click Facebook "https://github.com/denuoweb/questbycycle/blob/main/docs/FACEBOOK.md"
        Instagram["Instagram"]:::external
        click Instagram "https://github.com/denuoweb/questbycycle/blob/main/docs/INSTAGRAM.md"
    end

    subgraph "Data Layer"
        DB[(PostgreSQL)]:::database
        Models["Database Models"]:::database
        click Models "https://github.com/denuoweb/questbycycle/blob/main/app/models.py"
    end

    Browser --> NGINX
    NGINX --> Gunicorn
    click Gunicorn "https://github.com/denuoweb/questbycycle/blob/main/gunicorn.conf.py.example"
    Gunicorn --> Main

    Main --> Static
    Main --> Templates
    Main --> Forms

    Main --> Auth
    Main --> Games
    Main --> Quests
    Main --> Badges
    Main --> AI
    Main --> Social
    Main --> Admin
    Main --> Profile

    Auth --> Utils
    Games --> Utils
    Quests --> Utils
    Badges --> Utils
    AI --> Utils
    Social --> Utils
    Admin --> Utils
    Profile --> Utils

    Auth --> Models
    Games --> Models
    Quests --> Models
    Badges --> Models
    Social --> Models
    Admin --> Models
    Profile --> Models

    Models --> DB

    AI --> OpenAI
    Social --> Twitter
    Social --> Facebook
    Social --> Instagram
    Auth --> EmailService

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef module fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    classDef server fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef util fill:#e74c3c,stroke:#c0392b,color:white
    classDef app fill:#1abc9c,stroke:#16a085,color:white
```
