# anvidev/nit architecture

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

- Interactive diagram: https://gitdiagram.com/anvidev/nit
- Repository: https://github.com/anvidev/nit

## Overview

##### Main Components Identification

The project appears to be a modern web application following a clean architecture pattern. Here's how to represent the key components:

A. Frontend Layer:
- Template Engine (Templ) components in `/internal/view`
- Static assets (CSS/JS) with Tailwind CSS
- HTMX for dynamic interactions

B. Application Layer:
- HTTP handlers and routing (`/internal/application`)
- Middleware components
- Request/Response handling

C. Service Layer:
- Business logic (`/internal/service`)
- User and Project services

D. Storage Layer:
- Database operations (`/internal/store/database.go`)
- S3 storage integration (`/internal/store/s3.go`)

**┌─────────────────────────────────────────────────────────┐**
- Client Browser                       │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Frontend Layer                         │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────┐     │
- Templ Views │  │ Tailwind CSS│  │    HTMX     │     │
- ┘  └─────────────┘  └─────────────┘     │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Application Layer                      │
- ┌─────────────┐  ┌─────────────┐  ┌─────────────┐     │
- Routes    │  │  Handlers   │  │ Middleware  │     │
- ┘  └─────────────┘  └─────────────┘     │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Service Layer                         │
- ┌─────────────┐            ┌─────────────┐            │
- User Service │            │Project Service│           │
- ┘            └─────────────┘            │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────┐**
- Storage Layer                         │
- ┌─────────────┐            ┌─────────────┐            │
- Database   │            │     S3      │            │
- ┘            └─────────────┘            │
- ┘

##### Important Details

A. Technology Stack Callouts:
- Chi (HTTP router)
- Templ (Template engine)
- Tailwind CSS (Styling)
- HTMX (Frontend interactivity)
- PostgreSQL (implied by migrations)
- S3 (File storage)

B. Data Flow Indicators:
- HTTP request/response flow
- File upload paths to S3
- Database query paths

##### Key Interactions to Highlight

- User authentication flow
- Project creation and management
- Static asset serving
- File upload handling to S3
- Database operations

Remember to include notes about the development workflow, especially regarding the use of Docker Compose for local development and the required CLI tools (air, templ, tailwindcss).

This architecture follows a clean, layered approach with clear separation of concerns, making it easy to maintain and extend the application as needed.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph FrontendLayer["Frontend Layer"]
        Templates["Templ Views"]:::frontend
        StaticAssets["Static Assets"]:::frontend
        Layout["Layout Components"]:::frontend
        ProjectViews["Project Views"]:::frontend
        UIComponents["UI Components"]:::frontend
        HTMX["HTMX"]:::frontend
        TailwindCSS["Tailwind CSS"]:::frontend
    end

    subgraph ApplicationLayer["Application Layer"]
        MainHandler["Main Handler"]:::application
        Routes["Routes"]:::application
        Middleware["Middleware"]:::application
        AppCore["Application Core"]:::application
    end

    subgraph ServiceLayer["Service Layer"]
        ServiceCore["Service Core"]:::service
        UserService["User Service"]:::service
        ProjectService["Project Service"]:::service
    end

    subgraph StorageLayer["Storage Layer"]
        Database[(Database)]:::storage
        S3[("S3 Storage")]:::storage
    end

    subgraph Config["Configuration"]
        AppConfig["Config"]:::config
        Migrations["Database Migrations"]:::config
        EntryPoint["Application Entry"]:::config
    end

    %% Relationships
    Browser <--> FrontendLayer
    FrontendLayer <--> ApplicationLayer
    ApplicationLayer <--> ServiceLayer
    ServiceLayer <--> StorageLayer

    %% Click events
    click Templates "https://github.com/anvidev/nit/tree/main/internal/view/"
    click StaticAssets "https://github.com/anvidev/nit/tree/main/static/"
    click Layout "https://github.com/anvidev/nit/tree/main/internal/view/layout/"
    click ProjectViews "https://github.com/anvidev/nit/tree/main/internal/view/projects/"
    click UIComponents "https://github.com/anvidev/nit/tree/main/internal/view/ui/"
    click MainHandler "https://github.com/anvidev/nit/blob/main/internal/application/handler.go"
    click Routes "https://github.com/anvidev/nit/blob/main/internal/application/routes.go"
    click Middleware "https://github.com/anvidev/nit/blob/main/internal/application/middleware.go"
    click AppCore "https://github.com/anvidev/nit/blob/main/internal/application/application.go"
    click UserService "https://github.com/anvidev/nit/blob/main/internal/service/user_service.go"
    click ProjectService "https://github.com/anvidev/nit/blob/main/internal/service/project_service.go"
    click ServiceCore "https://github.com/anvidev/nit/blob/main/internal/service/service.go"
    click Database "https://github.com/anvidev/nit/blob/main/internal/store/database.go"
    click S3 "https://github.com/anvidev/nit/blob/main/internal/store/s3.go"
    click AppConfig "https://github.com/anvidev/nit/blob/main/config/config.go"
    click Migrations "https://github.com/anvidev/nit/tree/main/migrations/"
    click EntryPoint "https://github.com/anvidev/nit/blob/main/cmd/main.go"

    %% Styling
    classDef frontend fill:#e1f5fe,stroke:#01579b
    classDef application fill:#e8f5e9,stroke:#1b5e20
    classDef service fill:#fff3e0,stroke:#e65100
    classDef storage fill:#f3e5f5,stroke:#4a148c
    classDef config fill:#fafafa,stroke:#424242

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        App["Application Component"]:::application
        Svc["Service Component"]:::service
        Store["Storage Component"]:::storage
        Cfg["Configuration Component"]:::config
    end
```
