# elyseemb/momoapi architecture

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

- Interactive diagram: https://gitdiagram.com/elyseemb/momoapi
- Repository: https://github.com/elyseemb/momoapi

## Overview

##### Project type and purpose
- This is a full-stack, server-rendered web application built on AdonisJS (a Node.js MVC framework) with server-side rendered Edge templates and a Vite-powered asset pipeline.
- The README confirms typical AdonisJS setup: routing, controllers, models, migrations, and asset building via Vite.

##### File structure
- Top-level directories:
- app/           → MVC: controllers, models, exceptions, middleware
- start/         → bootstrapping (env, kernel, routes)
- config/        → framework/service configuration (database, auth, bodyparser, session, static, logger, etc.)
- database/      → migrations
- resources/     → frontend assets (CSS, JS) and Edge view templates
- bin/           → CLI entry points (console, server, tests)
- tests/         → automated tests setup
- Config files (tsconfig.json, eslint.config.js, vite.config.ts) and env management (.env.example) reveal development and build processes.

##### README for additional insights

a. Main components
- Client (Browser)
- Vite Dev Server (in dev mode) / Static Asset Server (in prod)
- AdonisJS HTTP Server
- Edge Templating Engine
- AdonisJS Middleware Pipeline
- Controllers (e.g., HomeController, MomoApiCreatesController)
- Lucid ORM & Models (e.g., User)
- Database (e.g., PostgreSQL/MySQL)
- External Services (e.g., Momo API)
- CLI (node ace commands for migrations, key gen)
b. Relationships and data flow
1. Browser → HTTP Server (requests for pages, API endpoints, static assets)
2. HTTP Server → Middleware chain (auth, guest, container_bindings, silent_auth, body-parser, session, static)
3. Middleware → Routes (start/routes.ts) → Controller logic
4. Controller → Models (Lucid ORM) → Database
5. Controller may call External Services (Momo API)
6. Controller → Edge Engine → Render view → HTTP Response → Browser
7. For CSS/JS changes: Vite bundler watches resources/js & resources/css, rebuilds, serves via dev server or outputs to public directory for static serving
c. Architectural patterns and design principles
- MVC (Model-View-Controller) with clear separation
- Middleware chain for cross-cutting concerns
- Dependency injection via IoC container (container_bindings middleware)
- Configuration-driven services (config/*.ts)
- Asset pipeline separated from backend logic (resources + Vite)
d. Technologies and frameworks
- Node.js + AdonisJS
- TypeScript
- Edge templating engine
- Lucid ORM
- Vite for frontend assets
- Database (configured in config/database.ts)
- ESLint, pnpm (lockfile), dotenv

##### Detailed breakdown to capture essential architectural elements
- CLI (ace) as a lateral component that interacts with the application lifecycle (migrations, key generation, testing).
- Where tests (tests/bootstrap.ts) integrate with the application via the testing harness.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["Browser"]:::frontend
        ViteDev["Vite Dev Server"]:::frontend
        StaticAssets["Static Asset Server"]:::frontend
    end

    %% Backend Core
    subgraph "AdonisJS Server" 
        direction TB
        ACE["AdonisJS HTTP Server\n(ace.js)"]:::backend
        Configs["Configuration\n(adonisrc.ts)"]:::backend
        subgraph "Bootstrapping"
            direction TB
            Env["Environment Bootstrapping"]:::backend
            Kernel["Middleware Kernel Setup"]:::backend
            Routes["Route Definitions"]:::backend
        end
        subgraph "Middleware Pipeline"
            direction TB
            Auth["Authentication"]:::backend
            Guest["Guest Guard"]:::backend
            SilentAuth["Silent Auth"]:::backend
            ContainerBindings["IoC Container Bindings"]:::backend
            BodyParser["Body Parsing"]:::backend
            Session["Session Management"]:::backend
            StaticServe["Static File Serving"]:::backend
        end
        subgraph "MVC Layer"
            direction TB
            Controllers["Controllers\n(e.g., MomoApiCreatesController)"]:::backend
            EdgeEngine["Edge Templating Engine"]:::backend
            ORM["Lucid ORM"]:::backend
        end
        Exceptions["Exception Handler"]:::backend
    end

    %% Data Stores & External
    subgraph "Data & Services"
        direction TB
        DB["Database"]:::datastore
        Momo["Momo API"]:::external
    end

    %% CLI Tools
    subgraph "CLI Tools"
        direction TB
        ServeCLI["Server Startup CLI\n(bin/server.ts)"]:::cli
        ConsoleCLI["Console CLI\n(bin/console.ts)"]:::cli
        TestCLI["Test CLI\n(bin/test.ts)"]:::cli
        TestBoot["Testing Bootstrap\n(tests/bootstrap.ts)"]:::cli
    end

    %% Assets & Views
    CSS["CSS Source\n(resources/css/app.css)"]:::frontend
    JS["JS Source\n(resources/js/app.js)"]:::frontend
    Views["Edge Views\n(resources/views/)"]:::frontend

    %% Config Files
    subgraph "Config Files"
        direction TB
        AppConfig["app.ts"]:::backend
        AuthConfig["auth.ts"]:::backend
        BodyParserConfig["bodyparser.ts"]:::backend
        DatabaseConfig["database.ts"]:::backend
        SessionConfig["session.ts"]:::backend
        StaticConfig["static.ts"]:::backend
        ViteConfig1["vite.config.ts"]:::frontend
        ViteConfig2["config/vite.ts"]:::frontend
        LoggerConfig["logger.ts"]:::backend
        ShieldConfig["shield.ts"]:::backend
        HashConfig["hash.ts"]:::backend
    end

    %% Asset Pipeline
    CSS -->|"import"| ViteDev
    JS -->|"import"| ViteDev
    ViteDev -->|"serves assets"| Browser
    ServeCLI -->|starts| ACE
    Browser -->|GET /assets| StaticAssets
    Browser -->|HTTP Requests| ACE
    ACE -->|bootstrap| Env
    ACE -->|load kernel| Kernel
    Kernel --> Auth
    Auth --> Guest
    Guest --> SilentAuth
    SilentAuth --> ContainerBindings
    ContainerBindings --> BodyParser
    BodyParser --> Session
    Session --> StaticServe
    StaticServe --> Routes
    Env --> Routes
    Routes --> Controllers
    Controllers --> ORM
    ORM -->|SQL Queries| DB
    Controllers -->|HTTP POST to Momo API| Momo
    Controllers --> EdgeEngine
    EdgeEngine -->|Render HTML| Browser
    ACE --> Exceptions
    ConsoleCLI --> ACE
    TestCLI --> ACE
    TestCLI --> TestBoot

    %% Click Events
    click ACE "https://github.com/elyseemb/momoapi/blob/main/ace.js"
    click ServeCLI "https://github.com/elyseemb/momoapi/blob/main/bin/server.ts"
    click ConsoleCLI "https://github.com/elyseemb/momoapi/blob/main/bin/console.ts"
    click TestCLI "https://github.com/elyseemb/momoapi/blob/main/bin/test.ts"
    click TestBoot "https://github.com/elyseemb/momoapi/blob/main/tests/bootstrap.ts"
    click Configs "https://github.com/elyseemb/momoapi/blob/main/adonisrc.ts"
    click Env "https://github.com/elyseemb/momoapi/blob/main/start/env.ts"
    click Kernel "https://github.com/elyseemb/momoapi/blob/main/start/kernel.ts"
    click Routes "https://github.com/elyseemb/momoapi/blob/main/start/routes.ts"
    click Controllers "https://github.com/elyseemb/momoapi/blob/main/app/controllers/momo_api_creates_controller.ts"
    click Exceptions "https://github.com/elyseemb/momoapi/blob/main/app/exceptions/handler.ts"
    click Auth "https://github.com/elyseemb/momoapi/blob/main/app/middleware/auth_middleware.ts"
    click Guest "https://github.com/elyseemb/momoapi/blob/main/app/middleware/guest_middleware.ts"
    click SilentAuth "https://github.com/elyseemb/momoapi/blob/main/app/middleware/silent_auth_middleware.ts"
    click ContainerBindings "https://github.com/elyseemb/momoapi/blob/main/app/middleware/container_bindings_middleware.ts"
    click ORM "https://github.com/elyseemb/momoapi/blob/main/app/models/user.ts"
    click DB "https://github.com/elyseemb/momoapi/blob/main/database/migrations/1734271416367_create_users_table.ts"
    click Views "https://github.com/elyseemb/momoapi/tree/main/resources/views/"
    click CSS "https://github.com/elyseemb/momoapi/blob/main/resources/css/app.css"
    click JS "https://github.com/elyseemb/momoapi/blob/main/resources/js/app.js"
    click ViteConfig1 "https://github.com/elyseemb/momoapi/blob/main/vite.config.ts"
    click ViteConfig2 "https://github.com/elyseemb/momoapi/blob/main/config/vite.ts"
    click StaticServe "https://github.com/elyseemb/momoapi/blob/main/config/static.ts"
    click BodyParserConfig "https://github.com/elyseemb/momoapi/blob/main/config/bodyparser.ts"
    click SessionConfig "https://github.com/elyseemb/momoapi/blob/main/config/session.ts"
    click AuthConfig "https://github.com/elyseemb/momoapi/blob/main/config/auth.ts"
    click DatabaseConfig "https://github.com/elyseemb/momoapi/blob/main/config/database.ts"
    click LoggerConfig "https://github.com/elyseemb/momoapi/blob/main/config/logger.ts"
    click AppConfig "https://github.com/elyseemb/momoapi/blob/main/config/app.ts"
    click ShieldConfig "https://github.com/elyseemb/momoapi/blob/main/config/shield.ts"
    click HashConfig "https://github.com/elyseemb/momoapi/blob/main/config/hash.ts"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000;
    classDef backend fill:#90EE90,stroke:#000;
    classDef datastore fill:#FFD580,stroke:#000;
    classDef external fill:#FFB6C1,stroke:#000;
    classDef cli fill:#EEEEAA,stroke:#000;
```
