Skip to content

avantifellows/cv-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CV Generator v2.0 - Clean Architecture

Overview

This is the refactored version of the CV Generator with clean architecture, Pydantic models, and proper service layer separation. It is a FastAPI application ready for deployment.

Architecture

Project Structure

cv-generator/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── cv_data.py          # Pydantic models for data validation
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── cv_service.py       # Business logic layer
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ exceptions.py       # Custom exceptions
β”‚   β”‚   └── logging.py          # Logging configuration
β”‚   └── utils/
β”œβ”€β”€ templates/                   # Jinja2 templates
β”œβ”€β”€ static/                      # Static assets
β”œβ”€β”€ generated/                   # Generated CV files
β”œβ”€β”€ main.py                      # FastAPI application
└── requirements.txt

Key Improvements

1. Pydantic Models πŸ”₯

  • Before: Manual field validation with 50+ individual parameters
  • After: Structured data models with automatic validation
class CVData(BaseModel):
    personal_info: PersonalInfo
    education: List[EducationEntry]
    internships: List[InternshipEntry]
    # ... etc

2. Service Layer πŸ”₯

  • Before: Business logic mixed with API endpoints
  • After: Clean separation with dedicated service classes
class CVService:
    def generate_cv(self, cv_data: CVData) -> str:
        # Clean business logic
    
    def get_cv_data(self, cv_id: str) -> CVDocument:
        # Data retrieval logic

3. Proper Error Handling πŸ”₯

  • Before: Generic HTTP exceptions
  • After: Custom exceptions with proper logging
@app.exception_handler(CVNotFoundError)
async def cv_not_found_handler(request: Request, exc: CVNotFoundError):
    logger.warning(f"CV not found: {str(exc)}")
    return HTTPException(status_code=404, detail=str(exc))

4. Structured Logging πŸ”₯

  • Before: Print statements
  • After: Proper structured logging with levels
logger.info(f"CV generated successfully: {cv_id}")
logger.error(f"Error generating PDF: {str(e)}")

5. API Versioning πŸ”₯

  • Before: No API structure
  • After: Versioned API endpoints
@app.get("/api/v1/cvs")
@app.get("/api/v1/cv/{cv_id}")
@app.delete("/api/v1/cv/{cv_id}")

Usage

Running the Application

# Install dependencies
pip install -r requirements.txt

# Run the application
uvicorn main:app --host 0.0.0.0 --port 8000 --reload

API Endpoints

Web Interface

  • GET / - CV form
  • GET /test - Pre-filled test form
  • POST /generate - Generate CV from form data
  • GET /cv/{cv_id} - View CV with download button
  • GET /cv/{cv_id}/pdf - Download PDF

API Endpoints

  • GET /api/v1/cvs - List all CVs
  • GET /api/v1/cv/{cv_id} - Get CV data
  • DELETE /api/v1/cv/{cv_id} - Delete CV
  • GET /health - Health check

Testing

# Test the models and services
python -c "
from app.models.cv_data import CVData
from app.services.cv_service import CVService
import json

# Load test data
with open('test_data_structured.json', 'r') as f:
    data = json.load(f)

# Validate data
cv_data = CVData(**data)
print(f'βœ“ Validation passed: {cv_data.personal_info.full_name}')

# Test service
service = CVService()
cv_id = service.generate_cv(cv_data)
print(f'βœ“ CV generated: {cv_id}')
"

Data Structure

The new version uses proper data structures instead of flat field names:

{
  "personal_info": {
    "full_name": "Jane Smith",
    "email": "[email protected]"
  },
  "education": [
    {
      "qualification": "M.Tech",
      "institute": "Stanford University",
      "year": "2023"
    }
  ],
  "internships": [
    {
      "company": "Google",
      "role": "Software Engineer",
      "points": ["Achievement 1", "Achievement 2"]
    }
  ]
}

The system still supports a legacy flat format for backward compatibility during form submission.

Features

Data Validation

  • Email validation with regex patterns
  • Required field validation with meaningful error messages
  • Data type validation (strings, lists, etc.)
  • Length constraints (min/max characters)
  • Array size limits (max entries per section)

Error Handling

  • Custom exceptions for different error types
  • Structured logging with different levels
  • Graceful error recovery with fallback options
  • Detailed error messages for debugging

Performance

  • Efficient data processing with Pydantic models
  • Proper file handling with context managers
  • Memory-efficient PDF generation
  • Caching-ready template rendering

Security

  • Input validation prevents injection attacks
  • Proper error messages don't expose internals
  • File path validation prevents directory traversal
  • Content-type validation for uploads

Development

Adding New Fields

  1. Update the models in app/models/cv_data.py:

    class PersonalInfo(BaseModel):
        full_name: str
        new_field: str = Field(..., min_length=1)
  2. Update the service in app/services/cv_service.py:

    def convert_legacy_data(self, legacy_data: dict) -> CVData:
        # Add conversion logic for new field
  3. Update templates to display the new field

Adding New Endpoints

  1. Add to main.py:

    @app.get("/api/v1/new-endpoint")
    async def new_endpoint():
        return {"message": "New endpoint"}
  2. Add proper error handling:

    try:
        result = service.new_operation()
        return result
    except CustomException as e:
        logger.error(f"Error in new endpoint: {str(e)}")
        raise HTTPException(status_code=500, detail=str(e))

Testing

Unit Tests

# Test models
python -m pytest tests/test_models.py

# Test services
python -m pytest tests/test_services.py

# Test API endpoints
python -m pytest tests/test_api.py

Integration Tests

# Test full workflow
python -m pytest tests/test_integration.py

Deployment

For detailed deployment instructions, please see DEPLOYMENT_GUIDE.md.

Monitoring

Health Check

curl http://localhost:8000/health

Logs

# View logs
tail -f app.log

# Filter by level
grep "ERROR" app.log

Contributing

  1. Follow the new architecture patterns
  2. Add proper validation for new fields
  3. Include error handling for new endpoints
  4. Add logging for debugging
  5. Update tests for new functionality
  6. Update documentation for API changes

Changelog

v2.0.0

  • βœ… Pydantic models for data validation
  • βœ… Service layer architecture
  • βœ… Proper error handling and logging
  • βœ… API versioning
  • βœ… Structured test data
  • βœ… Health check endpoint
  • βœ… Backward compatibility with legacy format

v1.0.0

  • βœ… Basic CV generation
  • βœ… HTML and PDF output
  • βœ… Form-based interface
  • βœ… Template rendering

About

Generate Resumes automatically

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •