# Daily Journal Prompt Generator - Webapp Refactoring Plan
## Overview
Refactor the existing Python CLI application into a modern web application with FastAPI backend and a lightweight frontend. The system will maintain all existing functionality while providing a web-based interface for easier access and better user experience.
- **Configuration**: `.env` file for API keys, `settings.cfg` for app settings
- **Functionality**:
1. AI-powered prompt generation using OpenAI-compatible APIs
2. Smart repetition avoidance with 60-prompt history buffer
3. Prompt pool system for offline usage
4. Interactive CLI with rich formatting
### Key Features to Preserve
1. AI prompt generation with history awareness
2. Prompt pool management (fill, draw, stats)
3. Configuration via environment variables
4. JSON-based data persistence
5. All existing prompt generation logic
As the user discards prompts, the themes will be very slowly steered, so it's okay to take some inspiration from the history.
## Proposed Web Application Architecture
### Backend: FastAPI
**Rationale**: FastAPI provides async capabilities, automatic OpenAPI documentation, and excellent performance. It's well-suited for AI API integrations.
**Components**:
1.**API Endpoints**:
-`GET /api/prompts/draw` - Draw prompts from pool
-`POST /api/prompts/fill-pool` - Fill prompt pool using AI
-`GET /api/prompts/stats` - Get pool and history statistics
-`GET /api/prompts/history` - Get prompt history
-`POST /api/prompts/select/{prompt_id}` - Select a prompt for journaling
2.**Core Services**:
- PromptGeneratorService (adapted from existing logic)
The refactoring from CLI to webapp will significantly improve accessibility and user experience while maintaining all existing functionality. The proposed architecture using FastAPI + Astro provides a modern, performant, and maintainable foundation for future enhancements.
The phased approach allows for incremental development with clear milestones and risk mitigation at each step.
1.**Complete Backend API** with all original CLI functionality
2.**Modern Frontend** with responsive design and interactive components
3.**Docker Configuration** for easy deployment and development
4.**Comprehensive Documentation** including API docs and setup instructions
5.**Testing Infrastructure** to ensure reliability
### Key Technical Achievements
- **Modular Service Architecture**: Clean separation of concerns
- **Async Operations**: Full async/await support for better performance
- **Error Handling**: Comprehensive error handling with custom exceptions
- **Data Compatibility**: Full backward compatibility with existing CLI data
- **Development Experience**: Hot reload, health checks, and easy setup
### Ready for Use
The web application is now ready for:
- Local development with Docker or manual setup
- Testing with existing prompt data
- Deployment to cloud platforms
- Further feature development
### Files Created/Modified
```
Created:
- backend/ (complete FastAPI application)
- frontend/ (complete Astro + React application)
- data/ (data directory with all existing files)
- docker-compose.yml
- .env.example
- API_DOCUMENTATION.md
- test_backend.py
- run_webapp.sh
Updated:
- README.md (webapp documentation)
- AGENTS.md (this file, with completion status)
```
The Phase 1 implementation successfully transforms the CLI tool into a modern web application while preserving all existing functionality and data compatibility.