feat: Complete MVP setup - Docker, Frontend, Migrations, CI/CD
Deploy Development / deploy (push) Failing after 4s
Deploy Development / deploy (push) Failing after 4s
Docker & Deployment: - docker-compose.yml (Prod: Port 3003/8003) - docker-compose.dev-env.yml (Dev: Port 3098/8098) - Backend Dockerfile (Python 3.12-slim) - Frontend Dockerfile (Node 20 + Nginx) - Gitea Actions (deploy-dev.yml, deploy-prod.yml) Frontend: - React 18 + Vite setup - package.json, vite.config.js, index.html - App.jsx (minimal with version display) - api.js (complete API client) - app.css + AuthContext from Mitai - main.jsx entry point Backend Migrations: - 001_auth_membership.sql (Auth + Features + Tier Limits) - 002_organization.sql (Clubs, Divisions, Training Groups) - 003_catalogs.sql (Skills + Methods with sample data) Documentation: - .claude/rules/ (ARCHITECTURE, CODING_RULES, etc.) - SHINKAN_PROJECT_SETUP.md (technical setup guide) Server: - Directories created on Pi: /home/lars/docker/shinkan[-dev] - Gitea Runner configured and running Ready for first deployment to dev.shinkan.jinkendo.de version: 0.1.0 date: 2026-04-21
This commit is contained in:
1 parent
a426c03598
commit
b2bc8590c4
25 files changed
+4972
No files matched your search
@@ -0,0 +1,34 @@
|
||||
# Build stage
|
||||
FROM node:20-alpine AS build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
COPY package*.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm install
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build argument for API URL
|
||||
ARG VITE_API_URL
|
||||
ENV VITE_API_URL=$VITE_API_URL
|
||||
|
||||
# Build app
|
||||
RUN npm run build
|
||||
|
||||
# Production stage
|
||||
FROM nginx:alpine
|
||||
|
||||
# Copy built app
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
|
||||
# Copy nginx config (if exists)
|
||||
# COPY nginx.conf /etc/nginx/nginx.conf
|
||||
|
||||
# Expose port
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
@@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="description" content="Shinkan Jinkendo - Trainer- und Vereinsplattform für Kampfsport-Trainingsplanung" />
|
||||
<title>Shinkan Jinkendo</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "shinkan-jinkendo-frontend",
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite --port 3098",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-router-dom": "^6.22.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-react": "^4.2.1",
|
||||
"vite": "^5.1.4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom'
|
||||
import { AuthProvider } from './context/AuthContext'
|
||||
|
||||
function App() {
|
||||
const [version, setVersion] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
// Load version from API
|
||||
fetch('/api/version')
|
||||
.then(res => res.json())
|
||||
.then(data => setVersion(data))
|
||||
.catch(err => console.error('Failed to load version:', err))
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<AuthProvider>
|
||||
<Router>
|
||||
<div className="app">
|
||||
<div className="container">
|
||||
<h1>🥋 Shinkan Jinkendo</h1>
|
||||
<p>Trainer- und Vereinsplattform für Kampfsport-Trainingsplanung</p>
|
||||
|
||||
{version && (
|
||||
<div className="card" style={{ marginTop: '2rem' }}>
|
||||
<h3>System Status</h3>
|
||||
<p><strong>Version:</strong> {version.app_version}</p>
|
||||
<p><strong>Build:</strong> {version.build_date}</p>
|
||||
<p><strong>Environment:</strong> {version.environment}</p>
|
||||
<p><strong>DB Schema:</strong> {version.db_schema_version}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="card" style={{ marginTop: '2rem' }}>
|
||||
<h3>🚧 In Entwicklung</h3>
|
||||
<p>Die App wird gerade aufgebaut.</p>
|
||||
<ul style={{ textAlign: 'left', marginTop: '1rem' }}>
|
||||
<li>✅ Backend-Basis</li>
|
||||
<li>✅ Docker-Setup</li>
|
||||
<li>✅ Datenbank-Schema</li>
|
||||
<li>🔲 Auth-System</li>
|
||||
<li>🔲 Übungsverwaltung</li>
|
||||
<li>🔲 Trainingsplanung</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Router>
|
||||
</AuthProvider>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,133 @@
|
||||
import { createContext, useContext, useState, useEffect } from 'react'
|
||||
|
||||
const AuthContext = createContext(null)
|
||||
|
||||
const TOKEN_KEY = 'bodytrack_token'
|
||||
const PROFILE_KEY = 'bodytrack_active_profile'
|
||||
|
||||
export function AuthProvider({ children }) {
|
||||
const [session, setSession] = useState(null) // {token, profile_id, role}
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [needsSetup, setNeedsSetup] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
checkStatus()
|
||||
}, [])
|
||||
|
||||
const checkStatus = async () => {
|
||||
try {
|
||||
const r = await fetch('/api/auth/status')
|
||||
const status = await r.json()
|
||||
|
||||
if (status.needs_setup) {
|
||||
setNeedsSetup(true)
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
// Try existing token
|
||||
const token = localStorage.getItem(TOKEN_KEY)
|
||||
if (token) {
|
||||
const me = await fetch('/api/auth/me', {
|
||||
headers: { 'X-Auth-Token': token }
|
||||
})
|
||||
if (me.ok) {
|
||||
const profile = await me.json()
|
||||
setSession({ token, profile_id: profile.id, role: profile.role, profile })
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
// Token expired
|
||||
localStorage.removeItem(TOKEN_KEY)
|
||||
}
|
||||
} catch(e) {
|
||||
console.error('Auth check failed', e)
|
||||
}
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
const login = async (credentials) => {
|
||||
// Support both new {email, pin} and legacy {profile_id, pin}
|
||||
const body = typeof credentials === 'object' ? credentials : { profile_id: credentials }
|
||||
const r = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
if (!r.ok) {
|
||||
const err = await r.json()
|
||||
throw new Error(err.detail || 'Login fehlgeschlagen')
|
||||
}
|
||||
const data = await r.json()
|
||||
localStorage.setItem(TOKEN_KEY, data.token)
|
||||
localStorage.setItem(PROFILE_KEY, data.profile_id)
|
||||
// Fetch full profile
|
||||
const me = await fetch('/api/auth/me', { headers: { 'X-Auth-Token': data.token } })
|
||||
const profile = await me.json()
|
||||
setSession({ token: data.token, profile_id: data.profile_id, role: data.role, profile })
|
||||
return data
|
||||
}
|
||||
|
||||
const setup = async (formData) => {
|
||||
const r = await fetch('/api/auth/setup', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(formData)
|
||||
})
|
||||
if (!r.ok) {
|
||||
const err = await r.json()
|
||||
throw new Error(err.detail || 'Setup fehlgeschlagen')
|
||||
}
|
||||
const data = await r.json()
|
||||
localStorage.setItem(TOKEN_KEY, data.token)
|
||||
localStorage.setItem(PROFILE_KEY, data.profile_id)
|
||||
setNeedsSetup(false)
|
||||
await checkStatus()
|
||||
return data
|
||||
}
|
||||
|
||||
const setAuthFromToken = (token, profile) => {
|
||||
// Direct token/profile set (for email verification auto-login)
|
||||
localStorage.setItem(TOKEN_KEY, token)
|
||||
localStorage.setItem(PROFILE_KEY, profile.id)
|
||||
setSession({
|
||||
token,
|
||||
profile_id: profile.id,
|
||||
role: profile.role || 'user',
|
||||
profile
|
||||
})
|
||||
}
|
||||
|
||||
const logout = async () => {
|
||||
const token = localStorage.getItem(TOKEN_KEY)
|
||||
if (token) {
|
||||
await fetch('/api/auth/logout', { method: 'POST', headers: { 'X-Auth-Token': token } })
|
||||
}
|
||||
localStorage.removeItem(TOKEN_KEY)
|
||||
setSession(null)
|
||||
}
|
||||
|
||||
const isAdmin = session?.role === 'admin'
|
||||
const canUseAI = session?.profile?.ai_enabled !== 0
|
||||
const canExport = session?.profile?.export_enabled !== 0
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={{
|
||||
session, loading, needsSetup,
|
||||
login, setup, logout, setAuthFromToken,
|
||||
isAdmin, canUseAI, canExport,
|
||||
token: session?.token,
|
||||
profileId: session?.profile_id,
|
||||
}}>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export function useAuth() {
|
||||
return useContext(AuthContext)
|
||||
}
|
||||
|
||||
export function getToken() {
|
||||
return localStorage.getItem(TOKEN_KEY)
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { createContext, useContext, useState, useEffect } from 'react'
|
||||
import { useAuth } from './AuthContext'
|
||||
|
||||
const ProfileContext = createContext(null)
|
||||
|
||||
export function ProfileProvider({ children }) {
|
||||
const { session } = useAuth()
|
||||
const [profiles, setProfiles] = useState([])
|
||||
const [activeProfile, setActiveProfileState] = useState(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
const loadProfiles = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('bodytrack_token') || ''
|
||||
const res = await fetch('/api/profiles', {
|
||||
headers: { 'X-Auth-Token': token }
|
||||
})
|
||||
if (!res.ok) return []
|
||||
return await res.json()
|
||||
} catch(e) { return [] }
|
||||
}
|
||||
|
||||
// Re-load whenever session changes (login/logout/switch)
|
||||
useEffect(() => {
|
||||
if (!session) {
|
||||
setActiveProfileState(null)
|
||||
setProfiles([])
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
setLoading(true)
|
||||
loadProfiles().then(data => {
|
||||
setProfiles(data)
|
||||
// Always use the profile_id from the session token – not localStorage
|
||||
const match = data.find(p => p.id === session.profile_id)
|
||||
setActiveProfileState(match || data[0] || null)
|
||||
setLoading(false)
|
||||
})
|
||||
}, [session?.profile_id]) // re-runs when profile changes
|
||||
|
||||
const setActiveProfile = (profile) => {
|
||||
setActiveProfileState(profile)
|
||||
localStorage.setItem('bodytrack_active_profile', profile.id)
|
||||
}
|
||||
|
||||
const refreshProfiles = () => loadProfiles().then(data => {
|
||||
setProfiles(data)
|
||||
if (activeProfile) {
|
||||
const updated = data.find(p => p.id === activeProfile.id)
|
||||
if (updated) setActiveProfileState(updated)
|
||||
}
|
||||
})
|
||||
|
||||
return (
|
||||
<ProfileContext.Provider value={{ profiles, activeProfile, setActiveProfile, refreshProfiles, loading }}>
|
||||
{children}
|
||||
</ProfileContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export function useProfile() {
|
||||
return useContext(ProfileContext)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App.jsx'
|
||||
import './app.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
)
|
||||
@@ -0,0 +1,223 @@
|
||||
/**
|
||||
* Shinkan Jinkendo API Client
|
||||
*
|
||||
* Zentrale API-Kommunikation mit automatischer Token-Injektion
|
||||
*/
|
||||
|
||||
const API_URL = import.meta.env.VITE_API_URL || ''
|
||||
|
||||
/**
|
||||
* Generic API request with automatic token injection
|
||||
*/
|
||||
async function request(endpoint, options = {}) {
|
||||
const token = localStorage.getItem('authToken')
|
||||
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers
|
||||
}
|
||||
|
||||
if (token) {
|
||||
headers['X-Auth-Token'] = token
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_URL}${endpoint}`, {
|
||||
...options,
|
||||
headers
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json().catch(() => ({ detail: 'Unknown error' }))
|
||||
throw new Error(error.detail || `HTTP ${response.status}`)
|
||||
}
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Auth
|
||||
// ============================================================================
|
||||
|
||||
export async function login(email, password) {
|
||||
return request('/api/auth/login', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ email, password })
|
||||
})
|
||||
}
|
||||
|
||||
export async function register(email, password, name) {
|
||||
return request('/api/auth/register', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ email, password, name })
|
||||
})
|
||||
}
|
||||
|
||||
export async function logout() {
|
||||
return request('/api/auth/logout', { method: 'POST' })
|
||||
}
|
||||
|
||||
export async function getCurrentProfile() {
|
||||
return request('/api/profiles/me')
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Clubs & Groups
|
||||
// ============================================================================
|
||||
|
||||
export async function listClubs() {
|
||||
return request('/api/clubs')
|
||||
}
|
||||
|
||||
export async function createClub(data) {
|
||||
return request('/api/clubs', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
}
|
||||
|
||||
export async function listTrainingGroups(clubId) {
|
||||
const query = clubId ? `?club_id=${clubId}` : ''
|
||||
return request(`/api/groups${query}`)
|
||||
}
|
||||
|
||||
export async function createTrainingGroup(data) {
|
||||
return request('/api/groups', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Skills & Methods
|
||||
// ============================================================================
|
||||
|
||||
export async function listSkills() {
|
||||
return request('/api/skills')
|
||||
}
|
||||
|
||||
export async function createSkill(data) {
|
||||
return request('/api/skills', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
}
|
||||
|
||||
export async function listMethods() {
|
||||
return request('/api/methods')
|
||||
}
|
||||
|
||||
export async function createMethod(data) {
|
||||
return request('/api/methods', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Exercises
|
||||
// ============================================================================
|
||||
|
||||
export async function listExercises(filters = {}) {
|
||||
const query = new URLSearchParams(filters).toString()
|
||||
return request(`/api/exercises${query ? '?' + query : ''}`)
|
||||
}
|
||||
|
||||
export async function getExercise(id) {
|
||||
return request(`/api/exercises/${id}`)
|
||||
}
|
||||
|
||||
export async function createExercise(data) {
|
||||
return request('/api/exercises', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
}
|
||||
|
||||
export async function updateExercise(id, data) {
|
||||
return request(`/api/exercises/${id}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
}
|
||||
|
||||
export async function deleteExercise(id) {
|
||||
return request(`/api/exercises/${id}`, { method: 'DELETE' })
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Training Planning
|
||||
// ============================================================================
|
||||
|
||||
export async function listTrainingUnits(groupId, startDate, endDate) {
|
||||
const query = new URLSearchParams({ group_id: groupId, start_date: startDate, end_date: endDate }).toString()
|
||||
return request(`/api/training-units?${query}`)
|
||||
}
|
||||
|
||||
export async function getTrainingUnit(id) {
|
||||
return request(`/api/training-units/${id}`)
|
||||
}
|
||||
|
||||
export async function createTrainingUnit(data) {
|
||||
return request('/api/training-units', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
}
|
||||
|
||||
export async function updateTrainingUnit(id, data) {
|
||||
return request(`/api/training-units/${id}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Version & Health
|
||||
// ============================================================================
|
||||
|
||||
export async function getVersion() {
|
||||
return request('/api/version')
|
||||
}
|
||||
|
||||
export async function healthCheck() {
|
||||
return request('/health')
|
||||
}
|
||||
|
||||
export const api = {
|
||||
// Auth
|
||||
login,
|
||||
register,
|
||||
logout,
|
||||
getCurrentProfile,
|
||||
|
||||
// Clubs & Groups
|
||||
listClubs,
|
||||
createClub,
|
||||
listTrainingGroups,
|
||||
createTrainingGroup,
|
||||
|
||||
// Skills & Methods
|
||||
listSkills,
|
||||
createSkill,
|
||||
listMethods,
|
||||
createMethod,
|
||||
|
||||
// Exercises
|
||||
listExercises,
|
||||
getExercise,
|
||||
createExercise,
|
||||
updateExercise,
|
||||
deleteExercise,
|
||||
|
||||
// Training Planning
|
||||
listTrainingUnits,
|
||||
getTrainingUnit,
|
||||
createTrainingUnit,
|
||||
updateTrainingUnit,
|
||||
|
||||
// System
|
||||
getVersion,
|
||||
healthCheck
|
||||
}
|
||||
|
||||
export default api
|
||||
@@ -0,0 +1,14 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
server: {
|
||||
port: 3098,
|
||||
host: true
|
||||
},
|
||||
build: {
|
||||
outDir: 'dist',
|
||||
sourcemap: false
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user