# shirakuyanai/comp1640 architecture

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

- Interactive diagram: https://gitdiagram.com/shirakuyanai/comp1640
- Repository: https://github.com/shirakuyanai/comp1640

## Overview

##### Main Components
- Frontend (Web Client): Located in the “web” folder. It contains presentation elements (pages, components, UI libraries), state management (GlobalStateContext), and actions for API calls (getData, postData). It uses Vite for bundling.
- Backend (Server): Found in the “server” folder. This comprises:
- Configuration and Setup: Includes environment variables (.env.example), database configuration (db_config.js, drizzle.config.js), and migration scripts.
- API Routes: In “server/src/routes” (e.g., class.js) handling HTTP requests.
- Business Logic & Utilities: Library functions (auth.js, encrypt.js, logger.js, mailer.js) and controllers interact with the database.
- Data Models/Schema: Located in “server/src/schema” and “server/src/db” representing entities like User, Class, Meeting, Role, etc.
- Database: A PostgreSQL database (configured via migration steps and the “demo_data” folder containing demo files) that holds the persistent data needed by the backend.

##### Relationships and Interactions
- The Frontend sends HTTP requests (and possibly socket messages, as suggested by “web/src/lib/socket.tsx”) to the Backend API endpoints.
- The Backend receives these requests via its routing modules, applies business logic (with help from the libraries in “lib”), and performs read/write operations using the database.
- The utilities (authentication, encryption, logger, mailer) support secure and reliable data processing and communication.
- Environment and configuration files (both in “server” and “web”) ensure proper setup and separation of concerns (e.g., API_KEY management).

##### Architectural Patterns & Design Principles
- Separation of Concerns: Clear split between frontend and backend components.
- API-Driven Communication: The client and server interact via well-defined REST (or potentially socket) endpoints.
- Modular Structure: Backend code is organized into configuration, routes, database models, and utility libraries. Similarly, the frontend has a modular component structure (pages, UI components, actions, and schemas).
- Data Migration/Seeding: The server includes migration scripts and demo data which are crucial for setting up the database schema.

##### Relevant Technologies & Frameworks
- Node.js for the backend, with packages managed via npm.
- Drizzle ORM (as suggested by “drizzle.config.js”) for database interaction.
- PostgreSQL as the underlying database.
- React (and potentially TypeScript) for the front-end application.
- Vite as the build tool for the web client.
- Additional libraries for UI components, routing, and utility functions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend – Web Client (React/Vite)"
        F1["Web Client"]:::frontendStyle
        F2["UI Components & Pages"]:::frontendStyle
        F3["Global State Management"]:::frontendStyle
        F4["API Actions (getData,postData)"]:::frontendStyle
        F5["Socket Communication"]:::frontendStyle
        F6["Build & Environment Configs"]:::frontendStyle
    end

    subgraph "Backend – Node.js Server"
        B1["Server Entry Point"]:::backendStyle
        B2["Configuration & DB Setup"]:::backendStyle
        B3["API Routes"]:::backendStyle
        B4["Business Logic & Utilities"]:::backendStyle
        B5["Data Models & Schemas"]:::backendStyle
        B6["Data Migration & Seeding"]:::backendStyle
    end

    DB["PostgreSQL Database"]:::dbStyle

    %% Frontend Internal Flow (optional grouping)
    F2 --> F4
    F3 --> F4
    F5 --> F4

    %% External Flow: Frontend to Backend
    F4 -->|"HTTP_requests"| B3

    %% Backend internal flow
    B1 -->|"initializes"| B2
    B2 -->|"configures"| B3
    B3 -->|"invokes"| B4
    B3 -->|"queries"| B5
    B4 -->|"uses"| B5
    B5 -->|"CRUD_operations"| DB
    B6 -->|"seeds"| DB
    DB -->|"responses"| B3
    B3 -->|"HTTP_response"| F4

    %% Click Events for Frontend Components
    click F1 "https://github.com/shirakuyanai/comp1640/tree/main/web/"
    click F2 "https://github.com/shirakuyanai/comp1640/tree/main/web/src/Components"
    click F3 "https://github.com/shirakuyanai/comp1640/blob/main/web/src/misc/GlobalStateContext.tsx"
    click F4 "https://github.com/shirakuyanai/comp1640/blob/main/web/src/actions/getData.tsx"
    click F5 "https://github.com/shirakuyanai/comp1640/blob/main/web/src/lib/socket.tsx"
    click F6 "https://github.com/shirakuyanai/comp1640/blob/main/web/vite.config.ts"

    %% Click Events for Backend Components
    click B1 "https://github.com/shirakuyanai/comp1640/blob/main/server/src/index.js"
    click B2 "https://github.com/shirakuyanai/comp1640/blob/main/server/src/config/db_config.js"
    click B3 "https://github.com/shirakuyanai/comp1640/blob/main/server/src/routes/class.js"
    click B4 "https://github.com/shirakuyanai/comp1640/blob/main/server/src/lib/auth.js"
    click B5 "https://github.com/shirakuyanai/comp1640/blob/main/server/src/schema/Class.js"
    click B6 "https://github.com/shirakuyanai/comp1640/blob/main/server/src/seed.js"

    %% Styles
    classDef frontendStyle fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef backendStyle fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef dbStyle fill:#F5B7B1,stroke:#333,stroke-width:2px;
```
