How vatsal112/live-code-editor works
Project Type and Purpose
• This is a full‐stack web application (“Live-Code-Editor”) that lets users sign up/sign in, write HTML/CSS/JS in a browser‐based code editor (CodeMirror), see instant preview, and CRUD (Download/Update) their code snippets stored on the server.
Top‐Level Components
a. Client/Web Browser
• Static pages: index.html (editor + preview), login.html, register.html, projects.html (list of saved snippets), update.html
• Code editor library: codemirror/ (all modes, addons, themes)
• Static assets: assets/css/*.css, assets/js/*.js, assets/fonts, assets/img
• Root scripts: main.js, style.css
b. API (Backend)
• Entry point: api/index.php
• Includes layer: includes/ (classes, constants, load.php)
• Business logic: user authentication, snippet CRUD
c. Data Storage
• JSON files under code/ (one .json per snippet)
• includes/tmp/data.json (temporary or metadata store)
d. Web Server
• Serves static assets and routes /api/* to the PHP application
Component Relationships & Data Flow
• User loads a static page (e.g., index.html) → Browser fetches HTML/CSS/JS from the Web Server
• Browser initializes CodeMirror (from codemirror/) and UI scripts (assets/js & main.js)
• On user actions (save/load/update snippet), front-end JS issues AJAX/Fetch calls to api/index.php
• api/index.php loads includes/constant.php & classes, validates/authenticates the request, reads/writes the appropriate JSON file in code/ or includes/tmp/data.json
• The API returns JSON responses; browser JS updates the UI and preview accordingly
Architectural Patterns & Principles
• N‐Tier separation: Presentation (Browser + CodeMirror UI), Application/API (PHP scripts + business classes), Data (JSON file storage)
• REST‐style API endpoints for snippet operations
• Modular design: distinct directories for assets, includes, code storage, and third‐party library (CodeMirror)
Key Technologies & Frameworks
• Frontend: HTML5, CSS3, JavaScript, CodeMirror editor
• Backend: PHP 7+, JSON file system storage (no RDBMS)
• Build/deploy: served via Apache or Nginx with PHP support