Afunana
Afunana Documentation

System Architecture

Components, data flow, storage layout, network topology, and scalability.

← Back to Docs

High-Level Architecture

+------------------+     +------------------+     +------------------+
|                  |     |                  |     |                  |
|   IBM i / AS400  |<--->|   Afunana App    |<--->|   SQL Server     |
|   (Source System)|     |   (Docker)       |     |   (Docker)       |
|                  |     |                  |     |                  |
+------------------+     +--------+---------+     +------------------+
                                  |
                         +--------+---------+
                         |                  |
                         |   Caddy Proxy    |
                         |   (HTTPS/TLS)    |
                         |                  |
                         +--------+---------+
                                  |
                    +-------------+-------------+
                    |                           |
              +-----+------+            +------+------+
              |            |            |             |
              |  Browser   |            |  VS Code    |
              |  (React)   |            |  Extension  |
              |            |            |             |
              +------------+            +-------------+

Components

1. Frontend (React SPA)

Key pages: Programs, Files, Tree, System Overview, Data Dictionary, Cross Reference, Chat, Tools, Admin (12+ sub-pages).

2. Backend (FastAPI)

3. Database (SQL Server 2022)

4. Caddy (Reverse Proxy)

5. IBM i Connector

Data Flow

Source Extraction Flow

IBM i -> TTDOCPGM1 batch job -> IFS output files -> FTP download -> Data/{collection}/

Extracted files:

Build Pipeline Flow

CSV files -> Parse -> LLM Analysis (batched) -> JSON output -> Embeddings -> Search indices

Stages:

  1. Parse — CSV to structured data (programs, files, relationships)
  2. Build Documents — LLM generates program JSON (purpose, IO, calls, files, errors)
  3. System Overview — LLM generates architecture analysis
  4. Embeddings — ChromaDB stores semantic vectors for RAG
  5. Auto-Tagging — Classify programs by business function

Request Flow

Browser -> Caddy (HTTPS) -> FastAPI -> Auth middleware -> Route handler -> Response
                                             |
                                        SQL Server (user/collection validation)
                                             |
                                        Data/{collection}/ (program JSON, source code)
                                             |
                                        LLM Provider (if chat or doc generation)

Data Storage

Per-Collection Directory

Data/{collection_name}/
|-- system_overview.json          # Architecture analysis
|-- output_program/               # One JSON per program (structured metadata)
|-- programs/                     # COBOL/RPG/CL source text
|-- programs_csv/                 # Call relationship data
|-- info-from-as400/              # Raw metadata CSVs from extraction
|-- chroma_store/                 # ChromaDB vector embeddings
|-- bm25_store/                   # BM25 full-text indices
|-- build_progress.json           # Live build status
+-- generated_docs/               # User-uploaded documentation

Database Tables

TablePurpose
AFUNANA_USERSUser accounts (username, email, password hash, role, status)
user_collectionsUser-to-collection access mapping
col_packsCollection metadata (name, language, status, AS/400 config)
app_configRuntime configuration (200+ keys, categorized)
security_event_logImmutable audit trail with hash chain
build_historyBuild status, timing, error tracking
chat_sessions / chat_messagesPersistent chat history
generated_spec_docsCached AI-generated specification documents
collection_tags / entity_tagsTag definitions and assignments
revoked_tokens / revoked_sessionsToken/session invalidation

Network Architecture

PortServiceAccess
443Caddy (HTTPS)Public
80Caddy (HTTP redirect)Public
8001FastAPIInternal (127.0.0.1 only)
1433SQL ServerInternal (container network)
8080Adminer (DB GUI)Internal (127.0.0.1 only)
9000Deploy ReceiverInternal (Docker bridge)

Scalability Considerations