initial config
This commit is contained in:
13
backend/Dockerfile
Normal file
13
backend/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm install --legacy-peer-deps
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
CMD ["npm", "run", "dev"]
|
||||
85
backend/database/init.sql
Normal file
85
backend/database/init.sql
Normal file
@@ -0,0 +1,85 @@
|
||||
-- Users table
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
password_hash VARCHAR(255) NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX idx_users_email ON users(email);
|
||||
|
||||
-- Shooting styles table
|
||||
CREATE TABLE IF NOT EXISTS shooting_styles (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name VARCHAR(255) NOT NULL UNIQUE,
|
||||
description TEXT,
|
||||
scoring_format VARCHAR(50) NOT NULL,
|
||||
max_points_per_arrow INT NOT NULL DEFAULT 10,
|
||||
configuration JSONB DEFAULT '{}',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- Tournaments table
|
||||
CREATE TABLE IF NOT EXISTS tournaments (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
shooting_style_id UUID NOT NULL REFERENCES shooting_styles(id),
|
||||
status VARCHAR(50) DEFAULT 'draft',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX idx_tournaments_user_id ON tournaments(user_id);
|
||||
CREATE INDEX idx_tournaments_status ON tournaments(status);
|
||||
|
||||
-- Archers table
|
||||
CREATE TABLE IF NOT EXISTS archers (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tournament_id UUID NOT NULL REFERENCES tournaments(id) ON DELETE CASCADE,
|
||||
user_id UUID REFERENCES users(id) ON DELETE SET NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
bib_number VARCHAR(50),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX idx_archers_tournament_id ON archers(tournament_id);
|
||||
|
||||
-- Rounds table
|
||||
CREATE TABLE IF NOT EXISTS rounds (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tournament_id UUID NOT NULL REFERENCES tournaments(id) ON DELETE CASCADE,
|
||||
round_number INT NOT NULL,
|
||||
distance_meters INT,
|
||||
arrow_count INT NOT NULL DEFAULT 72,
|
||||
max_score_per_arrow INT NOT NULL DEFAULT 10,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX idx_rounds_tournament_id ON rounds(tournament_id);
|
||||
|
||||
-- Shots table
|
||||
CREATE TABLE IF NOT EXISTS shots (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
round_id UUID NOT NULL REFERENCES rounds(id) ON DELETE CASCADE,
|
||||
archer_id UUID NOT NULL REFERENCES archers(id) ON DELETE CASCADE,
|
||||
arrow_number INT NOT NULL,
|
||||
score INT NOT NULL,
|
||||
notes TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX idx_shots_round_id ON shots(round_id);
|
||||
CREATE INDEX idx_shots_archer_id ON shots(archer_id);
|
||||
|
||||
-- Insert default shooting styles
|
||||
INSERT INTO shooting_styles (name, description, scoring_format, max_points_per_arrow, configuration)
|
||||
VALUES
|
||||
('Olympic Recurve', 'Standard Olympic archery format', 'point_based', 10, '{"rounds": 1, "arrows_per_round": 72}'),
|
||||
('3D Field', 'Field archery with variable distances', 'zone_based', 12, '{"variable_distance": true}'),
|
||||
('Indoor 18m', 'Indoor competition at 18 meters', 'point_based', 10, '{"distance_meters": 18, "arrows": 60}'),
|
||||
('Compound', 'Compound bow format', 'point_based', 10, '{"bow_type": "compound"}')
|
||||
ON CONFLICT (name) DO NOTHING;
|
||||
42
backend/package.json
Normal file
42
backend/package.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "archery-scoring-backend",
|
||||
"version": "1.0.0",
|
||||
"description": "Backend for archery scoring application",
|
||||
"main": "dist/app.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "node --import tsx src/app.ts",
|
||||
"build": "tsc",
|
||||
"start": "node dist/app.js",
|
||||
"migrate": "node --import tsx src/database/migrate.ts",
|
||||
"seed": "node --import tsx src/database/seed.ts",
|
||||
"test": "vitest",
|
||||
"lint": "eslint src/"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "4.18.2",
|
||||
"cors": "2.8.5",
|
||||
"dotenv": "16.3.1",
|
||||
"pg": "8.11.3",
|
||||
"redis": "4.6.12",
|
||||
"jsonwebtoken": "9.0.2",
|
||||
"bcryptjs": "2.4.3",
|
||||
"zod": "3.22.4",
|
||||
"uuid": "9.0.1",
|
||||
"express-rate-limit": "7.1.5",
|
||||
"helmet": "7.1.0",
|
||||
"morgan": "1.10.0",
|
||||
"axios": "1.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "20.10.6",
|
||||
"@types/express": "4.17.21",
|
||||
"@types/bcryptjs": "2.4.6",
|
||||
"@types/jsonwebtoken": "9.0.7",
|
||||
"typescript": "5.3.3",
|
||||
"tsx": "4.7.0",
|
||||
"vitest": "1.1.0",
|
||||
"supertest": "6.3.3",
|
||||
"@types/supertest": "6.0.2"
|
||||
}
|
||||
}
|
||||
66
backend/src/app.ts
Normal file
66
backend/src/app.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import helmet from 'helmet';
|
||||
import morgan from 'morgan';
|
||||
import rateLimit from 'express-rate-limit';
|
||||
import dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 5000;
|
||||
|
||||
// Security middleware
|
||||
app.use(helmet());
|
||||
app.use(cors({
|
||||
origin: process.env.NODE_ENV === 'production'
|
||||
? process.env.FRONTEND_URL
|
||||
: ['http://localhost:3000', 'http://localhost:5000'],
|
||||
credentials: true
|
||||
}));
|
||||
|
||||
// Rate limiting
|
||||
const limiter = rateLimit({
|
||||
windowMs: 15 * 60 * 1000,
|
||||
max: 100,
|
||||
message: 'Too many requests from this IP'
|
||||
});
|
||||
app.use(limiter);
|
||||
|
||||
// Logging
|
||||
app.use(morgan('combined'));
|
||||
|
||||
// Body parser
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
// Health check
|
||||
app.get('/health', (req, res) => {
|
||||
res.json({ status: 'ok', timestamp: new Date().toISOString() });
|
||||
});
|
||||
|
||||
// Routes (placeholder)
|
||||
app.get('/api', (req, res) => {
|
||||
res.json({ message: 'Archery Scoring API v1.0' });
|
||||
});
|
||||
|
||||
// 404 handler
|
||||
app.use((req, res) => {
|
||||
res.status(404).json({ error: 'Route not found' });
|
||||
});
|
||||
|
||||
// Error handler
|
||||
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
console.error(err);
|
||||
res.status(err.status || 500).json({
|
||||
error: process.env.NODE_ENV === 'production'
|
||||
? 'Internal server error'
|
||||
: err.message
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`🏹 Server running on http://localhost:${PORT}`);
|
||||
});
|
||||
|
||||
export default app;
|
||||
20
backend/tsconfig.json
Normal file
20
backend/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "ES2020",
|
||||
"lib": ["ES2020"],
|
||||
"moduleResolution": "node",
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist", "tests"]
|
||||
}
|
||||
Reference in New Issue
Block a user