# Development Guide
## Entwicklungsumgebung einrichten
### Voraussetzungen
- Go 1.21 oder höher
- Node.js 18+ und npm
- Git
- Docker (optional, für Container-Entwicklung)
### Erste Schritte
```bash
# Repository klonen oder kopieren
cd AdminTemplate
# Backend initialisieren
cd backend
go mod download
cp .env.example .env
# Frontend initialisieren
cd ../frontend
npm install
# Beide starten (mit Makefile)
cd ..
make dev
```
## Projektstruktur verstehen
### Backend (Go)
```
backend/
├── cmd/server/ # Hauptanwendung (main.go)
├── internal/
│ ├── auth/ # JWT & Passwort-Hashing
│ ├── database/ # DB-Verbindung & Migration
│ ├── handlers/ # HTTP Request Handler
│ ├── middleware/ # Auth Middleware
│ └── models/ # Datenmodelle
└── pkg/config/ # Konfiguration
```
### Frontend (Vue 3)
```
frontend/
├── src/
│ ├── components/ # Wiederverwendbare Komponenten
│ ├── views/ # Seiten-Komponenten
│ ├── router/ # Vue Router Konfiguration
│ ├── stores/ # Pinia State Management
│ ├── services/ # API Service Layer
│ └── styles/ # CSS Styles
```
## Entwicklungsworkflow
### Neue Features entwickeln
#### 1. Backend API Endpoint hinzufügen
**Schritt 1: Model definieren**
```go
// backend/internal/models/product.go
package models
type Product struct {
ID int64 `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Description string `json:"description" db:"description"`
Price float64 `json:"price" db:"price"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
```
**Schritt 2: Handler erstellen**
```go
// backend/internal/handlers/product_handler.go
package handlers
import (
"github.com/gin-gonic/gin"
"admintemplate/internal/database"
"admintemplate/internal/models"
)
type ProductHandler struct {
db *database.DB
}
func NewProductHandler(db *database.DB) *ProductHandler {
return &ProductHandler{db: db}
}
func (h *ProductHandler) List(c *gin.Context) {
// Implementation
}
func (h *ProductHandler) Create(c *gin.Context) {
// Implementation
}
```
**Schritt 3: Routen registrieren**
```go
// backend/cmd/server/main.go
productHandler := handlers.NewProductHandler(db)
api.GET("/products", productHandler.List)
api.POST("/products", productHandler.Create)
```
**Schritt 4: Datenbank-Migration**
```go
// backend/internal/database/database.go
func (db *DB) Migrate() error {
// Bestehende Migrationen...
createProductsTable := `
CREATE TABLE IF NOT EXISTS products (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
description TEXT,
price REAL NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);`
if _, err := db.Exec(createProductsTable); err != nil {
return err
}
return nil
}
```
#### 2. Frontend Features hinzufügen
**Schritt 1: Service erstellen**
```javascript
// frontend/src/services/products.js
import api from './api'
export const productService = {
async getAll() {
const response = await api.get('/products')
return response.data
},
async create(product) {
const response = await api.post('/products', product)
return response.data
}
}
```
**Schritt 2: Store erstellen (optional)**
```javascript
// frontend/src/stores/products.js
import { defineStore } from 'pinia'
import { productService } from '../services/products'
export const useProductStore = defineStore('products', {
state: () => ({
products: []
}),
actions: {
async fetchProducts() {
this.products = await productService.getAll()
}
}
})
```
**Schritt 3: View/Komponente erstellen**
```vue
Produkte