# seanhao/jobboard architecture

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

- Interactive diagram: https://gitdiagram.com/seanhao/jobboard
- Repository: https://github.com/seanhao/jobboard

## Overview

##### Project type and purpose
- This is a full-stack web application (“人力銀行網站”) built on Node.js using the Koa framework for the backend and MongoDB as the datastore.
- It provides job posting CRUD, address lookups via Google Maps API, article search/comments, OAuth (Facebook/Google) login, and role-based account permissions.

##### File-structure analysis
- Top-level entry: **app.js**
- **config/**: app initialization and environment settings
- **routes/**: route definitions (admin_route.js, route.js)
- **controls/**: controller layer (subfolders for admin vs. app/user flows)
- **models/**: data schemas and MongoDB access logic
- **views/**: HTML templates (admin & app views)
- **public/**: static assets (Bootstrap/AdminLTE theme, JS/CSS plugins, images)

This follows an MVC-style pattern:
- Models (models/)
- Controllers (controls/) invoked by Routes (routes/)
- Views (views/) rendered server-side
- Static resource serving from public/

##### Key README insights
- Backend: Koa (Node.js)
- Datastore: MongoDB
- External integrations: Google Maps API, OAuth providers
- Core features: job management, search, commenting, multi-provider sign-in, RBAC

##### Main components
a. Client layer (Web browser)
- Requests HTML views & static assets
- Forms/JS calls to REST endpoints
b. Static asset layer (public/)
- CSS/JS/theme served by Koa’s static middleware
c. Application server (Koa app)
- app.js (entry)
- config/init & config/config.js (bootstrapping, environment)
- routes/* → map URL → controls/*
- controls/admin & controls/app (business logic)
- models/models.js (MongoDB schemas & queries)
d. Database (MongoDB)
e. External services
- Google Maps API (geocoding, maps)
- OAuth providers (Facebook, Google)

##### Relationships and interactions
- Browser → HTTP GET/POST → Koa server
- Koa server routes → controllers → models → MongoDB (CRUD)
- Controllers call external APIs (Google Maps, OAuth flows)
- Server renders views (HTML) or returns JSON
- Browser fetches static assets (CSS, JS, plugins) in parallel

##### Architectural patterns & design principles
- MVC (Model, View, Controller) separation
- Single Koa process handles routing & rendering
- Static asset pipeline (public/) separate from dynamic logic
- Layered security: OAuth + role-based access in controllers

- All top-level directories as grouped components (config, routes, controls, models, views, public)
- Notes on OAuth and Google Maps integrations

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend Layer"
        Browser(["Web Browser"]):::frontend
        subgraph "Views"
            subgraph "Admin Views"
                VAdmin["admin.html"]:::frontend
                VCreate["create.html"]:::frontend
                VEdit["edit.html"]:::frontend
                VProfile["profile.html"]:::frontend
                VProfileEdit["profile_edit.html"]:::frontend
            end
            subgraph "App Views"
                VAppIndex["index.html"]:::frontend
                VAppDetail["detail.html"]:::frontend
                VAppLogin["login.html"]:::frontend
                VAppRegister["register.html"]:::frontend
                VAppVerify["verification.html"]:::frontend
                VLayout["layout.html"]:::frontend
                VIndexMain["index.html"]:::frontend
            end
        end
        Static["Static Assets (public/)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        App["Koa app.js"]:::backend
        ConfigInit["config/init.js"]:::backend
        Config["config/config.js"]:::backend
        subgraph "Routes"
            Route["routes/route.js"]:::backend
            AdminRoute["routes/admin_route.js"]:::backend
        end
        subgraph "Controllers"
            subgraph "Admin Controllers"
                AdminIndex["controls/admin/admin.js"]:::backend
                AdminCreate["controls/admin/create.js"]:::backend
            end
            subgraph "App Controllers"
                AppIndex["controls/app/index.js"]:::backend
                AppDetail["controls/app/detail.js"]:::backend
                AppLogin["controls/app/login.js"]:::backend
                AppRegister["controls/app/register.js"]:::backend
                AppSignout["controls/app/signout.js"]:::backend
            end
        end
        Model["models/models.js"]:::backend
    end

    %% Data Store
    subgraph "Data Store"
        DB["MongoDB"]:::datastore
    end

    %% External Services
    subgraph "External Services"
        GoogleMaps["Google Maps API"]:::external
        OAuthFB["Facebook OAuth"]:::external
        OAuthG["Google OAuth"]:::external
    end

    %% Data Flows
    Browser -->|"HTTP GET/POST"| App
    Browser --> Static
    Static --> Browser
    App --> ConfigInit
    App --> Config
    App --> Route
    App --> AdminRoute
    Route --> AppIndex
    Route --> AppDetail
    Route --> AppLogin
    Route --> AppRegister
    Route --> AppSignout
    AdminRoute --> AdminIndex
    AdminRoute --> AdminCreate
    App --> VAdmin
    App --> VCreate
    App --> VEdit
    App --> VProfile
    App --> VProfileEdit
    App --> VAppIndex
    App --> VAppDetail
    App --> VAppLogin
    App --> VAppRegister
    App --> VAppVerify
    App --> VLayout
    App --> VIndexMain
    AdminIndex --> Model
    AdminCreate --> Model
    AppIndex --> Model
    AppDetail --> Model
    AppLogin --> Model
    AppRegister --> Model
    AppSignout --> Model
    Model --> DB
    AdminIndex --> GoogleMaps
    AdminCreate --> GoogleMaps
    AppIndex --> GoogleMaps
    AppDetail --> GoogleMaps
    AppLogin --> OAuthFB
    AppRegister --> OAuthG

    %% Click Events
    click App "https://github.com/seanhao/jobboard/blob/master/app.js"
    click ConfigInit "https://github.com/seanhao/jobboard/blob/master/config/init.js"
    click Config "https://github.com/seanhao/jobboard/blob/master/config/config.js"
    click Route "https://github.com/seanhao/jobboard/blob/master/routes/route.js"
    click AdminRoute "https://github.com/seanhao/jobboard/blob/master/routes/admin_route.js"
    click AdminIndex "https://github.com/seanhao/jobboard/blob/master/controls/admin/admin.js"
    click AdminCreate "https://github.com/seanhao/jobboard/blob/master/controls/admin/create.js"
    click AppIndex "https://github.com/seanhao/jobboard/blob/master/controls/app/index.js"
    click AppDetail "https://github.com/seanhao/jobboard/blob/master/controls/app/detail.js"
    click AppLogin "https://github.com/seanhao/jobboard/blob/master/controls/app/login.js"
    click AppRegister "https://github.com/seanhao/jobboard/blob/master/controls/app/register.js"
    click AppSignout "https://github.com/seanhao/jobboard/blob/master/controls/app/signout.js"
    click Model "https://github.com/seanhao/jobboard/blob/master/models/models.js"
    click Static "https://github.com/seanhao/jobboard/tree/master/public/"
    click GoogleMaps "https://github.com/seanhao/jobboard/blob/master/public/map/googlemap.js"
    click VAdmin "https://github.com/seanhao/jobboard/blob/master/views/admin/admin.html"
    click VCreate "https://github.com/seanhao/jobboard/blob/master/views/admin/create.html"
    click VEdit "https://github.com/seanhao/jobboard/blob/master/views/admin/edit.html"
    click VProfile "https://github.com/seanhao/jobboard/blob/master/views/admin/profile.html"
    click VProfileEdit "https://github.com/seanhao/jobboard/blob/master/views/admin/profile_edit.html"
    click VAppIndex "https://github.com/seanhao/jobboard/blob/master/views/app/index.html"
    click VAppDetail "https://github.com/seanhao/jobboard/blob/master/views/app/detail.html"
    click VAppLogin "https://github.com/seanhao/jobboard/blob/master/views/app/login.html"
    click VAppRegister "https://github.com/seanhao/jobboard/blob/master/views/app/register.html"
    click VAppVerify "https://github.com/seanhao/jobboard/blob/master/views/app/verification.html"
    click VLayout "https://github.com/seanhao/jobboard/blob/master/views/layout.html"
    click VIndexMain "https://github.com/seanhao/jobboard/blob/master/views/index.html"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef datastore fill:#fff3cd,stroke:#856404,color:#856404
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
