# achyutem/notesforge architecture

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

- Interactive diagram: https://gitdiagram.com/achyutem/notesforge
- Repository: https://github.com/achyutem/notesforge

## Overview

##### Main Components
- Frontend (UI/Presentation Layer):
- The "app" directory includes pages (e.g., app/page.tsx, app/dashboard/page.tsx) and shared layout and global styles (app/layout.tsx, app/globals.css).
- UI elements and common components are split between app/(components) (e.g., authPage.tsx, editor.tsx, import.tsx, themeColor.tsx, todoSidebar.tsx) and additional reusable UI components provided under components/ui (such as alert.tsx, button.tsx, dropdown-menu.tsx, popover.tsx, select.tsx).

- API & Backend:
- The API endpoints under "app/api" manage business logic for authentication (login, logout, register), tasks (todos), and import/export functionalities.
- Utility functions (under app/utils) support authentication, logout logic, and theme handling.

- Database & Data Access:
- SQLite integration is evident from "app/lib/sqliteConnect.ts" and the database initialization scripts in "app/migrations/init-db.ts".

- Context & State Management:
- The "app/context" folder contains a themeProvider (themeProvider.tsx) to manage UI theming across the app.

- Infrastructure & Configuration:
- Files such as Dockerfile, next.config.ts, tailwind.config.ts, and tsconfig.json highlight the build configuration, styling, and deployment strategies.
- Docker-related files indicate containerization support for easy deployment.

##### Relationships and Interactions
- The Frontend is built using Next.js which serves pages and components. It interacts via the browser with both static content and dynamic API routes.
- API endpoints (e.g., authentication, todos) receive and process HTTP requests, perform operations (like database queries via SQLite), and return JSON responses.
- The SQLite database is interfaced through the SQLite connection utility and backed by migration scripts ensuring proper schema setup.
- Context providers (such as the themeProvider) are used on the client-side to maintain global state (like theming) across different UI components.
- Docker builds the entire application into a container, ensuring that the environment used for development (local) can seamlessly be deployed.

##### Highlights of Architectural Patterns
- Separation of Concerns: Clear separation between the UI layer (pages and components), API/business logic (under app/api), and data access/database (SQLite and migrations).
- Modular Structure: Organization of directory components (app/(components) vs. components/ui) and API routes enhances maintainability.
- Use of Next.js Routing: The file-based routing is evident in structured API endpoints.
- Containerization: Docker support for consistent and isolated environment deployment.

##### Relevant Technologies and Frameworks
- Next.js and React (with TypeScript) for frontend and API handling.
- SQLite as the lightweight database.
- Tailwind CSS for styling (evident from tailwind.config.ts and postcss.config.mjs).
- Docker for containerization, enhancing deployment capabilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser("Browser"):::browser

    subgraph "Frontend (UI/Presentation Layer)"
        subgraph "Pages & Layout"
            HomePage("Home Page"):::frontend
            DashboardPage("Dashboard Page"):::frontend
            Layout("Layout"):::frontend
            GlobalCSS("Global CSS"):::frontend
        end
        subgraph "Main UI Components"
            AuthComponent("Auth Page"):::frontend
            EditorComponent("Editor"):::frontend
            ImportComponent("Import"):::frontend
            ThemeColorComponent("Theme Color"):::frontend
            TodoSidebar("Todo Sidebar"):::frontend
        end
        subgraph "Reusable UI Components"
            AlertComponent("Alert"):::frontend
            ButtonComponent("Button"):::frontend
            DropdownMenu("Dropdown Menu"):::frontend
            PopoverComponent("Popover"):::frontend
            SelectComponent("Select"):::frontend
        end
    end

    subgraph "API & Backend"
        subgraph "Authentication API"
            APILogin("Login"):::api
            APILogout("Logout"):::api
            APIRegister("Register"):::api
        end
        subgraph "Other APIs"
            APIExport("Export"):::api
            APIImport("Import"):::api
            APITodos("Todos"):::api
        end
        subgraph "Utility Functions"
            UtilAuth("Auth Utility"):::api
            UtilLogout("Logout Utility"):::api
        end
    end

    subgraph "Database (SQLite)"
        SQLiteConnection("SQLite Connection"):::database
        DBMigration("DB Migration"):::database
    end

    subgraph "Context & State Management"
        ThemeProvider("Theme Provider"):::context
        ThemeColors("Theme Colors"):::context
        ThemeTypes("Theme Types"):::context
    end

    subgraph "Infrastructure & Configuration"
        Docker("Docker"):::infra
        NextConfig("Next Config"):::infra
        TailwindConfig("Tailwind Config"):::infra
        TSConfig("TS Config"):::infra
        PostCSSConfig("PostCSS Config"):::infra
        ESLintConfig("ESLint Config"):::infra
    end

    %% Connections between Layers
    Browser -->|"accesses"| HomePage
    Browser -->|"accesses"| DashboardPage

    AuthComponent -->|"calls_API"| APILogin
    EditorComponent -->|"fetches_todos"| APITodos
    TodoSidebar -->|"updates_tasks"| APITodos
    ImportComponent -->|"calls_API"| APIImport
    ThemeColorComponent -->|"provides_theme"| ThemeProvider

    APILogin -->|"uses"| UtilAuth
    APILogout -->|"uses"| UtilLogout

    APIExport -->|"queries_DB"| SQLiteConnection
    APIImport -->|"queries_DB"| SQLiteConnection
    APITodos -->|"queries_DB"| SQLiteConnection

    DBMigration -->|"initializes"| SQLiteConnection

    %% Docker encapsulates major components
    Docker --- HomePage
    Docker --- APILogin
    Docker --- SQLiteConnection
    Docker --- ThemeProvider

    Docker --- NextConfig
    Docker --- TailwindConfig
    Docker --- TSConfig
    Docker --- PostCSSConfig
    Docker --- ESLintConfig

    %% Styling
    classDef browser fill:#FCE5FF,stroke:#333,stroke-width:2px;
    classDef frontend fill:#B7E1CD,stroke:#333,stroke-width:2px;
    classDef api fill:#F4CCCC,stroke:#333,stroke-width:2px;
    classDef database fill:#C9DAF8,stroke:#333,stroke-width:2px;
    classDef context fill:#FFF2CC,stroke:#333,stroke-width:2px;
    classDef infra fill:#D9EAD3,stroke:#333,stroke-width:2px;

click HomePage "https://github.com/achyutem/notesforge/blob/main/app/page.tsx"
click DashboardPage "https://github.com/achyutem/notesforge/blob/main/app/dashboard/page.tsx"
click Layout "https://github.com/achyutem/notesforge/blob/main/app/layout.tsx"
click GlobalCSS "https://github.com/achyutem/notesforge/blob/main/app/globals.css"
click AuthComponent "https://github.com/achyutem/notesforge/blob/main/app/(components)/authPage.tsx"
click EditorComponent "https://github.com/achyutem/notesforge/blob/main/app/(components)/editor.tsx"
click ImportComponent "https://github.com/achyutem/notesforge/blob/main/app/(components)/import.tsx"
click ThemeColorComponent "https://github.com/achyutem/notesforge/blob/main/app/(components)/themeColor.tsx"
click TodoSidebar "https://github.com/achyutem/notesforge/blob/main/app/(components)/todoSidebar.tsx"
click AlertComponent "https://github.com/achyutem/notesforge/blob/main/components/ui/alert.tsx"
click ButtonComponent "https://github.com/achyutem/notesforge/blob/main/components/ui/button.tsx"
click DropdownMenu "https://github.com/achyutem/notesforge/blob/main/components/ui/dropdown-menu.tsx"
click PopoverComponent "https://github.com/achyutem/notesforge/blob/main/components/ui/popover.tsx"
click SelectComponent "https://github.com/achyutem/notesforge/blob/main/components/ui/select.tsx"
click APILogin "https://github.com/achyutem/notesforge/blob/main/app/api/auth/login/route.ts"
click APILogout "https://github.com/achyutem/notesforge/blob/main/app/api/auth/logout/route.ts"
click APIRegister "https://github.com/achyutem/notesforge/blob/main/app/api/auth/register/route.ts"
click APIExport "https://github.com/achyutem/notesforge/blob/main/app/api/export/route.ts"
click APIImport "https://github.com/achyutem/notesforge/blob/main/app/api/import/route.ts"
click APITodos "https://github.com/achyutem/notesforge/blob/main/app/api/todos/route.ts"
click UtilAuth "https://github.com/achyutem/notesforge/blob/main/app/utils/auth.ts"
click UtilLogout "https://github.com/achyutem/notesforge/blob/main/app/utils/logout.ts"
click SQLiteConnection "https://github.com/achyutem/notesforge/blob/main/app/lib/sqliteConnect.ts"
click DBMigration "https://github.com/achyutem/notesforge/blob/main/app/migrations/init-db.ts"
click ThemeProvider "https://github.com/achyutem/notesforge/blob/main/app/context/themeProvider.tsx"
click ThemeColors "https://github.com/achyutem/notesforge/blob/main/app/utils/themeColors.ts"
click ThemeTypes "https://github.com/achyutem/notesforge/blob/main/app/utils/themeTypes.ts"
click Docker "https://github.com/achyutem/notesforge/tree/main/Dockerfile"
click NextConfig "https://github.com/achyutem/notesforge/blob/main/next.config.ts"
click TailwindConfig "https://github.com/achyutem/notesforge/blob/main/tailwind.config.ts"
click TSConfig "https://github.com/achyutem/notesforge/blob/main/tsconfig.json"
click PostCSSConfig "https://github.com/achyutem/notesforge/blob/main/postcss.config.mjs"
click ESLintConfig "https://github.com/achyutem/notesforge/blob/main/eslint.config.mjs"
```
