Skip to content
rajdangi31Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸͺ΄ Athena β€” A Quiet Space for Growth

An AI-powered chatbot with a Humble Scholar persona, focused on Eudaimonia (human flourishing) and personal growth. Built with a Python (Flask) backend and vanilla JavaScript frontend following Modular Minimalist and Wabi-Sabi design principles.


πŸ“ Technical Architecture

System Overview

graph TB
    subgraph Frontend ["πŸ–₯️ Frontend (Vanilla JS/HTML/CSS)"]
        UI["index.html<br/>Semantic HTML5"]
        CSS["style.css<br/>Design System"]
        JS["app.js<br/>Chat Logic"]
    end

    subgraph Backend ["βš™οΈ Backend (Python/Flask)"]
        APP["app.py<br/>Flask Server"]
        CFG["config.py<br/>Configuration"]
        ENV[".env<br/>Secrets"]
    end

    subgraph External ["☁️ External Services"]
        OAI["OpenRouter API<br/>Gemma 4 31B (free)"]
    end

    UI --> JS
    CSS --> UI
    JS -- "POST /chat<br/>Fetch API" --> APP
    JS -- "GET /health" --> APP
    CFG --> APP
    ENV --> CFG
    APP -- "Chat Completions" --> OAI
    OAI -- "Structured Response" --> APP
    APP -- "JSON Response" --> JS

    style Frontend fill:#FAF3E0,stroke:#D4AF37,color:#1A1A2E
    style Backend fill:#004B8D,stroke:#D4AF37,color:#F2F2F2
    style External fill:#1A1A2E,stroke:#D4AF37,color:#F2F2F2
Loading

Request / Response Flow

sequenceDiagram
    participant U as User
    participant FE as Frontend (JS)
    participant BE as Backend (Flask)
    participant AI as OpenRouter API

    U->>FE: Types message & presses Enter
    FE->>FE: Validate input, show typing indicator
    FE->>BE: POST /chat { message, history }
    BE->>BE: Validate request, build prompt
    BE->>AI: chat.completions.create()
    AI-->>BE: Completion response
    BE-->>FE: { reply, model, usage }
    FE->>FE: Render markdown, hide indicator
    FE-->>U: Display formatted response

    Note over FE,BE: Error path
    BE--xFE: { error, code, suggestion }
    FE->>FE: Show error with retry button
Loading

Error Handling Architecture

flowchart LR
    REQ[Incoming Request] --> VAL{Valid JSON?}
    VAL -- No --> E1["400: VALIDATION_INVALID_JSON"]
    VAL -- Yes --> MSG{Has message?}
    MSG -- No --> E2["400: VALIDATION_EMPTY_MESSAGE"]
    MSG -- Yes --> KEY{API key set?}
    KEY -- No --> E3["503: CONFIG_MISSING_API_KEY"]
    KEY -- Yes --> API[Call OpenRouter API]
    API --> R1{Rate limited?}
    R1 -- Yes --> E4["429: API_RATE_LIMIT"]
    R1 -- No --> R2{Auth error?}
    R2 -- Yes --> E5["401: API_AUTH_ERROR"]
    R2 -- No --> R3{API error?}
    R3 -- Yes --> E6["502: API_SERVICE_ERROR"]
    R3 -- No --> OK["200: Success Response"]

    style OK fill:#22c55e,color:#000
    style E1 fill:#ef4444,color:#fff
    style E2 fill:#ef4444,color:#fff
    style E3 fill:#ef4444,color:#fff
    style E4 fill:#ef4444,color:#fff
    style E5 fill:#ef4444,color:#fff
    style E6 fill:#ef4444,color:#fff
Loading

πŸ“ Directory Structure

Athena/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app.py              # Flask application with /chat and /health endpoints
β”‚   β”œβ”€β”€ config.py           # Centralized configuration from environment variables
β”‚   β”œβ”€β”€ requirements.txt    # Pinned Python dependencies
β”‚   β”œβ”€β”€ .env.example        # Template for environment variables
β”‚   └── .env                # Your local secrets (git-ignored)
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ index.html          # Main HTML with semantic structure
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── style.css       # Complete design system (tokens, components, responsive)
β”‚   └── js/
β”‚       └── app.js          # Chat logic, API communication, markdown rendering
β”œβ”€β”€ .gitignore              # Git ignore rules
└── README.md               # This file

πŸš€ Setup Instructions

Prerequisites

1. Clone the Repository

git clone https://github.com/rajdangi31/Athena
cd Athena

2. Create a Virtual Environment

# Create the virtual environment
python -m venv venv

# Activate it
# Windows (PowerShell):
.\venv\Scripts\Activate.ps1

# Windows (CMD):
.\venv\Scripts\activate.bat

# macOS / Linux:
source venv/bin/activate

3. Install Dependencies

pip install -r backend/requirements.txt

4. Configure Environment Variables

# Copy the template
cp backend/.env.example backend/.env

# Edit backend/.env and add your OpenRouter API key
# OPENROUTER_API_KEY=sk-or-v1-your-actual-key-here

5. Start the Backend Server

cd backend
python app.py

You should see:

πŸ›οΈ Athena is listening on http://0.0.0.0:5000

6. Open the Frontend

Open frontend/index.html directly in your browser, or serve it with any static file server:

# Option A: Open directly
start frontend/index.html        # Windows
open frontend/index.html          # macOS

# Option B: Python HTTP server
cd frontend
python -m http.server 3000
# Then visit http://localhost:3000

πŸ“‘ API Reference

GET /health

Health check endpoint for monitoring.

Response:

{
    "status": "healthy",
    "model": "google/gemma-4-31b-it:free",
    "api_configured": true
}

POST /chat

Send a message to the Humble Scholar AI.

Request Headers:

Content-Type: application/json

Request Body:

{
    "message": "How should I design a real-time notification system?",
    "history": [
        { "role": "user", "content": "What is event-driven architecture?" },
        { "role": "assistant", "content": "Event-driven architecture is a design pattern..." }
    ]
}
Field Type Required Description
message string βœ… Yes The user's current message
history array ❌ No Previous conversation turns (max 20 retained)

Success Response (200):

{
    "reply": "## Real-Time Notification Architecture\n\n**Assess**: You're looking to build...",
    "model": "google/gemma-4-31b-it:free",
    "usage": {
        "prompt_tokens": 342,
        "completion_tokens": 512,
        "total_tokens": 854
    }
}

Error Response (4xx/5xx):

{
    "error": true,
    "code": "API_RATE_LIMIT",
    "message": "The AI service is currently rate-limited.",
    "suggestion": "Please wait a moment and try your request again. Rate limits typically reset within 60 seconds."
}

Error Codes

Code HTTP Status Description
VALIDATION_INVALID_JSON 400 Request body is not valid JSON
VALIDATION_EMPTY_MESSAGE 400 No message provided
CONFIG_MISSING_API_KEY 503 Server API key not configured
API_RATE_LIMIT 429 OpenRouter rate limit exceeded
API_AUTH_ERROR 401 Invalid or expired API key
API_SERVICE_ERROR 502 OpenRouter returned an error
INTERNAL_SERVER_ERROR 500 Unhandled server exception
NOT_FOUND 404 Endpoint does not exist
METHOD_NOT_ALLOWED 405 Wrong HTTP method

🧠 AI Persona: The Humble Scholar

The chatbot uses a meticulously crafted system prompt anchored in Eudaimonia:

Section Purpose
### ROLE ### Defines the AI as Athena, a companion in the pursuit of Eudaimonia
### TONE ### Warm, intellectually curious, and grounded (avoids grand language)
### CORE MISSION ### Provides rigorous architectural advice tied back to human flourishing
### RESPONSE STRUCTURE ### Listen (Acknowledge), Reflect (Insight), and Flourish (Growth thought)

The full prompt is defined in config.py and can be customized via the SYSTEM_PROMPT constant.


🎨 Frontend Features

  • Modular Minimalist Theme β€” Book-Paper White, Linen White, Muted Sage Green, and Deep Charcoal palette
  • Quiet Grid Layout β€” Generous whitespace, clean card components, and subtle low-contrast borders
  • Reflective UI Interactions β€” Breath-like animations (600ms ease-in-out) and a steady pulsed typing indicator
  • Subtle Eudaimonic Cues β€” A daily virtue quote gently anchoring the chat space
  • Markdown Rendering β€” Lightweight renderer for headers, code blocks, lists, bold, italic
  • Conversation History β€” Maintains context across the session (up to 20 turns)
  • Seed Thoughts β€” Pre-built minimalist pill-shaped starter questions for architectural dialogue
  • "A Momentary Pause" Modal β€” Context-aware error dialog with a gentle, apologetic tone

πŸ›‘οΈ Security Considerations

  • API keys are never committed to version control (.env is git-ignored)
  • Input is validated and sanitized on both frontend and backend
  • CORS is configurable via the CORS_ORIGINS environment variable
  • Conversation history is capped at 20 turns to prevent prompt injection attacks
  • HTML output is escaped before DOM insertion to prevent XSS

πŸ“œ License

This project was created for Software Engineering β€” Spring 2026.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages