Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
547 commits
Select commit Hold shift + click to select a range
6240918
albo d'oro campionato collegato al be
FAST-man-33 Sep 14, 2025
fa3af73
Aggiunto logo RaceForFederica a email automatica
paocela Sep 21, 2025
2884f87
Aggiornato punteggi sessioni nelle regole
paocela Sep 22, 2025
f8c8a04
Nome driver nella dashboard
paocela Sep 22, 2025
6d5f137
feat: Add constants for medals and flags, refactor usage in admin and…
DomiJAR Sep 27, 2025
55fb7c5
Fanta for new season
DomiJAR Sep 27, 2025
052caaf
fix: Update track identifiers in admin component for unique binding i…
DomiJAR Sep 27, 2025
e4e54a0
aggiunto dati albo d'oro fanta
FAST-man-33 Sep 28, 2025
3031742
fis admin
DomiJAR Sep 28, 2025
f73c172
bug fix e rifatta grafica pagina piloti
FAST-man-33 Sep 28, 2025
8ae4836
Merge branch 'develop' of https://github.com/paocela/f123dashboard in…
FAST-man-33 Sep 28, 2025
7633015
correzione caclolo grafica costruttori
FAST-man-33 Sep 28, 2025
334e9f7
Merge pull request #12 from paocela/paolo
paocela Sep 29, 2025
6563cc9
Merge pull request #13 from paocela/develop
paocela Sep 29, 2025
e14279a
inserite texture albo d'oro
FAST-man-33 Sep 29, 2025
459aa81
Merge branch 'develop' of https://github.com/paocela/f123dashboard in…
FAST-man-33 Sep 29, 2025
f566fd3
deploy prod
DomiJAR Sep 29, 2025
1e7483d
Fix colori championship
paocela Sep 29, 2025
d038522
merge
paocela Sep 29, 2025
fd523f0
inserite texture albo d'oro, aggiunto punteggi
FAST-man-33 Sep 29, 2025
9cc71e8
Sistemato spaziature pagina credits
paocela Oct 12, 2025
0be8ee4
Fix dimensionamento header
paocela Oct 12, 2025
4673ae2
Fanta improvment and refactor
DomiJAR Oct 13, 2025
8c0cbe7
Fixed type problems: models are now in interface, interface and serv…
DomiJAR Oct 14, 2025
30e1000
heavyButt Bello
DomiJAR Oct 14, 2025
dc0a474
fix gainded points when race fawer than 3
DomiJAR Oct 15, 2025
92fca65
Merge branch 'develop' into paolo
paocela Oct 15, 2025
8e4e68f
Aggiunto pilota e costruttore della settimana, e emojii a titoli
paocela Oct 15, 2025
aa59f88
Aggiustato dimensioni componenti header bar e link
paocela Oct 15, 2025
7d0d38a
Quasi aggiustato dimensioni foto pilota settimana
paocela Oct 15, 2025
6d1945c
Merge pull request #14 from paocela/paolo
paocela Oct 15, 2025
8977efd
Dimesione uguale immagine piste
FAST-man-33 Oct 15, 2025
dd5ed89
sidebar scura
FAST-man-33 Oct 15, 2025
7226982
Aggiunto immagini nuovi piloti, messaggio password dimenticata e corr…
paocela Oct 18, 2025
4bbad9d
Merge pull request #15 from paocela/paolo
paocela Oct 18, 2025
92a3af3
Removed unused LinkBoxComponent import from DefaultHeaderComponent
DomiJAR Oct 19, 2025
a36616c
Merge branch 'develop'
DomiJAR Oct 19, 2025
26ddfc3
fix: update radarChartOptions type and upgrade dependencies
DomiJAR Oct 19, 2025
20b7f03
modificati badge NEW
FAST-man-33 Oct 19, 2025
3b64e8d
fix albo d'oro
FAST-man-33 Oct 19, 2025
505d3f7
fix registration modal
DomiJAR Oct 19, 2025
463d03d
Merge branch 'develop'
DomiJAR Oct 19, 2025
8fd4feb
Merge branch 'develop' of https://github.com/paocela/f123dashboard in…
FAST-man-33 Oct 19, 2025
0e67269
Merge branch 'develop'
DomiJAR Oct 19, 2025
ee26ae8
dimensione card on fire fixata
FAST-man-33 Oct 19, 2025
75f5ab8
Colori piloti e squadre in esadecimale
paocela Oct 19, 2025
2e83a99
Merge pull request #16 from paocela/paolo
paocela Oct 19, 2025
935619a
Fix registration modal
DomiJAR Oct 19, 2025
8e483ed
Merge branch 'develop' of https://github.com/paocela/f123dashboard in…
DomiJAR Oct 19, 2025
6a82dee
Merge branch 'develop'
DomiJAR Oct 19, 2025
f96cc0e
Refactor user info update logic and remove unused types
DomiJAR Oct 19, 2025
6cb2704
update HeavyButt.png
DomiJAR Oct 22, 2025
95ed8b3
NEW RESET PASSWORD PAGE
DomiJAR Oct 28, 2025
1336735
improved fanta vote layout
DomiJAR Oct 28, 2025
0ebc856
remove success message from login process and clean up loading state …
DomiJAR Oct 28, 2025
3160e6d
Merge branch 'develop'
DomiJAR Oct 28, 2025
455702a
votazioni in classifica fanta
DomiJAR Oct 29, 2025
7d4ff54
fanta vote
DomiJAR Oct 29, 2025
c95d4d0
Fix grafico
DomiJAR Oct 29, 2025
5efe1e8
constructor and pilot card
DomiJAR Oct 30, 2025
48fef4f
Remove email check from login navigation and update runtime in genezi…
DomiJAR Oct 30, 2025
053341c
deploy test
DomiJAR Oct 30, 2025
50e091c
Update Node.js version in package.json and remove runtime from genezi…
DomiJAR Oct 30, 2025
d47d6e5
refactor: update component services and improve code readability
DomiJAR Oct 30, 2025
f660824
Aggiunto pagina playground, solo frontend e logica gioco
paocela Nov 8, 2025
0da4be7
Aggiunto connessione playground a backend
paocela Nov 8, 2025
995fe76
Aggiunto aggiornamento BE playground
paocela Nov 9, 2025
d080a72
Fix dimensioni scritte credits e problema tema playground
paocela Nov 9, 2025
ded0b04
Avatar update
DomiJAR Nov 9, 2025
f733c4f
Merge pull request #17 from paocela/develop
paocela Nov 9, 2025
a9f7557
Double click on touch screen devices bug - playground
paocela Nov 10, 2025
0412a80
Merge pull request #18 from paocela/develop
paocela Nov 10, 2025
3b971df
driver image fix
DomiJAR Nov 12, 2025
35ae7c1
Aggiornato punteggi
paocela Nov 12, 2025
ce7d235
Fanta mostra classifica anche senza gare, e fix sprint badge in class…
paocela Nov 12, 2025
5028a59
Remove unused genezio.yaml configuration and update package.json depe…
DomiJAR Nov 12, 2025
4f01f85
Merge branch 'develop'
DomiJAR Nov 12, 2025
0494911
Add new avatar images to the assets directory
DomiJAR Nov 13, 2025
cdc29fb
Merge pull request #19 from paocela/develop
DomiJAR Nov 13, 2025
71cdb72
express backend 0.1
DomiJAR Nov 14, 2025
56e076e
frontand a dto interface migration
DomiJAR Nov 14, 2025
4fc8d4c
updated README
DomiJAR Nov 14, 2025
d04b7aa
Update Node and npm engine requirements in package.json
DomiJAR Nov 14, 2025
4638a6d
Update Angular dependencies to version 20.2.0
DomiJAR Nov 14, 2025
32d16da
Dreandos img
DomiJAR Nov 14, 2025
b52b547
Refactor authentication endpoints to use 'Bearer' token for validatio…
DomiJAR Nov 14, 2025
c6ed96d
Update token validation and authentication header handling in services
DomiJAR Nov 14, 2025
325986f
remove build file
DomiJAR Nov 15, 2025
082eb4e
Update .gitignore to remove specific Genezio SDK files and include se…
DomiJAR Nov 15, 2025
45221f4
Add build and deployment scripts, including clean and copy functional…
DomiJAR Nov 16, 2025
3a97c34
Aggiornato immagini costruttori
paocela Nov 16, 2025
eaef05c
Fix temporanea costruttori
paocela Nov 16, 2025
9c5f8d5
Updated constructor team images
DomiJAR Nov 16, 2025
7c2c6f5
Refactor getConstructors method
DomiJAR Nov 16, 2025
f6f99f0
Merge pull request #20 from paocela/develop
DomiJAR Nov 16, 2025
23aff8e
Fix getConstructors method
DomiJAR Nov 16, 2025
392dcc8
Merge pull request #21 from paocela/develop
DomiJAR Nov 16, 2025
a708bc9
fix server static file serving after migration to ES modules
DomiJAR Nov 16, 2025
492fb6e
server and logs improve, commented jobs
DomiJAR Nov 16, 2025
e09066a
Fix pilota settimana
paocela Nov 18, 2025
28eb936
Typo
paocela Nov 18, 2025
2edf383
Merge pull request #22 from paocela/develop
paocela Nov 18, 2025
1f04952
Update logger configuration and enhance deployment script
DomiJAR Nov 22, 2025
5b8dbcb
Merge branch 'main' into server-migration
DomiJAR Nov 26, 2025
72cfe9c
actions for deploy
DomiJAR Nov 26, 2025
e9e655d
fix action
DomiJAR Nov 26, 2025
9f8b065
fix action
DomiJAR Nov 26, 2025
d6e0725
added package.json
DomiJAR Nov 26, 2025
d341281
refactor modals to use a unified visibility property and two-way binding
DomiJAR Nov 26, 2025
f64f9ba
refactor copy-to-dist script to use a consistent dist directory path
DomiJAR Nov 26, 2025
5bbb310
fix: update path in clean script to correctly target dist/ directory
DomiJAR Nov 26, 2025
511cd40
build and deply fix
DomiJAR Nov 26, 2025
babd5a3
build and deply fix
DomiJAR Nov 26, 2025
73ffa25
build and deply fix
DomiJAR Nov 26, 2025
d3d375b
build and deply fix
DomiJAR Nov 26, 2025
ef9b882
fix: update deployment script to use secrets and set NODE_ENV for ins…
DomiJAR Dec 6, 2025
9c5fd8a
fix: handle errors during Twitch stream status check in app initializ…
DomiJAR Dec 6, 2025
65bbaae
log deploy
DomiJAR Dec 6, 2025
c53653e
fix: specify path for loading environment variables in server configu…
DomiJAR Dec 6, 2025
9d0dbce
fix: specify path for loading environment variables in server configu…
DomiJAR Dec 6, 2025
34d0794
fix: update dotenv configuration
DomiJAR Dec 6, 2025
9d4e0b0
added auth headers in api service
DomiJAR Dec 6, 2025
98bc9f5
fix admin
DomiJAR Dec 6, 2025
dac64e2
Merge pull request #23 from paocela/server-migration
paocela Dec 6, 2025
36108df
Merge pull request #24 from paocela/develop
paocela Dec 6, 2025
2a0590b
Aggiornato regole
paocela Dec 6, 2025
4f330fc
aggiornato regole e delta punteggi nella classifica, e risolto pilota…
paocela Dec 8, 2025
b4d2ad5
Merge pull request #25 from paocela/develop
paocela Dec 8, 2025
2608e93
fix: update deployment condition to only trigger on main branch
DomiJAR Dec 8, 2025
53a7a62
Merge pull request #26 from paocela/develop
DomiJAR Dec 8, 2025
f07f879
integrate dynamic Twitch embed URL and add channel retrieval method
DomiJAR Dec 8, 2025
5eb9739
Aggiunto logo punti guadagnati ultima giornata e risolto errore in pu…
paocela Dec 8, 2025
b9da811
Merge pull request #27 from paocela/develop
paocela Dec 8, 2025
1fc3306
Improved dashboard , added rff constructor
DomiJAR Dec 8, 2025
68f8959
Merge
DomiJAR Dec 8, 2025
a107ca9
chore: update Angular and CoreUI dependencies to latest versions; ref…
DomiJAR Dec 23, 2025
d099170
chore: update @ng-bootstrap/ng-bootstrap dependency to version 20.0.0
DomiJAR Dec 23, 2025
ab279c8
Merge pull request #29 from paocela/develop
DomiJAR Dec 23, 2025
b9cca25
update Angular 21
DomiJAR Dec 23, 2025
e17ef01
Merge pull request #30 from paocela/develop
DomiJAR Dec 23, 2025
310f80d
Aggiornato regole e messo punteggi in tabella unica
paocela Jan 11, 2026
c19e65c
Aggiornato regole
paocela Jan 11, 2026
5b0b537
Merge pull request #31 from paocela/develop
paocela Jan 11, 2026
f3b6aeb
Aggiornato regole
paocela Jan 11, 2026
a1c94e3
Merge pull request #32 from paocela/develop
paocela Jan 11, 2026
6b7537c
pagina Gestione gp
DomiJAR Jan 14, 2026
540835d
Add backend tests step to CI workflow
DomiJAR Jan 14, 2026
09d7753
Fanta rules
DomiJAR Jan 14, 2026
ad70b2f
Set JWT_SECRET in test
DomiJAR Jan 14, 2026
285a85b
Set JWT_SECRET in test file
DomiJAR Jan 14, 2026
c464d99
Remove JWT_SECRET from test file and set it in vitest configuration
DomiJAR Jan 14, 2026
af3847a
Merge pull request #33 from paocela/develop
DomiJAR Jan 14, 2026
15a3773
Calendar component
DomiJAR Jan 26, 2026
63e004e
Merge pull request #34 from paocela/develop
DomiJAR Jan 26, 2026
d1ff9ad
Refactor podium card component and update Albo d'Oro to use typed ent…
DomiJAR Jan 30, 2026
8dc17de
Update instructions
DomiJAR Jan 30, 2026
b37ff42
Removed deprecated ngif and ngfor
DomiJAR Jan 30, 2026
e9dd808
Refactor countdown component
DomiJAR Jan 31, 2026
2223cdc
Refactor shadow generation in podium card component using list functions
DomiJAR Jan 31, 2026
fc00851
Refactor championship component to use centralized allFlags constant …
DomiJAR Jan 31, 2026
f5dabbd
Merge pull request #35 from paocela/develop
DomiJAR Jan 31, 2026
6fa0c4b
Added global code owner
Feb 1, 2026
62ccfb7
Merge pull request #36 from paocela/develop
paocela Feb 1, 2026
c6adba0
Rimosso fanta rules da pagina fanta
Feb 1, 2026
99d8f81
Merge pull request #37 from paocela/develop
paocela Feb 1, 2026
cd2340e
Updated github workflow to trigger only when PR is closed
Feb 1, 2026
969e1bd
Merge pull request #38 from paocela/develop
paocela Feb 1, 2026
b704e04
Update dependency path for shared package in package.json
DomiJAR Feb 6, 2026
47cd956
chore: update nodemailer to version 8.0.0 and @types/node to latest v…
DomiJAR Feb 6, 2026
968be08
refactor: update project instructions for Angular best practices and …
DomiJAR Feb 6, 2026
60b016c
refactor: remove standalone flag from multiple components
DomiJAR Feb 6, 2026
a99dbc5
refactor: improve date parsing in CalendarComponent
DomiJAR Feb 6, 2026
cf661f5
feat: implement ConstructorService for Single source of truth for con…
DomiJAR Feb 6, 2026
a88971f
feat: add DriverOfWeek and ConstructorOfWeek interfaces; refactor Das…
DomiJAR Feb 6, 2026
7785395
fix: update job title for Andrea Dominici from Backend Developer to F…
DomiJAR Feb 6, 2026
879f4de
feat: When multiple constructors tie for first place with the same po…
DomiJAR Feb 7, 2026
d7dea90
fix: ensure constructor points are correctly parsed as numbers when d…
DomiJAR Feb 7, 2026
0df2d8b
refactor: improve loading service tests and add noop animations to co…
DomiJAR Feb 7, 2026
7432f61
fix: ensure pilota is not null
DomiJAR Feb 7, 2026
c6d43d3
fix: allow displaying votes for pilots beyond the top 10
DomiJAR Feb 7, 2026
14538df
fix: ensure ID parameters are parsed as strings in update and delete …
DomiJAR Feb 7, 2026
3c1f0c3
fix: add step to build shared package in CI workflow
DomiJAR Feb 7, 2026
16d48d1
Refactor fanta related services to use Angular signals for state mana…
DomiJAR Feb 7, 2026
6c0c71e
refactor: update FantaService tests to use Angular signals and mock A…
DomiJAR Feb 7, 2026
702c674
refactor: update PilotiComponent to use Angular signals for state man…
DomiJAR Feb 7, 2026
bd5555c
refactor: migrate PlaygroundComponent to use Angular signals for stat…
DomiJAR Feb 7, 2026
3820ccf
refactor: update AuthService and related components to use consistent…
DomiJAR Feb 7, 2026
fff0797
refactor: update logout methods to validate JWT token from authorizat…
DomiJAR Feb 7, 2026
fb51201
refactor: irefactor auth service
DomiJAR Feb 9, 2026
121485b
refactor: optimize data fetching in DbDataService using forkJoin for …
DomiJAR Feb 9, 2026
0aa0ed0
refactor: migrate AdminComponent to use Angular signals for state man…
DomiJAR Feb 9, 2026
a2bfa44
refactor: update GpEditComponent to use Angular signals for state man…
DomiJAR Feb 9, 2026
4e6f340
refactor: enhance loading state handling in GpEditComponent test with…
DomiJAR Feb 9, 2026
cea8d6b
refactor(backend): attach JWT token to request context in auth middle…
DomiJAR Feb 10, 2026
030a542
refactor(client): migrate auth service to signal-based state management
DomiJAR Feb 10, 2026
50fcbdd
refactor(client): migrate guards to signal-based authentication
DomiJAR Feb 10, 2026
829ae18
refactor(client): migrate services to signal-based state management
DomiJAR Feb 10, 2026
75a148b
refactor(client): migrate default layout to use computed signal for n…
DomiJAR Feb 10, 2026
a7ca1a8
refactor(client): migrate login and password-change components to sig…
DomiJAR Feb 10, 2026
e085c84
refactor(client): migrate registration-modal to signals and modern An…
DomiJAR Feb 10, 2026
86e55d3
refactor(client): migrate vote-history-table to signals and computed …
DomiJAR Feb 10, 2026
e14b8ea
refactor(client): migrate leaderboard component to signals
DomiJAR Feb 10, 2026
eec71f3
refactor(client): migrate admin-change-password to signals
DomiJAR Feb 10, 2026
07a27bb
refactor(client): migrate admin component to signals and remove CoreU…
DomiJAR Feb 10, 2026
0e11010
refactor(client): migrate fanta component to comprehensive signal-bas…
DomiJAR Feb 10, 2026
b0b28b4
refactor(client): migrate playground component to signals and improve…
DomiJAR Feb 10, 2026
b3ee833
docs: update project instructions for Angular v20+ signal-based patterns
DomiJAR Feb 10, 2026
2faed63
refactor(tests): update admin and admin-change-password component tes…
DomiJAR Feb 10, 2026
95d3a37
refactor(client): complete calendar component signal migration
DomiJAR Feb 10, 2026
1684778
refactor(client): migrate card components to signal-based inputs
DomiJAR Feb 10, 2026
7f62040
refactor(client): migrate countdown component to signal-based state m…
DomiJAR Feb 10, 2026
0be3b97
refactor(client): fix template bindings for signal-based inputs in mo…
DomiJAR Feb 10, 2026
3500c1a
refactor(client): migrate core services from BehaviorSubject to signals
DomiJAR Feb 10, 2026
e704f42
refactor(client): remove deprecated service getters and update callers
DomiJAR Feb 10, 2026
7891fb0
refactor(client): update view components to use signal-based service API
DomiJAR Feb 10, 2026
4edb165
refactor(client): migrate utility components to signal-based patterns
DomiJAR Feb 10, 2026
13b0e0b
fix full race insert bug
DomiJAR Mar 24, 2026
5f28d61
refactor(database): convert gran_prix_has_sprint and gran_prix_has_x2…
DomiJAR Mar 24, 2026
95255fb
Merge pull request #39 from paocela/develop
paocela Mar 25, 2026
49e2373
Cleanup wrong dependency
paocela Mar 25, 2026
b7109d3
Merge pull request #40 from paocela/develop
paocela Mar 25, 2026
50d9645
Commented out github workflow angular tests
paocela Mar 25, 2026
6e31550
Merge pull request #41 from paocela/develop
paocela Mar 25, 2026
4e373c4
test
paocela Mar 25, 2026
2a9272d
Merge pull request #42 from paocela/develop
paocela Mar 25, 2026
0eff191
test
paocela Mar 25, 2026
6091c4a
Merge pull request #43 from paocela/develop
paocela Mar 25, 2026
f1fdef5
revert
paocela Mar 25, 2026
fd1fe3e
fix Tests
DomiJAR Mar 25, 2026
7369479
fix fanta loading
DomiJAR Mar 25, 2026
81c6245
remove quick status check section from Postman file index
DomiJAR Mar 25, 2026
5c5adba
refactor: update modal visibility handling and improve card styling i…
DomiJAR Mar 25, 2026
3807a6a
fix constructor of the week
DomiJAR Mar 25, 2026
cc34d41
chore: update actions versions in workflows for build and stale proce…
DomiJAR Mar 25, 2026
3ddb51d
Merge pull request #44 from paocela/develop
paocela Mar 25, 2026
28a3f6f
fix: remove unnecessary span from close button in vote history modal
DomiJAR Mar 25, 2026
97de971
miglioramento albo d'oro
FAST-man-33 Mar 25, 2026
1a44b07
Merge branch 'main' of https://github.com/paocela/f123dashboard
FAST-man-33 Mar 25, 2026
b441329
refactor: improve podium card rendering and added season 2 podium cards
DomiJAR Mar 25, 2026
51ded4e
Merge pull request #45 from paocela/develop
paocela Mar 25, 2026
5376ce6
Merge branch 'main' of https://github.com/paocela/f123dashboard
FAST-man-33 Mar 26, 2026
01220d8
update grafico albo d'oro
FAST-man-33 Mar 26, 2026
17ce30c
refactor podium card styles for improved layout and responsiveness
FAST-man-33 Mar 26, 2026
3831b82
Merge remote-tracking branch 'origin/albo-d'oro-new' into develop
DomiJAR Mar 26, 2026
3571ed9
style: update font sizes and line clamping for improved readability i…
DomiJAR Mar 26, 2026
dd745ef
Merge branch 'main' into develop
DomiJAR Mar 26, 2026
c5917ba
Merge pull request #46 from paocela/develop
paocela Mar 27, 2026
51824f2
enhance Albo d'Oro component with user data integration and responsiv…
FAST-man-33 Mar 28, 2026
35061b8
Merge branch 'main' into albo-d'oro-new
FAST-man-33 Apr 3, 2026
8b14d63
albo d'oro fix posizione numeri
FAST-man-33 Apr 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Global code owner
* @paocela
315 changes: 315 additions & 0 deletions .github/instructions/backend.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
---
applyTo: '/server/**'
---

# Backend Development Instructions

## Architecture Overview

**Full-Stack Structure**: Express.js backend + Angular frontend, deployed together. The server serves both API endpoints (`/api/*`) and static Angular files in production.

**Migration Context**: This backend was migrated from Genezio infrastructure to self-hosted Express.js. The `server/src/*_interface.ts` files are legacy Genezio files; new code uses the Service/Controller/Route pattern.

### Core Architecture Pattern: Service → Controller → Route

```
Request → Route → Middleware → Controller → Service → Database
```

**Example Flow**:
```typescript
// 1. Route (auth.routes.ts)
router.post('/login', authController.login);

// 2. Controller (auth.controller.ts) - handles req/res
async login(req: Request, res: Response) {
const result = await authService.login(req.body);
res.json(result);
}

// 3. Service (auth.service.ts) - business logic
async login(loginData: LoginRequest): Promise<AuthResponse> {
const user = await this.pool.query('SELECT ...');
return { success: true, token: jwt.sign(...) };
}
```

## Directory Structure

```
server/src/
├── server.ts # Express app entry point
├── config/
│ ├── db.ts # PostgreSQL pool singleton
│ └── logger.ts # Winston logging configuration
├── middleware/
│ └── auth.middleware.ts # JWT validation (authMiddleware, adminMiddleware)
├── routes/ # Express routers, mounted at /api/*
├── controllers/ # Request/response handlers
├── services/ # Business logic, database queries
├── *_interface.ts # Legacy Genezio files (DO NOT MODIFY)
└── email_templates.ts # Email HTML templates
```

## Database Access Pattern

**Singleton Pool Injection**: All services receive the database pool via constructor.

```typescript
// config/db.ts exports a singleton
const pool = new Pool({ connectionString: process.env.RACEFORFEDERICA_DB_DATABASE_URL });

// Services accept pool via constructor
export class AuthService {
constructor(private pool: pg.Pool) {}

async getUsers(): Promise<User[]> {
const result = await this.pool.query('SELECT * FROM users');
return result.rows;
}
}

// Controllers instantiate services with shared pool
import pool from '../config/db.js';
const authService = new AuthService(pool);
```

**Database Schema**: Entry-based result tables (`race_result_entries`, `sprint_result_entries`, etc.) store positions as rows, not columns. See `.github/instructions/db.instructions.md` for schema details.

## Authentication & Authorization

### Two-Level Middleware Chain

**authMiddleware** (JWT validation):
- Extracts `Authorization: Bearer <token>` header
- Verifies JWT signature with `process.env.JWT_SECRET`
- Decodes token payload: `{ userId, username, isAdmin }`
- Attaches `req.user` for downstream use
- Returns 401 if token missing/invalid/expired

**adminMiddleware** (admin check):
- Requires `authMiddleware` to run first
- Checks `req.user.isAdmin === true`
- Returns 403 if user not admin

### Route Protection Patterns

```typescript
// Public - no auth
router.post('/login', authController.login);

// Protected - requires valid JWT
router.post('/profile', authMiddleware, authController.getProfile);

// Admin only - requires JWT + admin flag
router.post('/users', authMiddleware, adminMiddleware, authController.getUsers);
```

**CRITICAL**: Always use both middleware for admin routes: `authMiddleware, adminMiddleware` (in that order).

### JWT Token Structure

```typescript
// Token created in auth.service.ts generateJWTToken()
jwt.sign({
userId: user.id,
username: user.username,
isAdmin: user.is_admin // From database
}, process.env.JWT_SECRET, { expiresIn: '24h' });
```

Session management: Tokens stored in `user_sessions` table with expiration tracking.

## Logging with Winston

**Logger Location**: `server/src/config/logger.ts`

### Log Levels (priority order)
1. **error**: Critical errors (database failures, authentication errors)
2. **warn**: Potentially harmful situations (rate limits, deprecated usage)
3. **info**: Application state (server start, successful operations)
4. **http**: HTTP requests (handled by Morgan middleware)
5. **debug**: Detailed debugging info

### Usage Pattern

```typescript
import logger from '../config/logger.js';

// Structured logging with metadata
logger.error('Database query failed', {
error: err.message,
stack: err.stack,
userId: req.user?.userId
});

logger.info('User logged in', { userId: user.id, username: user.username });

// HTTP logging - automatic via Morgan in server.ts
// No manual HTTP logging needed
```

**Environment Behavior**:
- **Development**: Colorized console logs, level=debug
- **Production**: JSON files in `server/logs/` (error.log, combined.log), level=info

**Configuration**: Set `LOG_LEVEL` in `.env` (error|warn|info|http|debug)

## Error Handling Pattern

**Controllers**: Always wrap service calls in try-catch

```typescript
async someMethod(req: Request, res: Response): Promise<void> {
try {
const result = await service.doSomething(req.body);
res.json(result);
} catch (error) {
logger.error('Operation failed', { error: error.message });
res.status(500).json({
success: false,
message: error instanceof Error ? error.message : 'Operation failed'
});
}
}
```

**Services**: Return structured responses with `success` boolean

```typescript
return {
success: false,
message: 'User not found'
};
```

## Development Commands

```bash
# Development with hot reload
npm run dev # Uses tsx watch

# Build TypeScript
npm run build # Outputs to dist/

# Production
npm start # Runs compiled dist/server.js

# Environment setup
cp .env.example .env # Then edit with actual credentials
```

**Required Environment Variables** (`.env`):
```env
RACEFORFEDERICA_DB_DATABASE_URL=postgresql://...
JWT_SECRET=your-secret-key
MAIL_USER=email@example.com
MAIL_PASS=email-password
RACEFORFEDERICA_DREANDOS_SECRET=twitch-secret
PORT=3000
NODE_ENV=development
LOG_LEVEL=debug
```

## API Endpoint Conventions

**Base Path**: All API routes mounted under `/api/*`

**HTTP Method**: Use correct HTTP methods (GET, POST, PUT, DELETE) according to REST conventions.

**Request Body**: Optional parameters handled with optional chaining
```typescript
const seasonId = req.body?.seasonId ? parseInt(req.body.seasonId) : undefined;
```

**Response Format**: Always include `success` boolean
```typescript
{ success: true, data: [...] }
{ success: false, message: 'Error description' }
```
## Unit Testing
When implementing a new feature or fixing/refactoring, create unit tests for all possible scenarios, including edge cases.
tests must mock database interactions and external resources to ensure isolation and reliability.
**Testing Framework**: vitest
**Test Files**: server/tests/*.test.ts


## Testing with Postman

Pre-configured collections in `server/`:
- `F123Dashboard.postman_collection.json` - All API endpoints
- `F123Dashboard.postman_environment.json` - Local env
- `F123Dashboard.postman_environment.prod.json` - Production env

Auto-authentication flow implemented (see `server/POSTMAN_README.md`)

## Common Patterns

### Adding a New API Endpoint

1. **Service** (`services/*.service.ts`):
```typescript
async getNewData(param: string): Promise<DataType[]> {
const result = await this.pool.query('SELECT * FROM table WHERE id = $1', [param]);
return result.rows;
}
```

2. **Controller** (`controllers/*.controller.ts`):
```typescript
async getNewData(req: Request, res: Response): Promise<void> {
try {
const data = await service.getNewData(req.body.param);
res.json(data);
} catch (error) {
logger.error('Error getting data:', error);
res.status(500).json({ success: false, message: 'Failed to get data' });
}
}
```

3. **Route** (`routes/*.routes.ts`):
```typescript
router.post('/new-data', (req, res) => controller.getNewData(req, res));
// Add authMiddleware if protected
```

4. **Import in server.ts**: Route already mounted if using existing router

### Database Query Pattern

Use parameterized queries to prevent SQL injection:
```typescript
// ✅ Correct
await pool.query('SELECT * FROM users WHERE id = $1', [userId]);

// ❌ Wrong - SQL injection risk
await pool.query(`SELECT * FROM users WHERE id = ${userId}`);
```

## ES Modules Configuration

**Important**: This project uses ES modules (`"type": "module"` in package.json)

- Use `.js` extensions in imports: `import x from './file.js'`
- Use `import` syntax, not `require()`
- Get `__dirname` via:
```typescript
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
```

## Key Files Reference

- **Architecture**: `server/src/server.ts` - Express app setup, middleware chain
- **Auth Flow**: `server/docs/authentication-flow.md` - Complete auth documentation
- **Database Schema**: `.github/instructions/db.instructions.md` - Entry-based result tables
- **Logging Guide**: `server/docs/winston-logging.md` - Winston usage and best practices

## Production Deployment

**Static Files**: Express serves Angular build from `client/dist/browser/` in production
**Fallback**: All non-API routes return `index.html` for Angular routing
**Environment**: Set `NODE_ENV=production` for file logging and optimizations
Loading