# rubenperezm/robda architecture

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

- Interactive diagram: https://gitdiagram.com/rubenperezm/robda
- Repository: https://github.com/rubenperezm/robda

## Overview

##### Project type and purpose
- This is a full-stack web application (“roBDa”), a quiz-based learning platform.
- The back end is a Django REST API (“api/”), structured as a monolithic Django project with multiple “apps” (base, eventos, partidas, preguntas, stats, users).
- The front end is a Next.js React application (“web/”), using both server-rendered pages and Next.js API routes as a BFF layer.

##### File structure
Top level:
- api/ – Django project
– api/api/ – Django settings, URLs, WSGI/ASGI
– api/apps/… – Six Django apps, each with models, serializers, viewsets, routers, migrations
– manage.py, requirements.txt, media/ (uploaded images)
- web/ – Next.js front-end
– public/ – static assets (logos, flags, avatars)
– src/pages/ – page components and Next.js API routes under pages/api
– src/components, sections, layouts, utils, hooks, contexts, theme – React UI code, HOCs, context providers
– .env.example, package.json, next.config.js
- robda-venv/ – Python virtual environment

##### README for additional insights
- Two main modes: “Modo repaso” (infinite personalized quiz) and “Modo online” (competitions + duels).
- Competitions have three phases: question creation, quiz play, reporting/voting.
- Real-time play with friends (“Jugar con Amigos”) vs. solo study.

##### Main components
a. Client browser (Users)
b. Next.js front-end server
- Static/SSR pages for UI
- Next.js API routes (“pages/api/*”) as BFF (handles authentication, token refresh, session, and proxies to Django)
c. Django REST API server
- Django project entrypoint (WSGI/ASGI)
- Apps:
– users (authentication, registration, password, profiles)
– eventos (manage quiz events)
– partidas (duels, rapid-play logic)
– preguntas (question bank, topics, images)
– stats (aggregation endpoints)
– base (shared models, pagination, permissions)
- Media storage (/media for question images)
d. Database (relational, e.g., PostgreSQL or SQLite in dev)
e. External services (if applicable – email SMTP for password reset, file storage for images)

##### Relationships and interactions
- Browser ↔ Next.js pages (HTTP/HTTPS): user navigates to UI, SSR or SSG pages render React components.
- Browser ↔ Next.js API routes (XHR/Fetch): login, refresh, quiz start, etc.
- Next.js API routes ↔ Django REST API (HTTP/REST + JSON): the BFF layer routes traffic to the appropriate API endpoints.
- Django REST API ↔ Database (ORM calls): storing users, questions, stats, events.
- Django REST API ↔ Media storage (file I/O or object store): store/retrieve question images.
- Optional: Django REST API ↔ Email service for notifications/reporting.

##### Architectural patterns and design principles
- BFF (Backend For Frontend) with Next.js API routes
- MVC pattern in Django (models, serializers, viewsets, routers)
- Component-based UI in React, using HOCs and React Context for auth and theming
- Separation of concerns: authentication, question management, gameplay logic, reporting, statistics each live in their own Django app
- Use of environment variables (.env files) for config in both layers

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Browser
    Browser["Browser"]:::external

    %% Front-end (Next.js)
    subgraph "Front-end (Next.js)"
        direction TB
        SSR["SSR/UI Pages"]:::frontend
        BFF["API Routes (pages/api/*)"]:::frontend
        FE_Config["Env & Build Config"]:::frontend
        FE_Config --> SSR
        FE_Config --> BFF
    end

    %% Back-end (Django)
    subgraph "Back-end (Django)"
        direction TB
        Entrypoint["Django Entrypoint\n(manage.py & api/)"]:::backend
        Apps["Django Apps"]:::backend
        subgraph "Apps"
            direction TB
            Base["base"]:::backend
            Users["users"]:::backend
            Eventos["eventos"]:::backend
            Partidas["partidas"]:::backend
            Preguntas["preguntas"]:::backend
            Stats["stats"]:::backend
        end
        BE_Config["Python Config & Deps"]:::backend
    end

    %% Data Stores & External
    DB["Database"]:::datastore
    Media["Media Storage"]:::datastore
    Email["Email Service"]:::external

    %% Connections
    Browser -->|HTTPS| SSR
    Browser -->|XHR/Fetch| BFF
    BFF -->|REST/JSON| Entrypoint
    Entrypoint -->|ORM Calls| DB
    Entrypoint -->|File I/O| Media
    Entrypoint -->|SMTP| Email

    %% Click Events - Front-end
    click SSR "https://github.com/rubenperezm/robda/tree/main/web/src/pages/"
    click BFF "https://github.com/rubenperezm/robda/tree/main/web/src/pages/api/"
    click FE_Config "https://github.com/rubenperezm/robda/blob/main/web/.env.example"
    click FE_Config "https://github.com/rubenperezm/robda/blob/main/web/next.config.js"
    click FE_Config "https://github.com/rubenperezm/robda/blob/main/web/package.json"
    click FE_Config "https://github.com/rubenperezm/robda/tree/main/web/"

    %% Click Events - Back-end
    click Entrypoint "https://github.com/rubenperezm/robda/blob/main/api/manage.py"
    click Entrypoint "https://github.com/rubenperezm/robda/tree/main/api/api/"
    click Base "https://github.com/rubenperezm/robda/tree/main/api/apps/base/"
    click Users "https://github.com/rubenperezm/robda/tree/main/api/apps/users/"
    click Eventos "https://github.com/rubenperezm/robda/tree/main/api/apps/eventos/"
    click Partidas "https://github.com/rubenperezm/robda/tree/main/api/apps/partidas/"
    click Preguntas "https://github.com/rubenperezm/robda/tree/main/api/apps/preguntas/"
    click Stats "https://github.com/rubenperezm/robda/tree/main/api/apps/stats/"
    click BE_Config "https://github.com/rubenperezm/robda/blob/main/api/.env.example"
    click BE_Config "https://github.com/rubenperezm/robda/blob/main/api/requirements.txt"
    click Media "https://github.com/rubenperezm/robda/tree/main/api/media/"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#0277BD,stroke-width:1px
    classDef backend fill:#E8F5E9,stroke:#2E7D32,stroke-width:1px
    classDef datastore fill:#F5F5F5,stroke:#757575,stroke-width:1px,stroke-dasharray: 5 5
    classDef external fill:#FFF3E0,stroke:#EF6C00,stroke-width:1px,stroke-dasharray: 5 5
```
