init
This commit is contained in:
367
README.md
Normal file
367
README.md
Normal file
@@ -0,0 +1,367 @@
|
||||
# Immorechner
|
||||
|
||||
Eine moderne Webanwendung zur Immobilienberechnung, entwickelt mit Symfony 7.3, PHP 8.4 und MariaDB.
|
||||
|
||||
## Features
|
||||
|
||||
- **REST-API**: Vollständige REST-API mit automatischer Dokumentation über API Platform
|
||||
- **Web-Interface**: Benutzerfreundliche Weboberfläche mit Twig-Templates
|
||||
- **User Management**: Benutzerverwaltung mit Rollenbasierter Zugriffskontrolle (USER, ADMIN, MODERATOR)
|
||||
- **Docker-Setup**: Vollständig containerisierte Entwicklungsumgebung
|
||||
- **Datenbank-Migrationen**: Versionskontrollierte Datenbankschema-Verwaltung mit Doctrine
|
||||
- **CORS-Unterstützung**: Konfigurierbare CORS-Einstellungen für API-Zugriffe
|
||||
- **phpMyAdmin**: Integriertes Datenbank-Verwaltungstool
|
||||
|
||||
## Technologie-Stack
|
||||
|
||||
- **Backend**: PHP 8.4
|
||||
- **Framework**: Symfony 7.3
|
||||
- **Datenbank**: MariaDB (Latest)
|
||||
- **ORM**: Doctrine 3.0
|
||||
- **API**: API Platform 4.2
|
||||
- **Template Engine**: Twig 3.22
|
||||
- **Webserver**: Apache 2.4 mit mod_rewrite
|
||||
- **Container**: Docker & Docker Compose
|
||||
- **Datenbank-Tool**: phpMyAdmin
|
||||
|
||||
## Voraussetzungen
|
||||
|
||||
- Docker Desktop (Windows/Mac) oder Docker Engine + Docker Compose (Linux)
|
||||
- Git
|
||||
|
||||
## Installation
|
||||
|
||||
### 1. Repository klonen
|
||||
|
||||
```bash
|
||||
git clone <repository-url>
|
||||
cd immorechner
|
||||
```
|
||||
|
||||
### 2. Docker-Container starten
|
||||
|
||||
```bash
|
||||
docker-compose up -d --build
|
||||
```
|
||||
|
||||
Dieser Befehl:
|
||||
- Baut das PHP 8.4 Image mit allen benötigten Extensions
|
||||
- Startet MariaDB
|
||||
- Startet phpMyAdmin
|
||||
- Startet den Apache-Webserver
|
||||
|
||||
### 3. Dependencies installieren
|
||||
|
||||
```bash
|
||||
docker-compose exec web composer install
|
||||
```
|
||||
|
||||
### 4. Datenbank-Schema erstellen
|
||||
|
||||
```bash
|
||||
docker-compose exec web php bin/console doctrine:migrations:migrate --no-interaction
|
||||
```
|
||||
|
||||
### 5. Cache leeren
|
||||
|
||||
```bash
|
||||
docker-compose exec web php bin/console cache:clear
|
||||
```
|
||||
|
||||
## Verwendung
|
||||
|
||||
### Anwendung aufrufen
|
||||
|
||||
- **Web-Interface**: http://localhost:8080
|
||||
- **API-Dokumentation**: http://localhost:8080/api
|
||||
- **phpMyAdmin**: http://localhost:8081
|
||||
- Server: `db`
|
||||
- Benutzer: `root`
|
||||
- Passwort: `root`
|
||||
|
||||
### REST-API Endpoints
|
||||
|
||||
#### User-API
|
||||
|
||||
| Methode | Endpoint | Beschreibung |
|
||||
|---------|----------|--------------|
|
||||
| GET | `/api/users` | Alle User abrufen |
|
||||
| GET | `/api/users/{id}` | Einzelnen User abrufen |
|
||||
| POST | `/api/users` | Neuen User erstellen |
|
||||
| PUT | `/api/users/{id}` | User aktualisieren |
|
||||
| DELETE | `/api/users/{id}` | User löschen |
|
||||
|
||||
#### Beispiel: User erstellen
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/api/users \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "Max Mustermann",
|
||||
"email": "max@example.com",
|
||||
"role": "user"
|
||||
}'
|
||||
```
|
||||
|
||||
#### Beispiel: Alle User abrufen
|
||||
|
||||
```bash
|
||||
curl http://localhost:8080/api/users
|
||||
```
|
||||
|
||||
## Datenbank-Schema
|
||||
|
||||
### User-Tabelle
|
||||
|
||||
| Feld | Typ | Beschreibung |
|
||||
|------|-----|--------------|
|
||||
| id | INT | Primärschlüssel (Auto-Increment) |
|
||||
| name | VARCHAR(255) | Benutzername |
|
||||
| email | VARCHAR(255) | E-Mail-Adresse (Unique) |
|
||||
| role | ENUM | Benutzerrolle (user, admin, moderator) |
|
||||
| created_at | DATETIME | Erstellungsdatum |
|
||||
|
||||
## Entwicklung
|
||||
|
||||
### Neue Entity erstellen
|
||||
|
||||
```bash
|
||||
docker-compose exec web php bin/console make:entity
|
||||
```
|
||||
|
||||
### Migration erstellen
|
||||
|
||||
```bash
|
||||
docker-compose exec web php bin/console doctrine:migrations:diff
|
||||
```
|
||||
|
||||
### Migration ausführen
|
||||
|
||||
```bash
|
||||
docker-compose exec web php bin/console doctrine:migrations:migrate
|
||||
```
|
||||
|
||||
### Controller erstellen
|
||||
|
||||
```bash
|
||||
docker-compose exec web php bin/console make:controller
|
||||
```
|
||||
|
||||
### Cache leeren
|
||||
|
||||
```bash
|
||||
docker-compose exec web php bin/console cache:clear
|
||||
```
|
||||
|
||||
### Symfony Console aufrufen
|
||||
|
||||
```bash
|
||||
docker-compose exec web php bin/console
|
||||
```
|
||||
|
||||
## Docker-Befehle
|
||||
|
||||
### Container starten
|
||||
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
### Container stoppen
|
||||
|
||||
```bash
|
||||
docker-compose down
|
||||
```
|
||||
|
||||
### Container neu bauen
|
||||
|
||||
```bash
|
||||
docker-compose up -d --build
|
||||
```
|
||||
|
||||
### Container-Logs anzeigen
|
||||
|
||||
```bash
|
||||
# Alle Container
|
||||
docker-compose logs -f
|
||||
|
||||
# Nur Web-Container
|
||||
docker-compose logs -f web
|
||||
|
||||
# Nur Datenbank-Container
|
||||
docker-compose logs -f db
|
||||
```
|
||||
|
||||
### In Container einloggen
|
||||
|
||||
```bash
|
||||
# Web-Container (PHP/Apache)
|
||||
docker-compose exec web bash
|
||||
|
||||
# Datenbank-Container
|
||||
docker-compose exec db bash
|
||||
```
|
||||
|
||||
### Composer-Befehle ausführen
|
||||
|
||||
```bash
|
||||
docker-compose exec web composer require <paket-name>
|
||||
docker-compose exec web composer update
|
||||
docker-compose exec web composer dump-autoload
|
||||
```
|
||||
|
||||
## Projekt-Struktur
|
||||
|
||||
```
|
||||
immorechner/
|
||||
├── bin/ # Symfony Console und andere Binaries
|
||||
├── config/ # Symfony Konfigurationsdateien
|
||||
├── docker/ # Docker-Konfigurationsdateien
|
||||
│ └── apache/ # Apache VirtualHost Konfiguration
|
||||
├── migrations/ # Doctrine Datenbank-Migrationen
|
||||
├── public/ # Web-Root (index.php, Assets)
|
||||
├── src/ # PHP-Quellcode
|
||||
│ ├── Controller/ # Controller
|
||||
│ ├── Entity/ # Doctrine Entities
|
||||
│ ├── Enum/ # PHP Enums
|
||||
│ ├── Repository/ # Doctrine Repositories
|
||||
│ └── Kernel.php # Symfony Kernel
|
||||
├── templates/ # Twig-Templates
|
||||
│ ├── base.html.twig # Basis-Template
|
||||
│ └── home/ # Homepage-Templates
|
||||
├── var/ # Cache, Logs
|
||||
├── vendor/ # Composer Dependencies
|
||||
├── .env # Umgebungsvariablen
|
||||
├── .env.example # Beispiel-Umgebungsvariablen
|
||||
├── .gitignore # Git Ignore-Datei
|
||||
├── composer.json # Composer-Konfiguration
|
||||
├── docker-compose.yml # Docker Compose-Konfiguration
|
||||
├── Dockerfile # Docker-Image für PHP/Apache
|
||||
└── README.md # Diese Datei
|
||||
```
|
||||
|
||||
## Umgebungsvariablen
|
||||
|
||||
Die Anwendung verwendet folgende Umgebungsvariablen (definiert in `.env`):
|
||||
|
||||
```env
|
||||
# Symfony
|
||||
APP_ENV=dev
|
||||
APP_SECRET=<generierter-secret-key>
|
||||
|
||||
# Datenbank
|
||||
DATABASE_URL="mysql://immorechner_user:immorechner_pass@db:3306/immorechner?serverVersion=mariadb-11.7.1&charset=utf8mb4"
|
||||
|
||||
# CORS
|
||||
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
|
||||
|
||||
# Routing
|
||||
DEFAULT_URI=http://localhost
|
||||
```
|
||||
|
||||
## Konfiguration
|
||||
|
||||
### CORS anpassen
|
||||
|
||||
CORS-Einstellungen können in `config/packages/nelmio_cors.yaml` angepasst werden.
|
||||
|
||||
### Datenbank-Verbindung ändern
|
||||
|
||||
Datenbank-Verbindung in `.env` anpassen:
|
||||
|
||||
```env
|
||||
DATABASE_URL="mysql://user:password@host:port/database?serverVersion=mariadb-11.7.1"
|
||||
```
|
||||
|
||||
### Apache-Konfiguration
|
||||
|
||||
Apache-VirtualHost-Konfiguration befindet sich in `docker/apache/000-default.conf`.
|
||||
|
||||
## Fehlerbehebung
|
||||
|
||||
### Container starten nicht
|
||||
|
||||
```bash
|
||||
# Container-Logs prüfen
|
||||
docker-compose logs
|
||||
|
||||
# Container-Status prüfen
|
||||
docker ps -a
|
||||
|
||||
# Container neu bauen
|
||||
docker-compose down
|
||||
docker-compose up -d --build
|
||||
```
|
||||
|
||||
### "Class not found" Fehler
|
||||
|
||||
```bash
|
||||
# Autoloader neu generieren
|
||||
docker-compose exec web composer dump-autoload
|
||||
|
||||
# Cache leeren
|
||||
docker-compose exec web php bin/console cache:clear
|
||||
|
||||
# Container neu starten
|
||||
docker-compose restart web
|
||||
```
|
||||
|
||||
### Datenbank-Verbindungsfehler
|
||||
|
||||
```bash
|
||||
# Prüfen ob DB-Container läuft
|
||||
docker ps | grep db
|
||||
|
||||
# DB-Logs prüfen
|
||||
docker-compose logs db
|
||||
|
||||
# In DB-Container einloggen und testen
|
||||
docker-compose exec db mysql -u root -proot
|
||||
```
|
||||
|
||||
### Port bereits belegt
|
||||
|
||||
Wenn Port 8080, 8081 oder 3306 bereits belegt ist, können die Ports in `docker-compose.yml` angepasst werden:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
web:
|
||||
ports:
|
||||
- "8090:80" # Statt 8080:80
|
||||
```
|
||||
|
||||
## API-Dokumentation
|
||||
|
||||
Die vollständige API-Dokumentation ist verfügbar unter:
|
||||
- **Swagger UI**: http://localhost:8080/api
|
||||
|
||||
Die API unterstützt mehrere Formate:
|
||||
- JSON-LD (Standard)
|
||||
- JSON
|
||||
- HTML
|
||||
|
||||
Beispiel für JSON-Format:
|
||||
|
||||
```bash
|
||||
curl -H "Accept: application/json" http://localhost:8080/api/users
|
||||
```
|
||||
|
||||
## Sicherheitshinweise
|
||||
|
||||
**Wichtig für Produktion:**
|
||||
|
||||
1. Ändern Sie alle Standardpasswörter in `docker-compose.yml` und `.env`
|
||||
2. Generieren Sie einen neuen `APP_SECRET` für `.env`
|
||||
3. Setzen Sie `APP_ENV=prod` in der Produktion
|
||||
4. Konfigurieren Sie CORS entsprechend Ihrer Domain
|
||||
5. Aktivieren Sie HTTPS
|
||||
6. Verwenden Sie sichere Datenbank-Credentials
|
||||
7. Entfernen Sie phpMyAdmin aus der Produktion
|
||||
|
||||
## Lizenz
|
||||
|
||||
[Lizenz hier einfügen]
|
||||
|
||||
## Kontakt
|
||||
|
||||
[Kontaktinformationen hier einfügen]
|
||||
Reference in New Issue
Block a user