There are a number of ways to identify the major mode for a file that don't rely on an extension, see Choosing File Modes in the manual.
Depending on the kinds of files you are dealing with, perhaps you could use the
magic-mode-alist. Also note that
auto-mode-alist is not limited to matching extensions: you can match any part of the file name or path.
If the files you are dealing with are not consistent enough for those mechanisms, one option is to add
auto-mode-alist entries that match the entire file name, or match the root path of some project and call a custom function to match names to modes.
If all the files in a given directory are of the same type you could also use a directory-local variable to set the mode. Directory variables can be set in your init file rather than in a .dir-locals file -- see Directory Variables for details.
Here's a quick attempt at managing your own alist of absolute file names and major-modes.
(defvar my-custom-mode-alist '())
(defvar my-custom-mode-alist-file (expand-file-name "custom-file-assoc" user-emacs-directory))
;; command to save the file->mode association of the current buffer
(defun save-file-mode-association ()
(add-to-list 'my-custom-mode-alist (cons buffer-file-name major-mode))
(defun write-custom-mode-alist (file)
(with-current-buffer (get-buffer-create " *Custom File Assocations*")
(delete-region (point-min) (point-max))
(pp my-custom-mode-alist (current-buffer))
(write-region (point-min) (point-max) file)
(file-error (message "Can't write %s" file)))
(message "Wrote custom file associations to file %s" file)))
(defun load-custom-mode-alist (file)
(when (file-exists-p file)
(let ((enable-local-variables nil))
(setq my-custom-mode-alist (read (current-buffer)))
(setq auto-mode-alist (append auto-mode-alist my-custom-mode-alist))
;; Load any custom file associations and add them to auto-mode-alist