# julian049/eventsproject architecture

> Architecture diagram of the GitHub repository julian049/eventsproject, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/julian049/eventsproject
- Repository: https://github.com/julian049/eventsproject

## Overview

1. **Overall shape**
   - This is a two-tier event management system: a **Node.js/Express backend** exposes a REST API, and a **React + Vite frontend** consumes it as a SPA.
   - Persistent storage is **PostgreSQL**, typically started via **Docker Compose**.

2. **Backend entry and runtime**
   - `backend/index.js` is the server entry point and likely wires together Express, routes, middleware, and database connectivity from `backend/database.js`.
   - The backend listens on a configurable port and uses environment variables for DB credentials and JWT secrets.

3. **Backend layering**
   - The backend is organized into a classic layered structure:
     - **routes** define HTTP endpoints,
     - **controllers** handle request/response orchestration,
     - **services** contain business rules,
     - **models** encapsulate SQL/data access.
   - This separation is consistent across auth, users, events, categories, ticket types, purchases, tickets, and dashboard features.

4. **Core domain subsystems**
   - The main business entities are **users**, **events**, **categories**, **ticket types**, **event-ticket-type assignments**, **purchases**, and **tickets**.
   - `eventTicketType` acts as the bridge between a base ticket type and a specific event, carrying event-specific pricing/capacity data.
   - `dashboard` is a read-only aggregation subsystem for metrics like sales and popular events.

5. **Authentication and authorization**
   - Authentication is JWT-based, with helpers in `backend/utils/jwt.js` and password hashing in `backend/utils/bcrypt.js`.
   - `backend/middlewares/authMiddleware.js` protects routes that require identity or role checks.
   - `backend/constants/role.js` suggests role-based access control, so some create/admin actions are gated.

6. **Event lifecycle and scheduled behavior**
   - `eventController`, `eventService`, and `eventModel` manage event creation, pagination, detail views, favorites, and interest tracking.
   - `backend/cron/eventCron.js` indicates periodic background work related to event state, likely cleanup or status updates independent of direct user requests.

7. **Purchase and ticket flow**
   - The purchase path runs through `purchaseRoute` → `purchaseController` → `purchaseService` → `purchaseModel`.
   - A successful purchase results in ticket records managed by `ticketController` / `ticketService`, and users can later fetch their own tickets.
   - This is the main transactional flow in the app: selecting an event, choosing ticket types, purchasing, then retrieving issued tickets.

8. **Database and persistence model**
   - `backend/database/init.sql` defines the schema; `seed.sql` provides initial data.
   - The project uses **soft deletes** via a `status` flag instead of removing rows physically.
   - The presence of separate model files with both singular and `*Model.js` variants suggests SQL-centric persistence with thin domain wrappers.

9. **Frontend structure**
   - The frontend is a React SPA built with Vite.
   - `frontend/src/main.jsx` boots the app, `App.jsx` likely defines routing/layout, and `AuthContext.jsx` holds global authentication state.
   - Reusable UI is centralized in `components/` for forms, modals, navbar, and loading states.

10. **Frontend page composition**
   - The pages map directly to major user journeys: browsing events, event details, categories, favorites, checkout, tickets, profile, login/register, and reporting.
   - `EventForm` suggests an admin/editor flow for creating or editing events inside the UI.
   - `ReportPage` corresponds to the backend dashboard/metrics subsystem.

11. **Frontend-to-backend integration**
   - `frontend/src/services/` contains API clients grouped by backend domain: auth, events, categories, checkout, ticket types, users, and dashboard.
   - `AuthContext` likely injects the JWT into requests and controls route access in the UI.
   - The frontend is therefore a thin presentation layer; most business logic lives on the backend.

12. **Infrastructure and deployment boundaries**
   - `docker-compose.yml` is used to provision PostgreSQL, keeping the database outside the application process.
   - The root-level and backend-specific package files indicate separate dependency/runtime boundaries for frontend and backend.
   - GitHub Actions CI is present, so the repo includes automated validation in addition to local dev startup.

Main entry points: [`backend/index.js`](https://github.com/julian049/eventsproject/blob/main/backend/index.js) (Server), [`frontend/src/services/index.js`](https://github.com/julian049/eventsproject/blob/main/frontend/src/services/index.js) (API Client), [`frontend/src/App.jsx`](https://github.com/julian049/eventsproject/blob/main/frontend/src/App.jsx) (App Shell), [`backend/services/purchaseService.js`](https://github.com/julian049/eventsproject/blob/main/backend/services/purchaseService.js) (Purchase Logic)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_backend_entry["Server<br/>express app<br/>[index.js]"]
  node_backend_db[("DB Conn<br/>postgres connector<br/>[database.js]")]
  node_backend_auth_route["Auth API<br/>route<br/>[authRoute.js]"]
  node_backend_event_route["Events API<br/>route<br/>[eventRoute.js]"]
  node_backend_purchase_route["Purchases API<br/>route<br/>[purchaseRoute.js]"]
  node_backend_ticket_route["Tickets API<br/>route<br/>[ticketRoute.js]"]
  node_backend_dashboard_route["Dashboard API<br/>route<br/>[dashboardRoute.js]"]
  node_backend_auth_service["Auth Logic<br/>[authService.js]"]
  node_backend_event_service["Event Logic<br/>[eventService.js]"]
  node_backend_purchase_service["Purchase Logic<br/>[purchaseService.js]"]
  node_backend_ticket_service["Ticket Logic<br/>[ticketService.js]"]
  node_backend_dashboard_service["Metrics Logic"]
  node_backend_event_model["Event Model<br/>sql model<br/>[eventModel.js]"]
  node_backend_user_model["User Model<br/>sql model<br/>[userModel.js]"]
  node_backend_purchase_model["Purchase Model<br/>sql model<br/>[purchaseModel.js]"]
  node_backend_ticket_model["Ticket Model<br/>sql model<br/>[ticketModel.js]"]
end

subgraph group_frontend["Frontend"]
  node_frontend_app["App Shell<br/>react app<br/>[App.jsx]"]
  node_frontend_auth_ctx["Auth State<br/>react context<br/>[AuthContext.jsx]"]
  node_frontend_services["API Client<br/>service layer<br/>[index.js]"]
  node_frontend_pages["Pages<br/>[EventsPage.jsx]"]
  node_frontend_components["UI Kit<br/>shared components<br/>[Navbar.jsx]"]
end

subgraph group_infra["Infra"]
  node_docker_compose["Compose<br/>infra<br/>[docker-compose.yml]"]
  node_db_schema[("Schema<br/>[init.sql]")]
  node_ci_workflow["CI<br/>workflow<br/>[ci.yml]"]
end

node_backend_entry -->|"connects"| node_backend_db
node_backend_entry -->|"mounts"| node_backend_auth_route
node_backend_entry -->|"mounts"| node_backend_event_route
node_backend_entry -->|"mounts"| node_backend_purchase_route
node_backend_entry -->|"mounts"| node_backend_ticket_route
node_backend_entry -->|"mounts"| node_backend_dashboard_route
node_backend_auth_route -->|"calls"| node_backend_auth_service
node_backend_event_route -->|"calls"| node_backend_event_service
node_backend_purchase_route -->|"calls"| node_backend_purchase_service
node_backend_ticket_route -->|"calls"| node_backend_ticket_service
node_backend_dashboard_route -->|"calls"| node_backend_dashboard_service
node_backend_auth_service -->|"uses"| node_backend_user_model
node_backend_event_service -->|"uses"| node_backend_event_model
node_backend_purchase_service -->|"uses"| node_backend_purchase_model
node_backend_purchase_service -->|"issues"| node_backend_ticket_model
node_backend_ticket_service -->|"uses"| node_backend_ticket_model
node_backend_dashboard_service -->|"aggregates"| node_backend_event_model
node_frontend_app -->|"uses"| node_frontend_auth_ctx
node_frontend_app -->|"calls"| node_frontend_services
node_frontend_app -->|"renders"| node_frontend_pages
node_frontend_app -->|"uses"| node_frontend_components
node_frontend_services -.->|"auth api"| node_backend_auth_route
node_frontend_services -.->|"events api"| node_backend_event_route
node_frontend_services -.->|"checkout api"| node_backend_purchase_route
node_frontend_services -.->|"tickets api"| node_backend_ticket_route
node_frontend_services -.->|"dashboard api"| node_backend_dashboard_route
node_docker_compose -->|"provisions"| node_db_schema
node_backend_db -->|"depends on"| node_db_schema
node_ci_workflow -.->|"validates"| node_backend_entry
node_ci_workflow -.->|"validates"| node_frontend_app

click node_backend_entry "https://github.com/julian049/eventsproject/blob/main/backend/index.js"
click node_backend_db "https://github.com/julian049/eventsproject/blob/main/backend/database.js"
click node_backend_auth_route "https://github.com/julian049/eventsproject/blob/main/backend/routes/authRoute.js"
click node_backend_event_route "https://github.com/julian049/eventsproject/blob/main/backend/routes/eventRoute.js"
click node_backend_purchase_route "https://github.com/julian049/eventsproject/blob/main/backend/routes/purchaseRoute.js"
click node_backend_ticket_route "https://github.com/julian049/eventsproject/blob/main/backend/routes/ticketRoute.js"
click node_backend_dashboard_route "https://github.com/julian049/eventsproject/blob/main/backend/routes/dashboardRoute.js"
click node_backend_auth_service "https://github.com/julian049/eventsproject/blob/main/backend/services/authService.js"
click node_backend_event_service "https://github.com/julian049/eventsproject/blob/main/backend/services/eventService.js"
click node_backend_purchase_service "https://github.com/julian049/eventsproject/blob/main/backend/services/purchaseService.js"
click node_backend_ticket_service "https://github.com/julian049/eventsproject/blob/main/backend/services/ticketService.js"
click node_backend_dashboard_service "https://github.com/julian049/eventsproject/blob/main/backend/services/dashboardService.js"
click node_backend_event_model "https://github.com/julian049/eventsproject/blob/main/backend/models/eventModel.js"
click node_backend_user_model "https://github.com/julian049/eventsproject/blob/main/backend/models/userModel.js"
click node_backend_purchase_model "https://github.com/julian049/eventsproject/blob/main/backend/models/purchaseModel.js"
click node_backend_ticket_model "https://github.com/julian049/eventsproject/blob/main/backend/models/ticketModel.js"
click node_frontend_app "https://github.com/julian049/eventsproject/blob/main/frontend/src/App.jsx"
click node_frontend_auth_ctx "https://github.com/julian049/eventsproject/blob/main/frontend/src/context/AuthContext.jsx"
click node_frontend_services "https://github.com/julian049/eventsproject/blob/main/frontend/src/services/index.js"
click node_frontend_pages "https://github.com/julian049/eventsproject/blob/main/frontend/src/pages/EventsPage/EventsPage.jsx"
click node_frontend_components "https://github.com/julian049/eventsproject/blob/main/frontend/src/components/Navbar/Navbar.jsx"
click node_docker_compose "https://github.com/julian049/eventsproject/blob/main/docker-compose.yml"
click node_db_schema "https://github.com/julian049/eventsproject/blob/main/backend/database/init.sql"
click node_ci_workflow "https://github.com/julian049/eventsproject/blob/main/.github/workflows/ci.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_backend_entry,node_backend_db,node_backend_auth_route,node_backend_event_route,node_backend_purchase_route,node_backend_ticket_route,node_backend_dashboard_route,node_backend_auth_service,node_backend_event_service,node_backend_purchase_service,node_backend_ticket_service,node_backend_dashboard_service,node_backend_event_model,node_backend_user_model,node_backend_purchase_model,node_backend_ticket_model toneBlue
class node_frontend_app,node_frontend_auth_ctx,node_frontend_services,node_frontend_pages,node_frontend_components toneAmber
class node_docker_compose,node_db_schema,node_ci_workflow toneMint
```

## Components

### Backend

Express API, business logic, and PostgreSQL persistence

- [Server](https://github.com/julian049/eventsproject/blob/main/backend/index.js): express app · Backend entry point wiring routes, middleware, and server startup · `backend/index.js`
- [DB Conn](https://github.com/julian049/eventsproject/blob/main/backend/database.js): postgres connector · Database connection and shared SQL access setup · `backend/database.js`
- [Auth API](https://github.com/julian049/eventsproject/blob/main/backend/routes/authRoute.js): route · Login and registration endpoints · `backend/routes/authRoute.js`
- [Events API](https://github.com/julian049/eventsproject/blob/main/backend/routes/eventRoute.js): route · Event browsing and event lifecycle endpoints · `backend/routes/eventRoute.js`
- [Purchases API](https://github.com/julian049/eventsproject/blob/main/backend/routes/purchaseRoute.js): route · Checkout and purchase endpoints · `backend/routes/purchaseRoute.js`
- [Tickets API](https://github.com/julian049/eventsproject/blob/main/backend/routes/ticketRoute.js): route · Issued ticket retrieval endpoints · `backend/routes/ticketRoute.js`
- [Dashboard API](https://github.com/julian049/eventsproject/blob/main/backend/routes/dashboardRoute.js): route · Read-only reporting and metrics endpoints · `backend/routes/dashboardRoute.js`
- [Auth Logic](https://github.com/julian049/eventsproject/blob/main/backend/services/authService.js): service · Credential handling, JWT issuance, and auth flows · `backend/services/authService.js`
- [Event Logic](https://github.com/julian049/eventsproject/blob/main/backend/services/eventService.js): service · Event creation, paging, favorites, and interest rules · `backend/services/eventService.js`
- [Purchase Logic](https://github.com/julian049/eventsproject/blob/main/backend/services/purchaseService.js): service · Transactional purchase orchestration · `backend/services/purchaseService.js`
- [Ticket Logic](https://github.com/julian049/eventsproject/blob/main/backend/services/ticketService.js): service · Ticket issuance and retrieval rules · `backend/services/ticketService.js`
- [Metrics Logic](https://github.com/julian049/eventsproject/blob/main/backend/services/dashboardService.js): service · Aggregates sales and popularity metrics · `backend/services/dashboardService.js`
- [Event Model](https://github.com/julian049/eventsproject/blob/main/backend/models/eventModel.js): sql model · Event data access and persistence · `backend/models/eventModel.js`
- [User Model](https://github.com/julian049/eventsproject/blob/main/backend/models/userModel.js): sql model · User data access and persistence · `backend/models/userModel.js`
- [Purchase Model](https://github.com/julian049/eventsproject/blob/main/backend/models/purchaseModel.js): sql model · Purchase persistence and lookup · `backend/models/purchaseModel.js`
- [Ticket Model](https://github.com/julian049/eventsproject/blob/main/backend/models/ticketModel.js): sql model · Ticket persistence and lookup · `backend/models/ticketModel.js`

### Frontend

React SPA and API client layer

- [App Shell](https://github.com/julian049/eventsproject/blob/main/frontend/src/App.jsx): react app · Top-level SPA composition and routing · `frontend/src/App.jsx`
- [Auth State](https://github.com/julian049/eventsproject/blob/main/frontend/src/context/AuthContext.jsx): react context · Global authentication state and token handling · `frontend/src/context/AuthContext.jsx`
- [API Client](https://github.com/julian049/eventsproject/blob/main/frontend/src/services/index.js): service layer · Domain API clients for backend integration · `frontend/src/services/index.js`
- [Pages](https://github.com/julian049/eventsproject/blob/main/frontend/src/pages/EventsPage/EventsPage.jsx): ui pages · User journeys for browsing, checkout, profile, and reporting · `frontend/src/pages/EventsPage/EventsPage.jsx`
- [UI Kit](https://github.com/julian049/eventsproject/blob/main/frontend/src/components/Navbar/Navbar.jsx): shared components · Reusable forms, modals, navbar, and spinner components · `frontend/src/components/Navbar/Navbar.jsx`

### Infra

Containerization, schema, and CI

- [Compose](https://github.com/julian049/eventsproject/blob/main/docker-compose.yml): infra · Database provisioning and local service orchestration · `docker-compose.yml`
- [Schema](https://github.com/julian049/eventsproject/blob/main/backend/database/init.sql): sql schema · Database schema and seed data · `backend/database/init.sql`
- [CI](https://github.com/julian049/eventsproject/blob/main/.github/workflows/ci.yml): workflow · Automated validation pipeline · `.github/workflows/ci.yml`

## Connections

- Server → DB Conn: connects · Initializes and uses the shared database layer
- Server → Auth API: mounts · Registers auth endpoints
- Server → Events API: mounts · Registers event endpoints
- Server → Purchases API: mounts · Registers purchase endpoints
- Server → Tickets API: mounts · Registers ticket endpoints
- Server → Dashboard API: mounts · Registers reporting endpoints
- Auth API → Auth Logic: calls · Delegates auth requests to business logic
- Events API → Event Logic: calls · Delegates event requests to business logic
- Purchases API → Purchase Logic: calls · Delegates checkout flow to business logic
- Tickets API → Ticket Logic: calls · Delegates ticket requests to business logic
- Dashboard API → Metrics Logic: calls · Delegates metrics requests to business logic
- Auth Logic → User Model: uses · Reads and writes user records
- Event Logic → Event Model: uses · Reads and writes event records
- Purchase Logic → Purchase Model: uses · Persists purchase transactions
- Purchase Logic → Ticket Model: issues · Creates ticket records after purchase
- Ticket Logic → Ticket Model: uses · Fetches issued tickets
- Metrics Logic → Event Model: aggregates · Builds metrics from event and sales data
- App Shell → Auth State: uses · Shares login state across the SPA
- App Shell → API Client: calls · Uses API clients for backend requests
- App Shell → Pages: renders · Composes the main page flows
- App Shell → UI Kit: uses · Reuses common UI building blocks
- API Client → Auth API: auth api · Calls auth endpoints
- API Client → Events API: events api · Calls event endpoints
- API Client → Purchases API: checkout api · Calls purchase endpoints
- API Client → Tickets API: tickets api · Calls ticket endpoints
- API Client → Dashboard API: dashboard api · Calls reporting endpoints
- Compose → Schema: provisions · Starts PostgreSQL with initialized schema/data
- DB Conn → Schema: depends on · Uses the defined schema and seed data
- CI → Server: validates · Runs backend checks in CI
- CI → App Shell: validates · Runs frontend checks in CI
