# kanmikan/c-chan architecture

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

- Interactive diagram: https://gitdiagram.com/kanmikan/c-chan
- Repository: https://github.com/kanmikan/c-chan

## Overview

##### Main system components
- Client (web browser)
- Web server (Node.js/Express)
- HTTP Server & Static asset serving
- View Renderer (EJS templates under client/views)
- API Layer (server/api/*.js + server/api/*.js modules)
- Business Logic & Middleware (server/routes.js, server/utils.js, server/sesion/, server/extra/)
- Data Access Layer (server/db/*: cache.js, dbmanager.js, models/)
- Database (MongoDB Atlas or local)
- External Services
- YouTube API
- Cloudinary or ImgBB
- Background Bots & Cron threads (server/extra/*.js, controlled via CRON_THREADS)

##### Relationships & data flows
- Browser → HTTPS → Express Router
- Router applies middleware (session management, rate limiter, sanitizer)
- Depending on the request:
- Static GET (CSS/JS/images) → Express static middleware (client/static/)
- View requests → EJS renderer uses views + fragments → HTML → Browser
- API calls → server/api modules → business logic → DB or external service → JSON response
- DB access flows: Express → dbmanager.js → specific model schemes → MongoDB
- External calls: API modules call YouTube, Cloudinary or ImgBB SDKs, return data to controllers
- Bots/Cron threads run independently, access the same DB & push content/alerts

##### Architectural patterns & design principles
- MVC-like separation:
- Models: server/db/models/*
- Views: client/views/*.ejs
- Controllers: server/api/*.js & server/routes.js
- Layered pattern:
- Presentation → Business → Data Access → Database
- Middleware pattern for cross-cutting concerns (sessions, sanitization, limiting)
- Plugin-style extensions via server/extra bots

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Client["Web Browser"]:::presentation
        Static["Static Assets (CSS/JS/Images)"]:::presentation
        EJS["EJS Templates"]:::presentation
    end

    Client -->|HTTPS| HTTP
    HTTP["HTTP Server & Static Asset Serving"]:::application
    HTTP --> Static
    HTTP --> EJS
    click Client "https://github.com/kanmikan/c-chan/tree/mv2/client/views/"
    click Static "https://github.com/kanmikan/c-chan/tree/mv2/client/static/"
    click EJS "https://github.com/kanmikan/c-chan/tree/mv2/client/views/"

    %% Application Server Layer
    subgraph "Application Server (Node.js/Express)"
        direction TB
        Router["Express Router"]:::application
        Middleware["Middleware & Utilities"]:::application
        subgraph "API Layer"
            direction TB
            Access["access.js"]:::api
            Avatar["avatar.js"]:::api
            Builder["builder.js"]:::api
            Cloudinary["cloudinary.js"]:::api
            Live["live.js"]:::api
            LiveWS["livews.js"]:::api
            Moderation["moderation.js"]:::api
            Parser["parser.js"]:::api
            Passport["passport.js"]:::api
            Recycle["recyclemanager.js"]:::api
            Sanitizer["sanitizer.js"]:::api
            Upload["upload.js"]:::api
            YouTube["youtube.js"]:::api
        end
        Business["Business Logic (routes.js)"]:::application
    end

    HTTP --> Router
    Router --> Middleware
    Router --> EJS
    Router --> API_Layer[API Layer]
    Middleware --> Business
    Business --> API_Layer
    click HTTP "https://github.com/kanmikan/c-chan/blob/mv2/app.js"
    click Router "https://github.com/kanmikan/c-chan/blob/mv2/server/routes.js"
    click Middleware "https://github.com/kanmikan/c-chan/blob/mv2/server/utils.js"
    click Access "https://github.com/kanmikan/c-chan/blob/mv2/server/api/access.js"
    click Avatar "https://github.com/kanmikan/c-chan/blob/mv2/server/api/avatar.js"
    click Builder "https://github.com/kanmikan/c-chan/blob/mv2/server/api/builder.js"
    click Cloudinary "https://github.com/kanmikan/c-chan/blob/mv2/server/api/cloudinary.js"
    click Live "https://github.com/kanmikan/c-chan/blob/mv2/server/api/live.js"
    click LiveWS "https://github.com/kanmikan/c-chan/blob/mv2/server/api/livews.js"
    click Moderation "https://github.com/kanmikan/c-chan/blob/mv2/server/api/moderation.js"
    click Parser "https://github.com/kanmikan/c-chan/blob/mv2/server/api/parser.js"
    click Passport "https://github.com/kanmikan/c-chan/blob/mv2/server/api/passport.js"
    click Recycle "https://github.com/kanmikan/c-chan/blob/mv2/server/api/recyclemanager.js"
    click Sanitizer "https://github.com/kanmikan/c-chan/blob/mv2/server/api/sanitizer.js"
    click Upload "https://github.com/kanmikan/c-chan/blob/mv2/server/api/upload.js"
    click YouTube "https://github.com/kanmikan/c-chan/blob/mv2/server/api/youtube.js"

    %% Middleware components
    subgraph "Session & Rate Limiting"
        direction TB
        ContentFilter["contentfilter.js"]:::application
        Limiter["limiter.js"]:::application
        SessionManager["sesionmanager.js"]:::application
    end
    Middleware --> ContentFilter
    Middleware --> Limiter
    Middleware --> SessionManager
    click ContentFilter "https://github.com/kanmikan/c-chan/blob/mv2/server/sesion/contentfilter.js"
    click Limiter "https://github.com/kanmikan/c-chan/blob/mv2/server/sesion/limiter.js"
    click SessionManager "https://github.com/kanmikan/c-chan/blob/mv2/server/sesion/sesionmanager.js"

    %% Configuration
    Config["Configuration Files"]:::application
    Config --> Router
    click Config "https://github.com/kanmikan/c-chan/blob/mv2/server/config/serverconfig.js"
    click Config "https://github.com/kanmikan/c-chan/blob/mv2/server/config/renderconfig.js"

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        Cache["cache.js"]:::data
        DBManager["dbmanager.js"]:::data
        Compat["compat.js"]:::data
        Defaults["defaults.js"]:::data
        subgraph "Models"
            direction TB
            DBModels["dbmodels.js"]:::data
            DefaultScheme["defaultscheme.js"]:::data
            JSONScheme["jsonscheme.js"]:::data
            MDBScheme["mdbscheme.js"]:::data
        end
    end
    Business --> DBManager
    DBManager --> Cache
    DBManager --> Compat
    DBManager --> Defaults
    DBManager --> DBModels
    DBManager --> DefaultScheme
    DBManager --> JSONScheme
    DBManager --> MDBScheme
    click Cache "https://github.com/kanmikan/c-chan/blob/mv2/server/db/cache.js"
    click DBManager "https://github.com/kanmikan/c-chan/blob/mv2/server/db/dbmanager.js"
    click Compat "https://github.com/kanmikan/c-chan/blob/mv2/server/db/compat.js"
    click Defaults "https://github.com/kanmikan/c-chan/blob/mv2/server/db/defaults.js"
    click DBModels "https://github.com/kanmikan/c-chan/blob/mv2/server/db/models/dbmodels.js"
    click DefaultScheme "https://github.com/kanmikan/c-chan/blob/mv2/server/db/models/defaultscheme.js"
    click JSONScheme "https://github.com/kanmikan/c-chan/blob/mv2/server/db/models/jsonscheme.js"
    click MDBScheme "https://github.com/kanmikan/c-chan/blob/mv2/server/db/models/mdbscheme.js"

    %% Database
    Database[(MongoDB Database)]:::database
    DBManager -->|Queries| Database

    %% External Services
    subgraph "External Services"
        direction TB
        YouTubeAPI["YouTube API"]:::external
        CloudService["Cloudinary/ImgBB"]:::external
    end
    API_Layer -->|REST/SDK| YouTubeAPI
    API_Layer -->|REST/SDK| CloudService

    %% Bots & Cron Threads
    subgraph "Background Bots & Cron Threads"
        direction TB
        ContentInterface["contentinterface.js"]:::bots
        Malbot["malbotv2.js"]:::bots
        Threads["threads.js"]:::bots
        Yuubot["yuubot.js"]:::bots
    end
    ContentInterface --> Database
    Malbot --> Database
    Threads --> Database
    Yuubot --> Database
    click ContentInterface "https://github.com/kanmikan/c-chan/blob/mv2/server/extra/contentinterface.js"
    click Malbot "https://github.com/kanmikan/c-chan/blob/mv2/server/extra/malbotv2.js"
    click Threads "https://github.com/kanmikan/c-chan/blob/mv2/server/extra/threads.js"
    click Yuubot "https://github.com/kanmikan/c-chan/blob/mv2/server/extra/yuubot.js"

    %% Classes
    classDef presentation fill:#D0E6FF,stroke:#005B96,color:#005B96
    classDef application fill:#DFF4DD,stroke:#228B22,color:#228B22
    classDef api fill:#E0F7FA,stroke:#00796B,color:#00796B
    classDef data fill:#FFF4E5,stroke:#FF8C00,color:#FF8C00
    classDef database fill:#FFE5E5,stroke:#C62828,color:#C62828
    classDef external fill:#F3E5F5,stroke:#6A1B9A,color:#6A1B9A
    classDef bots fill:#ECEFF1,stroke:#546E7A,color:#546E7A
```
