# htooaungphyolwin/adonisjs-blog architecture

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

- Interactive diagram: https://gitdiagram.com/htooaungphyolwin/adonisjs-blog
- Repository: https://github.com/htooaungphyolwin/adonisjs-blog

## Overview

##### Project type and purpose
- This is a full-stack Content Management System (CMS) built on AdonisJS (Node.js framework) with a server-side rendered frontend using the Edge template engine.
- The README describes core features: user authentication, posts, comments, likes, view tracking, and a modern UI built with Tailwind CSS/Flowbite and Vite.

##### File structure
- Top-level directories:
- app/ — Contains MVC elements: controllers, models, middleware, validators
- config/ — Application configuration (database, auth, bodyparser, sessions…)
- database/ — Migration scripts for SQLite tables
- resources/ — Static assets (css/js) and Edge view templates
- start/ — Bootstrap files: routes, kernel (middleware registration), view config
- public/ — Publicly hosted assets (images, compiled files)
- bin/ — Entry points for console commands, server start, tests
- tests/ — Automated test setup
- Patterns:
- MVC: controllers (handle requests), models (ORM Lucid), views (Edge)
- Middleware pipeline for auth/guest checks
- Database migrations define schema

##### README for additional insights
- Confirms use of AdonisJS 6, SQLite default, Edge templating, Vite dev server.
- No external microservices; it’s a monolithic server that renders pages and serves an API for client-side interactions.

a. Main components
1. Client Browser
- Sends HTTP requests, runs frontend JS/CSS (Vite-built assets)
2. AdonisJS Server
- HTTP server listening on port 3333
- Routes (start/routes.ts) → Middleware → Controllers
- Controllers invoke Models (Lucid ORM)
- Uses Edge to render HTML or returns JSON for AJAX
3. SQLite Database
- Persists users, posts, comments, likes, view_counts
4. Static Asset Pipeline
- Vite development server or built assets served from public/
5. Optional: Console & Test Runners
- bin/console.ts for CLI commands (e.g., migrations)
- bin/test.ts invokes test suite

b. Relationships & interactions
- Client → HTTP Request → Server Route
- Server Route → Middleware (auth_middleware, etc.) → Controller
- Controller → Model (Lucid) → Database
- Controller → Render Edge View or JSON Response → Client
- Client static asset requests → public/ folder or Vite dev server

c. Architectural patterns & design principles
- MVC separation: clear division of concerns
- Middleware pipeline for cross-cutting concerns (authentication, binding)
- RESTful resource controllers (posts, comments, user_profile)
- Config-driven environment (config/ files, .env)
- Monolithic deployment: single process handles web, API, CLI

d. Key technologies & libraries
- AdonisJS 6 core (HTTP server, Lucid ORM, Edge)
- SQLite (via Lucid)
- Tailwind CSS, Flowbite for styling
- Vite for asset bundling

##### Detailed breakdown to capture essential elements
- Routes (start/routes.ts)
- Middleware Layer
- Controllers (list key controllers: auth, posts, comments, profile)
- Validators
- Exception Handler
- Lucid ORM
- “bin/console” and “tests” as side utilities

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Browser" 
        direction TB
        VITE["Vite Dev Server"]:::frontend
        ASSETS["Static Assets\n(resources/js/app.js,\nresources/css/app.css)"]:::frontend
        PUBLIC["Compiled Assets\n(public/)"]:::frontend
        EDGE_HTML["Edge-rendered HTML"]:::frontend
    end

    %% Server Layer
    subgraph "AdonisJS Server" 
        direction TB
        SERVER["HTTP Server\n(bin/server.ts)"]:::backend
        CONFIG["Configuration"]:::config
        ROUTES["Routes\n(start/routes.ts)"]:::backend
        MIDDLEWARE["Middleware Layer"]:::backend
        CONTROLLERS["Controllers"]:::backend
        VALIDATORS["Validators"]:::backend
        EXCEPTIONS["Exception Handler\n(app/exceptions/handler.ts)"]:::backend
        ORM["Lucid ORM"]:::backend
        VIEW["Edge Engine\n(start/view.ts)"]:::backend
    end

    %% Database Layer
    subgraph "Database"
        direction TB
        DB["SQLite DB\n(tmp/db.sqlite3)"]:::database
    end

    %% Utility Layer
    subgraph "Utilities"
        direction TB
        CONSOLE["Console Runner\n(bin/console.ts)"]:::utility
        TESTS["Test Suite\n(tests/)"]:::utility
    end

    %% Config Files
    subgraph "Config Files"
        direction TB
        APP_CFG["app.ts"]:::config
        AUTH_CFG["auth.ts"]:::config
        DB_CFG["database.ts"]:::config
        BODY_CFG["bodyparser.ts"]:::config
        SESSION_CFG["session.ts"]:::config
        STATIC_CFG["static.ts"]:::config
        VITE_CFG["vite.ts"]:::config
    end

    %% Relationships
    VITE -->|serves assets| PUBLIC
    VITE -->|provides assets| ASSETS
    ASSETS -->|loaded by| EDGE_HTML
    VITE -->|hot reload| EDGE_HTML
    EDGE_HTML -->|renders in browser| VITE

    VITE -->|builds| ASSETS

    EDGE_HTML -->|HTTP requests| SERVER
    PUBLIC -->|HTTP requests| SERVER

    SERVER -->|reads| CONFIG
    SERVER -->|routes through| ROUTES
    ROUTES -->|passes through| MIDDLEWARE
    MIDDLEWARE -->|invokes| CONTROLLERS
    CONTROLLERS -->|uses| VALIDATORS
    CONTROLLERS -->|queries| ORM
    ORM -->|performs SQL| DB
    CONTROLLERS -->|renders| VIEW
    VIEW -->|returns HTML/JSON| EDGE_HTML

    SERVER -->|CLI commands| CONSOLE
    SERVER -->|runs tests| TESTS

    CONFIG -->|includes| APP_CFG
    CONFIG -->|includes| AUTH_CFG
    CONFIG -->|includes| DB_CFG
    CONFIG -->|includes| BODY_CFG
    CONFIG -->|includes| SESSION_CFG
    CONFIG -->|includes| STATIC_CFG
    CONFIG -->|includes| VITE_CFG

    %% Click Events
    click VITE "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/vite.config.ts"
    click ASSETS "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/resources/js/app.js"
    click ASSETS "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/resources/css/app.css"
    click PUBLIC "https://github.com/htooaungphyolwin/adonisjs-blog/tree/main/public/"
    click SERVER "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/bin/server.ts"
    click CONSOLE "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/bin/console.ts"
    click TESTS "https://github.com/htooaungphyolwin/adonisjs-blog/tree/main/tests/"
    click APP_CFG "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/config/app.ts"
    click AUTH_CFG "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/config/auth.ts"
    click DB_CFG "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/config/database.ts"
    click BODY_CFG "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/config/bodyparser.ts"
    click SESSION_CFG "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/config/session.ts"
    click STATIC_CFG "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/config/static.ts"
    click VITE_CFG "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/config/vite.ts"
    click ROUTES "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/start/routes.ts"
    click EXCEPTIONS "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/exceptions/handler.ts"
    click MIDDLEWARE "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/middleware/auth_middleware.ts"
    click MIDDLEWARE "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/middleware/guest_middleware.ts"
    click MIDDLEWARE "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/middleware/silent_auth_middleware.ts"
    click MIDDLEWARE "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/middleware/container_bindings_middleware.ts"
    click CONTROLLERS "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/controllers/auth_controller.ts"
    click CONTROLLERS "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/controllers/register_controller.ts"
    click CONTROLLERS "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/controllers/posts_controller.ts"
    click CONTROLLERS "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/controllers/comments_controller.ts"
    click CONTROLLERS "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/controllers/post_likes_controller.ts"
    click CONTROLLERS "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/controllers/view_counts_controller.ts"
    click CONTROLLERS "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/controllers/user_profile_controller.ts"
    click VALIDATORS "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/validators/register.ts"
    click VALIDATORS "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/validators/post.ts"
    click ORM "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/models/user.ts"
    click ORM "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/models/post.ts"
    click ORM "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/models/comment.ts"
    click ORM "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/app/models/view_count.ts"
    click VIEW "https://github.com/htooaungphyolwin/adonisjs-blog/blob/main/start/view.ts"

    %% Styles
    classDef frontend fill:#90cdf4,stroke:#3182ce,color:#1a365d
    classDef backend fill:#9ae6b4,stroke:#2f855a,color:#22543d
    classDef database fill:#fbd38d,stroke:#dd6b20,color:#975a16
    classDef utility fill:#cbd5e0,stroke:#4a5568,color:#2d3748
    classDef config fill:#d6bcfa,stroke:#6b46c1,color:#4c1d95
```
