# jorge-polanco-roque/aws_rpg architecture

> Architecture diagram of the GitHub repository jorge-polanco-roque/aws_rpg, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jorge-polanco-roque/aws_rpg
- Repository: https://github.com/jorge-polanco-roque/aws_rpg

## Overview

##### Project type and purpose
- This is a full-stack interactive training game (“NEURO-ARCHITECT”) built to help users prepare for the AWS Solutions Architect Associate exam in a cyberpunk style.
- Frontend: React 18 SPA with styled-components, Context API, Framer-Motion.
- Backend: Node.js + Express API with JWT auth, SQLite for persistence.
- Deployed via Docker Compose, served behind Nginx in production.

##### File structure
- Top-level Docker artifacts: multiple Dockerfiles (backend, dev, simple), .dockerignore, docker-compose YAMLs, nginx.conf.
- client/ – React app
- src/components – UI widgets (CombatArena, BossManager, etc.)
- src/pages – route-level views (HomePage, GamePage, LeaderboardPage, etc.)
- src/contexts – AuthContext, GameContext, SoundContext
- build/ – production bundle
- src/server/ – Express API
- index.js – server entry, middleware (CORS, Helmet, JWT)
- data/questions_expanded.js – question pool
- cosmic_codex.db – SQLite file
- start.sh – local development launcher
- Logging: combined.log, error.log

##### README for additional insights
- Architecture summary shows three main blocks: React UI ↔ Express API ↔ SQLite DB.
- Key services: Auth System, Game Engine, Question Pool, Score Logic, Progress API.
- External concerns: JWT authentication, CORS, security headers, monitoring via Winston.

a. Main components
- User’s Browser (React SPA)
- Nginx reverse proxy (in prod)
- Express API Server (Node.js)
- SQLite Database (cosmic_codex.db)
- Docker & Docker-Compose orchestration
b. Relationships & interactions
- Browser ←→ Nginx ←→ Express REST endpoints
- Express ←→ SQLite for reads/writes (profiles, progress, questions)
- React Contexts manage local state and call APIs via fetch/Axios
c. Architectural patterns & principles
- SPA + API server (separation of concerns)
- Context API for global client state
- JWT stateless authentication
- Modular service design (Auth, Game, Stats)
- Containerization for environment parity (dev, prod, simple)
d. Key technologies
- React 18, styled-components, framer-motion
- Node.js 18+, Express, JWT, Helmet, CORS
- SQLite for lightweight persistence
- Docker, Docker-Compose, Nginx

##### Detailed breakdown of components
- USER BROWSER
– Hosted by Nginx or local dev server
– React Contexts handle Auth, Game and Sound
– Calls /api/* endpoints
- NGINX (production)
– TLS termination, static asset serving for /client/build
– Proxy /api/* to Express
- EXPRESS API
– Middleware: Helmet, CORS, rate limiter
– Auth routes: /api/auth/login, /register, /logout
– Game routes: /api/game/start-session, /question/:id, /submit-answer, /stats, /leaderboard
– Health: /api/health, /api/game/cosmic-entities
– Logging: Winston to combined.log and error.log
- SQLITE DATABASE
– Tables: Users, Sessions, Questions, Progress, Stats
– Access via simple file path (./cosmic_codex.db)
- DOCKER & COMPOSE
– Services: frontend, backend, nginx
– Variants: dev (live-reload), simple (single container), prod (multi-container)
– Environment variables for PORT, JWT_SECRET, DB_PATH, CORS

##### Putting it all together
- Browser → Nginx (HTTPS/HTTP)
- Nginx → Express (HTTP)
- Express → SQLite (SQL queries)
5. Annotations for ports (3030 for API, 80/443 for Nginx, etc.), Docker Compose files, and environment variables.
6. Build pipeline if needed (Git → Docker build → Deploy).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Browser with React SPA and subcomponents
    subgraph "User Browser"
        direction TB
        ReactSPA["React SPA"]:::frontend
        AuthCtx["AuthContext"]:::frontend
        GameCtx["GameContext"]:::frontend
        SoundCtx["SoundContext"]:::frontend
        UIComps["UI Components"]:::frontend
        Pages["Route Pages"]:::frontend
        Styles["Global Styles & Theme"]:::frontend
        Entry["Entry Point"]:::frontend
        ReactSPA --> AuthCtx
        ReactSPA --> GameCtx
        ReactSPA --> SoundCtx
        ReactSPA --> UIComps
        ReactSPA --> Pages
        ReactSPA --> Styles
        ReactSPA --> Entry
    end

    %% Docker Host environment grouping infrastructure
    subgraph "Docker Host"
        direction TB
        Nginx["Nginx Proxy<br/>(TLS, Static)"]:::infra
        ExpressAPI["Express API Server"]:::backend
        SQLiteDB["SQLite DB"]:::persist

        Nginx --> ExpressAPI
        ExpressAPI --> SQLiteDB
    end

    %% Interactions between Browser and Infrastructure
    ReactSPA -->|"HTTPS/HTTP"| Nginx
    Nginx -->|"Proxy HTTP"| ExpressAPI
    ExpressAPI -->|"SQL Queries"| SQLiteDB

    %% Docker Compose orchestration
    DockerCompose["Docker Compose"]:::infra
    DockerCompose --> Nginx
    DockerCompose --> ExpressAPI
    DockerCompose --> SQLiteDB

    %% Click Events
    click ReactSPA "https://github.com/jorge-polanco-roque/aws_rpg/tree/main/Juego_Estudio_Arq_Soluciones/client/src"
    click AuthCtx "https://github.com/jorge-polanco-roque/aws_rpg/blob/main/Juego_Estudio_Arq_Soluciones/client/src/contexts/AuthContext.js"
    click GameCtx "https://github.com/jorge-polanco-roque/aws_rpg/blob/main/Juego_Estudio_Arq_Soluciones/client/src/contexts/GameContext.js"
    click SoundCtx "https://github.com/jorge-polanco-roque/aws_rpg/blob/main/Juego_Estudio_Arq_Soluciones/client/src/contexts/SoundContext.js"
    click UIComps "https://github.com/jorge-polanco-roque/aws_rpg/tree/main/Juego_Estudio_Arq_Soluciones/client/src/components"
    click Pages "https://github.com/jorge-polanco-roque/aws_rpg/tree/main/Juego_Estudio_Arq_Soluciones/client/src/pages"
    click Styles "https://github.com/jorge-polanco-roque/aws_rpg/blob/main/Juego_Estudio_Arq_Soluciones/client/src/styles/GlobalStyles.js"
    click Entry "https://github.com/jorge-polanco-roque/aws_rpg/blob/main/Juego_Estudio_Arq_Soluciones/client/src/index.js"
    click Nginx "https://github.com/jorge-polanco-roque/aws_rpg/blob/main/Juego_Estudio_Arq_Soluciones/nginx.conf"
    click ExpressAPI "https://github.com/jorge-polanco-roque/aws_rpg/blob/main/Juego_Estudio_Arq_Soluciones/Dockerfile.backend"
    click SQLiteDB "https://github.com/jorge-polanco-roque/aws_rpg/blob/main/Juego_Estudio_Arq_Soluciones/cosmic_codex.db"
    click DockerCompose "https://github.com/jorge-polanco-roque/aws_rpg/blob/main/Juego_Estudio_Arq_Soluciones/docker-compose.yml"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#1E90FF,color:#000
    classDef backend fill:#C8F7C5,stroke:#228B22,color:#000
    classDef persist fill:#FFD8A8,stroke:#FFA500,color:#000
    classDef infra fill:#E5E5E5,stroke:#A9A9A9,color:#000
```
