# mybitbox/bitbox architecture

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

- Interactive diagram: https://gitdiagram.com/mybitbox/bitbox
- Repository: https://github.com/mybitbox/bitbox

## Overview

##### Main Components

A. Frontend Layer:
- As a client-side block containing:
- Static content (HTML/CSS)
- JavaScript modules
- External components (Monaco Editor, Toast UI Editor)
- Different pages (dashboard, quiz, interview, etc.)

B. Backend Layer:
- FastAPI application structure:
- API Routes (/api/auth, /api/users, etc.)
- Core Services (database, logging, OpenAI integration)
- Data Models and Schemas
- Business Logic

C. External Services:
- OpenAI API for AI feedback
- Database (SQLite3)

**[Client Layer]**
- ↕️ HTTP/REST
**[Application Layer]**
- ↕️
**[Data Layer]**

##### Specific Component Details

Frontend Section:
- Pages (login, dashboard, quiz, etc.)
- Static assets (CSS, JS)
- External editors (Monaco, Toast UI)

Backend Section:
- API Gateway (FastAPI)
- Core Services:
- Authentication Service
- Quiz Management
- Content Type Management
- User Management
- Database Access Layer (SQLAlchemy)

Data Layer:
- SQLite database
- Tables for:
- Users
- Quizzes
- Subjects
- Content Types
- Answers

##### Connection Flows

- User interactions from frontend to backend
- API calls between components
- Database operations
- External API calls to OpenAI
- Authentication flows

##### Additional Elements

Include:
- Security layer (showing auth flow)
- API endpoints with major HTTP methods
- Data flow directions
- Caching mechanisms (if any)
- Error handling paths

##### Specific Implementation Notes

- The separation between frontend static content and backend API
- The role of FastAPI in handling requests
- The integration with OpenAI for AI-based feedback
- The data flow for different learning content types
- The user authentication and session management

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    classDef auth fill:#e74c3c,stroke:#c0392b,color:white

    %% Frontend Layer
    subgraph Frontend
        StaticContent["Static Content"]
        Pages["Pages"]
        JSModules["JavaScript Modules"]
        ExternalEditors["External Editors"]

        subgraph StaticFiles
            CSS["CSS Files"]
            HTML["HTML Files"]
        end

        subgraph PageComponents
            Dashboard["Dashboard"]
            Quiz["Quiz"]
            Interview["Interview"]
            Login["Login"]
            Signup["Signup"]
        end

        subgraph JSComponents
            AuthJS["Authentication"]
            ConfigJS["Configuration"]
        end

        subgraph Editors
            Monaco["Monaco Editor"]
            ToastUI["Toast UI Editor"]
        end
    end

    %% Backend Layer
    subgraph Backend
        FastAPI["FastAPI Gateway"]

        subgraph APIRoutes
            AuthAPI["Auth API"]
            QuizAPI["Quiz API"]
            UserAPI["User API"]
            SubjectAPI["Subject API"]
            ContentTypeAPI["Content Type API"]
        end

        subgraph CoreServices
            DBService["Database Service"]
            LoggingService["Logging Service"]
            OpenAIService["OpenAI Service"]
            UtilsService["Utils Service"]
        end

        subgraph DataModels
            UserModel["User Model"]
            QuizModel["Quiz Model"]
            SubjectModel["Subject Model"]
            ContentTypeModel["Content Type Model"]
            AnswerModel["Answer Model"]
        end

        subgraph DataSchemas
            UserSchema["User Schema"]
            QuizSchema["Quiz Schema"]
            SubjectSchema["Subject Schema"]
            ContentTypeSchema["Content Type Schema"]
        end
    end

    %% Data Layer
    subgraph DataLayer
        SQLite["SQLite Database"]
    end

    %% External Services
    OpenAI["OpenAI API"]

    %% Relationships
    Frontend --> FastAPI
    FastAPI --> APIRoutes
    APIRoutes --> CoreServices
    CoreServices --> DataModels
    DataModels --> DataSchemas
    CoreServices --> SQLite
    OpenAIService --> OpenAI

    %% Style Applications
    StaticContent:::frontend
    Pages:::frontend
    JSModules:::frontend
    ExternalEditors:::frontend
    FastAPI:::backend
    APIRoutes:::backend
    CoreServices:::backend
    DataModels:::backend
    DataSchemas:::backend
    SQLite:::database
    OpenAI:::external
    AuthAPI:::auth

    %% Click Events
    click CSS "https://github.com/MyBitBox/bitbox/blob/develop/frontend/css/style.css"
    click HTML "https://github.com/MyBitBox/bitbox/blob/develop/frontend/index.html"
    click Dashboard "https://github.com/MyBitBox/bitbox/blob/develop/frontend/pages/dashboard.html"
    click Quiz "https://github.com/MyBitBox/bitbox/blob/develop/frontend/pages/quiz.html"
    click Interview "https://github.com/MyBitBox/bitbox/blob/develop/frontend/pages/interview.html"
    click Login "https://github.com/MyBitBox/bitbox/blob/develop/frontend/pages/login.html"
    click Signup "https://github.com/MyBitBox/bitbox/blob/develop/frontend/pages/signup.html"
    click AuthJS "https://github.com/MyBitBox/bitbox/blob/develop/frontend/js/auth.js"
    click ConfigJS "https://github.com/MyBitBox/bitbox/blob/develop/frontend/js/config.js"
    click AuthAPI "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/api/auth.py"
    click QuizAPI "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/api/quiz.py"
    click UserAPI "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/api/user.py"
    click SubjectAPI "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/api/subject.py"
    click ContentTypeAPI "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/api/content_type.py"
    click DBService "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/core/database.py"
    click LoggingService "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/core/logging.py"
    click OpenAIService "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/core/openai.py"
    click UtilsService "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/core/utils.py"
    click UserModel "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/models/user.py"
    click QuizModel "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/models/quiz.py"
    click SubjectModel "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/models/subject.py"
    click ContentTypeModel "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/models/content_type.py"
    click AnswerModel "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/models/answer.py"
    click UserSchema "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/schemas/user.py"
    click QuizSchema "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/schemas/quiz.py"
    click SubjectSchema "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/schemas/subject.py"
    click ContentTypeSchema "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/schemas/content_type.py"
    click SQLite "https://github.com/MyBitBox/bitbox/blob/develop/backend/bitbox.db"
    click FastAPI "https://github.com/MyBitBox/bitbox/blob/develop/backend/app/main.py"
```
