Sophia Codex

Intelligent Developer Knowledge Management System

Technologies
Python Flask SQLAlchemy Bootstrap 5 Google Gemini and Minimax API Vector Embeddings WTForms Alembic/Flask-Migrate Pygments python-markdown Werkzeug NumPy
Status Production Ready
Category Developer Productivity Tools

Project Overview

Project Sophia is a comprehensive AI-powered knowledge management system designed to help developers organize, manage, and share code snippets, solutions, and technical insights. It combines powerful AI capabilities with robust organization features to streamline your coding workflow.

Sophia Codex addresses the common problem developers face in managing an ever-growing collection of code snippets, solutions to problems, and general technical knowledge. It provides a structured environment to organize code snippets, leverage AI-powered development tools, build a personal knowledge base, and track progress through gamification.

31+
API Endpoints
11
Database Models
60%
CPU Optimization

Key Features

🔍

Semantic Search

AI-powered search using vector embeddings and natural language queries to find relevant code snippets instantly. Combines keyword and semantic search with search scoring and highlighting.

🤖

AI Code Generation

Generate production-ready code from natural language prompts with real-time streaming display. Features modern gradient UI, syntax highlighting with Prism.js, copy code buttons, and save directly as snippet capability.

📖

AI Code Explanation

Get detailed, formatted explanations for any code snippet with markdown-rendered output, copy explanation to clipboard, and one-click apply to snippet description.

🏷️

Smart Tag Suggestions

Automatically generate relevant tags for your code snippets using AI-powered code analysis with 100+ programming term vocabulary and intelligent tag extraction.

💬

Chat Assistant

Context-aware AI coding assistant with streaming responses, multiple chat sessions, conversation history, and the ability to refer to your snippets for contextual help.

🏆

Gamification System

Achievement badges (25+), points system, and activity streaks encouraging consistent knowledge management. Track progress with profile analytics and insights.

📁

Collection Organization

Hierarchical organization with nested collections, drag-and-drop reordering, move and copy snippets between collections, and collection statistics.

📝

Rich Note System

Create and manage personal notes with Markdown support, AI-powered note explanations, and integrated chat assistant for contextual coding help.

🔄

Version History

Every edit creates an automatic snapshot. View all historical versions, compare changes with diff view, and rollback to any previous version.

📤

Export & Backup

Export snippets as Markdown files, bulk export to ZIP archive, automatic daily snapshots, and comprehensive backup system with one-click restore.

Core Capabilities

User Authentication

Secure registration and login with Flask-Login, password hashing using Werkzeug, session management with configurable timeout, Remember Me functionality, and account lockout after failed attempts.

Code Snippet Management

Create, view, edit, and delete code snippets with syntax highlighting for multiple programming languages. Supports tag-based organization, collection categorization, and version history with rollback capability.

Bulk Operations

Perform operations like deleting, copying, or moving multiple snippets simultaneously with intuitive checkbox selection and batch action buttons.

AI Code Formatting

Automatically format code with proper indentation, spacing, and style using AI to ensure consistency and readability across your codebase.

Technical Architecture

Backend

  • Framework: Flask with application factory pattern
  • Database: SQLite with SQLAlchemy ORM and automatic migrations via Alembic/Flask-Migrate
  • Authentication: Flask-Login with Werkzeug password hashing
  • Forms: WTForms with validation and CSRF protection
  • AI Integration: Google Gemini API (gemini-2.5-flash, flash-lite, pro) with multi-step thinking pipeline

Frontend

  • Styling: Bootstrap 5 with custom CSS and glassmorphism design
  • Syntax Highlighting: Pygments and Prism.js
  • Markdown: python-markdown for note rendering
  • JavaScript: Vanilla JS with streaming AI display and tooltip system

Database Models

User

Authentication & preferences

Snippet

Code with embeddings

SnippetVersion

Version history

Collection

Hierarchical org

ChatSession

Chat conversations

ChatMessage

AI messages

MultiStepResult

4-layer thinking

Badge

Achievement defs

UserBadge

User achievements

Note

Knowledge base

Point

Gamification pts

Technical Implementation

$ Architected full-stack Flask application with SQLite database and Flask-SQLAlchemy ORM for efficient data persistence, including migrations via Alembic

$ Integrated Google Gemini and Minimax APIs for AI-powered code generation, line-by-line explanation, intelligent tag suggestions, bug fixing, and refactoring with multi-step thinking

$ Implemented semantic search functionality using vector embeddings and NumPy for similarity calculations, with keyword and advanced filters

$ Developed secure user authentication system with Flask-Login, Werkzeug password hashing, session management, and account lockout after 5 failed attempts

$ Built complete CRUD operations for code snippets, collections, folders, notes, and LeetCode problems with ownership enforcement and version history

$ Integrated Pygments for syntax highlighting supporting dozens of programming languages, and python-markdown for rendering with input validation

$ Implemented Markdown-rich notes system with AI explanation, and chat assistant for context-aware coding help with session history and streaming output

$ Created client-side enhancements including one-click clipboard copying, code formatting, drag-and-drop organization, and profile customization

$ Developed pagination system for efficient handling of large snippet collections, and export/backup features (Markdown, ZIP, daily snapshots)

$ Engineered comprehensive security measures including CSRF protection, SQL injection prevention, XSS mitigation, security headers, and input validation

$ Implemented gamification with badge system (25+ badges), points for actions, activity streaks, and profile analytics via badge_system.py

$ Built LeetCode integration for adding problems, AI-generated solutions, approval workflow, and explanations, with fallback between AI providers

Getting Started

Prerequisites

  • Python 3.9+
  • pip (Python package installer)
  • Git

Installation

  1. Clone the repository:
    git clone https://github.com/AlexBiobelemo/Sophia-Code.git
  2. Create and activate virtual environment:
    python -m venv venv && venv\Scripts\activate
  3. Install dependencies:
    pip install -r requirements.txt
  4. Set up environment variables:
    Create a .env file with SECRET_KEY, DATABASE_URL, and GEMINI_API_KEY
  5. Initialize the database:
    flask db upgrade
  6. Initialize badges:
    python -c "from app.badge_system import initialize_default_badges; ..."
  7. Run the application:
    python run.py