# praveenreddy4512/sdp architecture

> Architecture diagram of the GitHub repository praveenreddy4512/sdp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/praveenreddy4512/sdp
- Repository: https://github.com/praveenreddy4512/sdp

## Overview

- Frontend/UI: Represented by the Next.js “pages” in the src/app directory. This includes several distinct sections such as:
– Admin Dashboard (under src/app/admin): managing buses, machines, reports, routes, trips, and vendors.
– Authentication pages (src/app/auth) for login and registration.
– Self-service and vendor POS interfaces (src/app/self-pos and src/app/vendor-pos) for customer interactions.
– Public booking and dashboard pages.
- API Backend: Next.js API routes (under src/app/api) are divided into multiple endpoints. For example:
– Authentication endpoints (src/app/api/auth) for user sessions and registration.
– Domain-specific endpoints for buses, machines, seats, tickets (including cancellation), routes, and trips.
– Reporting endpoints (e.g., sales reports under src/app/api/reports/sales).
- Database: The PostgreSQL database is managed via Prisma. Illustrate the Prisma folder where migrations, schema definitions, and seeds exist.
- Authentication Service: NextAuth.js integration is configured in the API (see the [...nextauth] routes) and further supported by frontend components.
- Utility/Shared Libraries: The src/lib folder, containing helper modules for authentication, database connection, Prisma setup, and scripts for resetting the DB.
- Deployment & Configuration: Include configuration files like next.config.ts, vercel.json, and the deployment README steps that manage environment variables and migration commands.

- API routes act as intermediaries that process requests, interact with business logic, and then communicate with the PostgreSQL database by leveraging Prisma.
- Authentication flows are managed by NextAuth.js: illustrate how the frontend sends credentials that are handled by API endpoints, which in turn interact with the authentication service.
- How the Admin dashboard, Self-Service, and Vendor POS modules each connect to the underlying API for bus and ticket data.
- How the Prisma migrations and seeding scripts ensure that the database schema stays in sync, which is essential during both local development (prisma migrate dev) and production deployment (prisma migrate deploy).

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly demarcate the UI layer, API/business logic layer, and database layer.
- Modular Organization: Each major domain (buses, machines, trips, reports, routes, tickets, vendors) has its own module both at the API and the UI level.
- Extensibility: With separate modules for admin, self-service, and vendor interfaces, it is easier to extend functionalities without interfering with other parts.
- Use of modern, serverless deployment practices (Vercel) so highlight the stateless aspects of API endpoints and the state managed in the database.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Define Global Node
    User("User"):::ui

    %% Frontend/UI Cluster
    subgraph "Frontend/UI"
        AdminUI("Admin Dashboard"):::ui
        AuthUI("Authentication Pages"):::ui
        SelfUI("Self-Service Interface"):::ui
        VendorUI("Vendor POS Interface"):::ui
        PublicUI("Public Booking Page"):::ui
        DashboardUI("Dashboard Page"):::ui
    end

    %% API Backend Cluster
    subgraph "API Backend"
        API_NextAuth("NextAuth Endpoint"):::api
        API_Register("Register Endpoint"):::api
        API_Buses("Buses API"):::api
        API_Machines("Machines API"):::api
        API_Routes("Routes API"):::api
        API_PublicRoutes("Public Routes API"):::api
        API_Seats("Seats API"):::api
        API_Tickets("Tickets API"):::api
        API_TicketCancel("Ticket Cancel API"):::api
        API_Trips("Trips API"):::api
        API_PublicTrips("Public Trips API"):::api
        API_Vendors("Vendors API"):::api
        API_SalesReports("Sales Reports API"):::api
    end

    %% Database Cluster
    subgraph "Database"
        PrismaDB("PostgreSQL DB (Prisma)"):::db
    end

    %% Utility/Shared Libraries Cluster
    subgraph "Utility/Shared Libraries"
        Lib("Utility Library"):::utility
    end

    %% Deployment & Configuration Cluster
    subgraph "Deployment & Configuration"
        NextConfig("Next Config"):::config
        Vercel("Vercel Config"):::config
    end

    %% Connections: User to Frontend/UI
    User -->|"access"| AdminUI
    User -->|"access"| AuthUI
    User -->|"access"| SelfUI
    User -->|"access"| VendorUI
    User -->|"access"| PublicUI
    User -->|"access"| DashboardUI

    %% Connections: UI to API Backend
    %% Admin Dashboard calls domain endpoints
    AdminUI -->|"calls"| API_Buses
    AdminUI -->|"calls"| API_Machines
    AdminUI -->|"calls"| API_Routes
    AdminUI -->|"calls"| API_Tickets
    AdminUI -->|"calls"| API_Trips
    AdminUI -->|"calls"| API_Vendors
    AdminUI -->|"calls"| API_SalesReports

    %% Authentication Pages call auth endpoints
    AuthUI -->|"calls"| API_NextAuth
    AuthUI -->|"calls"| API_Register

    %% Self-Service Interface calls ticket and trip endpoints
    SelfUI -->|"calls"| API_Tickets
    SelfUI -->|"calls"| API_Trips

    %% Vendor POS Interface calls vendor and ticket endpoints
    VendorUI -->|"calls"| API_Vendors
    VendorUI -->|"calls"| API_Tickets

    %% Public Booking Page calls public routes and trips
    PublicUI -->|"calls"| API_PublicRoutes
    PublicUI -->|"calls"| API_PublicTrips

    %% Dashboard Page calls sales reports endpoint
    DashboardUI -->|"calls"| API_SalesReports

    %% Connections: API Endpoints to Database
    API_NextAuth -->|"CRUD"| PrismaDB
    API_Register -->|"CRUD"| PrismaDB
    API_Buses -->|"CRUD"| PrismaDB
    API_Machines -->|"CRUD"| PrismaDB
    API_Routes -->|"CRUD"| PrismaDB
    API_PublicRoutes -->|"CRUD"| PrismaDB
    API_Seats -->|"CRUD"| PrismaDB
    API_Tickets -->|"CRUD"| PrismaDB
    API_TicketCancel -->|"CRUD"| PrismaDB
    API_Trips -->|"CRUD"| PrismaDB
    API_PublicTrips -->|"CRUD"| PrismaDB
    API_Vendors -->|"CRUD"| PrismaDB
    API_SalesReports -->|"CRUD"| PrismaDB

    %% Connections: API Endpoints using Utility Shared Libraries
    API_NextAuth ---|"uses"| Lib
    API_Register ---|"uses"| Lib
    API_Buses ---|"uses"| Lib
    API_Machines ---|"uses"| Lib
    API_Routes ---|"uses"| Lib
    API_PublicRoutes ---|"uses"| Lib
    API_Seats ---|"uses"| Lib
    API_Tickets ---|"uses"| Lib
    API_TicketCancel ---|"uses"| Lib
    API_Trips ---|"uses"| Lib
    API_PublicTrips ---|"uses"| Lib
    API_Vendors ---|"uses"| Lib
    API_SalesReports ---|"uses"| Lib

    %% Styles
    classDef ui fill:#BBDEFB,stroke:#1565C0,stroke-width:2px;
    classDef api fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef db fill:#FFE082,stroke:#FF6F00,stroke-width:2px;
    classDef utility fill:#F8BBD0,stroke:#AD1457,stroke-width:2px;
    classDef config fill:#D1C4E9,stroke:#673AB7,stroke-width:2px;

    %% Click Events
    click AdminUI "https://github.com/praveenreddy4512/sdp/tree/main/src/app/admin"
    click AuthUI "https://github.com/praveenreddy4512/sdp/tree/main/src/app/auth"
    click SelfUI "https://github.com/praveenreddy4512/sdp/tree/main/src/app/self-pos"
    click VendorUI "https://github.com/praveenreddy4512/sdp/tree/main/src/app/vendor-pos"
    click PublicUI "https://github.com/praveenreddy4512/sdp/blob/main/src/app/page.tsx"
    click DashboardUI "https://github.com/praveenreddy4512/sdp/tree/main/src/app/dashboard"

    click API_NextAuth "https://github.com/praveenreddy4512/sdp/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click API_Register "https://github.com/praveenreddy4512/sdp/tree/main/src/app/api/auth/register"
    click API_Buses "https://github.com/praveenreddy4512/sdp/blob/main/src/app/api/buses/route.ts"
    click API_Machines "https://github.com/praveenreddy4512/sdp/blob/main/src/app/api/machines/route.ts"
    click API_Routes "https://github.com/praveenreddy4512/sdp/blob/main/src/app/api/routes/route.ts"
    click API_PublicRoutes "https://github.com/praveenreddy4512/sdp/blob/main/src/app/api/routes/public/route.ts"
    click API_Seats "https://github.com/praveenreddy4512/sdp/blob/main/src/app/api/seats/route.ts"
    click API_Tickets "https://github.com/praveenreddy4512/sdp/blob/main/src/app/api/tickets/route.ts"
    click API_TicketCancel "https://github.com/praveenreddy4512/sdp/blob/main/src/app/api/tickets/cancel/route.ts"
    click API_Trips "https://github.com/praveenreddy4512/sdp/blob/main/src/app/api/trips/route.ts"
    click API_PublicTrips "https://github.com/praveenreddy4512/sdp/blob/main/src/app/api/trips/public/route.ts"
    click API_Vendors "https://github.com/praveenreddy4512/sdp/blob/main/src/app/api/vendors/route.ts"
    click API_SalesReports "https://github.com/praveenreddy4512/sdp/blob/main/src/app/api/reports/sales/route.ts"

    click Lib "https://github.com/praveenreddy4512/sdp/tree/main/src/lib"
    click NextConfig "https://github.com/praveenreddy4512/sdp/blob/main/next.config.ts"
    click Vercel "https://github.com/praveenreddy4512/sdp/blob/main/vercel.json"
    click PrismaDB "https://github.com/praveenreddy4512/sdp/tree/main/prisma"
```
