Python Initializer is a full-stack web application that generates customized Python project boilerplates for FastAPI, Django, and Flask frameworks. Users can configure their projects through an interactive UI and download ready-to-use project structures.
- Frontend: React 18, TypeScript, Vite, TailwindCSS, Radix UI, Wouter (routing)
- Backend: Express.js, TypeScript, Node.js
- Database: PostgreSQL with Drizzle ORM
- Authentication: Google SSO, Apple SSO (token-based sessions)
- Template Engine: EJS for Python code generation
- Build Tools: Vite (frontend), esbuild (backend)
- Code Editor: Monaco Editor for file preview
python-initializer/
├── client/ # React frontend application
│ ├── src/
│ │ ├── components/ # Reusable UI components
│ │ │ └── ui/ # Radix UI component wrappers
│ │ ├── hooks/ # Custom React hooks
│ │ ├── lib/ # Utility functions
│ │ ├── pages/ # Route pages (Home, Documentation)
│ │ ├── providers/ # React context providers
│ │ ├── App.tsx # Main app component
│ │ ├── main.tsx # React entry point
│ │ └── index.css # Global styles with Tailwind
│ └── index.html # HTML entry point
│
├── server/ # Express backend
│ ├── generators/ # Framework-specific generators
│ │ ├── fastapi.ts # FastAPI project generator
│ │ ├── django.ts # Django project generator
│ │ └── flask.ts # Flask project generator
│ ├── templates/ # EJS templates for code generation
│ │ ├── common/ # Shared templates (README, .gitignore, etc.)
│ │ ├── django/ # Django-specific templates
│ │ ├── fastapi/ # FastAPI-specific templates
│ │ └── flask/ # Flask-specific templates
│ ├── utils/ # Server utilities
│ │ ├── templateRenderer.ts # EJS template rendering logic
│ │ └── zipGenerator.ts # Project zip archive creation
│ ├── index.ts # Server entry point
│ ├── routes.ts # API route handlers
│ ├── storage.ts # Database access layer
│ └── vite.ts # Vite dev server integration
│
├── shared/ # Shared code between client/server
│ └── schema.ts # Zod schemas, Drizzle tables, types
│
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── vite.config.ts # Vite configuration
├── drizzle.config.ts # Drizzle ORM configuration
├── tailwind.config.ts # TailwindCSS configuration
└── .gitignore
Defined in shared/schema.ts, the project configuration includes:
- projectName: String (1-100 chars)
- framework:
fastapi|django|flask - pythonVersion:
3.13.2|3.12.0|3.11.4|3.10.12|3.9.18 - database:
postgresql|mysql|sqlite|mongodb - orm:
sqlalchemy|pymongo|django|none - features: Array of features like
auth,docker,testing,migrations,cors, etc.
Each framework has a dedicated generator:
- FastAPI Generator (
server/generators/fastapi.ts) - Django Generator (
server/generators/django.ts) - Flask Generator (
server/generators/flask.ts)
Generators:
- Create directory structure based on config
- Use
TemplateRendererto render EJS templates - Generate files with proper Python code
- Return the project directory path
Templates are EJS files stored in server/templates/[framework]/:
- Variables are passed via
ProjectConfig - Conditional rendering based on selected features
- Templates generate Python files, configs, Dockerfiles, requirements.txt, etc.
Token-based authentication with SSO support:
- Providers: Google, Apple (email/password planned)
- Session Management: Bearer tokens stored in database
- Session Expiry: 30 days
- Middleware:
authenticateUser()in routes.ts
Tables defined in shared/schema.ts:
- users: User accounts with SSO provider info
- user_sessions: Authentication sessions
- generation_history: Track generated projects
- project_templates: Pre-configured project templates
POST /api/auth/google- Google SSO loginPOST /api/auth/apple- Apple SSO loginPOST /api/auth/logout- Logout (requires auth)GET /api/auth/me- Get current user (requires auth)
GET /api/templates- List project templatesGET /api/templates/:id- Get specific templatePOST /api/generate- Generate and download project zipPOST /api/preview/structure- Get file structure previewPOST /api/preview/file- Get file content previewGET /api/history- Get generation history
# Install dependencies
npm install
# Set up environment variables
# Required: DATABASE_URL
echo "DATABASE_URL=postgresql://..." > .env
# Push database schema
npm run db:push
# Start development server
npm run devThe dev server runs on port 5000 and serves both frontend and API.
# Type check
npm run check
# Build for production
npm run build
# Start production server
npm start# Push schema changes to database
npm run db:push@/*→client/src/*@shared/*→shared/*
Configured in:
tsconfig.json(TypeScript)vite.config.ts(Vite bundler)
- Shared Code: Type definitions and schemas in
shared/ - Server Logic: Business logic in
server/routes.ts, data access inserver/storage.ts - Client Logic: React components in
client/src/, pages use Wouter routing - Validation: Zod schemas for runtime validation (from
@shared/schema)
- Zod validation errors return 400 with error details
- Authentication errors return 401
- Server errors return 500 with error message
- Errors logged to console with context
Request logging middleware in server/index.ts:
- Logs API requests with method, path, status, duration
- Includes response JSON for debugging
- Truncates long log lines to 80 characters
- Create generator file:
server/generators/[framework].ts - Add templates:
server/templates/[framework]/ - Update
projectConfigSchemainshared/schema.ts - Add route handler case in
server/routes.ts - Update frontend UI to support the framework
- Add feature to
featureEnuminshared/schema.ts - Update generator to handle feature flag
- Create/update templates with conditional logic
- Update directory structure if needed
Templates receive the ProjectConfig object with all configuration:
# Example template usage
project_name = "<%= projectName %>"
python_version = "<%= pythonVersion %>"
<% if (features.includes('docker')) { %>
# Docker configuration
<% } %>- Add route handler in
server/routes.ts - Use Zod for input validation
- Call storage methods from
server/storage.ts - Return appropriate HTTP status codes
- Handle errors with try-catch
- Update table definitions in
shared/schema.ts - Update insert schemas if needed
- Run
npm run db:pushto apply changes - Update storage methods in
server/storage.ts
- Create component in
client/src/components/ - Use Radix UI primitives from
client/src/components/ui/ - Style with TailwindCSS classes
- Import and use in pages
- Check template files in
server/templates/[framework]/ - Verify generator logic in
server/generators/[framework].ts - Test with
/api/preview/structureand/api/preview/file - Generate and inspect zip file locally
# Start dev server
npm run dev
# Test project generation
curl -X POST http://localhost:5000/api/generate \
-H "Content-Type: application/json" \
-d '{
"projectName": "test_project",
"framework": "fastapi",
"pythonVersion": "3.12.0",
"database": "postgresql",
"orm": "sqlalchemy",
"features": ["auth", "docker", "testing"]
}'Use preview endpoints to verify generated code without creating zip:
# Get file structure
curl -X POST http://localhost:5000/api/preview/structure \
-H "Content-Type: application/json" \
-d '{ ... config ... }'
# Get file content
curl -X POST http://localhost:5000/api/preview/file \
-H "Content-Type: application/json" \
-d '{
"config": { ... },
"filePath": "app/main.py"
}'- Passwords are stored as nullable (SSO users don't have passwords)
- Sessions expire after 30 days
- Bearer tokens are 64-byte random hex strings
- Always validate input with Zod schemas
- Sanitize file paths to prevent directory traversal
- Temporary files cleaned up after download/preview
- Template rendering is synchronous (may block for large projects)
- Zip creation happens in temp directories
- Frontend code-splitting with Vite
- Production: Server runs on port 5000 only (not firewalled)
- Development: Vite dev server integrated with Express
- Required ENV:
DATABASE_URL(PostgreSQL connection string)
- Database Connection: Ensure
DATABASE_URLis set correctly - Template Not Found: Check template path and file existence
- Empty Zip: Verify generator creates files before zip
- Type Errors: Run
npm run checkto verify TypeScript - Port Already in Use: Port 5000 is hardcoded, ensure it's available
- Use
console.login generators to debug file creation - Check temp directory contents if files aren't generated
- Verify EJS template syntax with online validators
- Test templates with minimal config first
- Use preview endpoints before implementing download
- main: Production-ready code (currently empty)
- feat/v1: Main development branch with full application
- claude/*: AI assistant working branches
- Always check current branch context
- For new features, branch from
feat/v1 - Test changes with
npm run dev - Run
npm run checkbefore committing - Use descriptive commit messages
- Drizzle ORM: Type-safe SQL query builder
- Zod: Runtime type validation
- EJS: Embedded JavaScript templates
- Wouter: Lightweight React router
- Radix UI: Unstyled, accessible components
- TailwindCSS: Utility-first CSS framework
- Monaco Editor: VS Code editor component
- drizzle.config.ts: Database migration settings
- vite.config.ts: Frontend build configuration
- tsconfig.json: TypeScript compiler options
- tailwind.config.ts: TailwindCSS theme and plugins
- postcss.config.js: PostCSS with autoprefixer
When working on this codebase:
- Understand the flow: Config → Generator → Templates → Zip → Download
- Validate inputs: Use Zod schemas from
@shared/schema - Test incrementally: Use preview endpoints before full generation
- Follow patterns: Match existing code style and structure
- Update related files: Changes often require updates to schema, routes, storage, and generators
- Consider features: Always check feature flags in config
- Clean up resources: Temporary files and directories must be removed
- Log appropriately: Use console.log for debugging, structured logging for API requests
This codebase is well-structured with clear separation of concerns. The generator pattern makes it easy to add new frameworks, and the template system provides flexibility for customization.