# sungbinlee/mock-interviewer-be architecture

> Architecture diagram of the GitHub repository sungbinlee/mock-interviewer-be, 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/sungbinlee/mock-interviewer-be
- Repository: https://github.com/sungbinlee/mock-interviewer-be

## Overview

##### Main Components

a) Client-Side (Frontend):
- GitHub Pages hosting
- Speech-to-Text (STT) component
- User Interface components
- Token management system

b) Server-Side (Backend):
- Django application server
- Authentication system
- Chat management system
- Text-to-Speech (TTS) engine
- Database (for user data and chat history)

c) External Services:
- OpenAI API integration
- AWS EC2 deployment environment
- Nginx reverse proxy
- Gunicorn WSGI server

##### Component Relationships

a) Presentation Layer:
- Web browser interface
- Frontend components (React/JavaScript)
- Audio input/output handling

b) API Gateway Layer:
- Nginx reverse proxy
- API endpoints (/api/user/, /api/chat/)

c) Application Layer:
- Django application server
- Authentication middleware
- Chat processing logic
- TTS conversion service

d) External Services Layer:
- OpenAI API connection
- Cloud services (AWS)

##### Data Flow Representation

- User requests flow
- Authentication token flow
- Chat message processing
- Audio conversion paths
- Database interactions

##### Specific Elements

a) User Flow:
- Registration/Login process
- Chat interaction flow
- Voice input/output processing

b) Security Layer:
- Token authentication
- Daily chat limits
- API security

c) Database Schema:
- User model
- Chat history storage
- Daily limit tracking

##### Technical Details to Highlight

- Django REST framework endpoints
- Token-based authentication system
- OpenAI API integration points
- Audio processing pipeline
- Database relationships

##### Deployment Architecture

- AWS EC2 instance
- Nginx configuration
- Gunicorn worker processes
- Static file serving

Annotations for key technical decisions, such as the choice of Token Authentication and the daily chat limit implementation. This will help other developers understand the architectural decisions made in the project.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        Browser["Web Browser"]
        STT["Speech-to-Text"]:::frontend
        UI["User Interface"]:::frontend
        TokenMgmt["Token Management"]:::frontend
    end

    subgraph Gateway["API Gateway Layer"]
        Nginx["Nginx Reverse Proxy"]:::infra
        APIEndpoints["/api Endpoints"]:::api
    end

    subgraph AppServer["Application Server Layer"]
        Django["Django Server"]:::backend
        click Django "https://github.com/sungbinlee/Mock-Interviewer-BE/blob/main/mock_interviewer/mock_interviewer/wsgi.py"
        
        subgraph Auth["Authentication"]
            AuthSystem["Auth System"]:::security
            DailyLimit["Daily Chat Limit"]:::security
            click DailyLimit "https://github.com/sungbinlee/Mock-Interviewer-BE/blob/main/mock_interviewer/chatbot/migrations/0002_user_daily_chat_limit.py"
        end
        
        subgraph Core["Core Components"]
            ChatMgmt["Chat Management"]:::backend
            click ChatMgmt "https://github.com/sungbinlee/Mock-Interviewer-BE/blob/main/mock_interviewer/chatbot/views.py"
            TTSEngine["Text-to-Speech Engine"]:::backend
            URLRouter["URL Router"]:::backend
            click URLRouter "https://github.com/sungbinlee/Mock-Interviewer-BE/blob/main/mock_interviewer/mock_interviewer/urls.py"
            Settings["App Settings"]:::backend
            click Settings "https://github.com/sungbinlee/Mock-Interviewer-BE/blob/main/mock_interviewer/mock_interviewer/settings.py"
        end
        
        subgraph Data["Data Layer"]
            Models["Database Models"]:::data
            click Models "https://github.com/sungbinlee/Mock-Interviewer-BE/blob/main/mock_interviewer/chatbot/models.py"
            ChatHistory["Chat History"]:::data
            UserData["User Data"]:::data
        end
    end

    subgraph External["External Services"]
        OpenAI["OpenAI API"]:::external
        AWS["AWS EC2"]:::external
        Gunicorn["Gunicorn WSGI"]:::infra
    end

    %% Relationships
    Browser --> STT
    Browser --> UI
    Browser --> TokenMgmt
    UI --> APIEndpoints
    STT --> APIEndpoints
    TokenMgmt --> APIEndpoints
    
    APIEndpoints --> Nginx
    Nginx --> Django
    
    Django --> AuthSystem
    Django --> ChatMgmt
    Django --> TTSEngine
    Django --> URLRouter
    Django --> Settings
    
    ChatMgmt --> OpenAI
    ChatMgmt --> Models
    AuthSystem --> Models
    DailyLimit --> Models
    
    Models --> ChatHistory
    Models --> UserData
    
    AWS --> Nginx
    Nginx --> Gunicorn
    Gunicorn --> Django

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef security fill:#e74c3c,stroke:#c0392b,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef infra fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef api fill:#9b59b6,stroke:#8e44ad,color:white
    classDef data fill:#1abc9c,stroke:#16a085,color:white
```
