Below is a comprehensive, wide-ranging overview of my entire codebase and web application, based on the merged repository content. This overview is designed to be extremely detailed so that someone unfamiliar with the project can grasp the context, architecture, goals, data flow, and even the intricacies of the front-end (Redux usage, components) and back-end (database, models, routes, concurrency, Celery tasks, etc.). While it’s called a “high-level overview,” it is intentionally exhaustive—covering most relevant code structures, design decisions, and logic flow.
This project is a gamified platform centered around cybersecurity, certification practice, daily newsletters, scenario-driven learning, and more. It has multiple services (backend, frontend, database, caching, etc.) that coordinate to deliver:
- Practice Test Functionality for certifications (e.g., CompTIA A+, Security+, CySA+, CASP+, etc.).
- User Account Management, including registration, login, XP leveling, achievements, and a virtual shop.
- Daily Newsletter System to send routine cybersecurity briefs via Celery and SendGrid.
- Scenario Generators, GRC question generators, analogy generators, and more, many leveraging OpenAI-based LLM calls.
- Streaming endpoints to serve chunked content for real-time updates in the UI.
- Gamification elements like XP, coins, daily bonuses, achievements, an in-app store for purchasing items and XP boosts.
- Integration with additional modules (Xploitcraft, GRC, daily scenario tasks, etc.) to create an immersive cybersecurity learning environment.
Overall, the site aims to combine an interactive quiz/practice system with daily content, scenario-based question streams, and a robust user experience that fosters repeated engagement and learning.
My application is split among these major components:
- Frontend (React) running at
:3000
(or served by the Apache container). - Backend (Flask + Socket.IO) running at
:5000
. This connects to:- MongoDB for persistent data (Users, Achievements, Tests, etc.).
- Redis for caching, Celery message broker, and result backend.
- Celery worker processes for asynchronous tasks (newsletter emailing, AI generation tasks, etc.).
- Apache (or Nginx in some config) serving as a reverse proxy, forwarding
/api
calls to the backend and everything else to the frontend.
apache/
: Contains aDockerfile.apache
referencinghttpd:2.4
plus a customapache_server.conf
andhttpd.conf
.backend/
: Contains aDockerfile.backend
that sets up Python (3.11), installs dependencies, and runs the Flask (Gunicorn) server on0.0.0.0:5000
.frontend/my-react-app/
: Contains multiple Dockerfiles for dev, audit, production, etc. Builds the React application.
- MongoDB stores user data, test metadata, achievements, newsletter content, subscription info, etc.
- Redis used by Celery for message brokering and result storage. Also used for session management (if configured with Flask-Session).
- Celery tasks handle:
- Generating analogies, scenario text, and GRC questions with OpenAI.
- Sending daily newsletters.
- Generating exploit payloads or bigger tasks in an asynchronous manner.
- Backend (Flask) organizes code in subdirectories such as
routes/
,helpers/
,models/
,mongodb/
, etc. - Frontend uses React, Redux (with slices for user, achievements, shop, etc.) to orchestrate page navigations, test taking, user sign-in, etc.
Located in backend/
, the backend uses Flask + Socket.IO. Key subdirectories include:
-
API/
AI.py
sets up the OpenAI client. It loads theOPENAI_API_KEY
from.env
and creates a globalOpenAI
client object for usage across the codebase.
-
helpers/
analogy_helper.py
/analogy_stream_helper.py
: Generate single/comparison/triple analogies with GPT. There’s streaming support for chunk-based analogy responses.async_tasks.py
: Celery tasks that wrap the logic for generating analogies, scenarios, interactive questions, exploit payloads, etc.celery_app.py
: The Celery application entry point, loads environment variables, sets schedules (like daily newsletter at midnight), configures broker (Redis) and concurrency.daily_newsletter_helper.py
/daily_newsletter_task.py
: Manage newsletter content in the database, send daily newsletter to subscribers (via SendGrid).email_helper.py
: Uses SendGrid to send emails.grc_helper.py
/grc_stream_helper.py
: Generate GRC-related multiple-choice questions, or stream them chunk by chunk. The content includes JSON structures with question, options, correct answer index, explanations, exam tips, etc.scenario_helper.py
: Generate scenario narratives for cybersecurity incidents, break them down into context/actors/risks, generate interactive questions, etc.xploitcraft_helper.py
:Xploits
class uses rate limiting and streams content from GPT to produce exploit payloads and thorough code snippet examples.
-
models/
newsletter_content.py
: Basic CRUD with anewsletter
collection in Mongo for storing a single doc with the current newsletter content.test.py
: A central, large file containing numerous helper functions for user creation, validation, test attempts, achievements, leveling, daily bonus, shop logic, etc.- Contains the advanced input sanitization for username, password, and email.
- Defines the XP leveling logic (progressing from level to level with certain XP thresholds).
- Achievement unlocking logic: checks total tests, perfect tests, consecutive perfect streaks, categories, etc.
user_subscription.py
: Manages creation and removal of user subscriptions (for daily briefs). Has separateusers
collection from main user system (some duplication possible).
-
mongodb/
database.py
: Instantiates a FlaskPyMongo
object, references environment’sMONGO_URI
, sets upmainusers_collection
,shop_collection
,achievements_collection
,tests_collection
, plus newtestAttempts_collection
,correctAnswers_collection
,dailyQuestions_collection
,dailyAnswers_collection
.
-
routes/
analogy_routes.py
: 2 endpoints:/generate_analogy
(uses Celery tasks for single/comparison/triple)./stream_analogy
streams analogy in real time to the client.
daily_brief_routes.py
: Subscribing to daily briefs, scheduling them, etc. (some references to aschedule_email_task
).grc_routes.py
: Acceptscategory
anddifficulty
, generates GRC question JSON via Celery.scenario_routes.py
: Streams scenario text chunk-by-chunk; streams interactive scenario-based questions chunk-by-chunk.subscribe_routes.py
/unsubscribe_routes.py
: Basic routes for subscription and unsubscribing user emails. Includes email validation, usesrequire_api_key
for admin route, etc.test_routes.py
: Very large file containing:- User Endpoints: register, login, retrieving user doc, updating XP, coins, etc.
- Shop: listing items, purchase flow, equipping items, XP boosts, etc.
- Tests: fetching a test by ID + category, finishing an attempt, listing attempts, storing user’s answers, awarding XP/coins for correct answers (only first time).
- Achievements: endpoint for retrieving all achievements from DB.
- Leaderboard: caching top 1000 users in memory for 15 seconds, serving data with skip/limit for pagination.
- Daily Bonus: awarding 1000 coins once every 24 hours (plus daily question logic).
- Username/Email/Password changes: includes password validation again, etc.
xploit_routes.py
: Generating exploit payload (GPT-based) with optional streaming, returning code examples that highlight vulnerabilities, with commentary in code comments.
-
app.py
- The main Flask entry point, sets up
CORS
,Session
,SocketIO
, logs requests, registers all blueprint routes, and runs via Gunicorn.
- The main Flask entry point, sets up
In database.py
, you define multiple collections in a single MongoDB instance:
mainusers
: The primary user storage (username, email, password, xp, level, coins, purchasedItems, achievements, subscriptionActive, xpBoost, lastDailyClaim).shopItems
: Items in the in-app shop (avatars, XP boosts, color changes, etc.).achievements
: Documents describing achievements, each withachievementId
,criteria
, etc.tests
: The stored test questions (some references to “aplus,” “security+,” “cissp,” etc.). Each doc hastestId
,category
, and an array of questions or some structure.testAttempts
: Tracks a user’s attempt on a specific test, storing answers, the current question index, the final score, and whether finished.correctAnswers
: Tracks which specific question a user has gotten correct for the first time (so awarding XP/coins is only given once).dailyQuestions
/dailyAnswers
: For daily question logic. Each day can have a special question.dailyAnswers
stores who answered what, awarding coin bonuses if correct.
- Rate Limiting: The exploit generation route uses a simple token bucket in
xploitcraft_helper.py
. - Celery:
- Scheduled tasks (
app.conf.beat_schedule
) for daily newsletters at midnight. async_tasks.py
wraps generating analogies, GRC questions, scenario text, etc.
- Scheduled tasks (
- OpenAI usage: A single
client
object is imported fromAPI/AI.py
. LLM calls happen for scenario generation, GRC question creation, exploit code, etc. - Security: Basic request validation in user registration, password checks, etc. Some potential duplication across front-end validation. Rate limiting for exploit endpoints. Achievements logic ensures no duplication of awarding.
- Routing: Divided by blueprint for organizational clarity.
In frontend/my-react-app/
, you have a typical Create React App folder layout:
public/
- Some static files like
xp_mongo.js
,index.html
,manifest.json
,robots.txt
. - Possibly images for XP boost items, logos, etc.
- Some static files like
src/
App.js
,index.js
, etc. typical React bootstrapping.global.css
,index.css
for global styles.components/
: The heart of the front-end, subdivided into pages, store slices, etc.pages/
: Contains many subfolders, each representing a set of tests or pages:- AnalogyPage (with
AnalogyHub.js
,.css
). - aplus/ (with
APlusTestList.js
,APlusTestPage.js
). - aplus2/, auth/, awscloud/, casp/, cissp/, cloudplus/, cysa/, DailyPage/, dataplus/, GRCpage/, Info/, linuxplus/, nplus/, penplus/, ResourcesPage/, ScenarioPage/, secplus/, serverplus/, etc.
- AnalogyPage (with
- The pattern: each certification has two components:
XYZTestList.js
for listing tests, andXYZTestPage.js
to handle a single test instance (some use the new universalGlobalTestPage.js
). store/
: Redux slices for achievements, shop, user, etc., plus astore.js
combining them.Sidebar/Sidebar.js
,ProtectedRoute.js
, etc. shared components.
store/userSlice.js
(found in the user’s directory mention, typically) manages login, registration, user state. Possibly also caches tokens or user data in localStorage.store/shopSlice.js
might fetch or store the user’s coins, purchase actions, items.store/achievementsSlice.js
tracks achievements unlocked, shows toasts, etc.
Key Note: Some test pages are fully localStorage-based (like awscloud
, caspplus
, cissp
, etc.), while others (like aplus
, aplus2
) demonstrate fetching attempts from the server. This indicates a partial migration from local-only test progress to server-based progress.
- Registration/Login:
- Uses forms that dispatch Redux actions (like
loginUser
,registerUser
). - Validations are done on the front-end (like not allowing certain usernames or trivial passwords) and also re-validated on the server.
- On success, the store is updated with
userId
and other user info. ThenlocalStorage
is updated for persistence.
- Uses forms that dispatch Redux actions (like
- Test Taking:
- The user navigates to a “Test List” page for a specific category (A+, CASP+, etc.).
- Each test card can be started, resumed, or restarted.
- If it’s a “server-based” category (like A+), the system calls backend endpoints to upsert attempt docs in
testAttempts_collection
. - If it’s a “local-based” category (like AWSCloud or CASP+), the system uses localStorage to store progress.
- Shop:
- The user can see available items. The store fetches from the
/shop
endpoint. - Purchasing triggers a server call that decrements coins and marks the item as purchased. Some items might apply
xpBoost
or change the user’snameColor
orcurrentAvatar
.
- The user can see available items. The store fetches from the
- Achievements:
- When finishing tests or gaining coins/XP, the front-end might re-check achievements from the server. The server automatically calls
check_and_unlock_achievements
. - The front-end can display a toast or modal if new achievements are unlocked.
- When finishing tests or gaining coins/XP, the front-end might re-check achievements from the server. The server automatically calls
- Daily Features:
- A “Daily Bonus” button awarding 1000 coins once per 24 hours is done by calling
/user/<user_id>/daily-bonus
. - The “Daily Question” is fetched from
dailyQuestions_collection
, awarding bonus coins if correct.
- A “Daily Bonus” button awarding 1000 coins once per 24 hours is done by calling
- Analogy / GRC / Scenario pages:
- Send POST requests to the relevant “/stream_... ” or “/generate_...” endpoints. The UI streams the chunked text from GPT’s response, showing partial output in real time.
- For example, the “AnalogyHub.js” fetches
/analogy/stream_analogy
and uses aReadableStream
to accumulate text chunks.
- User Document (in
mainusers_collection
):{ "_id": ObjectId("..."), "username": "alice", "email": "[email protected]", "password": "...", "coins": 500, "xp": 3400, "level": 5, "achievements": ["first_test_complete", "coin_collector"], "subscriptionActive": false, "purchasedItems": [ObjectId("..."), ...], "xpBoost": 1.0, "currentAvatar": ObjectId("..."), "nameColor": null, "lastDailyClaim": Date(), // etc. }
- Test Document (in
tests_collection
):{ "_id": ObjectId("..."), "testId": 1, "category": "aplus", "questions": [ { "question": "Which tool would you use to check file system integrity?", "options": ["CHKDSK", "FORMAT", "DISKPART", "FDISK"], "correctIndex": 0, "explanation": "CHKDSK verifies the file system..." }, ... ] }
- Test Attempts (in
testAttempts_collection
):{ "_id": ObjectId("..."), "userId": ObjectId("..."), "testId": 1, "category": "aplus", "answers": [ { "questionId": "...some question ID or index...", "userAnswerIndex": 2, "correctAnswerIndex": 0 } ], "score": 10, "totalQuestions": 100, "currentQuestionIndex": 15, "finished": false, "finishedAt": null }
- Achievement (in
achievements_collection
):{ "_id": ObjectId("..."), "achievementId": "coin_collector", "title": "Coin Collector", "description": "Accumulate 10,000 coins", "criteria": { "coins": 10000 }, "iconUrl": "/icons/coinCollector.png" }
-
Analogy Generation:
analogy_helper.py
and routes let the user input concepts or categories, which calls GPT with a prompt. The reply is a fun analogy, used for educational or entertainment value. Streams partial text if desired.
-
Scenario Generation:
- The user picks an industry, attack type, skill level, threat intensity. The system produces a multi-paragraph scenario with detailed context. Then breaks it into structured data or generates interactive questions with GPT.
-
GRC (Governance, Risk, Compliance):
- API that returns a JSON question object with multiple choice answers, an
explanations
map for each choice, and anexam_tip
. These can be displayed in the front-end as practice questions for advanced certifications (CISSP, CASP+, CRISC, etc.).
- API that returns a JSON question object with multiple choice answers, an
-
Newsletter:
daily_newsletter_task.send_daily_newsletter
runs nightly. Retrieves newsletter content from DB, enumerates subscribers, sends via SendGrid.
-
Xploitcraft:
- Provides “educational” exploit payload generation with code samples in Python. The user or a training environment can see how vulnerabilities might be exploited. Includes rate limiting to prevent excessive GPT usage.
-
Achievements:
- Comprehensive logic in
check_and_unlock_achievements
. The user can unlock achievements for finishing tests, scoring 100%, finishing multiple tests, collecting coins, reaching certain XP levels, etc.
- Comprehensive logic in
- Blueprint-based Route Organization: Each route file focuses on a logical grouping (analogy, scenario, etc.).
- Celery for Asynchronicity: CPU or I/O heavy tasks (like sending out mass emails or large GPT calls) run outside the main request cycle to keep the app responsive.
- MongoDB Data Model: Non-relational approach with flexible structures for tests, attempts, daily content, etc.
- Front-end:
- Functional React Components with hooks (
useState
,useEffect
). - Redux for global state, managing user login state, achievements, shop items. The slices dispatch asynchronous actions for calling the backend or reading localStorage.
- Test Merging: Some tests are localStorage-based, others stored on the server. This is presumably an ongoing refactor.
- Styling: Each page/feature typically has a dedicated
.css
file. Some global overrides. TheSidebar
andApp.js
handle primary layout or navigation.
- Functional React Components with hooks (
Inside frontend/my-react-app/src/components/pages/store/
:
userSlice.js
:- Typically has
loginUser
andregisterUser
thunks that fetch the backend/test/login
or/test/user
endpoints. - On success, sets
userId
,username
,coins
,xp
, etc. in Redux state.
- Typically has
achievementsSlice.js
:- Might fetch user’s achievements or handle newly unlocked ones.
- Possibly displays notifications or confetti upon unlocking achievements.
shopSlice.js
:- Fetches shop items, stores them in a global state. Let’s you dispatch “purchaseItem” which calls the backend’s “/shop/purchase/<item_id>”.
Actions are triggered from React pages (like a “Buy” button or “Login” button). The reducers update the global store. Components read the store (like useSelector(state => state.user)
), so they can show user’s coins or logged-in status.
- docker-compose.yml likely orchestrates containers for
backend
,frontend
,apache
(ornginx
),redis
,mongodb
. - The
backend
runs Gunicorn with gevent workers. - The
frontend
is served either by Node or built and served by theapache
container as static assets. - ENV Variables from
.env
or environment:OPENAI_API_KEY
,MONGO_URI
,SENDGRID_API_KEY
,REDIS_PASSWORD
, etc.
Development: Possibly you run docker-compose up
or each container individually. Then:
- Frontend on
http://localhost:3000
. - Backend on
http://localhost:5000
. - The reverse proxy on
http://localhost:8080
or so. (My config might vary.)
- Modular code design with strong separation: routes vs. models vs. Celery tasks vs. front-end pages.
- Scalable approach to concurrency, thanks to Celery, Redis, and streaming responses.
- Gamification aspects are robust: XP, coins, achievements, daily claims, shop items, etc.
- Rich AI functionality: analogy generation, scenario creation, GRC question generation, exploit payloads, etc.
- Security improvements: user input validations, password rules, achievements awarding logic to prevent duplication, minimal rate-limiting for GPT usage.
- Consistency in how test attempts are stored (server-based vs. localStorage). Migrating all to server-based might unify the user experience.
- Enhanced integration for daily newsletters with more dynamic content or personalization.
- Further rate limiting or advanced security for the open AI endpoints if usage spikes.
- UI improvements to unify styling between the many test lists and categories.
- Improving environment-based configuration to facilitate staging vs. production.
My web application is a multi-container platform that unites a gamified cybersecurity practice environment, daily content, AI-based scenario and question generation, a robust user system with achievements/levels, an item shop, and daily tasks. The back-end is structured with blueprint routes, Celery tasks for asynchronous operations, a well-thought-out schema in MongoDB, and a front-end React/Redux code structure that organizes test features by certification category. By combining streaming GPT responses, e-commerce-like item purchasing, and daily engagement loops, the project fosters a creative and educational experience focusing on repeated user engagement in cybersecurity topics.
This concludes the extremely lengthy, detailed, and “high-level” (but ironically deeply comprehensive) overview. It should give any newcomer a solid sense of the entire codebase and its underlying logic, from data models and route design to front-end Redux patterns, achievements, daily engagement, and Celery-based tasks.