# insektionen/control-app architecture

> Architecture diagram of the GitHub repository insektionen/control-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/insektionen/control-app
- Repository: https://github.com/insektionen/control-app

## Overview

##### Main System Components

a) Frontend Layer:
- Next.js Application (Client-side)
- Components Structure
- Pages Structure
- API Routes

b) Backend Layer:
- Next.js API Routes
- MongoDB Database (indicated by mongo-init.js)

c) External Systems:
- Lights Control System
- Sound System

- Pages
- Collections Views
- Help Page
- Home Page
- Components
- Layout
- ActionButton
- EditPile
- Other UI Components

- Next.js API Routes
- /api/[id]
- /api/index

- MongoDB
- Light System Interface
- Sound System Interface

##### Key Relationships to Highlight

- Flow from pages through API routes to the database
- Connection between API routes and external systems
- Demonstrate the component hierarchy in the frontend

##### Technical Details

Annotations for:
- TypeScript usage (indicated by tsconfig.json)
- Docker containerization (Dockerfile, docker-compose.yml)
- Environment configurations (.env.development)
- Testing infrastructure (Jest)

##### Additional Notes

A small section showing:
- Development tools integration
- CI/CD workflow (from .github/workflows)
- Docker container architecture

This approach will give other engineers a clear understanding of both the application's structure and its role as a control system for the physical infrastructure in Kistan 2.0.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        Pages["Pages"]
        click Pages "https://github.com/insektionen/control-app/tree/master/pages/"
        Pages --> HomePage["Home Page"]
        click HomePage "https://github.com/insektionen/control-app/blob/master/pages/index.tsx"
        Pages --> HelpPage["Help Page"]
        click HelpPage "https://github.com/insektionen/control-app/blob/master/pages/help.tsx"
        Pages --> CollectionsView["Collections Views"]
        click CollectionsView "https://github.com/insektionen/control-app/tree/master/pages/collections/"
        Pages --> AppEntry["App Entry"]
        click AppEntry "https://github.com/insektionen/control-app/blob/master/pages/_app.tsx"

        Components["Components"]
        Components --> Layout["Layout Component"]
        click Layout "https://github.com/insektionen/control-app/blob/master/components/Layout/Layout.tsx"
        Components --> ActionBtn["Action Button"]
        click ActionBtn "https://github.com/insektionen/control-app/blob/master/components/ActionButton/ActionButton.tsx"
        Components --> EditPile["Edit Pile"]
        click EditPile "https://github.com/insektionen/control-app/blob/master/components/EditPile/EditPile.tsx"
        Components --> CollectionList["Collection List"]
        click CollectionList "https://github.com/insektionen/control-app/blob/master/components/List/CollectionListItem.tsx"
    end

    subgraph APILayer
        APIRoutes["API Routes"]
        click APIRoutes "https://github.com/insektionen/control-app/tree/master/pages/api/"
        APIRoutes --> CollectionAPI["Collection API"]
        click CollectionAPI "https://github.com/insektionen/control-app/blob/master/pages/api/[id].ts"
        APIRoutes --> MainAPI["Main API"]
        click MainAPI "https://github.com/insektionen/control-app/blob/master/pages/api/index.ts"
        
        APIClient["API Client"]
        click APIClient "https://github.com/insektionen/control-app/blob/master/util/client.ts"
    end

    subgraph Infrastructure
        Database["MongoDB"]
        click Database "https://github.com/insektionen/control-app/blob/master/mongo-init.js"
        DBUtils["Database Utilities"]
        click DBUtils "https://github.com/insektionen/control-app/blob/master/util/db.ts"
        LightSystem["Light System Interface"]
        SoundSystem["Sound System Interface"]
        
        Docker["Docker Config"]
        click Docker "https://github.com/insektionen/control-app/blob/master/docker-compose.yml"
        Dockerfile["Dockerfile"]
        click Dockerfile "https://github.com/insektionen/control-app/tree/master/Dockerfile"
        EnvConfig["Environment Config"]
        click EnvConfig "https://github.com/insektionen/control-app/blob/master/.env.development"
    end

    subgraph DevTools
        Storybook["Storybook"]
        click Storybook "https://github.com/insektionen/control-app/blob/master/.storybook/main.js"
        Jest["Jest"]
        click Jest "https://github.com/insektionen/control-app/blob/master/jest.config.js"
        TypeScript["TypeScript"]
        click TypeScript "https://github.com/insektionen/control-app/blob/master/tsconfig.json"
        Types["Type Definitions"]
        click Types "https://github.com/insektionen/control-app/blob/master/types/types.ts"
        CICD["CI/CD Workflow"]
        click CICD "https://github.com/insektionen/control-app/blob/master/.github/workflows/build-and-deploy.yml"
    end

    %% Relationships
    Pages --> APIClient
    Components --> APIClient
    APIClient --> APIRoutes
    APIRoutes --> DBUtils
    DBUtils --> Database
    APIRoutes --> LightSystem
    APIRoutes --> SoundSystem

    %% Styling
    classDef frontend fill:#a8d1ff
    classDef api fill:#90EE90
    classDef database fill:#FFD700
    classDef external fill:#FFB6C1
    classDef devtools fill:#DDA0DD

    class Pages,Components,HomePage,HelpPage,CollectionsView,AppEntry,Layout,ActionBtn,EditPile,CollectionList frontend
    class APIRoutes,APIClient,CollectionAPI,MainAPI api
    class Database,DBUtils database
    class LightSystem,SoundSystem external
    class Storybook,Jest,TypeScript,Types,CICD,Docker,Dockerfile,EnvConfig devtools
```
