/scp-g

A modern full-stack web application with an integrated code generation system. Generate complete Go Fiber API projects with CRUD operations based on your database models.

Primary LanguageAstroMIT LicenseMIT

SCP-G (Code Generator)

A modern full-stack web application with an integrated code generation system. Generate complete Go Fiber API projects with CRUD operations based on your database models.

๐Ÿš€ Features

  • Full-Stack Architecture: Astro frontend + Python Flask backend + Go API generation
  • Code Generation: Generate complete Go Fiber projects with REST APIs
  • Database Management: SQLite-based model and field management
  • Modern UI: Clean Astro-based interface with Tailwind CSS
  • API-First: RESTful APIs with comprehensive CRUD operations
  • Development Ready: Hot reload, testing, and production deployment support

๐Ÿ—๏ธ Architecture

scp-g/
โ”œโ”€โ”€ apps/                    # Frontend (Astro + Tailwind CSS)
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/      # Reusable UI components
โ”‚   โ”‚   โ”œโ”€โ”€ layouts/         # Page layouts
โ”‚   โ”‚   โ”œโ”€โ”€ pages/           # Route pages
โ”‚   โ”‚   โ””โ”€โ”€ styles/          # Global styles
โ”‚   โ””โ”€โ”€ public/              # Static assets
โ”œโ”€โ”€ api/                     # Backend API (Python Flask)
โ”‚   โ”œโ”€โ”€ app.py              # Main Flask application
โ”‚   โ”œโ”€โ”€ routes.py           # API endpoints
โ”‚   โ”œโ”€โ”€ generate_go.py      # Go code generation
โ”‚   โ”œโ”€โ”€ requirements.txt    # Python dependencies
โ”‚   โ””โ”€โ”€ test_api.py         # API tests
โ””โ”€โ”€ go/                     # Generated Go projects (example)
    โ”œโ”€โ”€ main.go            # Fiber application
    โ”œโ”€โ”€ models/            # Data models
    โ””โ”€โ”€ handlers/          # CRUD handlers

๐Ÿ› ๏ธ Tech Stack

Frontend

  • Framework: Astro v5.14.6
  • Styling: Tailwind CSS v4.1.14
  • Build Tool: Vite (integrated with Astro)

Backend

  • API Framework: Flask 3.0.3
  • Database: SQLite3
  • Code Generation: Python-based Go project generator

Generated Go Projects

  • Framework: Fiber v2.52.5
  • Language: Go 1.21+
  • Features: REST API, CRUD operations, in-memory storage

๐Ÿ“‹ Prerequisites

  • Node.js 18+ (for Astro frontend)
  • Python 3.8+ (for Flask backend)
  • Go 1.21+ (for generated projects)

๐Ÿš€ Quick Start

1. Clone the Repository

git clone https://github.com/gusdeyw/scp-g.git
cd scp-g

2. Setup Backend (Python Flask)

cd api
python -m venv venv
venv\Scripts\activate  # Windows
# or
source venv/bin/activate  # macOS/Linux

pip install -r requirements.txt
python app.py

Backend runs on: http://localhost:5000

3. Setup Frontend (Astro)

cd apps
npm install
npm run dev

Frontend runs on: http://localhost:4321

๐ŸŽฏ API Endpoints

Configuration Management

GET    /api/config           # Get all configs
GET    /api/config/{key}     # Get config by key
PUT    /api/config/{key}     # Update config value

Model Management

GET    /api/model            # Get all models
POST   /api/model            # Create new model
GET    /api/model/{code}     # Get model by code
PUT    /api/model/{code}     # Update model
DELETE /api/model/{code}     # Delete model

Model Details (Fields)

GET    /api/model_detail              # Get all model details
POST   /api/model_detail              # Create model detail
GET    /api/model_detail/{code}       # Get detail by code
PUT    /api/model_detail/{code}       # Update detail
DELETE /api/model_detail/{code}       # Delete detail

Code Generation

GET    /api/generate_go      # Generate and download Go project ZIP

๐Ÿ”ง Configuration

Set the language for code generation:

curl -X PUT http://localhost:5000/api/config/LANG \
  -H "Content-Type: application/json" \
  -d '{"value_conf": "Go"}'

๐Ÿ“ Creating Models

1. Create a Model

curl -X POST http://localhost:5000/api/model \
  -H "Content-Type: application/json" \
  -d '{
    "table_code": "users",
    "table_name": "Users"
  }'

2. Add Model Fields

curl -X POST http://localhost:5000/api/model_detail \
  -H "Content-Type: application/json" \
  -d '{
    "model_code": "users",
    "model_detail_code": "id",
    "model_detail_name": "ID",
    "model_detail_type": "id"
  }'

curl -X POST http://localhost:5000/api/model_detail \
  -H "Content-Type: application/json" \
  -d '{
    "model_code": "users",
    "model_detail_code": "name",
    "model_detail_name": "Name",
    "model_detail_type": "varchar"
  }'

3. Generate Go Project

curl -O -J http://localhost:5000/api/generate_go

๐Ÿƒโ€โ™‚๏ธ Development

Backend Development

cd api
python app.py              # Start Flask server
pytest                    # Run tests
black .                   # Format code
flake8 .                  # Lint code

Frontend Development

cd apps
npm run dev              # Start dev server
npm run build            # Build for production
npm run preview          # Preview production build

Generated Go Projects

cd generated_project
go mod tidy              # Install dependencies
go run main.go           # Start the generated API

๐Ÿงช Testing

API Testing

cd api
pytest test_api.py

Manual Testing

Import api/postman_collection.json into Postman for comprehensive API testing.

๐Ÿšข Deployment

Backend (Production)

cd api
gunicorn --bind 0.0.0.0:8000 app:app

Frontend (Production)

cd apps
npm run build
# Deploy the dist/ folder to your web server

๐Ÿ“ Project Structure Details

Frontend (apps/)

  • src/components/ - Reusable Astro components
  • src/layouts/ - Page layout templates
  • src/pages/ - File-based routing
  • src/styles/ - Global CSS and Tailwind config

Backend (api/)

  • app.py - Flask application factory
  • routes.py - API route definitions
  • generate_go.py - Go code generation logic
  • production.db - SQLite database

Generated Go Projects

  • main.go - Fiber application with routes
  • models/ - Go structs for data models
  • handlers/ - CRUD operation handlers
  • go.mod - Go module dependencies

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Astro - The web framework for content-driven websites
  • Flask - The Python micro framework
  • Fiber - Express-inspired web framework for Go
  • Tailwind CSS - A utility-first CSS framework

Made with โค๏ธ for developers who want to generate code faster