Synapse
Synapse: AI-powered FastAPI app for dev automation. Processes requirements, generates code (Gemini), & integrates with GitHub/MongoDB.
Created on 6th May 2025
•
Synapse
Synapse: AI-powered FastAPI app for dev automation. Processes requirements, generates code (Gemini), & integrates with GitHub/MongoDB.
The problem Synapse solves
How it Works & Helps
AI Task Planning
Synapse's TaskPlannerAgent outlines development tasks and suggests a tech stack. This brings clarity to your vision.
Automated Code Generation
The DevBot uses these tasks to create a project skeleton with initial code (e.g., for Python/FastAPI apps), saving significant setup time.
GitHub Integration
Automatically creates a GitHub repo, pushes the generated code, and adds tasks as issues. Your project is instantly ready for version control and collaboration.
MongoDB Backend
Stores project details for tracking.
Benefits – Making Development:
Easier
- Simplifies complex project initiation.
- Translates requirements into actionable steps.
- Lets you focus on core logic, not boilerplate.
Faster
- Launches projects in minutes.
- Automates repetitive setup tasks.
More Efficient & Potentially Safer
- Promotes consistent project structures.
- Reduces manual configuration errors.
- Streamlines the workflow from concept to a managed codebase.
Ideal For:
- Rapidly building MVPs.
- Automating routine project setup.
- Learning tool for new project structures.
- Boosting productivity for solo devs and small teams.
Challenges we ran into
Handling ZIP File Cleanup in Synapse
One of the trickiest issues we faced while building Synapse was cleaning up temporary ZIP files generated by the DevBot after they were downloaded by users.
The Challenge
Initially, we tried to delete the ZIP file right after triggering FileResponse in our FastAPI endpoint. But due to FastAPI’s asynchronous nature and how file streaming works, this led to several problems:
- Race Conditions: The file could get deleted before the download finished, leading to broken or incomplete downloads.
- Permission Errors: Sometimes the OS still had the file in use, so trying to delete it caused a
PermissionError. - Silent Failures: If anything went wrong while sending the file, the cleanup step might be skipped—leaving orphaned files behind and wasting disk space.
The Solution
We solved this by using FastAPI’s background task mechanism, which runs cleanup logic after the response is fully sent to the client.
Here’s how we implemented it:
# In app.py
# A safe file cleanup function with error handling
def cleanup_zip_file(zip_path: str):
try:
if os.path.exists(zip_path):
os.remove(zip_path)
print(f"Successfully cleaned up: {zip_path}")
except OSError as e:
print(f"Error cleaning up {zip_path}: {e}")
# Create the response and attach the cleanup as a background task
response = FileResponse(path=zip_path, media_type='application/zip', filename=fn)
response.background = lambda: cleanup_zip_file(zip_path) # or use functools.partial
