# kingreapermax/copsweek architecture

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

- Interactive diagram: https://gitdiagram.com/kingreapermax/copsweek
- Repository: https://github.com/kingreapermax/copsweek

## Overview

##### Project type and purpose
- This is a monolithic, server-rendered full-stack web application built with Node.js/Express and EJS templates.
- Purpose: a “Civic Portal” where authenticated users can register, log in, post infrastructure complaints, and view both a general dashboard and personal profile pages.

##### File structure
- Top-level:
- `.gitignore`, `README.md`
- `server/` – main application code
- Inside `server/`:
- `index.js` – Express app entry point (routes, middleware)
- `database.sql` – PostgreSQL schema and table definitions
- `package.json` & lock – dependencies and scripts
- `public/` – static assets (CSS)
- `views/` – EJS templates (login, register, dashboard, user) plus shared partials (header/footer)
- Patterns:
- MVC-style separation:
– Views: `views/`
– Controller & router logic in `index.js` (could be refactored into `controllers/`, `routes/` dirs)
– Model: SQL schema + database connection in `index.js`
- JWT authentication middleware protecting API/endpoints

##### README for additional insights
- Tech stack: Node.js, Express, EJS, PostgreSQL, JWT
- Authentication flow: registration/login → issue JWT → subsequent API requests carry token
- Workflows:
- Public pages: login, register
- Protected pages: dashboard, user profile
- Data flow: user complaint posts → saved in PostgreSQL → retrieved for dashboard

##### Elements
- Clear labels: “Browser / Client,” “Express.js Server,” “JWT Auth Module,” “PostgreSQL DB,” etc.
- Request flow: browser → server → DB
- Response flow: DB → server → browser
- Token issuance: server → browser
- Rectangles for components

##### Final advice
- How EJS templates tie into the view layer.
- JWT token storage and usage cycle.
- Don’t overthink—capture every logical piece (client, routes, auth, DB, static files, views) to make the architecture crystal clear.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        Browser["Browser / Client"]:::client
    end

    %% Server Layer
    subgraph "Express.js Server"
        Router["Express Routes"]:::server
        JWT["JWT Auth Middleware"]:::auth
        subgraph "View Rendering"
            DS["dashboard.ejs"]:::view
            LG["login.ejs"]:::view
            RG["register.ejs"]:::view
            US["user.ejs"]:::view
            subgraph "Partials"
                HD["header.ejs"]:::view
                FT["footer.ejs"]:::view
            end
        end
        subgraph "Static File Serving"
            PublicDir["public/"]:::static
            CSS["styles.css"]:::static
        end
        Dep["package.json"]:::external
    end

    %% Database Layer
    DB["PostgreSQL Database"]:::db

    %% External Config
    Env["Environment Variables"]:::external

    %% Documentation
    Docs["README.md"]:::external
    GitIgnore[".gitignore"]:::external

    %% Connections
    Browser -->|"HTTP Request (public)"| Router
    Router -->|"/login, /register"| DS
    Router -->|"Render EJS"| DS
    Router -->|"Render EJS"| LG
    Router -->|"Render EJS"| RG
    Router -->|"Render EJS"| US
    Router -->|"Include Partials"| HD
    Router -->|"Include Partials"| FT
    Router -->|"Serve Static Assets"| PublicDir
    Browser -->|"GET CSS"| CSS
    Router -->|"Issue JWT Token"| Browser
    Browser -.->|"JWT Token"| Router
    Router -->|"Protected Routes"| JWT
    JWT -->|"Verify Token"| Router
    Router -->|"SQL Queries"| DB
    DB -->|"Data"| Router
    Env -->|"DB Credentials & JWT Secret"| Router
    Env -->|"DB Credentials & JWT Secret"| JWT
    Env -->|"Port Config"| Router
    Env -->|"DB Config"| DB
    Docs --> Router
    GitIgnore --> Router

    %% Click Events
    click Router "https://github.com/kingreapermax/copsweek/blob/main/server/index.js"
    click JWT "https://github.com/kingreapermax/copsweek/blob/main/server/index.js"
    click DB "https://github.com/kingreapermax/copsweek/blob/main/server/database.sql"
    click Dep "https://github.com/kingreapermax/copsweek/blob/main/server/package.json"
    click PublicDir "https://github.com/kingreapermax/copsweek/tree/main/server/public/"
    click CSS "https://github.com/kingreapermax/copsweek/blob/main/server/public/styles.css"
    click DS "https://github.com/kingreapermax/copsweek/blob/main/server/views/dashboard.ejs"
    click LG "https://github.com/kingreapermax/copsweek/blob/main/server/views/login.ejs"
    click RG "https://github.com/kingreapermax/copsweek/blob/main/server/views/register.ejs"
    click US "https://github.com/kingreapermax/copsweek/blob/main/server/views/user.ejs"
    click HD "https://github.com/kingreapermax/copsweek/blob/main/server/views/partials/header.ejs"
    click FT "https://github.com/kingreapermax/copsweek/blob/main/server/views/partials/footer.ejs"
    click Docs "https://github.com/kingreapermax/copsweek/blob/main/README.md"
    click GitIgnore "https://github.com/kingreapermax/copsweek/blob/main/.gitignore"

    %% Styles
    classDef client fill:#9f6,stroke:#060,stroke-width:2px
    classDef server fill:#bbf,stroke:#36c,stroke-width:2px
    classDef auth fill:#fb8,stroke:#f80,stroke-width:2px,stroke-dasharray: 5 5
    classDef view fill:#dbe,stroke:#558,stroke-width:2px
    classDef static fill:#ffecb3,stroke:#cc9,stroke-width:2px
    classDef db fill:#fea,stroke:#a50,stroke-width:2px,stroke-dasharray: 2 2
    classDef external fill:#eee,stroke:#999,stroke-width:1px,stroke-dasharray: 2 2
```
